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

Last change on this file since 309 was 78, checked in by ra33, 16 years ago

Added @b and @v...
Also changed @f... so that images can be displayed with transparent backgrounds.
Did a bunch of refactoring in the process to remove duplicated code and simplify managing @i, @f and @b.

File size: 1.8 KB
Line 
1package org.expeditee.stats;
2
3import java.io.BufferedWriter;
4import java.io.File;
5import java.io.FileWriter;
6import java.io.IOException;
7
8import org.expeditee.io.Logger;
9
10/**
11 * This class is used to create all stats log files. Files are created with
12 * filename: Date-Time.stat<br>
13 * Where Date is in the format DDMMMYYYY and Time is in the format HHMM.
14 *
15 * @author mrww1
16 *
17 */
18public class StatsLogger {
19
20 private static String _filename = null;
21 private static final String FRAMES_EDITED_FILENAME = "FramesEdited.stat";
22
23 /**
24 * Sets the path on disk that the statlog files will be created in.
25 *
26 * @param location
27 * The path on disk to create the log files in.
28 */
29 private static void Init() {
30 if (!org.expeditee.gui.UserSettings.LogStats)
31 return;
32
33 File test = new File(org.expeditee.gui.FrameIO.STATISTICS_DIR);
34 if (!test.exists())
35 test.mkdir();
36
37 _filename = Logger.EasyDateFormat("ddMMMyy-HHmm") + ".stat";
38 }
39
40 /**
41 * Writes the current stats to a file.
42 *
43 */
44 public static void WriteStatsFile() {
45 if (!org.expeditee.gui.UserSettings.LogStats)
46 return;
47
48 Init();
49
50 try {
51 BufferedWriter writer = new BufferedWriter(new FileWriter(
52 org.expeditee.gui.FrameIO.STATISTICS_DIR + _filename, true));
53 writer.write(SessionStats.getCurrentStats());
54 writer.newLine();
55 writer.newLine();
56 writer.write(SessionStats.getItemStats());
57 writer.newLine();
58 writer.newLine();
59 writer.write(SessionStats.getEventStats());
60 writer.newLine();
61
62 writer.flush();
63 writer.close();
64
65 writer = new BufferedWriter(new FileWriter(
66 org.expeditee.gui.FrameIO.STATISTICS_DIR + FRAMES_EDITED_FILENAME, true));
67 writer.write(SessionStats.getFramesEdited());
68 writer.newLine();
69
70 writer.flush();
71 writer.close();
72 } catch (IOException ioe) {
73 ioe.printStackTrace();
74 }
75 }
76}
Note: See TracBrowser for help on using the repository browser.