source: trunk/src/org/expeditee/stats/StatsLogger.java@ 1532

Last change on this file since 1532 was 1532, checked in by bnemhaus, 4 years ago

New feature: when creating a frameset, if the item being used is linked and you hold shift, it will use the items on the linked frame to populate the zero frame of the new frameset

File size: 3.6 KB
Line 
1/**
2 * StatsLogger.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.io.BufferedWriter;
22import java.io.File;
23import java.io.FileWriter;
24import java.io.IOException;
25import java.lang.reflect.Method;
26
27import org.expeditee.gui.Frame;
28import org.expeditee.gui.FrameIO;
29import org.expeditee.items.Text;
30import org.expeditee.settings.UserSettings;
31
32/**TODO make this threadsafe*/
33
34/**
35 * This class is used to create all stats log files. Files are created with
36 * filename: Date-Time.stat<br>
37 * Where Date is in the format DDMMMYYYY and Time is in the format HHMM.
38 *
39 * @author mrww1
40 *
41 */
42public class StatsLogger {
43
44 private static String _filename = null;
45
46 private static final String FRAMES_EDITED_FILENAME = "FramesEdited.log";
47
48 /**
49 * Sets the path on disk that the statlog files will be created in.
50 *
51 * @param location
52 * The path on disk to create the log files in.
53 */
54 private static void Init() {
55 if (!org.expeditee.settings.UserSettings.LogStats.get())
56 return;
57
58 File test = new File(org.expeditee.gui.FrameIO.STATISTICS_PATH);
59 if (!test.exists())
60 test.mkdir();
61
62 _filename = Formatter.getDateTime() + ".stat";
63 _filename = _filename.replace(":","_");
64 }
65
66 /**
67 * Writes the current stats to a file.
68 *
69 */
70 public static void WriteStatsFile() {
71 if (!org.expeditee.settings.UserSettings.LogStats.get())
72 return;
73
74 Init();
75
76 String statsFrameset = UserSettings.StatisticsFrameset.get();
77 if (statsFrameset != null) {
78 try {
79 Frame statsFrame = null;
80 if (FrameIO.LoadFrame(statsFrameset + "0") == null) {
81 statsFrame = FrameIO.CreateNewFrameset(statsFrameset, null);
82 statsFrame.setTitle(Formatter.getDateTime());
83 } else {
84 statsFrame = FrameIO.CreateFrame(statsFrameset, Formatter
85 .getDateTime(), null);
86 }
87
88 //Now check the attribute value pairs
89 for(Text t: statsFrame.getBodyTextItems(false)){
90 Method m = StatsFrame.getMethod(t.getText());
91 if(m != null){
92 String value = m.invoke(null, new Object[]{}).toString();
93 t.setText(t.getText() + ": " + value);
94 }
95 }
96 FrameIO.ForceSaveFrame(statsFrame);
97 } catch (Exception e) {
98 e.printStackTrace();
99 }
100 }
101
102 try {
103 BufferedWriter writer = new BufferedWriter(new FileWriter(
104 org.expeditee.gui.FrameIO.STATISTICS_PATH + _filename, true));
105
106 writer.write(SessionStats.getCurrentStats());
107 writer.newLine();
108 writer.newLine();
109 writer.write(SessionStats.getItemStats());
110 writer.newLine();
111 writer.newLine();
112 writer.write(SessionStats.getEventStats());
113 writer.newLine();
114
115 writer.flush();
116 writer.close();
117
118 writer = new BufferedWriter(new FileWriter(
119 org.expeditee.gui.FrameIO.STATISTICS_PATH
120 + FRAMES_EDITED_FILENAME, true));
121 writer.write(SessionStats.getFramesEdited());
122 writer.newLine();
123
124 writer.flush();
125 writer.close();
126 } catch (IOException ioe) {
127 ioe.printStackTrace();
128 }
129 }
130}
Note: See TracBrowser for help on using the repository browser.