source: trunk/src/org/expeditee/stats/CometStats.java@ 1442

Last change on this file since 1442 was 919, checked in by jts21, 10 years ago

Added license headers to all files, added full GPL3 license file, moved license header generator script to dev/bin/scripts

File size: 3.5 KB
Line 
1/**
2 * CometStats.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
19package org.expeditee.stats;
20
21import java.sql.Time;
22
23import org.expeditee.gui.Frame;
24
25public class CometStats extends Stats{
26 protected int _sessions = 0;
27
28 protected String _name = null;
29 protected String _title = null;
30
31 protected long _active = 0;
32
33 protected long _dark = 0;
34
35 public CometStats(Frame topFrame) {
36 _name = topFrame.getName();
37 _title = topFrame.getTitle();
38
39 _active = getFrameActiveTime().getTime()
40 + topFrame.getActiveTime().getTime();
41 _dark = getFrameDarkTime().getTime()
42 + topFrame.getDarkTime().getTime();
43 _sessions = topFrame.getVersion() + 1;
44 }
45
46 @Override
47 public String toString() {
48 Time total = new Time(_active + _dark);
49 Time active = new Time(_active);
50 Time dark = new Time(_dark);
51
52 StringBuffer sb = new StringBuffer();
53 sb.append(SessionStats.getDate());
54 sb.append("CometStats: ").append(_name).append('\n');
55 sb.append("Versions: ").append(_sessions).append('\n');
56 sb.append(String.format(" %c Current %c Average %c Total", SessionStats.COLUMN_SEPARATOR_CHAR,SessionStats.COLUMN_SEPARATOR_CHAR,SessionStats.COLUMN_SEPARATOR_CHAR)).append('\n');
57
58
59 StringBuffer rowSeparator = new StringBuffer();
60 rowSeparator.append(getBufferedString(10, ROW_SEPARATOR_CHAR));
61 for(int i=0;i<3;i++){
62 rowSeparator.append(ROW_COLUMN_SEPARATOR).append(getBufferedString(8, ROW_SEPARATOR_CHAR));
63 }
64 sb.append(rowSeparator).append('\n');
65
66
67 Time averageActive = new Time((long) (0.5 + active.getTime()
68 / (1.0 * _sessions)));
69 Time averageDark = new Time((long) (0.5 + dark.getTime()
70 / (1.0 * _sessions)));
71 Time averageTotal = new Time((long) (0.5 + total.getTime()
72 / (1.0 * _sessions)));
73 Time currentActive = SessionStats.getFrameActiveTime();
74 Time currentDark = SessionStats.getFrameDarkTime();
75 Time currentTotal = SessionStats.getFrameTotalTime();
76
77 sb.append("ActiveTime").append(COLUMN_SEPARATOR).append(Formatter.getTimePeriod(currentActive))
78 .append(COLUMN_SEPARATOR).append(
79 Formatter.getTimePeriod(averageActive)).append(
80 COLUMN_SEPARATOR).append(Formatter.getTimePeriod(active))
81 .append('\n');
82 sb.append(" DarkTime").append(COLUMN_SEPARATOR).append(Formatter.getTimePeriod(currentDark))
83 .append(COLUMN_SEPARATOR).append(
84 Formatter.getTimePeriod(averageDark)).append(
85 COLUMN_SEPARATOR).append(Formatter.getTimePeriod(dark))
86 .append('\n');
87 sb.append(" TotalTime").append(COLUMN_SEPARATOR).append(Formatter.getTimePeriod(currentTotal))
88 .append(COLUMN_SEPARATOR).append(
89 Formatter.getTimePeriod(averageTotal)).append(
90 COLUMN_SEPARATOR).append(Formatter.getTimePeriod(total)).append('\n');
91 sb.append(rowSeparator.toString().replace(ROW_COLUMN_SEPARATOR_CHAR, BOTTOM_COLUMN_SEPARATOR_CHAR));
92 return sb.toString();
93 }
94}
Note: See TracBrowser for help on using the repository browser.