[919] | 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 |
|
---|
[90] | 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;
|
---|
[121] | 27 | import org.expeditee.gui.MessageBay;
|
---|
[90] | 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 |
|
---|
[105] | 39 | public TreeStats(Frame topFrame) {
|
---|
| 40 | this(topFrame, new HashSet<String>());
|
---|
[90] | 41 | }
|
---|
| 42 |
|
---|
[105] | 43 | public TreeStats(Frame topFrame, Set<String> visited) {
|
---|
| 44 | super(topFrame);
|
---|
[414] | 45 | //TreeStats doesnt include the current session.
|
---|
| 46 | _active = topFrame.getActiveTime().getTime();
|
---|
| 47 | _dark = topFrame.getDarkTime().getTime();
|
---|
| 48 | _sessions -= 1;
|
---|
| 49 |
|
---|
[90] | 50 | visited.add(_name.toLowerCase());
|
---|
[121] | 51 | MessageBay.overwriteMessage("Computed: " + _name);
|
---|
[115] | 52 |
|
---|
[90] | 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
|
---|
[1415] | 59 | for (Item i : topFrame.getSortedItems()) {
|
---|
[90] | 60 | String link = i.getAbsoluteLink();
|
---|
[115] | 61 | if (link == null)
|
---|
[90] | 62 | continue;
|
---|
[115] | 63 | if (i.isAnnotation())
|
---|
[90] | 64 | continue;
|
---|
| 65 | // Stop infinate loops by not visiting nodes we have already visited
|
---|
[115] | 66 | if (visited.contains(link.toLowerCase())) {
|
---|
[90] | 67 | continue;
|
---|
| 68 | }
|
---|
[115] | 69 | Frame childFrame = FrameIO.LoadFrame(i.getAbsoluteLink());
|
---|
| 70 | if (childFrame == null)
|
---|
[90] | 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();
|
---|
[103] | 88 | sb.append(SessionStats.getDate());
|
---|
[105] | 89 | sb.append("TreeStats: ").append(_name).append('\n');
|
---|
[90] | 90 | sb.append("Frames: ").append(_treeFrames).append('\n');
|
---|
| 91 | sb.append("Versions: ").append(_treeSessions).append('\n');
|
---|
[115] | 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 |
|
---|
[90] | 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 |
|
---|
[115] | 118 | sb.append("ActiveTime").append(COLUMN_SEPARATOR).append(
|
---|
[419] | 119 | Formatter.getTimePeriod(averageActiveEdit)).append(
|
---|
| 120 | COLUMN_SEPARATOR).append(Formatter.getTimePeriod(averageActive))
|
---|
| 121 | .append(COLUMN_SEPARATOR).append(Formatter.getTimePeriod(active))
|
---|
[115] | 122 | .append('\n');
|
---|
| 123 | sb.append(" DarkTime").append(COLUMN_SEPARATOR).append(
|
---|
[419] | 124 | Formatter.getTimePeriod(averageDarkEdit))
|
---|
[115] | 125 | .append(COLUMN_SEPARATOR).append(
|
---|
[419] | 126 | Formatter.getTimePeriod(averageDark)).append(
|
---|
| 127 | COLUMN_SEPARATOR).append(Formatter.getTimePeriod(dark))
|
---|
[115] | 128 | .append('\n');
|
---|
| 129 | sb.append(" TotalTime").append(COLUMN_SEPARATOR).append(
|
---|
[419] | 130 | Formatter.getTimePeriod(averageTotalEdit)).append(
|
---|
| 131 | COLUMN_SEPARATOR).append(Formatter.getTimePeriod(averageTotal))
|
---|
| 132 | .append(COLUMN_SEPARATOR).append(Formatter.getTimePeriod(total))
|
---|
[115] | 133 | .append('\n');
|
---|
| 134 | sb.append(rowSeparator.toString().replace(ROW_COLUMN_SEPARATOR_CHAR,
|
---|
| 135 | BOTTOM_COLUMN_SEPARATOR_CHAR));
|
---|
[424] | 136 |
|
---|
[90] | 137 | return sb.toString();
|
---|
| 138 | }
|
---|
| 139 | }
|
---|