[chronojump] Added djPower to statics stats and graphs



commit 9aaccdccf5da701a61dec67aa0fcd0545df4465d
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Jul 14 19:38:16 2014 +0200

    Added djPower to statics stats and graphs

 src/Makefile.am             |    2 +
 src/constants.cs            |    6 +-
 src/gui/stats.cs            |    3 +-
 src/sqlite/stat.cs          |   36 +++++++--
 src/statType.cs             |    9 ++
 src/stats/djPower.cs        |  139 +++++++++++++++++++++++++++++++
 src/stats/graphs/djPower.cs |  190 +++++++++++++++++++++++++++++++++++++++++++
 src/treeViewJump.cs         |    2 +-
 8 files changed, 376 insertions(+), 11 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 1ab0128..6b69462 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -50,6 +50,7 @@ SOURCES = \
        stats/sjCmjAbk.cs\
        stats/sjCmjAbkPlus.cs\
        stats/djIndex.cs\
+       stats/djPower.cs\
        stats/djQ.cs\
        stats/jumpSimpleSubtraction.cs\
        stats/rjIndex.cs\
@@ -68,6 +69,7 @@ SOURCES = \
        stats/graphs/sjCmjAbk.cs\
        stats/graphs/sjCmjAbkPlus.cs\
        stats/graphs/djIndex.cs\
+       stats/graphs/djPower.cs\
        stats/graphs/djQ.cs\
        stats/graphs/rjIndex.cs\
        stats/graphs/rjPotencyBosco.cs\
diff --git a/src/constants.cs b/src/constants.cs
index ccf8335..13b4fd4 100644
--- a/src/constants.cs
+++ b/src/constants.cs
@@ -74,10 +74,12 @@ public class Constants
        public static string ChronojumpWebsite = "http://www.chronojump.org";;
        
        //formulas
-       public static string DjIndexFormula = "Dj Index (tv-tc)/tc *100)";
-       public static string QIndexFormula = "Q index (tv/tc)";
+       public static string DjIndexFormula = "Dj Index: (tv-tc)/tc *100)";
+       public static string QIndexFormula = "Q index: (tv/tc)";
+       public static string DjPowerFormula = "Dj Power: mass*g*(fallHeight+1.226*(tv^2)) / (tc+tv)";
        public static string DjIndexFormulaOnly = "(tv-tc)*100/(tc*1.0)"; //*1.0 for having double division
        public static string QIndexFormulaOnly = "tv/(tc*1.0)"; //*1.0 for having double division
+       public static string DjPowerFormulaOnly = PersonSessionTable + ".weight * 9.81 * (fall/100.0 + 1.226 
* (tv*tv) ) / ((tc+tv)*1.0)";
        
        public const string FvIndexFormula = "F/V sj+(100%)/sj *100";
        public const string IeIndexFormula = "IE (cmj-sj)/sj *100";
diff --git a/src/gui/stats.cs b/src/gui/stats.cs
index 8679105..17b4ea3 100644
--- a/src/gui/stats.cs
+++ b/src/gui/stats.cs
@@ -174,7 +174,8 @@ public partial class ChronoJumpWindow {
        
        private static string [] comboStatsSubTypeWithTCOptions = {
                Constants.DjIndexFormula,
-               Constants.QIndexFormula
+               Constants.QIndexFormula,
+               Constants.DjPowerFormula
        };
        
        private static string [] comboStatsSubTypeReactiveOptions = {
diff --git a/src/sqlite/stat.cs b/src/sqlite/stat.cs
index b1ce327..a4a5fa9 100644
--- a/src/sqlite/stat.cs
+++ b/src/sqlite/stat.cs
@@ -254,7 +254,7 @@ class SqliteStat : Sqlite
                }
        }
 
-       //dj index, Q index, ... (indexType)
+       //dj index, Q index, Dj Power ( ... (indexType)
        public static ArrayList DjIndexes (string indexType, string sessionString, bool multisession, string 
operationString, string jumpType, bool showSex)
        {
                string tp = Constants.PersonTable;
@@ -264,6 +264,8 @@ class SqliteStat : Sqlite
                        formula = Constants.DjIndexFormulaOnly;
                } else if (indexType == "indexQ") {
                        formula = Constants.QIndexFormulaOnly;
+               } else if (indexType == "djPower") {
+                       formula = Constants.DjPowerFormulaOnly;
                }
                string ini = "";
                string end = "";
