chronojump r454 - in trunk: . build/data src src/execute src/gui



Author: xaviblas
Date: Wed Feb  4 17:26:59 2009
New Revision: 454
URL: http://svn.gnome.org/viewvc/chronojump?rev=454&view=rev

Log:
0.8.1.8
distancesString:
-working on eventExecute speed on runInterval variable distance
allowing to select a runInterval distance variable test
-fixed runIntervalMore distancesString selection
-fixed on gui/chronojump.cs get the image from runIntervalMore
-done treviewRunInterval speed avg ok
-fixed runInterval execute speedNow when finish is clicked
-eventExecuteWin works ok with distancesString except, 
TODO: top margin when showing speed

-fixed crash bug on recuperate jumpRj or runI (on a crash) that cannot
recuperate because connection is open
-fixed MTGUG from button doesn't ask now for speed


Modified:
   trunk/build/data/chronojump.prg
   trunk/build/data/chronojump_mini.prg
   trunk/build/data/version.txt
   trunk/changelog.txt
   trunk/src/chronojump.cs
   trunk/src/execute/event.cs
   trunk/src/execute/run.cs
   trunk/src/gui/chronojump.cs
   trunk/src/gui/eventExecute.cs
   trunk/src/gui/run.cs
   trunk/src/prepareEventGraphObjects.cs
   trunk/src/treeViewRun.cs
   trunk/src/util.cs
   trunk/version.txt

Modified: trunk/build/data/chronojump.prg
==============================================================================
Binary files. No diff available.

Modified: trunk/build/data/chronojump_mini.prg
==============================================================================
Binary files. No diff available.

Modified: trunk/build/data/version.txt
==============================================================================
--- trunk/build/data/version.txt	(original)
+++ trunk/build/data/version.txt	Wed Feb  4 17:26:59 2009
@@ -1 +1 @@
-0.8.1.7
+0.8.1.8

Modified: trunk/changelog.txt
==============================================================================
--- trunk/changelog.txt	(original)
+++ trunk/changelog.txt	Wed Feb  4 17:26:59 2009
@@ -1,7 +1,8 @@
 TODO (sorted)
 
 1.- upload SEvaluator and edit it and re-upload
-2.- on stats show data updated by user
+2.- on stats show data updated by user on a window with columns:
+"in server", "uploaded by you"
 3.- write a version compatibility thing for each server method, and if not
 compatible, tell user to update it's chronojump version
 
@@ -20,9 +21,23 @@
 all this will be release as 0.8.2 or 0.9
 
 distancesString:
--eventExecute speed
 -stats (graphs)
 
+4 feb 2009
+	0.8.1.8
+	distancesString:
+	-working on eventExecute speed on runInterval variable distance
+	allowing to select a runInterval distance variable test
+	-fixed runIntervalMore distancesString selection
+	-fixed on gui/chronojump.cs get the image from runIntervalMore
+	-done treviewRunInterval speed avg ok
+	-fixed runInterval execute speedNow when finish is clicked
+	-eventExecuteWin works ok with distancesString except, 
+	TODO: top margin when showing speed
+	
+	-fixed crash bug on recuperate jumpRj or runI (on a crash) that cannot
+	recuperate because connection is open
+	-fixed MTGUG from button doesn't ask now for speed
 
 3 feb 2009 (2)
 	small code cleaning

