[chronojump] 0.80 Added initialSpeed tag on runs, rI (remaining gui/edit) and test



commit 65bc15ff1c84cc80cf80e2312487be64f8ef24ab
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Mar 8 18:32:48 2011 +0100

    0.80 Added initialSpeed tag on runs, rI (remaining gui/edit) and test

 src/execute/run.cs        |   17 +++++++++--------
 src/exportSession.cs      |   26 ++++++++++++++++----------
 src/run.cs                |   20 ++++++++++++++++----
 src/sqlite/main.cs        |   45 ++++++++++++++++++++++++++++++++++++++++++---
 src/sqlite/run.cs         |   14 ++++++++------
 src/sqlite/runInterval.cs |   16 ++++++++++------
 src/util.cs               |    7 +++++++
 7 files changed, 108 insertions(+), 37 deletions(-)
---
diff --git a/src/execute/run.cs b/src/execute/run.cs
index 48c5a1f..3589d37 100644
--- a/src/execute/run.cs
+++ b/src/execute/run.cs
@@ -29,11 +29,8 @@ public class RunExecute : EventExecute
 {
 	protected double distance;
 	protected double time;
-
-	//for not checking always in database
 	protected bool startIn;
 	
-	
 	protected Chronopic cp;
 	//private Chronopic cp; //thi doesn't work
 	protected bool metersSecondsPreferred;
@@ -317,10 +314,12 @@ Log.WriteLine("MANAGE(3)!!!!");
 
 		uniqueID = SqliteRun.Insert(false, Constants.RunTable, "NULL", personID, sessionID, 
 				type, distance, time, description, 
-				Util.BoolToNegativeInt(simulated)); 
+				Util.BoolToNegativeInt(simulated), 
+				!startIn	//initialSpeed true if not startIn
+				); 
 		
 		//define the created object
-		eventDone = new Run(uniqueID, personID, sessionID, type, distance, time, description, Util.BoolToNegativeInt(simulated)); 
+		eventDone = new Run(uniqueID, personID, sessionID, type, distance, time, description, Util.BoolToNegativeInt(simulated), !startIn); 
 		
 		
 		//event will be raised, and managed in chronojump.cs
@@ -781,7 +780,8 @@ public class RunIntervalExecute : RunExecute
 					distanceInterval, intervalTimesString, tracks, 
 					description,
 					limitString,
-					Util.BoolToNegativeInt(simulated) 
+					Util.BoolToNegativeInt(simulated),
+					!startIn	//initialSpeed true if not startIn
 					);
 		else {
 			uniqueID = SqliteRunInterval.Insert(false, Constants.RunIntervalTable, "NULL", personID, sessionID, type, 
@@ -789,11 +789,12 @@ public class RunIntervalExecute : RunExecute
 					distanceInterval, intervalTimesString, tracks, 
 					description,
 					limitString,
-					Util.BoolToNegativeInt(simulated) 
+					Util.BoolToNegativeInt(simulated),
+					!startIn
 					);
 
 			//define the created object
-			eventDone = new RunInterval(uniqueID, personID, sessionID, type, distanceTotal, timeTotal, distanceInterval, intervalTimesString, tracks, description, limitString, Util.BoolToNegativeInt(simulated)); 
+			eventDone = new RunInterval(uniqueID, personID, sessionID, type, distanceTotal, timeTotal, distanceInterval, intervalTimesString, tracks, description, limitString, Util.BoolToNegativeInt(simulated), !startIn); 
 
 
 			string tempValuesString = "";
diff --git a/src/exportSession.cs b/src/exportSession.cs
index ad2e00b..e06dadd 100644
--- a/src/exportSession.cs
+++ b/src/exportSession.cs
@@ -91,7 +91,7 @@ public class ExportSession
 				//add ".csv" if needed
 				fileName = addCsvIfNeeded(fileName);
 			}
