/
report.cs
437 lines (358 loc) · 12.4 KB
/
report.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
/*
* This file is part of ChronoJump
*
* ChronoJump is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* ChronoJump is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Copyright (C) 2004-2023 Xavier de Blas <xaviblas@gmail.com>
*/
using System;
using System.Data;
using System.IO;
using System.Collections; //ArrayList
using System.Collections.Generic; //List
using Gtk;
//using Glade;
using Mono.Unix;
public class Report : ExportSession
{
public bool ShowCurrentSessionData;
public bool ShowCurrentSessionJumpers;
public bool ShowSimpleJumps;
public bool ShowReactiveJumps;
public bool ShowReactiveJumpsWithSubjumps;
public bool ShowSimpleRuns;
public bool ShowIntervalRuns;
public bool ShowIntervalRunsWithSubruns;
//public bool ShowReactionTimes;
//public bool ShowPulses;
bool toReport = true;
public ArrayList StatisticsData;
public static string home = Environment.GetEnvironmentVariable("HOME")+"/.chronojump";
private string progversion;
public Report(int sessionID)
{
this.SessionID = sessionID;
ShowCurrentSessionData = true;
ShowCurrentSessionJumpers = true;
ShowSimpleJumps = true;
ShowReactiveJumps = true;
ShowSimpleRuns = true;
ShowIntervalRuns = true;
//ShowReactionTimes = true;
//ShowPulses = true;
spreadsheetString = "";
showDialogMessage = true;
fakeButtonDone = new Gtk.Button ();
StatisticsData = new ArrayList(1);
mySession = SqliteSession.Select(sessionID.ToString());
}
public void PrepareFile () {
checkFile("report");
}
//when a session changes, remove all stats because in report they refer to previoud session
public void StatisticsRemove() {
StatisticsData = new ArrayList(1);
}
protected override bool getData()
{
//to avoid a crash since jumps_ll on exportSession
jumps_ll = new List<List<SqliteStruct.IntTypeDoubleDouble>> ();
//create directory filename_files/
string directoryName = Util.GetReportDirectoryName(filename);
if(!Directory.Exists(directoryName)) {
Directory.CreateDirectory (directoryName);
} else {
//if it exists before, delete all pngs
string [] pngs = Directory.GetFiles(directoryName, "*.png");
foreach(string myFile in pngs) {
File.Delete(myFile);
}
}
if(ShowCurrentSessionJumpers) {
myPersonsAndPS = SqlitePersonSession.SelectCurrentSessionPersons(sessionID, true);
}
//Leave SQL opened in all this process
Sqlite.Open(); // ------------------------------
bool hasData = false;
if (ShowSimpleJumps) {
myJumps = SqliteJump.SelectJumpsSA (true, sessionID, -1, "", "",
Sqlite.Orders_by.DEFAULT, 0);
if (myJumps.Length > 0)
hasData = true;
}
if (ShowReactiveJumps) {
myJumpsRj = SqliteJumpRj.SelectJumpsSA(true, sessionID, -1, "", "");
if (myJumpsRj.Length > 0)
hasData = true;
}
if (ShowSimpleRuns) {
myRuns = SqliteRun.SelectRunsSA (true, sessionID, -1, "",
Sqlite.Orders_by.DEFAULT, -1);
if (myRuns.Length > 0)
hasData = true;
}
if (ShowIntervalRuns) {
myRunsInterval = SqliteRunInterval.SelectRunsSA (true, sessionID, -1, "");
if (myRunsInterval.Length > 0)
hasData = true;
}
/*
if(ShowReactionTimes) {
myReactionTimes= SqliteReactionTime.SelectReactionTimes(true, sessionID, -1, "",
Sqlite.Orders_by.DEFAULT, -1);
}
if(ShowPulses) {
myPulses= SqlitePulse.SelectPulses(true, sessionID, -1);
}
*/
Sqlite.Close(); // ------------------------------
return hasData;
}
protected override void printTitles(string title) {
writer.WriteLine("<h2>" + title + "</h2>");
}
protected override void printData ()
{
copyCssAndLogo();
printHtmlHeader();
if(ShowCurrentSessionData) {
printTitles(Catalog.GetString("Session"));
printSessionInfo();
}
if(ShowCurrentSessionJumpers) {
printTitles(Catalog.GetString("Persons"));
printPersons();
}
if(ShowSimpleJumps)
printJumps(Catalog.GetString("Simple jumps"));
if(ShowReactiveJumps) {
string myTitle = "";
if(ShowReactiveJumpsWithSubjumps) {
myTitle = Catalog.GetString("Reactive jumps") +
" (" + Catalog.GetString("with subjumps") + ")";
} else {
myTitle = Catalog.GetString("Reactive jumps") +
" (" + Catalog.GetString("without subjumps") + ")";
}
printJumpsRj(ShowReactiveJumpsWithSubjumps, myTitle);
}
if(ShowSimpleRuns)
printRuns(Catalog.GetString("Simple races"));
if (ShowIntervalRuns) {
string myTitle = "";
if(ShowIntervalRunsWithSubruns) {
myTitle = Catalog.GetString("interval races") +
" (" + Catalog.GetString("with laps") + ")";
} else {
myTitle = Catalog.GetString("interval races") +
" (" + Catalog.GetString("without laps") + ")";
}
printRunsInterval(ShowIntervalRunsWithSubruns, myTitle);
}
/*
if(ShowReactionTimes)
printReactionTimes(Catalog.GetString("Reaction times"));
if(ShowPulses)
printPulses(Catalog.GetString("Pulses"));
*/
printStats();
printFooter();
}
void copyCssAndLogo() {
//copy files, and continue if already exists
try {
File.Copy(Util.GetCssDir()+ Path.DirectorySeparatorChar + Constants.FileNameCSS,
Util.GetReportDirectoryName(filename) + Path.DirectorySeparatorChar + Constants.FileNameCSS );
} catch {}
try {
File.Copy(Util.GetImagesDir() + Path.DirectorySeparatorChar + Constants.FileNameLogo,
Util.GetReportDirectoryName(filename) + Path.DirectorySeparatorChar + Constants.FileNameLogo );
} catch {}
}
protected void printHtmlHeader()
{
writer.WriteLine("<HTML><HEAD><TITLE>Chronojump Report (" + DateTime.Now + ")</TITLE>\n");
writer.WriteLine("<meta HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=UTF-8\">\n");
writer.WriteLine("<style type=\"text/css\">");
writer.WriteLine(" @import url(\"" + Util.GetLastPartOfPath(Util.GetReportDirectoryName(filename)) +
"/report_web_style.css\"); ");
writer.WriteLine("</style>");
writer.WriteLine("</HEAD>\n<BODY BGCOLOR=\"#ffffff\" TEXT=\"#444444\">\n");
writer.WriteLine("<table width=\"100%\" class=\"empty\"><tr><td>\n");
writer.WriteLine("<img src=\"" +
Util.GetLastPartOfPath(Util.GetReportDirectoryName(filename))
+ "/" + Constants.FileNameLogo + "\">\n ");
writer.WriteLine("</td><td width=\"80%\" valign=\"bottom\"><h1>Chronojump report</h1></td></tr>\n");
writer.WriteLine("</table>\n");
}
protected override void printSessionInfo()
{
ArrayList myData = new ArrayList(2);
myData.Add( "\n" +
Catalog.GetString ("SessionID") + ":" + Catalog.GetString ("Name") + ":" +
Catalog.GetString ("Place") + ":" + Catalog.GetString ("Date") + ":" +
Catalog.GetString ("Comments")
);
myData.Add ( mySession.UniqueID + ":" + mySession.Name + ":" +
mySession.Place + ":" + mySession.DateShort + ":" + mySession.Comments );
writeData(myData);
writeData("VERTICAL-SPACE");
}
protected override void writeData (ArrayList exportData) {
writer.WriteLine( "<table cellpadding=2 cellspacing=2>" );
string iniCell = "<th align=\"left\">";
string endCell = "</th>";
for(int i=0; i < exportData.Count ; i++) {
exportData[i] = exportData[i].ToString().Replace(":", endCell + iniCell);
writer.WriteLine( "<tr>" + iniCell + exportData[i] + endCell + "</tr>" );
iniCell = "<td>";
endCell = "</td>";
}
writer.WriteLine( "</table>\n" );
}
protected override void writeData (string exportData)
{
if(exportData == "VERTICAL-SPACE") {
writer.WriteLine( "<br>" );
}
}
public ArrayList GetSelectedSessions(string sessionsString) {
ArrayList sendSelectedSessions = new ArrayList(1);
string [] sessionsStrFull = sessionsString.Split(new char[] {':'});
for (int j=0; j < sessionsStrFull.Length ; j++) {
Session tempSession = SqliteSession.Select(sessionsStrFull[j]);
sendSelectedSessions.Add(tempSession.UniqueID + ":" + tempSession.Name + ":" + tempSession.DateShort);
}
return sendSelectedSessions;
}
public int GetStatsJumpTypeAndLimit(string str, out int limit) {
int jumpsType = 0;
limit = -1;
string [] strJumpsType = str.ToString().Split(new char[] {'.'});
if(strJumpsType[0] == Catalog.GetString("All"))
jumpsType = 0;
else if(strJumpsType[0] == Catalog.GetString("Limit")) {
jumpsType = 1;
limit = Convert.ToInt32 ( strJumpsType[1] );
} else if(strJumpsType[0] == Catalog.GetString("Jumper's best")) {
jumpsType = 2;
limit = Convert.ToInt32 ( strJumpsType[1] );
} else if(strJumpsType[0] == Catalog.GetString("Jumper's average"))
jumpsType = 3;
return jumpsType;
}
public int GetRjEvolutionMarkConsecutives(string strIni, out string strEnd) {
strEnd = strIni;
int rj_evolution_mark_consecutives = -1;
if(strEnd.StartsWith(Catalog.GetString("Evolution."))) {
string [] strEvo = strEnd.Split(new char[] {'.'});
strEnd = strEvo[0];
rj_evolution_mark_consecutives = Convert.ToInt32(strEvo[1]);
}
return rj_evolution_mark_consecutives;
}
protected void printStats()
{
if(StatisticsData.Count > 0)
writer.WriteLine("<h2>Statistics</h2>");
//obtain every report stats one by one
for(int statCount=0; statCount < StatisticsData.Count ; statCount++) {
string [] strFull = StatisticsData[statCount].ToString().Split(new char[] {'\t'});
string myHeaderStat = "";
//separate in sessions
ArrayList sendSelectedSessions = GetSelectedSessions(strFull[3]);
//separate in markedRows
ArrayList arrayListMarkedRows = Util.StringToArrayList(strFull[6], ':');
string applyTo = strFull[2];
myHeaderStat += "<h3> " + strFull[0] + " : " + strFull[1] + " : " + applyTo + "</h3> ";
bool showSex = Util.StringToBool(strFull[5]);
int limit;
int statsJumpsType = GetStatsJumpTypeAndLimit(strFull[4], out limit);
//obtain marked jumps of rj evolution if needed
string subType;
int rj_evolution_mark_consecutives = GetRjEvolutionMarkConsecutives(strFull[1], out subType);
myHeaderStat += "\n<p><TABLE cellpadding=2 cellspacing=2><tr><td>\n";
writer.WriteLine(myHeaderStat);
StatType myStatType;
//bool allFine;
//report of stat
GraphROptions graphROptions = new GraphROptions(strFull[7]);
myStatType = new StatType(
strFull[0], //statisticType
subType, //statisticSubType
strFull[2], //statisticApplyTo
sendSelectedSessions,
showSex,
statsJumpsType,
limit,
arrayListMarkedRows,
rj_evolution_mark_consecutives,
graphROptions,
false, //graph
toReport,
preferences,
writer,
"",
statCount
);
//allFine = myStatType.ChooseStat();
myStatType.ChooseStat();
string myEnunciate ="<tr><td>" + myStatType.Enunciate + "</td></tr>";
writer.WriteLine("<br>");
//report of graph
myStatType = new StatType(
strFull[0], //statisticType
subType, //statisticSubType
strFull[2], //statisticApplyTo
sendSelectedSessions,
showSex,
statsJumpsType,
limit,
arrayListMarkedRows,
rj_evolution_mark_consecutives,
graphROptions,
true, //graph
toReport,
preferences,
writer,
filename, //filename for exporting there
statCount
);
myStatType.ChooseStat();
//enunciate is prented here and not before
//because myStatType of a graph doesn't know the numContinuous value
//needed for enunciate in rj evolution statistic
writer.WriteLine(myEnunciate);
writer.WriteLine("<tr><td>" + strFull[8] + "</td></tr>"); //comment
writer.WriteLine("</table>");
}
}
protected override void printFooter()
{
writer.WriteLine("\n<div id=\"footer\"><hr align=\"right\" width=\"50%\">");
writer.WriteLine("\nGenerated on " + DateTime.Now + ", by <a href=\"http://chronojump.org\">Chronojump</a> v." + progversion );
writer.WriteLine("\n</BODY></HTML>");
}
public int SessionID {
set {
sessionID = value;
mySession = SqliteSession.Select(sessionID.ToString());
}
}
public string Progversion {
set { progversion = value; }
}
~Report() {}
}