[chronojump] stat subtraction between jump types works (graph pending)



commit a9a2c04596590f40cb75511f8a92a47eb8d54495
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Feb 22 13:55:01 2011 +0100

    stat subtraction between jump types works (graph pending)

 glade/chronojump.glade             |    9 ++--
 po/POTFILES.in                     |    1 +
 src/Makefile.am                    |    1 +
 src/sqlite/stat.cs                 |   77 ++++++++++++++++++++++++++++++++++++
 src/statType.cs                    |   58 ++++++++++++---------------
 src/stats/fv.cs                    |    2 +-
 src/stats/jumpSimpleSubtraction.cs |   21 +++++-----
 src/stats/main.cs                  |    8 ++-
 8 files changed, 125 insertions(+), 52 deletions(-)
---
diff --git a/glade/chronojump.glade b/glade/chronojump.glade
index e832f6d..69a59e0 100644
--- a/glade/chronojump.glade
+++ b/glade/chronojump.glade
@@ -3828,11 +3828,9 @@ options</property>
                   </packing>
                 </child>
                 <child>
-                  <placeholder/>
-                </child>
-                <child>
                   <widget class="GtkHBox" id="hbox_subtraction_between">
                     <property name="visible">True</property>
+                    <property name="spacing">8</property>
                     <child>
                       <widget class="GtkHBox" id="hbox_subtraction_between_1">
                         <property name="visible">True</property>
@@ -3853,6 +3851,7 @@ options</property>
                         <property name="use_markup">True</property>
                       </widget>
                       <packing>
+                        <property name="expand">False</property>
                         <property name="fill">False</property>
                         <property name="position">1</property>
                       </packing>
@@ -3876,7 +3875,6 @@ options</property>
                     <property name="right_attach">2</property>
                     <property name="top_attach">4</property>
                     <property name="bottom_attach">5</property>
-                    <property name="x_options">GTK_FILL</property>
                     <property name="y_options"></property>
                   </packing>
                 </child>
@@ -3894,6 +3892,9 @@ options</property>
                     <property name="y_options"></property>
                   </packing>
                 </child>
+                <child>
+                  <placeholder/>
+                </child>
               </widget>
               <packing>
                 <property name="tab_fill">False</property>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 7614d64..ac2812a 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -66,6 +66,7 @@ src/stats/graphs/runSimple.cs
 src/stats/graphs/sjCmjAbk.cs
 src/stats/graphs/sjCmjAbkPlus.cs
 src/stats/ieIub.cs
+src/stats/jumpSimpleSubtraction.cs
 src/stats/main.cs
 src/stats/rjAVGSD.cs
 src/stats/rjEvolution.cs
diff --git a/src/Makefile.am b/src/Makefile.am
index fb1f1f5..4196775 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -107,6 +107,7 @@ FILES = \
  	stats/sjCmjAbkPlus.cs\
  	stats/djIndex.cs\
  	stats/djQ.cs\
+ 	stats/jumpSimpleSubtraction.cs\
  	stats/rjIndex.cs\
  	stats/rjPotencyBosco.cs\
  	stats/rjEvolution.cs\
diff --git a/src/sqlite/stat.cs b/src/sqlite/stat.cs
index 5b42dc0..2d1bde3 100644
--- a/src/sqlite/stat.cs
+++ b/src/sqlite/stat.cs
@@ -800,6 +800,82 @@ class SqliteStat : Sqlite
 		dbcon.Close();
 		return myArray;
 	}