-			try {
+//			try {
 				if (File.Exists(fileName)) {
 					Log.WriteLine(string.Format("File {0} exists with attributes {1}, created at {2}", 
 								fileName, File.GetAttributes(fileName), File.GetCreationTime(fileName)));
@@ -107,11 +107,11 @@ public class ExportSession
 					string myString = string.Format(Catalog.GetString("Saved to {0}"), fileName) + spreadsheetString;
 					new DialogMessage(Constants.MessageTypes.INFO, myString);
 				}
-			} 
-			catch {
-				string myString = string.Format(Catalog.GetString("Cannot export to file {0} "), fileName);
-				new DialogMessage(Constants.MessageTypes.WARNING, myString);
-			}
+//			} 
+//			catch {
+//				string myString = string.Format(Catalog.GetString("Cannot export to file {0} "), fileName);
+//				new DialogMessage(Constants.MessageTypes.WARNING, myString);
+//			}
 		}
 		else {
 			Log.WriteLine("cancelled");
@@ -487,7 +487,8 @@ public class ExportSession
 					Catalog.GetString("Time") + ":" + 
 					Catalog.GetString("Speed") + ":" + 
 					Catalog.GetString("Description") + ":" +
-					Catalog.GetString("Simulated") );
+					Catalog.GetString("Simulated") + ":" +
+					Catalog.GetString("Initial Speed") );
 
 			foreach (string runString in myRuns) {
 				string [] myStr = runString.Split(new char[] {':'});
@@ -501,7 +502,9 @@ public class ExportSession
 						myStr[4] + ":" +  myStr[5] + ":" + 	//run.type, run.distance
 						Util.TrimDecimals(myStr[6], dec) + ":" +  	//run.time
 						speed + ":" + 				//speed in m/s (true)
-						Util.RemoveNewLine(myStr[7]) + ":" + Util.SimulatedTestNoYes(Convert.ToInt32(myStr[8])) //description, simulated
+						Util.RemoveNewLine(myStr[7]) + ":" + 	//description
+						Util.SimulatedTestNoYes(Convert.ToInt32(myStr[8])) + ":" + //simulated
+						Util.NoYes(Util.StringToBool(myStr[9]))	//initialSpeed
 					   );
 			}
 			writeData(myData);
@@ -539,7 +542,8 @@ public class ExportSession
 						Catalog.GetString("Tracks") + ":" + 
 						Catalog.GetString("Limited") + ":" +
 						Catalog.GetString("Description") + ":" +
-						Catalog.GetString("Simulated") );
+						Catalog.GetString("Simulated") + ":" +
+						Catalog.GetString("Initial Speed") );
 				isFirstHeader = false;
 			}
 
@@ -552,7 +556,9 @@ public class ExportSession
 					Util.TrimDecimals(Util.GetSpeed(myStr[5], myStr[6], true), dec) + ":" + 	//speed AVG in m/s(true)
 					myStr[7] + ":" + 	 	//run.distanceInterval
 					myStr[9] + ":" +  Util.GetLimitedRounded(myStr[11], dec) + ":" + 	//tracks, limited
-					Util.RemoveNewLine(myStr[10]) + ":" + Util.SimulatedTestNoYes(Convert.ToInt32(myStr[12]))	//description, simulated
+					Util.RemoveNewLine(myStr[10]) + ":" + 	//description
+					Util.SimulatedTestNoYes(Convert.ToInt32(myStr[12])) + ":" +	//simulated
+					Util.NoYes(Util.StringToBool(myStr[13]))	//initialSpeed
 				   );
 			
 			if(showSubruns) {
diff --git a/src/run.cs b/src/run.cs
index 17d606d..f0643d7 100644
--- a/src/run.cs
+++ b/src/run.cs
@@ -32,6 +32,7 @@ public class Run : Event
 	//for not checking always in database
 	protected bool startIn;
 	
+	protected bool initialSpeed;
 	
 	//protected Chronopic cp;
 	protected bool metersSecondsPreferred;
@@ -50,7 +51,7 @@ public class Run : Event
 	}
 
 	//after inserting database (SQL)
