1 | package org.expeditee.stats;
|
---|
2 |
|
---|
3 | import java.io.BufferedWriter;
|
---|
4 | import java.io.File;
|
---|
5 | import java.io.FileWriter;
|
---|
6 | import java.io.IOException;
|
---|
7 |
|
---|
8 | import 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 | */
|
---|
18 | public 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 |
|
---|
56 | writer.flush();
|
---|
57 | writer.close();
|
---|
58 |
|
---|
59 | writer = new BufferedWriter(new FileWriter(
|
---|
60 | org.expeditee.gui.FrameIO.STATISTICS_DIR + FRAMES_EDITED_FILENAME, true));
|
---|
61 | writer.write(SessionStats.getFramesEdited());
|
---|
62 | writer.newLine();
|
---|
63 |
|
---|
64 | writer.flush();
|
---|
65 | writer.close();
|
---|
66 | } catch (IOException ioe) {
|
---|
67 | ioe.printStackTrace();
|
---|
68 | }
|
---|
69 | }
|
---|
70 | }
|
---|