+	
+	//is the same as IeIub except the moreSelect lines
+	public static ArrayList JumpSimpleSubtraction (string sessionString, bool multisession, string ini, string end, string jump1, string jump2, bool showSex)
+	{
+		string tp = Constants.PersonTable;
+		string orderByString = "ORDER BY ";
+		string moreSelect = ""; 
+		
+		//*1.0 for having double division
+		if(ini == "MAX(") {
+			//search MAX of two jumps, not max index!!
+			moreSelect = " (MAX(j1.tv) - MAX(j2.tv)) AS myIndex, " +
+				"MAX(j1.tv), MAX(j2.tv) ";
+		} else if(ini == "AVG(") {
+			moreSelect = " (AVG(j1.tv) - AVG(j2.tv)) AS myIndex, " +
+				"AVG(j1.tv), AVG(j2.tv)";
+		}
+
+		//if we use AVG or MAX, then we have to group by the results
+		//if there's more than one session, it sends the avg or max
+		string groupByString = "";
+		if (ini.Length > 0) {
+			groupByString = " GROUP BY j1.personID, j1.sessionID ";
+		}
+		//if multisession, order by person.name, sessionID for being able to present results later
+		if(multisession) {
+			orderByString = orderByString + tp + ".name, j1.sessionID, ";
+		}
+		
+		dbcon.Open();
+		dbcmd.CommandText = "SELECT " + tp + ".name, " + tp + ".sex, j1.sessionID, " + moreSelect +
+			" FROM jump AS j1, jump AS j2, " + tp + " " +
+			sessionString +
+			" AND j1.type == '" + jump1 + "' " +
+			" AND j2.type == '" + jump2 + "' " +
+			" AND j1.personID == " + tp + ".uniqueID " +
+			" AND j2.personID == " + tp + ".uniqueID " +
+			groupByString +
+			orderByString + " myIndex DESC ";
+
+		Log.WriteLine(dbcmd.CommandText.ToString());
+		dbcmd.ExecuteNonQuery();
+		
+		SqliteDataReader reader;
+		reader = dbcmd.ExecuteReader();
+		
+		string showSexString = "";
+		string returnSessionString = "";
+		string returnJump1String = "";
+		string returnJump2String = "";
+		ArrayList myArray = new ArrayList(2);
+		while(reader.Read()) {
+			if(showSex) {
+				showSexString = "." + reader[1].ToString() ;
+			}
+			if(multisession) {
+				returnSessionString = ":" + reader[2].ToString();
+			} else {
+				//in multisession we show only one column x session
+				//in simplesession we show all
+				
+				returnJump1String = ":" + Util.ChangeDecimalSeparator(reader[4].ToString());
+				returnJump2String = ":" + Util.ChangeDecimalSeparator(reader[5].ToString());
+			}
+			myArray.Add (reader[0].ToString() + showSexString +
+					returnSessionString + ":" + 		//session
+					Util.ChangeDecimalSeparator(reader[3].ToString()) +			//index
+					returnJump1String + 			//jump1
+					returnJump2String  			//jump2
+				    );
+		}
+		reader.Close();
+		dbcon.Close();
+		return myArray;
+	}
+
 
 	public static ArrayList Fv (string sessionString, bool multisession, string ini, string end, string jump1, string jump2, bool showSex)
 	{
@@ -1146,6 +1222,7 @@ class SqliteStat : Sqlite
 		return myArray;
 	}
 	