-	public Run(int uniqueID, int personID, int sessionID, string type, double distance, double time, string description, int simulated)
+	public Run(int uniqueID, int personID, int sessionID, string type, double distance, double time, string description, int simulated, bool initialSpeed)
 	{
 		this.uniqueID = uniqueID;
 		this.personID = personID;
@@ -60,6 +61,7 @@ public class Run : Event
 		this.time = time;
 		this.description = description;
 		this.simulated = simulated;
+		this.initialSpeed = initialSpeed;
 	}
 
 	//used to select a run at SqliteRun.SelectNormalRunData and at Sqlite.convertTables
@@ -73,6 +75,7 @@ public class Run : Event
 		this.time = Convert.ToDouble(Util.ChangeDecimalSeparator(eventString[5]));
 		this.description = eventString[6].ToString();
 		this.simulated = Convert.ToInt32(eventString[7]);
+		this.initialSpeed = Util.IntToBool(Convert.ToInt32(eventString[8]));
 	}
 	
 
@@ -81,7 +84,7 @@ public class Run : Event
 				uniqueID.ToString(), 
 				personID, sessionID, 
 				type, distance, time, 
-				description, simulated);
+				description, simulated, initialSpeed);
 	}
 
 	
@@ -111,6 +114,13 @@ public class Run : Event
 	public bool MetersSecondsPreferred {
 		set { metersSecondsPreferred = value; }
 	}
+	
+	public bool InitialSpeed
+	{
+		get { return initialSpeed; }
+		set { initialSpeed = value; }
+	}
+	
 
 	
 	~Run() {}
@@ -133,7 +143,7 @@ public class RunInterval : Run
 	}
 	
 	//after inserting database (SQL)
-	public RunInterval(int uniqueID, int personID, int sessionID, string type, double distanceTotal, double timeTotal, double distanceInterval, string intervalTimesString, double tracks, string description, string limited, int simulated)
+	public RunInterval(int uniqueID, int personID, int sessionID, string type, double distanceTotal, double timeTotal, double distanceInterval, string intervalTimesString, double tracks, string description, string limited, int simulated, bool initialSpeed)
 	{
 		this.uniqueID = uniqueID;
 		this.personID = personID;
@@ -147,6 +157,7 @@ public class RunInterval : Run
 		this.description = description;
 		this.limited = limited;
 		this.simulated = simulated;
+		this.initialSpeed = initialSpeed;
 	}
 
 	//used to select a run at SqliteRun.SelectIntervalRunData and at Sqlite.convertTables
@@ -164,6 +175,7 @@ public class RunInterval : Run
 		this.description = eventString[9].ToString();
 		this.limited = eventString[10].ToString();
 		this.simulated = Convert.ToInt32(eventString[11]);
+		this.initialSpeed = Util.IntToBool(Convert.ToInt32(eventString[12]));
 	}
 	
 
@@ -174,7 +186,7 @@ public class RunInterval : Run
 				type, distanceTotal, timeTotal, 
 				distanceInterval, intervalTimesString,
 				tracks, description, 
-				limited, simulated);
+				limited, simulated, initialSpeed);
 	}
 
 	public string IntervalTimesString
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index d0fdff8..9312d09 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -72,7 +72,7 @@ class Sqlite
 	 * Important, change this if there's any update to database
 	 * Important2: if database version get numbers higher than 1, check if the comparisons with currentVersion works ok
 	 */
-	static string lastChronojumpDatabaseVersion = "0.79";
+	static string lastChronojumpDatabaseVersion = "0.80";
 
 	public Sqlite() {
 	}