@@ -275,16 +277,28 @@ class SqliteStat : Sqlite
                        end = ")";
                }
                
+               //djPower needs personWeight on that session
+               string sep = "";
+               string tps = "";
+               string personSessionString = "";
+               string selectWeight = "";
+               if (indexType == "djPower") {
+                       sep = ", ";
+                       tps = Constants.PersonSessionTable;
+                       personSessionString = " AND " + tp + ".uniqueID == " + tps + ".personID ";
+                       selectWeight = ", " + tps + ".weight";
+               }
+               
                string orderByString = "ORDER BY ";
                string moreSelect = "";
-               moreSelect = ini + formula + end + " AS myIndex, jump.tv, jump.tc, jump.fall";
+               moreSelect = ini + formula + end + " AS myIndex, jump.tv, jump.tc, jump.fall" + selectWeight;
                
                //manage allJumps
-               string fromString = " FROM jump, " + tp + " ";
+               string fromString = " FROM jump, " + tp + sep + tps + " ";
                string jumpTypeString = " AND jump.type == '" + jumpType + "' ";
                if(jumpType == Constants.AllJumpsName) {
                        moreSelect = moreSelect + ", jump.type ";
-                       fromString = " FROM jump, " + tp + ", jumpType ";
+                       fromString = " FROM jump, " + tp + sep + tps + ", jumpType ";
                        jumpTypeString = " AND jumpType.startIn == 0 AND jump.Type == jumpType.name "; 
                }
 
@@ -297,13 +311,14 @@ class SqliteStat : Sqlite
                }
                //if multisession, order by person.name, sessionID for being able to present results later
                if(multisession) {
-                       orderByString = orderByString + tp + ".name, sessionID, ";
+                       orderByString = orderByString + tp + ".name, jump.sessionID, ";
                }
                
                dbcon.Open();
-               dbcmd.CommandText = "SELECT " + tp + ".name, " + tp + ".sex, sessionID, " + moreSelect +
+               dbcmd.CommandText = "SELECT " + tp + ".name, " + tp + ".sex, jump.sessionID, " + moreSelect +
                        fromString +
                        sessionString +
+                       personSessionString +
                        jumpTypeString +
                        " AND jump.personID == " + tp + ".uniqueID " +
                        groupByString +
@@ -322,6 +337,7 @@ class SqliteStat : Sqlite
                string returnTvString = "";
                string returnTcString = "";
                string returnFallString = "";
+               string returnWeightString = "";
                ArrayList myArray = new ArrayList(2);
                while(reader.Read()) {
                        if(showSex) {
@@ -344,6 +360,11 @@ class SqliteStat : Sqlite
                                returnTvString = ":" + Util.ChangeDecimalSeparator(reader[4].ToString());
                                returnTcString = ":" + Util.ChangeDecimalSeparator(reader[5].ToString());
                                returnFallString = ":" + reader[6].ToString();
+                               
+                               returnWeightString = "";
+                               if (indexType == "djPower")
+                                       returnWeightString = ":" + 
Util.ChangeDecimalSeparator(reader[7].ToString());
+
                        }
 
                        myArray.Add (reader[0].ToString() + showSexString + showJumpTypeString +
@@ -352,7 +373,8 @@ class SqliteStat : Sqlite
                                        returnHeightString +                    //height
                                        returnTvString +                        //tv
                                        returnTcString +                        //tc
-                                       returnFallString                        //fall
+                                       returnFallString +                      //fall
+                                       returnWeightString
                                    );
                }
                reader.Close();