+	
 	/*
 	public static ArrayList GlobalNormal (string sessionString, string operation, bool sexSeparated, 
 			int personID, bool heightPreferred)
diff --git a/src/statType.cs b/src/statType.cs
index 0047c23..425da4b 100644
--- a/src/statType.cs
+++ b/src/statType.cs
@@ -238,9 +238,9 @@ public class StatType {
 					indexType = "subtraction";
 				else if(statisticSubType == Constants.IeIndexFormula) 
 					indexType = "IE";
-				else if(statisticSubType == Constants.IubIndexFormula) {
+				else if(statisticSubType == Constants.IubIndexFormula) 
 					indexType = "IUB";
-				else if(statisticSubType == Constants.FvIndexFormula) {
+				else if(statisticSubType == Constants.FvIndexFormula) 
 					indexType = "F/V";
 				else if(
 						statisticSubType == Constants.PotencyLewisFormula ||
@@ -261,7 +261,8 @@ public class StatType {
 			
 				if(indexType == "subtraction") {
 					if(graph) 
-//						myStat = new GraphStatJumpSimpleSubtraction (myStatTypeStruct);
+						//myStat = new GraphStatJumpSimpleSubtraction (myStatTypeStruct);
+						myStat = new StatJumpSimpleSubtraction(myStatTypeStruct, treeview_stats); 
 					else 
 						myStat = new StatJumpSimpleSubtraction(myStatTypeStruct, treeview_stats); 
 				} else if(indexType == "IE" || indexType == "IUB") {
@@ -289,17 +290,15 @@ public class StatType {
 				if(myType.HasWeight || 
 						statisticApplyTo == Constants.AllJumpsName) 
 				{
-					if(graph) {
+					if(graph) 
 						myStat = new GraphSjCmjAbkPlus (myStatTypeStruct);
-					} else {
+					else 
 						myStat = new StatSjCmjAbkPlus (myStatTypeStruct, treeview_stats);
-					}
 				} else {
-					if(graph) {
+					if(graph) 
 						myStat = new GraphSjCmjAbk (myStatTypeStruct);
-					} else {
+					else 
 						myStat = new StatSjCmjAbk (myStatTypeStruct, treeview_stats);
-					}
 				}
 			}
 		}
@@ -312,64 +311,58 @@ public class StatType {
 			
 			if(statisticSubType == Constants.DjIndexFormula)
 			{
-				if(graph) {
+				if(graph) 
 					myStat = new GraphDjIndex (myStatTypeStruct);
 							//heightPreferred is not used, check this
-				} else {
+				else 
 					myStat = new StatDjIndex(myStatTypeStruct, treeview_stats);
 							//heightPreferred is not used, check this
-				}
+				
 			} else if(statisticSubType == Constants.QIndexFormula)
 			{
-				if(graph) {
+				if(graph) 
 					myStat = new GraphDjQ (myStatTypeStruct);
 							//heightPreferred is not used, check this
-				} else {
+				else 
 					myStat = new StatDjQ(myStatTypeStruct, treeview_stats);
 							//heightPreferred is not used, check this
-				}
 			}
 		}
 		else if(statisticType == Constants.TypeJumpsReactive) {
 			if(statisticSubType == Catalog.GetString("Average Index"))
 			{
-				if(graph) {
+				if(graph) 
 					myStat = new GraphRjIndex (myStatTypeStruct);
-				} else {
+				else 
 					myStat = new StatRjIndex(myStatTypeStruct, treeview_stats);
-				}
 			}	
 			else if(statisticSubType == Constants.RJPotencyBoscoFormula)
 			{
-				if(graph) {
+				if(graph) 
 					myStat = new GraphRjPotencyBosco (myStatTypeStruct);
-				} else {
+				else 
 					myStat = new StatRjPotencyBosco(myStatTypeStruct, treeview_stats);
-				}
 			}
 			else if(statisticSubType == Catalog.GetString("Evolution"))
 			{
-				if(graph) {
+				if(graph) 
 					myStat = new GraphRjEvolution (myStatTypeStruct, rj_evolution_mark_consecutives);
-				} else {
+				else 
 					myStat = new StatRjEvolution(myStatTypeStruct, rj_evolution_mark_consecutives, treeview_stats);
-				}
 			}
 			else if(statisticSubType == Constants.RJAVGSDRjIndexName)
 			{
-				if(graph) {
+				if(graph) 
 					myStat = new GraphRjAVGSD(myStatTypeStruct, Constants.RjIndexName);
-				} else {
+				else
 					myStat = new StatRjAVGSD(myStatTypeStruct, treeview_stats, Constants.RjIndexName);
-				}
 			}
 			else if(statisticSubType == Constants.RJAVGSDQIndexName)
 			{
-				if(graph) {
+				if(graph) 
 					myStat = new GraphRjAVGSD(myStatTypeStruct, Constants.QIndexName);
-				} else {
+				else
 					myStat = new StatRjAVGSD(myStatTypeStruct, treeview_stats, Constants.QIndexName);
-				}
 			}
 		}
 		else if(statisticType == Constants.TypeRunsSimple)
@@ -379,11 +372,10 @@ public class StatType {
 				return false;
 			}
 		
-			if(graph) {
+			if(graph) 
 				myStat = new GraphRunSimple (myStatTypeStruct);
-			} else {
+			else
 				myStat = new StatRunSimple (myStatTypeStruct, treeview_stats);
-			}
 		}
 		
 		myStat.FakeButtonRowCheckedUnchecked.Clicked += 
diff --git a/src/stats/fv.cs b/src/stats/fv.cs
index 2eb9053..0837ccb 100644
--- a/src/stats/fv.cs
+++ b/src/stats/fv.cs
@@ -62,7 +62,7 @@ public class StatFv : StatIeIub
 	
 	public override void PrepareData() 
 	{
-		string sessionString = obtainSessionSqlStringIndexes(sessions);
+		string sessionString = obtainSessionSqlStringTwoTests(sessions);
 		bool multisession = false;
 		if(sessions.Count > 1) {
 			multisession = true;
diff --git a/src/stats/jumpSimpleSubtraction.cs b/src/stats/jumpSimpleSubtraction.cs
index 3950bfb..81de26f 100644
--- a/src/stats/jumpSimpleSubtraction.cs
+++ b/src/stats/jumpSimpleSubtraction.cs
@@ -25,29 +25,29 @@ using System.Collections; //ArrayList
 using Mono.Unix;
 
 
-public class StatJumpsSimpleSubtraction : Stat
+public class StatJumpSimpleSubtraction : Stat
 {
 	protected string test1;
 	protected string test2;
 	protected string [] columnsString = new String[4];
 	
 	//if this is not present i have problems like (No overload for method `xxx' takes `0' arguments) with some inherited classes
-	public StatJumpsSimpleSubtraction () 
+	public StatJumpSimpleSubtraction () 
 	{
 		this.showSex = false;
 		this.statsJumpsType = 0;
 		this.limit = 0;
 	}
 
-	public StatJumpsSimpleSubtraction (StatTypeStruct myStatTypeStruct, Gtk.TreeView treeview)
+	public StatJumpSimpleSubtraction (StatTypeStruct myStatTypeStruct, Gtk.TreeView treeview)
 	{
 		completeConstruction (myStatTypeStruct, treeview);
 		
 		this.dataColumns = 3;	//for simplesession (result, test1, test2)
 
 		string [] applyTos = myStatTypeStruct.StatisticApplyTo.Split(new char[] {':'});
-		test1 = applyTos[0]
-		test2 = applyTos[1]
+		test1 = applyTos[0];
+		test2 = applyTos[1];
 		
 		if(sessions.Count > 1) {
 			store = getStore(sessions.Count +3); //+3 (for jumper, the AVG horizontal and SD horizontal)
@@ -79,11 +79,11 @@ public class StatJumpsSimpleSubtraction : Stat
 		if(statsJumpsType == 3) { //avg of each jumper
 			if(multisession) {
 				processDataMultiSession ( 
-						SqliteStat.JumpsSimpleSubtraction(sessionString, multisession, "AVG(", ")", test1, test2, showSex), 
+						SqliteStat.JumpSimpleSubtraction(sessionString, multisession, "AVG(", ")", test1, test2, showSex), 
 						true, sessions.Count);
 			} else {
 				processDataSimpleSession ( cleanDontWanted (
-							SqliteStat.JumpsSimpleSubtraction(sessionString, multisession, "AVG(", ")", test1, test2, showSex), 
+							SqliteStat.JumpSimpleSubtraction(sessionString, multisession, "AVG(", ")", test1, test2, showSex), 
 							statsJumpsType, limit),
 						true, dataColumns);
 			}
@@ -91,10 +91,10 @@ public class StatJumpsSimpleSubtraction : Stat
 			//if more than on session, show only the avg or max of each jump/jumper
 			//some of this options are never called becase we don't allow radiobutton all and limit (only avg and best)
 			if(multisession) {
-				processDataMultiSession ( SqliteStat.JumpsSimpleSubtraction(sessionString, multisession, "MAX(", ")", test1, test2, showSex),  
+				processDataMultiSession ( SqliteStat.JumpSimpleSubtraction(sessionString, multisession, "MAX(", ")", test1, test2, showSex),  
 						true, sessions.Count);
 			} else {
-				processDataSimpleSession ( SqliteStat.JumpsSimpleSubtraction(sessionString, multisession, "MAX(", ")", test1, test2, showSex), 
+				processDataSimpleSession ( SqliteStat.JumpSimpleSubtraction(sessionString, multisession, "MAX(", ")", test1, test2, showSex), 
 						true, dataColumns);
 			}
 		}
@@ -122,7 +122,6 @@ public class StatJumpsSimpleSubtraction : Stat
 				strFull[0] + "(" + strFull[2] + ")";
 		}
 
-		string indexString = "IE [(cmj-sj)/sj * 100]";
-		return string.Format(Catalog.GetString("{0} in test {1} - {2} on {3}"), selectedValuesString, test1, test2, mySessionString);
+		return string.Format(Catalog.GetString("{0} in test {1} - test {2} on {3}"), selectedValuesString, test1, test2, mySessionString);
 	}
 }
diff --git a/src/stats/main.cs b/src/stats/main.cs
index fdee9c7..fe34036 100644
--- a/src/stats/main.cs
+++ b/src/stats/main.cs
@@ -424,19 +424,21 @@ public class Stat
 		return newStr;		
 	}
 	
-	protected string obtainSessionSqlStringTwoTests(ArrayList sessions, string tableName)
+	protected string obtainSessionSqlStringTwoTests(ArrayList sessions)
 	{
 		string newStr = "WHERE (";
 		for (int i=0; i < sessions.Count; i++) {
 			string [] stringFullResults = sessions[i].ToString().Split(new char[] {':'});
-			newStr = newStr + " " + tableName + ".sessionID == " + stringFullResults[0];
+			newStr = newStr + " (j1.sessionID == " + stringFullResults[0] +
+				" AND j2.sessionID == " + stringFullResults[0] + ")";
 			if (i+1 < sessions.Count) {
 				newStr = newStr + " OR ";
 			}
 		}
 		newStr = newStr + ") ";
-		return newStr;		
+		return newStr;
 	}
+
 	
 	public virtual void PrepareData () {
 	}



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