1 | /**
|
---|
2 | * TreeStats.java
|
---|
3 | * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
|
---|
4 | *
|
---|
5 | * This program is free software: you can redistribute it and/or modify
|
---|
6 | * it under the terms of the GNU General Public License as published by
|
---|
7 | * the Free Software Foundation, either version 3 of the License, or
|
---|
8 | * (at your option) any later version.
|
---|
9 | *
|
---|
10 | * This program is distributed in the hope that it will be useful,
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
13 | * GNU General Public License for more details.
|
---|
14 | *
|
---|
15 | * You should have received a copy of the GNU General Public License
|
---|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
17 | */
|
---|
18 |
|
---|
19 | package org.expeditee.stats;
|
---|
20 |
|
---|
21 | import java.sql.Time;
|
---|
22 | import java.util.HashSet;
|
---|
23 | import java.util.Set;
|
---|
24 |
|
---|
25 | import org.expeditee.gui.Frame;
|
---|
26 | import org.expeditee.gui.FrameIO;
|
---|
27 | import org.expeditee.gui.MessageBay;
|
---|
28 | import org.expeditee.items.Item;
|
---|
29 |
|
---|
30 | public class TreeStats extends CometStats {
|
---|
31 | protected int _treeFrames = 0;
|
---|
32 |
|
---|
33 | protected int _treeSessions = 0;
|
---|
34 |
|
---|
35 | protected long _treeActive = 0;
|
---|
36 |
|
---|
37 | protected long _treeDark = 0;
|
---|
38 |
|
---|
39 | public TreeStats(Frame topFrame) {
|
---|
40 | this(topFrame, new HashSet<String>());
|
---|
41 | }
|
---|
42 |
|
---|
43 | public TreeStats(Frame topFrame, Set<String> visited) {
|
---|
44 | super(topFrame);
|
---|
45 | //TreeStats doesnt include the current session.
|
---|
46 | _active = topFrame.getActiveTime().getTime();
|
---|
47 | _dark = topFrame.getDarkTime().getTime();
|
---|
48 | _sessions -= 1;
|
---|
49 |
|
---|
50 | visited.add(_name.toLowerCase());
|
---|
51 | MessageBay.overwriteMessage("Computed: " + _name);
|
---|
52 |
|
---|
53 | // Initialise variables with the data for this frames comet
|
---|
54 | _treeActive = _active;
|
---|
55 | _treeDark = _dark;
|
---|
56 | _treeSessions = _sessions;
|
---|
57 | _treeFrames = 1;
|
---|
58 | // Now get all add all the trees for linked items
|
---|
59 | for (Item i : topFrame.getSortedItems()) {
|
---|
60 | String link = i.getAbsoluteLink();
|
---|
61 | if (link == null)
|
---|
62 | continue;
|
---|
63 | if (i.isAnnotation())
|
---|
64 | continue;
|
---|
65 | // Stop infinate loops by not visiting nodes we have already visited
|
---|
66 | if (visited.contains(link.toLowerCase())) {
|
---|
67 | continue;
|
---|
68 | }
|
---|
69 | Frame childFrame = FrameIO.LoadFrame(i.getAbsoluteLink());
|
---|
70 | if (childFrame == null)
|
---|
71 | continue;
|
---|
72 |
|
---|
73 | TreeStats childItemStats = new TreeStats(childFrame, visited);
|
---|
74 | _treeActive += childItemStats._treeActive;
|
---|
75 | _treeDark += childItemStats._treeDark;
|
---|
76 | _treeSessions += childItemStats._treeSessions;
|
---|
77 | _treeFrames += childItemStats._treeFrames;
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | @Override
|
---|
82 | public String toString() {
|
---|
83 | Time total = new Time(_treeActive + _treeDark);
|
---|
84 | Time active = new Time(_treeActive);
|
---|
85 | Time dark = new Time(_treeDark);
|
---|
86 |
|
---|
87 | StringBuffer sb = new StringBuffer();
|
---|
88 | sb.append(SessionStats.getDate());
|
---|
89 | sb.append("TreeStats: ").append(_name).append('\n');
|
---|
90 | sb.append("Frames: ").append(_treeFrames).append('\n');
|
---|
91 | sb.append("Versions: ").append(_treeSessions).append('\n');
|
---|
92 | sb.append(String.format(
|
---|
93 | " %cVersionAve%c FrameAve %c Total%n",
|
---|
94 | COLUMN_SEPARATOR_CHAR, COLUMN_SEPARATOR_CHAR,
|
---|
95 | COLUMN_SEPARATOR_CHAR));
|
---|
96 |
|
---|
97 | StringBuffer rowSeparator = new StringBuffer();
|
---|
98 | rowSeparator.append(getBufferedString(10, ROW_SEPARATOR_CHAR));
|
---|
99 | for (int i = 0; i < 3; i++) {
|
---|
100 | rowSeparator.append(ROW_COLUMN_SEPARATOR).append(
|
---|
101 | getBufferedString(8, ROW_SEPARATOR_CHAR));
|
---|
102 | }
|
---|
103 | sb.append(rowSeparator).append('\n');
|
---|
104 |
|
---|
105 | Time averageActive = new Time((long) (0.5 + active.getTime()
|
---|
106 | / (1.0 * _treeFrames)));
|
---|
107 | Time averageDark = new Time((long) (0.5 + dark.getTime()
|
---|
108 | / (1.0 * _treeFrames)));
|
---|
109 | Time averageTotal = new Time((long) (0.5 + total.getTime()
|
---|
110 | / (1.0 * _treeFrames)));
|
---|
111 | Time averageActiveEdit = new Time((long) (0.5 + active.getTime()
|
---|
112 | / (1.0 * _treeSessions)));
|
---|
113 | Time averageDarkEdit = new Time((long) (0.5 + dark.getTime()
|
---|
114 | / (1.0 * _treeSessions)));
|
---|
115 | Time averageTotalEdit = new Time((long) (0.5 + total.getTime()
|
---|
116 | / (1.0 * _treeSessions)));
|
---|
117 |
|
---|
118 | sb.append("ActiveTime").append(COLUMN_SEPARATOR).append(
|
---|
119 | Formatter.getTimePeriod(averageActiveEdit)).append(
|
---|
120 | COLUMN_SEPARATOR).append(Formatter.getTimePeriod(averageActive))
|
---|
121 | .append(COLUMN_SEPARATOR).append(Formatter.getTimePeriod(active))
|
---|
122 | .append('\n');
|
---|
123 | sb.append(" DarkTime").append(COLUMN_SEPARATOR).append(
|
---|
124 | Formatter.getTimePeriod(averageDarkEdit))
|
---|
125 | .append(COLUMN_SEPARATOR).append(
|
---|
126 | Formatter.getTimePeriod(averageDark)).append(
|
---|
127 | COLUMN_SEPARATOR).append(Formatter.getTimePeriod(dark))
|
---|
128 | .append('\n');
|
---|
129 | sb.append(" TotalTime").append(COLUMN_SEPARATOR).append(
|
---|
130 | Formatter.getTimePeriod(averageTotalEdit)).append(
|
---|
131 | COLUMN_SEPARATOR).append(Formatter.getTimePeriod(averageTotal))
|
---|
132 | .append(COLUMN_SEPARATOR).append(Formatter.getTimePeriod(total))
|
---|
133 | .append('\n');
|
---|
134 | sb.append(rowSeparator.toString().replace(ROW_COLUMN_SEPARATOR_CHAR,
|
---|
135 | BOTTOM_COLUMN_SEPARATOR_CHAR));
|
---|
136 |
|
---|
137 | return sb.toString();
|
---|
138 | }
|
---|
139 | }
|
---|