Modified: trunk/src/chronojump.cs
==============================================================================
--- trunk/src/chronojump.cs	(original)
+++ trunk/src/chronojump.cs	Wed Feb  4 17:26:59 2009
@@ -426,7 +426,9 @@
 		if(existsTempData > 0)
 		{
 			JumpRj myJumpRj = SqliteJumpRj.SelectJumpData("tempJumpRj", existsTempData);
-			myJumpRj.InsertAtDB (false, Constants.JumpRjTable);
+			try {
+				myJumpRj.InsertAtDB (true, Constants.JumpRjTable);
+			} catch {} //pitty, cannot insert
 
 			Sqlite.DeleteTempEvents(tableName);
 			returnString = "Recuperated last Reactive Jump";
@@ -437,7 +439,9 @@
 		if(existsTempData > 0)
 		{
 			RunInterval myRun = SqliteRunInterval.SelectRunData("tempRunInterval", existsTempData);
-			myRun.InsertAtDB (false, Constants.RunIntervalTable);
+			try {
+				myRun.InsertAtDB (true, Constants.RunIntervalTable);
+			} catch {} //pitty, cannot insert
 
 			Sqlite.DeleteTempEvents(tableName);
 			returnString = "Recuperated last Intervallic Run";

Modified: trunk/src/execute/event.cs
==============================================================================
--- trunk/src/execute/event.cs	(original)
+++ trunk/src/execute/event.cs	Wed Feb  4 17:26:59 2009
@@ -358,6 +358,8 @@
 						prepareEventGraphRunInterval.distance, 
 						prepareEventGraphRunInterval.lastTime,
 						prepareEventGraphRunInterval.timesString,
+						prepareEventGraphRunInterval.distanceTotal,
+						prepareEventGraphRunInterval.distancesString,
 						volumeOn, repetitiveConditionsWin);
 				break;
 			case eventType.PULSE:

Modified: trunk/src/execute/run.cs
==============================================================================
--- trunk/src/execute/run.cs	(original)
+++ trunk/src/execute/run.cs	Wed Feb  4 17:26:59 2009
@@ -330,7 +330,11 @@
 	string limited; //the teorically values, eleven runs: "11=R" (time recorded in "time"), 10 seconds: "10=T" (tracks recorded in tracks)
 	double limitAsDouble;	//-1 for non limited (unlimited repetitive run until "finish" is clicked)
 	bool tracksLimited;
-	
+
+
+	string distancesString; //if distances are variable (distanceInterval == -1), this is used
+	double distanceIntervalFixed; //if distanceInterval i -1, then Fixed is the corresponding base on distancesString
+
 	//private Chronopic cp;
 
 	public RunIntervalExecute() {
@@ -349,6 +353,13 @@
 		this.limitAsDouble = limitAsDouble;
 		this.tracksLimited = tracksLimited;
 
+		//if distances are variable
+		distancesString = "";
+		if(distanceInterval == -1) {
+			RunType runType = SqliteRunIntervalType.SelectAndReturnRunIntervalType(type);
+			distancesString = runType.DistancesString;
+		}
+
 		if(tracksLimited) {
 			this.limited = limitAsDouble.ToString() + "R"; //'R'uns (don't put 'T'racks for not confusing with 'T'ime)
 		} else {
@@ -399,6 +410,8 @@
 		int countForSavingTempTable = 0;
 	
 		double lastTc = 0;
+					
+		distanceIntervalFixed = distanceInterval;
 		
 		do {
 
@@ -409,6 +422,9 @@
 		
 	
 			if (ok && !cancel && !finish) {
+				if(distanceInterval == -1)
+					distanceIntervalFixed = Util.GetRunIVariableDistancesStringRow(distancesString, (int) tracks);
+
 				if (platformState == Chronopic.Plataforma.ON && loggedState == States.OFF) {
 					//has arrived
 					loggedState = States.ON;
@@ -444,8 +460,12 @@
 									);  
 							needUpdateEventProgressBar = true;
 							
+							distanceTotal = Util.GetRunITotalDistance(distanceInterval, distancesString, tracks);
+
 							//update graph
-							prepareEventGraphRunInterval = new PrepareEventGraphRunInterval(distanceInterval, myRaceTime, intervalTimesString);
+							prepareEventGraphRunInterval = new PrepareEventGraphRunInterval(
+									distanceIntervalFixed, myRaceTime, intervalTimesString, distanceTotal, distancesString);
+
 							needUpdateGraphType = eventType.RUNINTERVAL;
 							needUpdateGraph = true;
 							
@@ -493,8 +513,12 @@
 										);  
 								needUpdateEventProgressBar = true;
 							
+								distanceTotal = Util.GetRunITotalDistance(distanceInterval, distancesString, tracks);
+							
 								//update graph
-								prepareEventGraphRunInterval = new PrepareEventGraphRunInterval(distanceInterval, myRaceTime, intervalTimesString);
+								prepareEventGraphRunInterval = new PrepareEventGraphRunInterval(
+										distanceIntervalFixed, myRaceTime, intervalTimesString, distanceTotal, distancesString);
+
 								needUpdateGraphType = eventType.RUNINTERVAL;
 								needUpdateGraph = true;
 
@@ -542,9 +566,13 @@
 										tracks
 										);  
 								needUpdateEventProgressBar = true;
+								
+								distanceTotal = Util.GetRunITotalDistance(distanceInterval, distancesString, tracks);
 							
 								//update graph
-								prepareEventGraphRunInterval = new PrepareEventGraphRunInterval(distanceInterval, myRaceTime, intervalTimesString);
+								prepareEventGraphRunInterval = new PrepareEventGraphRunInterval(
+										distanceIntervalFixed, myRaceTime, intervalTimesString, distanceTotal, distancesString);
+
 								needUpdateGraphType = eventType.RUNINTERVAL;
 								needUpdateGraph = true;
 
@@ -663,7 +691,6 @@
 		timerCount =  Util.GetTotalTime(timesString);
 	}
 				
-
 	protected void writeRunInterval(bool tempTable)
 	{
 		int tracks = 0;
@@ -715,12 +742,11 @@
 			}
 		}
 
-		distanceTotal = tracks * distanceInterval;
+		distanceTotal = Util.GetRunITotalDistance(distanceInterval, distancesString, tracks);
 		timeTotal = Util.GetTotalTime(intervalTimesString); 
 		
 	
 		if(tempTable)
-			{
 			SqliteRunInterval.Insert(false, Constants.TempRunIntervalTable, "NULL", personID, sessionID, type, 
 					distanceTotal, timeTotal,
 					distanceInterval, intervalTimesString, tracks, 
@@ -728,8 +754,6 @@
 					limitString,
 					Util.BoolToNegativeInt(simulated) 
 					);
-			}
-
 		else {
 			uniqueID = SqliteRunInterval.Insert(false, Constants.RunIntervalTable, "NULL", personID, sessionID, type, 
 					distanceTotal, timeTotal,
@@ -745,9 +769,9 @@
 
 			string tempValuesString = "";
 			if(tracksLimited) 
-				tempValuesString = " (" + distanceInterval + "x" + tracks + "R), " + Catalog.GetString("Time") + ": " + Util.TrimDecimals( timeTotal.ToString(), pDN);
+				tempValuesString = " (" + distanceIntervalFixed + "x" + tracks + "R), " + Catalog.GetString("Time") + ": " + Util.TrimDecimals( timeTotal.ToString(), pDN);
 			else
-				tempValuesString = " (" + distanceInterval + "x" + Util.TrimDecimals( timeTotal.ToString(), pDN) + "T), " + Catalog.GetString("Tracks") + ": " + tracks;
+				tempValuesString = " (" + distanceIntervalFixed + "x" + Util.TrimDecimals( timeTotal.ToString(), pDN) + "T), " + Catalog.GetString("Tracks") + ": " + tracks;
 
 			string myStringPush =   Catalog.GetString("Last run") + ": " + RunnerName + ", " + 
 				type + tempValuesString + ", " +
@@ -761,8 +785,8 @@
 			//event will be raised, and managed in chronojump.cs
 			fakeButtonFinished.Click();
 
-			//eventExecuteWin.PrepareRunIntervalGraph(distanceInterval, Util.GetLast(intervalTimesString), intervalTimesString);
-			prepareEventGraphRunInterval = new PrepareEventGraphRunInterval(distanceInterval, Util.GetLast(intervalTimesString), intervalTimesString);
+			prepareEventGraphRunInterval = new PrepareEventGraphRunInterval(
+					distanceIntervalFixed, Util.GetLast(intervalTimesString), intervalTimesString, distanceTotal, distancesString);
 			needUpdateGraphType = eventType.RUNINTERVAL;
 			needUpdateGraph = true;
 

Modified: trunk/src/gui/chronojump.cs
==============================================================================
--- trunk/src/gui/chronojump.cs	(original)
+++ trunk/src/gui/chronojump.cs	Wed Feb  4 17:26:59 2009
@@ -3058,6 +3058,9 @@
 	{
 		runsIntervalMoreWin.Button_accept.Clicked -= new EventHandler(on_more_runs_interval_accepted);
 		
+		Console.WriteLine(runsIntervalMoreWin.SelectedEventName);
+		Console.WriteLine(runsIntervalMoreWin.SelectedDistance.ToString());
+		Console.WriteLine(runsIntervalMoreWin.SelectedDistancesString);
 		currentRunType = new RunType(
 				runsIntervalMoreWin.SelectedEventName,	//name
 				true,					//hasIntervals
@@ -3066,8 +3069,8 @@
 				runsIntervalMoreWin.SelectedLimitedValue,
 				runsIntervalMoreWin.SelectedUnlimited,
 				runsIntervalMoreWin.SelectedDescription,
-				"", // distancesstring (deactivated now, TODO: activate)
-				SqliteEvent.GraphLinkSelectFileName(Constants.RunIntervalTable, runsMoreWin.SelectedEventName)
+				runsIntervalMoreWin.SelectedDistancesString,
+				SqliteEvent.GraphLinkSelectFileName(Constants.RunIntervalTable, runsIntervalMoreWin.SelectedEventName)
 				);
 
 		bool unlimited = false;
@@ -3116,9 +3119,14 @@
 			currentRunType = new RunType("MTGUG");
 		}
 		
+		if( currentRunType.Distance == 0 || 
+				(currentRunType.FixedValue == 0 && ! currentRunType.Unlimited) ) {
+			runExtraWin = RunExtraWindow.Show(app1, currentRunType);
+			runExtraWin.Button_accept.Clicked += new EventHandler(on_run_interval_accepted);
+		} else {
+			on_run_interval_accepted(o, args);
+		}
 			
-		runExtraWin = RunExtraWindow.Show(app1, currentRunType);
-		runExtraWin.Button_accept.Clicked += new EventHandler(on_run_interval_accepted);
 	}
 	
 	private void on_run_interval_accepted (object o, EventArgs args)
@@ -3515,10 +3523,23 @@
 						eventExecuteWin.PrepareJumpSimpleGraph(currentJump.Tv, currentJump.Tc);
 					break;
 				case EventType.Types.RUN:
-					if(currentRunType.HasIntervals) 
-						eventExecuteWin.PrepareRunIntervalGraph(currentRunInterval.DistanceInterval, 
-								Util.GetLast(currentRunInterval.IntervalTimesString), currentRunInterval.IntervalTimesString, volumeOn, repetitiveConditionsWin);
-					else
+					if(currentRunType.HasIntervals) {
+							RunType runType = SqliteRunIntervalType.SelectAndReturnRunIntervalType(currentRunInterval.Type);
+							double distanceTotal = Util.GetRunITotalDistance(currentRunInterval.DistanceInterval, 
+									runType.DistancesString, currentRunInterval.Tracks);
+
+							double distanceInterval = currentRunInterval.DistanceInterval;
+							if(distanceInterval == -1) //variable distances
+								distanceInterval = Util.GetRunIVariableDistancesStringRow(
+										runType.DistancesString, (int) currentRunInterval.Tracks -1);
+
+							eventExecuteWin.PrepareRunIntervalGraph(distanceInterval, 
+								Util.GetLast(currentRunInterval.IntervalTimesString), 
+								currentRunInterval.IntervalTimesString, 
+								distanceTotal,
+								runType.DistancesString,
+								volumeOn, repetitiveConditionsWin);
+					} else
 						eventExecuteWin.PrepareRunSimpleGraph(currentRun.Time, currentRun.Speed);
 					break;
 				case EventType.Types.PULSE:

Modified: trunk/src/gui/eventExecute.cs
==============================================================================
--- trunk/src/gui/eventExecute.cs	(original)
+++ trunk/src/gui/eventExecute.cs	Wed Feb  4 17:26:59 2009
@@ -754,7 +754,8 @@
 	}
 	
 	// run interval
-	public void PrepareRunIntervalGraph(double distance, double lastTime, string timesString,
+	// distanceTotal is passed because it can change in variable distances test
+	public void PrepareRunIntervalGraph(double distance, double lastTime, string timesString, double distanceTotal, string distancesString,
 			bool volumeOn, RepetitiveConditionsWindow repetitiveConditionsWin) {
 		//check graph properties window is not null (propably user has closed it with the DeleteEvent
 		//then create it, but not show it
@@ -774,8 +775,12 @@
 		if(eventGraphConfigureWin.Max == -1) {
 			if(paintTime)
 				maxValue = Util.GetMax(timesString);
-			else
-				maxValue = distance / Util.GetMin(timesString); //getMin because is on the "denominador"
+			else {
+				if(distancesString == "")
+					maxValue = distance / Util.GetMin(timesString); //getMin because is on the "denominador"
+				else
+					maxValue = Util.GetRunIVariableDistancesSpeeds(distancesString, timesString, true);
+			}
 		} else {
 			maxValue = eventGraphConfigureWin.Max;
 			topMargin = 0;
@@ -785,12 +790,16 @@
 		double minValue = 1000;
 		int bottomMargin = 10; 
 		//if min value of graph is automatic
-		if(eventGraphConfigureWin.Min == -1) 
+		if(eventGraphConfigureWin.Min == -1) { 
 			if(paintTime)
 				minValue = Util.GetMin(timesString);
-			else
-				minValue = distance / Util.GetMax(timesString); //getMax because is in the "denominador"
-		else {
+			else {
+				if(distancesString == "")
+					minValue = distance / Util.GetMax(timesString); //getMax because is in the "denominador"
+				else
+					minValue = Util.GetRunIVariableDistancesSpeeds(distancesString, timesString, false);
+			}
+		} else {
 			minValue = eventGraphConfigureWin.Min;
 			bottomMargin = 10; 
 		}		
@@ -798,7 +807,9 @@
 		int tracks = Util.GetNumberOfJumps(timesString, true); 
 
 		//paint graph
-		paintRunInterval (drawingarea, paintTime, distance, lastTime, timesString, Util.GetAverage(timesString), maxValue, minValue, tracks, topMargin, bottomMargin,
+		paintRunInterval (drawingarea, paintTime, distance, distanceTotal, distancesString,
+				lastTime, timesString, Util.GetAverage(timesString), 
+				maxValue, minValue, tracks, topMargin, bottomMargin,
 				Util.GetPosMax(timesString), Util.GetPosMin(timesString),
 				volumeOn, repetitiveConditionsWin);
 		
@@ -1204,7 +1215,7 @@
 		graphProgress = phasesGraph.DONE; 
 	}
 
-	private void paintRunInterval (Gtk.DrawingArea drawingarea, bool paintTime, double distance, double lastTime, 
+	private void paintRunInterval (Gtk.DrawingArea drawingarea, bool paintTime, double distance, double distanceTotal, string distancesString, double lastTime, 
 			string timesString, double avgTime, double maxValue, double minValue, int tracks, int topMargin, int bottomMargin, 
 			int hightValuePosition, int lowValuePosition,
 			bool volumeOn, RepetitiveConditionsWindow repetitiveConditionsWin)
@@ -1257,7 +1268,12 @@
 				} else {
 					//blue speed evolution	
 					myPen = pen_azul;
-					myValue = distance / myTimeDouble;
+
+					//if distances are variable
+					if(distancesString == "") 
+						myValue = distance / myTimeDouble;
+					else
+						myValue = Util.GetRunIVariableDistancesStringRow(distancesString, count) / myTimeDouble;
 				}
 
 				if (count > 0) {
@@ -1311,7 +1327,7 @@
 		label_run_interval_time_now.Text = Util.TrimDecimals(lastTime.ToString(), pDN);
 		label_run_interval_time_avg.Text = Util.TrimDecimals(avgTime.ToString(), pDN);
 		label_run_interval_speed_now.Text = Util.TrimDecimals((distance / lastTime).ToString(), pDN);
-		label_run_interval_speed_avg.Text = Util.TrimDecimals((distance / avgTime).ToString(), pDN);
+		label_run_interval_speed_avg.Text = Util.TrimDecimals((distanceTotal / Util.GetTotalTime(timesString)).ToString(), pDN);
 		
 		graphProgress = phasesGraph.DONE; 
 	}

Modified: trunk/src/gui/run.cs
==============================================================================
--- trunk/src/gui/run.cs	(original)
+++ trunk/src/gui/run.cs	Wed Feb  4 17:26:59 2009
@@ -857,6 +857,7 @@
 	private bool selectedTracksLimited;
 	private int selectedLimitedValue;
 	private bool selectedUnlimited;
+	private string selectedDistancesString;
 	
 	RunsIntervalMoreWindow (Gtk.Window parent) {
 		//the glade window is the same as jumps_more
@@ -955,6 +956,7 @@
 		selectedLimitedValue = 0;
 		selectedUnlimited = false; //true if it's an unlimited run
 		selectedDescription = "";
+		selectedDistancesString = "";
 
 		if (((TreeSelection)o).GetSelected(out model, out iter)) {
 			selectedEventName = (string) model.GetValue (iter, 0);
@@ -966,13 +968,15 @@
 			 * if a '-' exists then distances are variable, else, distance is defined
 			 */
 			string distance = (string) model.GetValue (iter, 1);
-			if(distance == Catalog.GetString("Not defined"))
+			if(distance == Catalog.GetString("Not defined")) 
 				selectedDistance = 0;
-			else if(distance.Contains("-"))
+			else if(distance.Contains("-")) {
 				selectedDistance = -1;
-			else 
+				selectedDistancesString = distance;
+			} else 
 				selectedDistance = Convert.ToDouble(distance);
 
+
 			if( (string) model.GetValue (iter, 2) == Catalog.GetString("Unlimited") ) {
 				selectedUnlimited = true;
 			} 
@@ -1003,7 +1007,18 @@
 
 		if (tv.Selection.GetSelected (out model, out iter)) {
 			selectedEventName = (string) model.GetValue (iter, 0);
-			selectedDistance = Convert.ToDouble( (string) model.GetValue (iter, 1) );
+			
+			//selectedDistance = Convert.ToDouble( (string) model.GetValue (iter, 1) );
+			
+			string distance = (string) model.GetValue (iter, 1);
+			if(distance == Catalog.GetString("Not defined")) 
+				selectedDistance = 0;
+			else if(distance.Contains("-")) {
+				selectedDistance = -1;
+				selectedDistancesString = distance;
+			} else 
+				selectedDistance = Convert.ToDouble(distance);
+
 
 			if( (string) model.GetValue (iter, 2) == Catalog.GetString("Unlimited") ) {
 				selectedUnlimited = true;
@@ -1051,23 +1066,23 @@
 		RunsIntervalMoreWindowBox = null;
 	}
 	
-	public double SelectedDistance 
-	{
+	public double SelectedDistance {
 		get { return selectedDistance; }
 	}
 	
-	public bool SelectedTracksLimited 
-	{
+	public string SelectedDistancesString {
+		get { return selectedDistancesString; }
+	}
+	
+	public bool SelectedTracksLimited {
 		get { return selectedTracksLimited; }
 	}
 	
-	public int SelectedLimitedValue 
-	{ 
+	public int SelectedLimitedValue { 
 		get { return selectedLimitedValue; }
 	}
 	
-	public bool SelectedUnlimited 
-	{
+	public bool SelectedUnlimited {
 		get { return selectedUnlimited; }
 	}
 }

Modified: trunk/src/prepareEventGraphObjects.cs
==============================================================================
--- trunk/src/prepareEventGraphObjects.cs	(original)
+++ trunk/src/prepareEventGraphObjects.cs	Wed Feb  4 17:26:59 2009
@@ -77,14 +77,18 @@
 	public double distance;
 	public double lastTime;
 	public string timesString;
+	public double distanceTotal; //we pass this because it's dificult to calculate in runs with variable distances
+	public string distancesString; //we pass this because it's dificult to calculate in runs with variable distances
 
 	public PrepareEventGraphRunInterval() {
 	}
 
-	public PrepareEventGraphRunInterval(double distance, double lastTime, string timesString) {
+	public PrepareEventGraphRunInterval(double distance, double lastTime, string timesString, double distanceTotal, string distancesString) {
 		this.distance = distance;
 		this.lastTime = lastTime;
 		this.timesString = timesString;
+		this.distanceTotal = distanceTotal;
+		this.distancesString = distancesString;
 	}
 
 	~PrepareEventGraphRunInterval() {}

Modified: trunk/src/treeViewRun.cs
==============================================================================
--- trunk/src/treeViewRun.cs	(original)
+++ trunk/src/treeViewRun.cs	Wed Feb  4 17:26:59 2009
@@ -179,12 +179,6 @@
 		return myData;
 	}
 	
-	private string getDistancesStringRow(string distancesString, int row) {
-		string [] str = distancesString.Split(new char[] {'-'});
-		row = row % str.Length;
-		return str[row];
-	}
-
 	protected override string [] getSubLineToStore(System.Object myObject, int lineCount)
 	{
 		RunInterval newRunI = (RunInterval)myObject;
@@ -201,11 +195,11 @@
 		if(newRunI.DistanceInterval == -1) {
 			RunType runType = SqliteRunIntervalType.SelectAndReturnRunIntervalType(newRunI.Type);
 			myData[count++] = (lineCount + 1).ToString() +  
-				" (" + getDistancesStringRow(runType.DistancesString, lineCount) + "m)";
+				" (" + Util.GetRunIVariableDistancesStringRow(runType.DistancesString, lineCount).ToString() + "m)";
 			
 			myData[count++] =  Util.TrimDecimals( 
 					Util.GetSpeed(
-						getDistancesStringRow(runType.DistancesString, lineCount), //distancesString (variable)
+						Util.GetRunIVariableDistancesStringRow(runType.DistancesString, lineCount).ToString(), //distancesString (variable)
 						timeInterval,
 						metersSecondsPreferred )
 					, pDN );

Modified: trunk/src/util.cs
==============================================================================
--- trunk/src/util.cs	(original)
+++ trunk/src/util.cs	Wed Feb  4 17:26:59 2009
@@ -951,4 +951,55 @@
 	}
 
 
+	/* 
+	 * when distances are variable on run interval 
+	 */
+	//thought for values starting by 0
+	public static double GetRunIVariableDistancesStringRow(string distancesString, int row) {
+		string [] str = distancesString.Split(new char[] {'-'});
+		row = row % str.Length;
+		return Convert.ToDouble(str[row]);
+	}
+	
+	public static double GetRunIVariableDistancesDistanceDone(string distancesString, int tracks) {
+		double distanceTotal = 0;
+		for(int i=0; i < tracks; i++) 
+			distanceTotal += GetRunIVariableDistancesStringRow(distancesString, i);
+		return distanceTotal;
+	}
+
+	//decides if it's variable or not
+	public static double GetRunITotalDistance(double distanceInterval, string distancesString, double tracks) {
+		if(distanceInterval == -1) 
+			return GetRunIVariableDistancesDistanceDone(distancesString, (int) tracks);
+		else
+			return tracks * distanceInterval;
+	}
+
+	public static double GetRunIVariableDistancesSpeeds(string distancesString, string timesString, bool max) {
+		double  searchedValue = -1; //to find max values (higher than this)
+		if(! max)
+			searchedValue = 1000; //to find min values (lower than this)
+
+		string [] times = timesString.Split(new char[] {'='});
+		string [] distances = distancesString.Split(new char[] {'-'});
+		for(int i=0; i < times.Length; i++) {
+			double time = Convert.ToDouble(times[i]);
+		
+			int distPos = i % times.Length;
+			double distance = Convert.ToDouble(distances[distPos]);
+
+			double speed = DivideSafe(distance, time);
+			if(max) {
+				if(speed > searchedValue)
+					searchedValue = speed;
+			} else {
+				if(speed < searchedValue)
+					searchedValue = speed;
+			}
+		}
+		return searchedValue;
+	}
+
+
 }

Modified: trunk/version.txt
==============================================================================
--- trunk/version.txt	(original)
+++ trunk/version.txt	Wed Feb  4 17:26:59 2009
@@ -1 +1 @@
-0.8.1.7
+0.8.1.8



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