@@ -462,8 +462,10 @@ class Sqlite
 		} else {
 			Log.WriteLine("Old database, need to convert");
 			Log.WriteLine("db version: " + currentVersion);
+
 			bool needToConvertPersonToSport = false;
 			bool jumpFallAsDouble = false;
+	 		bool runAndRunIntervalInitialSpeedAdded = false;
 
 			SqliteJumpRj sqliteJumpRjObject = new SqliteJumpRj();
 			SqliteRunInterval sqliteRunIntervalObject = new SqliteRunInterval();
@@ -681,6 +683,11 @@ class Sqlite
 				arrayAngleAndSimulated.Add("-1"); //angle
 				arrayAngleAndSimulated.Add("-1"); //simulated
 				
+				//run and runInterval
+				ArrayList arraySimulatedAndInitialSpeed = new ArrayList(1);
+				arraySimulatedAndInitialSpeed.Add("-1"); //simulated
+				arraySimulatedAndInitialSpeed.Add("0"); //initial speed
+				
 				//others
 				ArrayList arraySimulated = new ArrayList(1);
 				arraySimulated.Add("-1"); //simulated
@@ -695,6 +702,8 @@ class Sqlite
 				convertTables(new SqliteRun(), Constants.RunTable, 7, arraySimulated, false);
 				conversionRate ++;
 				convertTables(new SqliteRunInterval(), Constants.RunIntervalTable, 11, arraySimulated, false);
+				runAndRunIntervalInitialSpeedAdded = true;
+				
 				conversionRate ++;
 				convertTables(new SqliteReactionTime(), Constants.ReactionTimeTable, 6, arraySimulated, false);
 				conversionRate ++;
@@ -731,7 +740,7 @@ class Sqlite
 				SqlitePreferences.Update ("databaseVersion", "0.57", true); 
 				dbcon.Close();
 				
-				Log.WriteLine("Added simulated column to each event table on client. Added to person: race, country, serverUniqueID. Convert to sport related done here if needed");
+				Log.WriteLine("Added simulated column to each event table on client. Added to person: race, country, serverUniqueID. Convert to sport related done here if needed. Added also run and runInterval initial speed");
 				currentVersion = "0.57";
 			}
 			if(currentVersion == "0.57") {
@@ -1047,6 +1056,27 @@ class Sqlite
 				dbcon.Close();
 				currentVersion = "0.79";
 			}
+			if(currentVersion == "0.79") {
+				dbcon.Open();
+
+	 			if(! runAndRunIntervalInitialSpeedAdded) {
+					ArrayList myArray = new ArrayList(1);
+					myArray.Add("0"); //initial speed
+				
+					conversionRateTotal = 3;
+					conversionRate = 1;
+					convertTables(new SqliteRun(), Constants.RunTable, 8, myArray, false);
+					conversionRate ++;
+					convertTables(new SqliteRunInterval(), Constants.RunIntervalTable, 12, myArray, false);
+					conversionRate ++;
+					Log.WriteLine("Converted DB to 0.80 (Added multimediaStorage structure)"); 
+				}
+
+				SqlitePreferences.Update ("databaseVersion", "0.80", true); 
+				
+				dbcon.Close();
+				currentVersion = "0.80";
+			}
 		}
 
 		//if changes are made here, remember to change also in CreateTables()
@@ -1179,6 +1209,7 @@ class Sqlite
 		SqliteCountry.initialize();
 		
 		//changes [from - to - desc]
+		//0.79 - 0.80 Converted DB to 0.80 Added run and runInterval initial speed (if not done in 0.56 conversion)
 		//0.78 - 0.79 Converted DB to 0.79 (Added multimediaStorage structure id)
 		//0.77 - 0.78 Converted DB to 0.78 (Added machineID to preferences, takeOffWeight has no weight in db conversions since 0.66)
 		//0.76 - 0.77 Converted DB to 0.77 (person77, personSession77)
@@ -1201,7 +1232,7 @@ class Sqlite
 		//0.59 - 0.60 added volumeOn and evaluatorServerID to preferences. Session has now serverUniqueID. Simulated now are -1, because 0 is real and positive is serverUniqueID
 		//0.58 - 0.59 Added 'showAngle' to preferences, changed angle on jump to double
 		//0.57 - 0.58 Countries without kingdom or republic (except when needed)