diff --git a/src/statType.cs b/src/statType.cs
index 75f3463..27bf8b0 100644
--- a/src/statType.cs
+++ b/src/statType.cs
@@ -330,6 +330,15 @@ public class StatType {
                                else 
                                        myStat = new StatDjQ(myStatTypeStruct, treeview_stats);
                                                        //heightPreferred is not used, check this
+                       
+                       } else if(statisticSubType == Constants.DjPowerFormula)
+                       {
+                               if(graph) 
+                                       myStat = new GraphDjPower (myStatTypeStruct);
+                                                       //heightPreferred is not used, check this
+                               else 
+                                       myStat = new StatDjPower(myStatTypeStruct, treeview_stats);
+                                                       //heightPreferred is not used, check this
                        }
                }
                else if(statisticType == Constants.TypeJumpsReactive) {
diff --git a/src/stats/djPower.cs b/src/stats/djPower.cs
new file mode 100644
index 0000000..973e7f5
--- /dev/null
+++ b/src/stats/djPower.cs
@@ -0,0 +1,139 @@
+/*
+ * 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-2014   Xavier de Blas <xaviblas gmail com> 
+ */
+
+using System;
+using System.Data;
+using Gtk;
+using System.Collections; //ArrayList
+using Mono.Unix;
+
+
+public class StatDjPower : Stat
+{
+       protected string [] columnsString = { 
+               Catalog.GetString("Jumper"), 
+               Catalog.GetString("Power"), 
+               Catalog.GetString("Height"), 
+               Catalog.GetString("TF"), 
+               Catalog.GetString("TC"), 
+               Catalog.GetString("Fall"),
+               Catalog.GetString("Weight")
+       };
+       
+       //if this is not present i have problems like (No overload for method `xxx' takes `0' arguments) with 
some inherited classes
+       public StatDjPower () 
+       {
+               this.showSex = false;
+               this.statsJumpsType = 0;
+               this.limit = 0;
+       }
+
+       public StatDjPower (StatTypeStruct myStatTypeStruct, Gtk.TreeView treeview) 
+       {
+               completeConstruction (myStatTypeStruct, treeview);
+               
+               this.dataColumns = 6;   //for simplesession (index, height, tv, tc, fall, weight)
+               
+               if(sessions.Count > 1) {
+                       store = getStore(sessions.Count +3); //+3 (for jumper, the AVG horizontal and SD 
horizontal)
+               } else {
+                       store = getStore(dataColumns +1); //jumper, index, height, tv, tc, fall, weight
+               }
+               
+               if(toReport) {
+                       reportString = prepareHeadersReport(columnsString);
+               } else {
+                       treeview.Model = store;
+                       prepareHeaders(columnsString);
+               }
+       }
+       
+       public override void PrepareData() 
+       {
+               string sessionString = obtainSessionSqlString(sessions, "jump");
+               bool multisession = false;
+               if(sessions.Count > 1) {
+                       multisession = true;
+               }
+
+               string indexType = "djPower";
+               if(statsJumpsType == 3) { //avg of each jumper
+                       if(multisession) {
+                               string operation = "AVG";
+                               processDataMultiSession ( 
+                                               SqliteStat.DjIndexes(indexType, sessionString, multisession, 
+                                                       operation, jumpType, showSex), 
+                                               true, sessions.Count);
+                       } else {
+                               string operation = "AVG";
+                               processDataSimpleSession ( cleanDontWanted (
+                                                       SqliteStat.DjIndexes(indexType, sessionString, 
multisession, 
+                                                               operation, jumpType, showSex), 
+                                                       statsJumpsType, limit),
+                                               true, dataColumns);
+                       }
+               } else {
+                       //if more than on session, show only the avg or max of each jump/jumper
+                       if(multisession) {
+                               string operation = "MAX";
+                               processDataMultiSession ( SqliteStat.DjIndexes(indexType, sessionString, 
multisession, 
+                                                       operation, jumpType, showSex),  
+                                               true, sessions.Count);
+                       } else {
+                               string operation = ""; //no need of "MAX", there's an order by jump.tv desc
+                                                       //and clenaDontWanted will do his work
+                               processDataSimpleSession ( cleanDontWanted (
+                                                       SqliteStat.DjIndexes(indexType, sessionString, 
multisession, 
+                                                               operation, jumpType, showSex), 
+                                                       statsJumpsType, limit),
+                                               true, dataColumns);
+                       }
+               }
+       }
+               
+       public override string ToString () 
+       {
+               string selectedValuesString = "";
+               if(statsJumpsType == 0) { //all jumps
+                       selectedValuesString = allValuesString; 
+               } else if(statsJumpsType == 1) { //limit
+                       selectedValuesString = string.Format(Catalog.GetPluralString(
+                                               "First value", "First {0} values", limit), limit);
+               } else if(statsJumpsType == 2) { //best of each jumper
+                       selectedValuesString = string.Format(Catalog.GetPluralString(
+                                               "Max value of each person", "Max {0} values of each person", 
limit), limit);
+               } else if(statsJumpsType == 3) { //avg of each jumper
+                       selectedValuesString = avgValuesString; 
+               }  
+
+               string mySessionString = "";
+               if(sessions.Count > 1) {
+                       mySessionString =  Catalog.GetString (" various sessions "); 
+               } else {
+                       string [] strFull = sessions[0].ToString().Split(new char[] {':'});
+                       mySessionString =  Catalog.GetString (" session ") + 
+                               strFull[0] + "(" + strFull[2] + ")";
+               }
+
+               return string.Format(Catalog.GetString("{0} in Dj Power [mass * g * (fallHeight + 1.226 * 
(tv^2) ) / (tc+tv)] applied to {1} on {2}"), selectedValuesString, jumpType, mySessionString);
+       }
+}
+
+
diff --git a/src/stats/graphs/djPower.cs b/src/stats/graphs/djPower.cs
new file mode 100644
index 0000000..c51270e
--- /dev/null
+++ b/src/stats/graphs/djPower.cs
@@ -0,0 +1,190 @@
+/*
+ * 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-2014   Xavier de Blas <xaviblas gmail com> 
+ */
+
+using System;
+using System.Data;
+using Gtk;
+using System.Collections; //ArrayList
+using System.Drawing;
+using System.Drawing.Imaging;
+using Mono.Unix;
+
+public class GraphDjPower : StatDjPower
+{
+       protected string operation;
+
+       //for simplesession
+       GraphSerie serieIndex;
+       GraphSerie serieHeight;
+       GraphSerie serieTc;
+       GraphSerie serieTv;
+       GraphSerie serieFall;
+       GraphSerie serieWeight;
+
+       public GraphDjPower (StatTypeStruct myStatTypeStruct) 
+       {
+               completeConstruction (myStatTypeStruct, treeview);
+               
+               this.dataColumns = 6; //for Simplesession (index, height, tv, tc, fall, weight)
+               
+               if (statsJumpsType == 2) {
+                       this.operation = "MAX";
+               } else {
+                       this.operation = "AVG";
+               }
+
+               CurrentGraphData.WindowTitle = Catalog.GetString("ChronoJump graph");
+               //title is shown on the graph except it's a report, then title will be on the html
+               if(myStatTypeStruct.ToReport) {
+                       CurrentGraphData.GraphTitle = "";
+               } else {
+                       //CurrentGraphData.GraphTitle = this.ToString();
+                       CurrentGraphData.GraphTitle = Constants.DjPowerFormula;
+               }
+               
+               if(sessions.Count == 1) {
+                       //four series, the four columns
+                       serieIndex = new GraphSerie();
+                       serieHeight = new GraphSerie();
+                       serieTc = new GraphSerie();
+                       serieTv = new GraphSerie();
+                       serieFall = new GraphSerie();
+                       serieWeight = new GraphSerie();
+                               
+                       serieIndex.Title = Catalog.GetString("Dj Index");
+                       serieHeight.Title = Catalog.GetString("Height");
+                       serieTc.Title = Catalog.GetString("TC");
+                       serieTv.Title = Catalog.GetString("TF");
+                       serieFall.Title = Catalog.GetString("Fall");
+                       serieWeight.Title = Catalog.GetString("Weight");
+                       
+                       serieIndex.IsLeftAxis = false;
+                       serieHeight.IsLeftAxis = false;
+                       serieTc.IsLeftAxis = true;
+                       serieTv.IsLeftAxis = true;
+                       serieFall.IsLeftAxis = false;
+                       serieWeight.IsLeftAxis = false;
+
+                       CurrentGraphData.LabelLeft = 
+                               Catalog.GetString("TC") + "(s), " +
+                               Catalog.GetString("TF") + "(s)";
+                       CurrentGraphData.LabelRight = 
+                               Catalog.GetString("Index") + "(%), " +
+                               Catalog.GetString("Height") + "(cm), " +
+                               Catalog.GetString("Fall") + "(cm), " +
+                               Catalog.GetString("Weight") + "(Kg)";
+               } else {
+                       for(int i=0; i < sessions.Count ; i++) {
+                               string [] stringFullResults = sessions[i].ToString().Split(new char[] {':'});
+                               CurrentGraphData.XAxisNames.Add(stringFullResults[1].ToString());
+                       }
+                       CurrentGraphData.LabelLeft = Catalog.GetString("Power") + "(W)";
+                       CurrentGraphData.LabelRight = "";
+               }
+       }
+
+       protected override void printData (string [] statValues) 
+       {
+               //values are recorded for calculating later AVG and SD
+               recordStatValues(statValues);
+
+               if(sessions.Count == 1) {
+                       int i = 0;
+                       bool foundAVG = false;
+                       //we need to save this transposed
+                       foreach (string myValue in statValues) 
+                       {
+                               if(i == 0) {
+                                       //don't plot AVG and SD rows
+                                       if( myValue == Catalog.GetString("AVG")) 
+                                               foundAVG = true;
+                                       else
+                                               CurrentGraphData.XAxisNames.Add(myValue);
+                               } else if(i == 1) {
+                                       if(foundAVG)
+                                               serieIndex.Avg = Convert.ToDouble(myValue);
+                                       else
+                                               serieIndex.SerieData.Add(myValue);
+                               } else if(i == 2) {
+                                       if(foundAVG)
+                                               serieHeight.Avg = Convert.ToDouble(myValue);
+                                       else
+                                               serieHeight.SerieData.Add(myValue);
+                               } else if(i == 3) {
+                                       if(foundAVG)
+                                               serieTv.Avg = Convert.ToDouble(myValue);
+                                       else
+                                               serieTv.SerieData.Add(myValue);
+                               } else if(i == 4) {
+                                       if(foundAVG)
+                                               serieTc.Avg = Convert.ToDouble(myValue);
+                                       else
+                                               serieTc.SerieData.Add(myValue);
+                               } else if(i == 5) {
+                                       if(foundAVG)
+                                               serieFall.Avg = Convert.ToDouble(myValue);
+                                       else
+                                               serieFall.SerieData.Add(myValue);
+                               } else if(i == 6) {
+                                       if(foundAVG)
+                                               serieWeight.Avg = Convert.ToDouble(myValue);
+                                       else
+                                               serieWeight.SerieData.Add(myValue);
+                               }
+
+                               if(foundAVG && i == dataColumns) {
+                                       //add created series to GraphSeries ArrayList
+                                       //check don't do it two times
+                                       if(GraphSeries.Count == 0) {
+                                               GraphSeries.Add(serieTc);
+                                               GraphSeries.Add(serieTv);
+                                               GraphSeries.Add(serieIndex);
+                                               GraphSeries.Add(serieHeight);
+                                               GraphSeries.Add(serieFall);
+                                               GraphSeries.Add(serieWeight);
+                                       }
+                                       return;
+                               }
+
+                               i++;
+                       }
+               } else {
+                       GraphSerie mySerie = new GraphSerie();
+                       mySerie.IsLeftAxis = true;
+               
+                       int i=0;
+                       foreach (string myValue in statValues) {
+                               if( myValue == Catalog.GetString("SD") ) 
+                                       return;
+                               
+                               if(i == 0) 
+                                       mySerie.Title = myValue;
+                               else if( i == sessions.Count + 1 ) { //eg, for 2 sessions: [(0)person name, 
(1)sess1, (2)sess2, (3)AVG]
+                                       if(myValue != "-")
+                                               mySerie.Avg = Convert.ToDouble(myValue);
+                               } else 
+                                       mySerie.SerieData.Add(myValue);
+                               
+                               i++;
+                       }
+                       GraphSeries.Add(mySerie);
+               }
+       }
+}
diff --git a/src/treeViewJump.cs b/src/treeViewJump.cs
index 2daa539..01a94b4 100644
--- a/src/treeViewJump.cs
+++ b/src/treeViewJump.cs
@@ -209,7 +209,7 @@ public class TreeViewJumps : TreeViewEvent
                        myData[count++] = 
Util.TrimDecimals(Util.GetHeightInCentimeters(newJump.Tv.ToString()), pDN);
 
                
-               
+               Log.WriteLine("personWeight: " + personWeight.ToString());              
 
 
                if (showPower)  {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]