Commit 0878f48f authored by Xavier de Blas's avatar Xavier de Blas

report of all stats and graphs done (TODO: improve graph size and info to user...

report of all stats and graphs done (TODO: improve graph size and info to user included in HTML) (task 295 at 90%)

report: images save in correct directory and are linked in html

cleaning StatType (added StatTypeStruct, affects all stats and graphs classes)

fixed bug: program crashed when graphing an empty stat (report or not)
parent 34b49b60
......@@ -22,8 +22,6 @@ CHRONOJUMP_DEP_GUI = src/gui/confirm.cs src/gui/error.cs src/gui/jump.cs src/gui
CHRONOJUMP_DEP_STATS = src/statType.cs src/stats/main.cs src/stats/global.cs src/stats/sjCmjAbk.cs src/stats/sjCmjAbkPlus.cs src/stats/djIndex.cs src/stats/djQ.cs src/stats/rjIndex.cs src/stats/rjPotencyBosco.cs src/stats/rjEvolution.cs src/stats/ieIub.cs src/stats/fv.cs
CHRONOJUMP_DEP_GRAPHS = src/stats/graphs/graphData.cs src/stats/graphs/graphSerie.cs src/stats/graphs/global.cs src/stats/graphs/sjCmjAbk.cs src/stats/graphs/sjCmjAbkPlus.cs src/stats/graphs/djIndex.cs src/stats/graphs/djQ.cs src/stats/graphs/rjIndex.cs src/stats/graphs/rjPotencyBosco.cs src/stats/graphs/rjEvolution.cs src/stats/graphs/ieIub.cs src/stats/graphs/fv.cs
CHRONOJUMP_DEP_REPORT = src/stats/report/sjCmjAbk.cs
CHRONOJUMP_DEP_SQLITE = src/sqlite/main.cs src/sqlite/preferences.cs src/sqlite/person.cs src/sqlite/session.cs src/sqlite/jump.cs src/sqlite/jumpType.cs src/sqlite/run.cs src/sqlite/runType.cs src/sqlite/personSession.cs src/sqlite/stat.cs
CHRONOJUMP_DEP = src/chronojump.cs src/person.cs src/jump.cs src/jumpType.cs src/run.cs src/runType.cs src/session.cs src/catalog.cs src/exportSession.cs src/treeViewJump.cs src/treeViewRun.cs src/util.cs src/report.cs $(CHRONOJUMP_DEP_GUI) $(CHRONOJUMP_DEP_STATS) $(CHRONOJUMP_DEP_GRAPHS) $(CHRONOJUMP_DEP_SQLITE) $(CHRONOJUMP_DEP_REPORT)
......
CHANGELOG:
19 set 2005
report of all stats and graphs done (TODO: improve graph size and info
to user included in HTML) (task 295 at 90%)
report: images save in correct directory and are linked in html
cleaning StatType (added StatTypeStruct, affects all stats and graphs
classes)
fixed bug: program crashed when graphing an empty stat (report or not)
16 set 2005
more code for report:
1.- new file src/statType.cs (statType class), now gui/stats.cs and report.cs create needed stat and call to prepareData and CreateGraph if needed
......
No preview for this file type
......@@ -282,6 +282,12 @@ public class ChronoJump
Console.WriteLine("AllJumpsName: {0}", allJumpsName);
cpRunning = false;
report = new Report(-1); //when a session is loaded or created, it will change the report.SessionID value
//TODO: check what happens if a session it's deleted
//i suppose report it's deactivated until a new session is created or loaded,
//but check what happens if report window is opened
loadPreferences ();
createTreeView_jumps(treeview_jumps);
......@@ -296,11 +302,6 @@ public class ChronoJump
createComboSujetoCurrent();
createdStatsWin = false;
report = new Report(-1); //when a session is loaded or created, it will change the report.SessionID value
//TODO: check what happens if a session it's deleted
//i suppose report it's deactivated until a new session is created or loaded,
//but check what happens if report window is opened
//We have no session, mark some widgets as ".Sensitive = false"
sensitiveGuiNoSession();
......@@ -397,6 +398,12 @@ public class ChronoJump
} else {
metersSecondsPreferred = false;
}
//pass to report
report.PrefsDigitsNumber = prefsDigitsNumber;
report.HeightPreferred = heightPreferred;
report.WeightStatsPercent = weightStatsPercent;
Console.WriteLine ( Catalog.GetString ("Preferences loaded") );
}
......
......@@ -51,7 +51,14 @@ public class ExportSession
protected void checkFile (string formatFile)
{
string exportString = Catalog.GetString ("Export session in " + formatFile + " format");
string exportString = "";
if(formatFile == "report") {
exportString = Catalog.GetString ("Save report in ");
} else {
exportString = Catalog.GetString ("Export session in " + formatFile + " format");
}
FileSelection fs = new FileSelection (exportString);
fs.SelectMultiple = false;
......@@ -66,6 +73,9 @@ public class ExportSession
fileName = fs.Filename;
fs.Hide ();
//add ".html" if needed, remember that on windows should be .htm
fileName = addHtmlIfNeeded(fileName);
try {
if (File.Exists(fileName)) {
Console.WriteLine("File {0} exists with attributes {1}, created at {2}",
......@@ -94,6 +104,16 @@ public class ExportSession
printData();
closeWriter();
}
//remember on windows should be .htm
private string addHtmlIfNeeded(string myFile)
{
int posOfDot = myFile.LastIndexOf('.');
if (posOfDot == -1) {
myFile += ".html";
}
return myFile;
}
protected virtual void getData()
{
......
......@@ -316,7 +316,7 @@ public class StatsWindow {
int limit = -1;
if (radiobutton_stats_jumps_all.Active) {
statsJumpsType = 0;
limit = -1; //FIXME: this changed form 0 to -1, check problems in stats.cs
limit = -1;
} else if (radiobutton_stats_jumps_limit.Active) {
statsJumpsType = 1;
limit = Convert.ToInt32 ( spin_stats_jumps_limit.Value );
......@@ -325,7 +325,7 @@ public class StatsWindow {
limit = Convert.ToInt32 ( spin_stats_jumps_person_bests.Value );
} else {
statsJumpsType = 3;
limit = -1; //FIXME: this changed form 0 to -1, check problems in stats.cs
limit = -1;
}
//we use sendSelectedSessions for not losing selectedSessions ArrayList
......@@ -609,31 +609,15 @@ public class StatsWindow {
statisticApplyTo = "-";
}
/*
string sessionsAsAString = "";
if (radiobutton_current_session.Active) {
//sessionsAsAString = (currentSession.Name + "[" + currentSession.UniqueID + "]");
sessionsAsAString = (currentSession.UniqueID + ":" + currentSession.Name );
} else if (radiobutton_selected_sessions.Active) {
for (int i=0; i < selectedSessions.Count ; i++) {
if(i>0) {
sessionsAsAString += "\n";
}
string [] myStrFull = selectedSessions[i].ToString().Split(new char[] {':'});
//sessionsAsAString += myStrFull[1] + "[" + myStrFull[0] + "] ";
sessionsAsAString += myStrFull[0] + ":" + myStrFull[1];
}
}
*/
string statsShowJumps = "";
if (radiobutton_stats_jumps_all.Active) {
statsShowJumps = Catalog.GetString("All");
} else if (radiobutton_stats_jumps_limit.Active) {
statsShowJumps = Catalog.GetString("Limit") + " " + spin_stats_jumps_limit.Value.ToString();
statsShowJumps = Catalog.GetString("Limit") + "." +
spin_stats_jumps_limit.Value.ToString();
} else if (radiobutton_stats_jumps_person_bests.Active) {
statsShowJumps = Catalog.GetString("Jumper's best") + " " + spin_stats_jumps_person_bests.Value.ToString();
statsShowJumps = Catalog.GetString("Jumper's best") + "." +
spin_stats_jumps_person_bests.Value.ToString();
} else {
statsShowJumps = Catalog.GetString("Jumper's average");
}
......
......@@ -21,6 +21,7 @@
using System;
using System.Data;
using System.IO;
using System.Collections; //ArrayList
using Gtk;
using Glade;
......@@ -37,8 +38,12 @@ public class Report : ExportSession
public bool ShowReactiveJumps;
public bool ShowSimpleRuns;
public bool ShowIntervalRuns;
private int prefsDigitsNumber;
private bool heightPreferred;
private bool weightStatsPercent;
bool toFile = true;
bool toReport = true;
public ArrayList StatisticsData;
......@@ -94,11 +99,24 @@ public class Report : ExportSession
*/
public void PrepareFile () {
checkFile("none");
}
checkFile("report");
}
protected override void getData()
{
//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);
}
}
//session stuff?
......@@ -141,6 +159,9 @@ public class Report : ExportSession
if (ShowIntervalRuns) {
printRunsInterval();
}
printStats();
printFooter();
}
......@@ -159,61 +180,105 @@ public class Report : ExportSession
protected override void printJumps()
{
writer.WriteLine("<h2>Simple Jumps</h2>");
writer.WriteLine("<h2>Simple jumps</h2>");
}
protected void printStats()
{
writer.WriteLine("<h2>Statitistics</h2>");
//obtain every report stats one by one
for(int i=0; i < StatisticsData.Count ; i++) {
string [] strFull = StatisticsData[i].ToString().Split(new char[] {'\n'});
if( strFull[0] == Catalog.GetString("Simple") ) {
ArrayList sendSelectedSessions = new ArrayList(1);;
//separate in sessions
string [] sessionsStrFull = strFull[3].Split(new char[] {':'});
for (int j=0; j < sessionsStrFull.Length ; j++) {
Session mySession = SqliteSession.Select(sessionsStrFull[j]);
sendSelectedSessions.Add(mySession.UniqueID + ":" + mySession.Name + ":" + mySession.Date);
}
string applyTo = strFull[2];
//if( applyTo == Catalog.GetString("All Jumps") ) {
// applyTo = "-1";
//}
/*
ReportSjCmjAbk myReport = new ReportSjCmjAbk(
sendSelectedSessions,
4, //prefsDigitsNumber
applyTo, //applyTo (jumpType)
false, //showSex
3, //statsJumpType
2, //limit
false //heightPreferred
);
*/
StatType myStatType = new StatType(
strFull[0], //statisticType
strFull[1], //statisticSubType
strFull[2], //statisticApplyTo
sendSelectedSessions,
4, //prefsDigitsNumber
false, //checkbutton_stats_sex.Active
3, //statsJumpsType
2, //limit
false, //heightPreferred
false, //weightStatsPercent
false, //graph
toFile,
writer
);
bool allFine = myStatType.ChooseStat();
//writer.WriteLine(myReport.TableString);
string myHeaderStat = "";
ArrayList sendSelectedSessions = new ArrayList(1);;
//separate in sessions
string [] sessionsStrFull = strFull[3].Split(new char[] {':'});
for (int j=0; j < sessionsStrFull.Length ; j++) {
Session mySession = SqliteSession.Select(sessionsStrFull[j]);
sendSelectedSessions.Add(mySession.UniqueID + ":" + mySession.Name + ":" + mySession.Date);
}
string applyTo = strFull[2];
myHeaderStat += "<h3>" + applyTo + "</h3> ";
bool showSex = false;
if(strFull[5] == "True") {
showSex = true;
}
int statsJumpsType = 0;
int limit = -1;
string [] strJumpsType = strFull[4].ToString().Split(new char[] {'.'});
if(strJumpsType[0] == Catalog.GetString("All")) {
statsJumpsType = 0;
} else if(strJumpsType[0] == Catalog.GetString("Limit")) {
statsJumpsType = 1;
limit = Convert.ToInt32 ( strJumpsType[1] );
} else if(strJumpsType[0] == Catalog.GetString("Jumper's best")) {
statsJumpsType = 2;
limit = Convert.ToInt32 ( strJumpsType[1] );
} else if(strJumpsType[0] == Catalog.GetString("Jumper's average")) {
statsJumpsType = 3;
}
myHeaderStat += strJumpsType[0];
if(limit != -1) {
myHeaderStat += " (" + limit.ToString() + ")";
}
myHeaderStat += "\n<p><TABLE BORDER=\"0\"><tr><td>\n";
writer.WriteLine(myHeaderStat);
StatType myStatType;
bool allFine;
//report of stat
myStatType = new StatType(
strFull[0], //statisticType
strFull[1], //statisticSubType
strFull[2], //statisticApplyTo
sendSelectedSessions,
prefsDigitsNumber,
showSex,
statsJumpsType,
limit,
heightPreferred,
weightStatsPercent,
false, //graph
toReport,
writer,
""
);
allFine = myStatType.ChooseStat();
writer.WriteLine("</td><td>");
//report of graph
myStatType = new StatType(
strFull[0], //statisticType
strFull[1], //statisticSubType
strFull[2], //statisticApplyTo
sendSelectedSessions,
prefsDigitsNumber,
showSex,
statsJumpsType,
limit,
heightPreferred,
weightStatsPercent,
true, //graph
toReport,
writer,
fileName //fileName for exporting there
);
allFine = myStatType.ChooseStat();
writer.WriteLine("</table>");
}
}
......@@ -242,6 +307,19 @@ public class Report : ExportSession
set { sessionID = value; }
}
public int PrefsDigitsNumber {
set { prefsDigitsNumber = value; }
}
public bool HeightPreferred {
set { heightPreferred = value; }
}
public bool WeightStatsPercent {
set { weightStatsPercent = value; }
}
~Report() {}
}
......
......@@ -25,6 +25,36 @@ using System.Text; //StringBuilder
using System.Collections; //ArrayList
using System.IO; //TextWriter
//the onbly purpose of this class is to pass parameters nicer between statType and stat and graphs constructors
public class StatTypeStruct
{
public string StatisticApplyTo;
public ArrayList SendSelectedSessions;
public int PrefsDigitsNumber;
public bool Sex_active;
public int StatsJumpsType;
public int Limit;
public bool HeightPreferred;
public bool WeightStatsPercent;
public bool ToReport;
public StatTypeStruct (string statisticApplyTo,
ArrayList sendSelectedSessions, int prefsDigitsNumber, bool sex_active,
int statsJumpsType, int limit, bool heightPreferred, bool weightStatsPercent,
bool toReport)
{
this.StatisticApplyTo = statisticApplyTo;
this.SendSelectedSessions = sendSelectedSessions;
this.PrefsDigitsNumber = prefsDigitsNumber;
this.Sex_active = sex_active;
this.StatsJumpsType = statsJumpsType;
this.Limit = limit;
this.HeightPreferred = heightPreferred;
this.WeightStatsPercent = weightStatsPercent;
this.ToReport = toReport;
}
}
public class StatType {
string statisticType;
......@@ -41,6 +71,7 @@ public class StatType {
bool graph;
bool toReport;
TextWriter writer;
string fileName;
Stat myStat;
//Report myReport;
......@@ -54,6 +85,7 @@ public class StatType {
string allJumpsName = Catalog.GetString("All jumps");
StatTypeStruct myStatTypeStruct;
//comes from gui/stats.cs
public StatType (string statisticType, string statisticSubType, string statisticApplyTo, Gtk.TreeView treeview_stats,
......@@ -61,6 +93,7 @@ public class StatType {
int statsJumpsType, int limit, bool heightPreferred, bool weightStatsPercent,
bool graph, bool toReport)
{
//some of this will disappear when we use myStatTypeStruct in all classes:
this.statisticType = statisticType;
this.statisticSubType = statisticSubType;
this.statisticApplyTo = statisticApplyTo;
......@@ -74,6 +107,12 @@ public class StatType {
this.weightStatsPercent = weightStatsPercent;
this.graph = graph;
this.toReport = toReport;
myStatTypeStruct = new StatTypeStruct (
statisticApplyTo,
sendSelectedSessions, prefsDigitsNumber, sex_active,
statsJumpsType, limit, heightPreferred, weightStatsPercent,
toReport);
myStat = new Stat(); //create and instance of myStat
}
......@@ -82,12 +121,11 @@ public class StatType {
public StatType (string statisticType, string statisticSubType, string statisticApplyTo,
ArrayList sendSelectedSessions, int prefsDigitsNumber, bool sex_active,
int statsJumpsType, int limit, bool heightPreferred, bool weightStatsPercent,
bool graph, bool toReport, TextWriter writer)
bool graph, bool toReport, TextWriter writer, string fileName)
{
this.statisticType = statisticType;
this.statisticSubType = statisticSubType;
this.statisticApplyTo = statisticApplyTo;
this.treeview_stats = treeview_stats ;
this.sendSelectedSessions = sendSelectedSessions;
this.prefsDigitsNumber = prefsDigitsNumber;
this.sex_active = sex_active;
......@@ -98,6 +136,13 @@ public class StatType {
this.graph = graph;
this.toReport = toReport;
this.writer = writer;
this.fileName = fileName;
myStatTypeStruct = new StatTypeStruct (
statisticApplyTo,
sendSelectedSessions, prefsDigitsNumber, sex_active,
statsJumpsType, limit, heightPreferred, weightStatsPercent,
toReport);
myStat = new Stat(); //create and instance of myStat
}
......@@ -110,22 +155,9 @@ public class StatType {
int jumperID = -1; //all jumpers
string jumperName = ""; //all jumpers
if(graph) {
myStat = new GraphGlobal(
sendSelectedSessions,
jumperID, jumperName,
prefsDigitsNumber, sex_active,
statsJumpsType, heightPreferred
);
myStat.PrepareData();
myStat.CreateGraph();
myStat = new GraphGlobal(myStatTypeStruct, jumperID, jumperName);
} else {
myStat = new StatGlobal(treeview_stats,
sendSelectedSessions,
jumperID, jumperName,
prefsDigitsNumber, sex_active,
statsJumpsType, heightPreferred
);
myStat.PrepareData();
myStat = new StatGlobal(myStatTypeStruct, treeview_stats, jumperID, jumperName);
}
}
else if (statisticType == Catalog.GetString("Jumper"))
......@@ -141,23 +173,11 @@ public class StatType {
string jumperName = Util.FetchName(statisticApplyTo);
if(graph) {
myStat = new GraphGlobal(
sendSelectedSessions,
jumperID, jumperName,
prefsDigitsNumber, sex_active,
statsJumpsType, heightPreferred
);
myStat.PrepareData();
myStat.CreateGraph();
myStat = new GraphGlobal(myStatTypeStruct, jumperID, jumperName);
}
else {
myStat = new StatGlobal(treeview_stats,
sendSelectedSessions,
jumperID, jumperName,
prefsDigitsNumber, sex_active,
statsJumpsType, heightPreferred
);
myStat.PrepareData();
myStat = new StatGlobal(myStatTypeStruct, treeview_stats,
jumperID, jumperName);
}
}
else if(statisticType == Catalog.GetString("Simple"))
......@@ -177,44 +197,18 @@ public class StatType {
} else if(statisticSubType == fvIndexFormula) {
indexType = "F/V";
}
if(indexType == "IE" || indexType == "IUB") {
if(graph) {
myStat = new GraphIeIub (
sendSelectedSessions,
indexType,
prefsDigitsNumber, sex_active,
statsJumpsType,
limit);
myStat.PrepareData();
myStat.CreateGraph();
myStat = new GraphIeIub (myStatTypeStruct, indexType);
} else {
myStat = new StatIeIub(treeview_stats,
sendSelectedSessions,
indexType,
prefsDigitsNumber, sex_active,
statsJumpsType,
limit);
myStat.PrepareData();
myStat = new StatIeIub(myStatTypeStruct, treeview_stats, indexType);
}
} else { //F/V
if(graph) {
myStat = new GraphFv (
sendSelectedSessions,
indexType,
prefsDigitsNumber, sex_active,
statsJumpsType,
limit);
myStat.PrepareData();
myStat.CreateGraph();
myStat = new GraphFv (myStatTypeStruct, indexType);
} else {
myStat = new StatFv(treeview_stats,
sendSelectedSessions,
indexType,
prefsDigitsNumber, sex_active,
statsJumpsType,
limit);
myStat.PrepareData();
myStat = new StatFv(myStatTypeStruct, treeview_stats, indexType);
}
}
}
......@@ -226,79 +220,15 @@ public class StatType {
statisticApplyTo == allJumpsName)
{
if(graph) {
myStat = new GraphSjCmjAbkPlus (
sendSelectedSessions,
prefsDigitsNumber, statisticApplyTo,
sex_active,
statsJumpsType,
limit,
weightStatsPercent,
heightPreferred
);
myStat.PrepareData();
myStat.CreateGraph();
myStat = new GraphSjCmjAbkPlus (myStatTypeStruct);
} else {
myStat = new StatSjCmjAbkPlus (treeview_stats,
sendSelectedSessions,
prefsDigitsNumber, statisticApplyTo,
sex_active,
statsJumpsType,
limit,
weightStatsPercent,
heightPreferred
);
myStat.PrepareData();
myStat = new StatSjCmjAbkPlus (myStatTypeStruct, treeview_stats);
}
} else {
if(toReport) {
if(graph) {
/*
myStat = new GraphSjCmjAbk (
sendSelectedSessions,
prefsDigitsNumber, statisticApplyTo,
sex_active,
statsJumpsType,
limit,
heightPreferred
);
myStat.PrepareData();
myStat.CreateGraph();
*/
} else {
myStat = new ReportSjCmjAbk (
sendSelectedSessions,
prefsDigitsNumber, statisticApplyTo,
sex_active,
statsJumpsType,
limit,
heightPreferred
);
myStat.PrepareData();
writer.WriteLine(myStat.ToString());
}
if(graph) {
myStat = new GraphSjCmjAbk (myStatTypeStruct);
} else {
if(graph) {
myStat = new GraphSjCmjAbk (
sendSelectedSessions,
prefsDigitsNumber, statisticApplyTo,
sex_active,
statsJumpsType,
limit,
heightPreferred
);
myStat.PrepareData();
myStat.CreateGraph();
} else {
myStat = new StatSjCmjAbk (treeview_stats,
sendSelectedSessions,
prefsDigitsNumber, statisticApplyTo,
sex_active,
statsJumpsType,
limit,
heightPreferred
);
myStat.PrepareData();
}
myStat = new StatSjCmjAbk (myStatTypeStruct, treeview_stats);
}
}
}
......@@ -313,50 +243,20 @@ public class StatType {
if(statisticSubType == djIndexFormula)
{
if(graph) {
myStat = new GraphDjIndex (
sendSelectedSessions,
prefsDigitsNumber, statisticApplyTo,
sex_active,
statsJumpsType,
limit//,
//heightPreferred
);
myStat.PrepareData();
myStat.CreateGraph();
myStat = new GraphDjIndex (myStatTypeStruct);
//heightPreferred is not used, check this
} else {
myStat = new StatDjIndex(treeview_stats,
sendSelectedSessions,
prefsDigitsNumber, statisticApplyTo,
sex_active,
statsJumpsType,
limit//,
//heightPreferred
);
myStat.PrepareData();
myStat = new StatDjIndex(myStatTypeStruct, treeview_stats);
//heightPreferred is not used, check this
}
} else if(statisticSubType == qIndexFormula)
{
if(graph) {
myStat = new GraphDjQ (
sendSelectedSessions,
prefsDigitsNumber, statisticApplyTo,
sex_active,
statsJumpsType,
limit//,
//heightPreferred
);
myStat.PrepareData();
myStat.CreateGraph();
myStat = new GraphDjQ (myStatTypeStruct);
//heightPreferred is not used, check this
} else {
myStat = new StatDjQ(treeview_stats,
sendSelectedSessions,
prefsDigitsNumber, statisticApplyTo,
sex_active,
statsJumpsType,
limit//,
//heightPreferred
);
myStat.PrepareData();
myStat = new StatDjQ(myStatTypeStruct, treeview_stats);
//heightPreferred is not used, check this
}
}
}
......@@ -364,77 +264,54 @@ public class StatType {
if(statisticSubType == Catalog.GetString("Average Index"))
{
if(graph) {
myStat = new GraphRjIndex (
sendSelectedSessions,
prefsDigitsNumber,
statisticApplyTo,
sex_active,
statsJumpsType,
limit);