-		//0.56 - 0.57 Added simulated column to each event table on client. person: race, country, serverID. Convert to sport related done here if needed");
+		//0.56 - 0.57 Added simulated column to each event table on client. person: race, country, serverID. Convert to sport related done here if needed. Added also run and runInterval initial speed);
 		//0.55 - 0.56 Added session default sport stuff into session table
 		//0.54 - 0.55 Added undefined to speciallity table
 		//0.53 - 0.54 created sport tables. Added sport data, speciallity and level of practice to person table
@@ -1613,6 +1644,14 @@ class Sqlite
 
 
 
+	/*
+	 * The problem of this method is that uses class constructors: person, jump, ...
+	 * and if the sqlite version is updated from a really old version
+	 * maybe the object has to be converted from really older class to old, and then to new class (two conversions)
+	 * and this can have problems in the class construction
+	 * The best seem to have a boolean that indicates if certain conversion has done before
+	 * (see bool runAndRunIntervalInitialSpeedAdded)
+	 */
 	protected internal static void convertTables(Sqlite sqliteObject, string tableName, int columnsBefore, ArrayList columnsToAdd, bool putDescriptionInMiddle) 
 	{
 		conversionSubRate = 1;
diff --git a/src/sqlite/run.cs b/src/sqlite/run.cs
index 6b84e2d..d8ae6cf 100644
--- a/src/sqlite/run.cs
+++ b/src/sqlite/run.cs
@@ -47,7 +47,8 @@ class SqliteRun : Sqlite
 			"distance FLOAT, " +
 			"time FLOAT, " +
 			"description TEXT, " +
-			"simulated INT )";
+			"simulated INT, " +
+			"initialSpeed INT )";
 		dbcmd.ExecuteNonQuery();
 	}
 	
@@ -56,7 +57,7 @@ class SqliteRun : Sqlite
 	 * Run class methods
 	 */
 	
-	public static int Insert(bool dbconOpened, string tableName, string uniqueID, int personID, int sessionID, string type, double distance, double time, string description, int simulated)
+	public static int Insert(bool dbconOpened, string tableName, string uniqueID, int personID, int sessionID, string type, double distance, double time, string description, int simulated, bool initialSpeed)
 	{
 		if(! dbconOpened)
 			dbcon.Open();
@@ -65,11 +66,11 @@ class SqliteRun : Sqlite
 			uniqueID = "NULL";
 
 		dbcmd.CommandText = "INSERT INTO " + tableName + 
-				" (uniqueID, personID, sessionID, type, distance, time, description, simulated)" +
+				" (uniqueID, personID, sessionID, type, distance, time, description, simulated, initialSpeed)" +
 				" VALUES (" + uniqueID + ", " +
 				+ personID + ", " + sessionID + ", '" + type + "', "
 				+ Util.ConvertToPoint(distance) + ", " + Util.ConvertToPoint(time) + ", '" + 
-				description + "', " + simulated + ")" ;
+				description + "', " + simulated + ", " + Util.BoolToInt(initialSpeed) + ")" ;
 		Log.WriteLine(dbcmd.CommandText.ToString());
 		dbcmd.ExecuteNonQuery();
 
@@ -133,7 +134,8 @@ class SqliteRun : Sqlite
 					Util.ChangeDecimalSeparator(reader[5].ToString()) + ":" + //run.distance
 					Util.ChangeDecimalSeparator(reader[6].ToString()) + ":" + //run.time
 					reader[7].ToString() + ":" + 	//description
-					reader[8].ToString() 		//simulated
+					reader[8].ToString() + ":" +	//simulated
+					Util.IntToBool(Convert.ToInt32(reader[9])) //initialSpeed
 					);
 			count ++;
 		}
@@ -164,7 +166,7 @@ class SqliteRun : Sqlite
 		reader = dbcmd.ExecuteReader();
 		reader.Read();
 	
-		Run myRun = new Run(DataReaderToStringArray(reader, 8));
+		Run myRun = new Run(DataReaderToStringArray(reader, 9));
 	
 		reader.Close();
 		dbcon.Close();
diff --git a/src/sqlite/runInterval.cs b/src/sqlite/runInterval.cs
index b3f4c6e..70891e0 100644
--- a/src/sqlite/runInterval.cs
+++ b/src/sqlite/runInterval.cs
@@ -49,11 +49,12 @@ class SqliteRunInterval : SqliteRun
 			"tracks FLOAT, " +	//float because if we limit by time (runType tracksLimited false), we do n.nn tracks
 			"description TEXT, " +
 			"limited TEXT, " +
-			"simulated INT )";
+			"simulated INT, " +
+			"initialSpeed INT)";
 		dbcmd.ExecuteNonQuery();
 	}
 
-	public static int Insert(bool dbconOpened, string tableName, string uniqueID, int personID, int sessionID, string type, double distanceTotal, double timeTotal, double distanceInterval, string intervalTimesString, double tracks, string description, string limited, int simulated )
+	public static int Insert(bool dbconOpened, string tableName, string uniqueID, int personID, int sessionID, string type, double distanceTotal, double timeTotal, double distanceInterval, string intervalTimesString, double tracks, string description, string limited, int simulated, bool initialSpeed )
 	{
 		if(! dbconOpened)
 			dbcon.Open();
@@ -62,7 +63,7 @@ class SqliteRunInterval : SqliteRun
 			uniqueID = "NULL";
 
 		dbcmd.CommandText = "INSERT INTO "+ tableName + 
-				" (uniqueID, personID, sessionID, type, distanceTotal, timeTotal, distanceInterval, intervalTimesString, tracks, description, limited, simulated )" +
+				" (uniqueID, personID, sessionID, type, distanceTotal, timeTotal, distanceInterval, intervalTimesString, tracks, description, limited, simulated, initialSpeed)" +
 				"VALUES (" + uniqueID + ", " +
 				personID + ", " + sessionID + ", '" + type + "', " +
 				Util.ConvertToPoint(distanceTotal) + ", " + 
@@ -70,7 +71,9 @@ class SqliteRunInterval : SqliteRun
 				Util.ConvertToPoint(distanceInterval) + ", '" + 
 				Util.ConvertToPoint(intervalTimesString) + "', " +
 				Util.ConvertToPoint(tracks) + ", '" + 
-				description + "', '" + limited + "', " + simulated + ")" ;
+				description + "', '" + limited + "', " + simulated + ", " +
+				Util.BoolToInt(initialSpeed) + ")" ;
+				
 		Log.WriteLine(dbcmd.CommandText.ToString());
 		dbcmd.ExecuteNonQuery();
 
@@ -135,7 +138,8 @@ class SqliteRunInterval : SqliteRun
 					Util.ChangeDecimalSeparator(reader[9].ToString()) + ":" + //tracks
 					reader[10].ToString() + ":" + 	//description
 					reader[11].ToString() + ":" +  	//limited
-					reader[12].ToString() 	 	//simulated
+					reader[12].ToString() + ":" +	//simulated
+					Util.IntToBool(Convert.ToInt32(reader[13])) //initialSpeed
 					);
 			count ++;
 		}
@@ -167,7 +171,7 @@ class SqliteRunInterval : SqliteRun
 		reader = dbcmd.ExecuteReader();
 		reader.Read();
 
-		RunInterval myRun = new RunInterval(DataReaderToStringArray(reader, 12));
+		RunInterval myRun = new RunInterval(DataReaderToStringArray(reader, 13));
 
 		reader.Close();
 		dbcon.Close();
diff --git a/src/util.cs b/src/util.cs
index 0f035ec..f435bb4 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -1199,6 +1199,13 @@ public class Util
 			return Constants.No;
 	}
 
+	public static string NoYes(bool b) {
+		if(! b)
+			return Constants.No;
+		else
+			return Constants.Yes;
+	}
+
 
 	/* 
 	 * when distances are variable on run interval 



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