[chronojump] Bug 653477 - fix photocells double-cut (run done)



commit 21114baaac9bafd8cd6c0119a15f722c84e945e7
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Dec 7 20:20:04 2012 +0100

    Bug 653477 - fix photocells double-cut (run done)

 glade/chronojump.glade |  200 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/constants.cs       |    3 +
 src/execute/run.cs     |  123 ++++++++++++++++++++++--------
 src/gui/chronojump.cs  |   18 ++++-
 src/gui/run.cs         |   11 +++-
 5 files changed, 322 insertions(+), 33 deletions(-)
---
diff --git a/glade/chronojump.glade b/glade/chronojump.glade
index 76263e3..fed0c6b 100644
--- a/glade/chronojump.glade
+++ b/glade/chronojump.glade
@@ -4338,6 +4338,206 @@ weight</property>
                                                             <property name="position">1</property>
                                                             </packing>
                                                             </child>
+                                                            <child>
+                                                            <widget class="GtkHSeparator" id="hseparator4">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">True</property>
+                                                            <property name="position">2</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
+                                                            <widget class="GtkVBox" id="vbox84">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="spacing">6</property>
+                                                            <child>
+                                                            <widget class="GtkCheckButton" id="checkbutton_runs_prevent_double_contact">
+                                                            <property name="label" translatable="yes">Prevent double contacts (recommended)</property>
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">True</property>
+                                                            <property name="receives_default">False</property>
+                                                            <property name="use_action_appearance">False</property>
+                                                            <property name="active">True</property>
+                                                            <property name="draw_indicator">True</property>
+                                                            <signal name="toggled" handler="on_checkbutton_runs_prevent_double_contact_toggled" swapped="no"/>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">True</property>
+                                                            <property name="fill">True</property>
+                                                            <property name="position">0</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
+                                                            <widget class="GtkAlignment" id="alignment28">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="left_padding">12</property>
+                                                            <child>
+                                                            <widget class="GtkVBox" id="vbox_runs_prevent_double_contact">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="spacing">4</property>
+                                                            <child>
+                                                            <widget class="GtkLabel" id="label103">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="xalign">0</property>
+                                                            <property name="label" translatable="yes">Fix when two or more contacts
+happen in less than</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="position">0</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
+                                                            <widget class="GtkHBox" id="hbox101">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <child>
+                                                            <widget class="GtkSpinButton" id="spinbutton_runs_prevent_double_contact">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">True</property>
+                                                            <property name="invisible_char">â</property>
+                                                            <property name="invisible_char_set">True</property>
+                                                            <property name="primary_icon_activatable">False</property>
+                                                            <property name="secondary_icon_activatable">False</property>
+                                                            <property name="primary_icon_sensitive">True</property>
+                                                            <property name="secondary_icon_sensitive">True</property>
+                                                            <property name="adjustment">1000 0 3000 100 1000 0</property>
+                                                            <property name="snap_to_ticks">True</property>
+                                                            <property name="numeric">True</property>
+                                                            <property name="update_policy">if-valid</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">True</property>
+                                                            <property name="padding">12</property>
+                                                            <property name="position">0</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
+                                                            <widget class="GtkLabel" id="label105">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="label" translatable="yes">ms</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="position">1</property>
+                                                            </packing>
+                                                            </child>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="position">1</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
+                                                            <widget class="GtkLabel" id="label104">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="xalign">0</property>
+                                                            <property name="label" translatable="yes">Proceed</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="position">2</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
+                                                            <widget class="GtkAlignment" id="alignment29">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="left_padding">12</property>
+                                                            <child>
+                                                            <widget class="GtkVBox" id="vbox86">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="spacing">4</property>
+                                                            <child>
+                                                            <widget class="GtkRadioButton" id="radio_runs_prevent_double_contact_first">
+                                                            <property name="label" translatable="yes">Take first contact (recommended)</property>
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">True</property>
+                                                            <property name="receives_default">False</property>
+                                                            <property name="use_action_appearance">False</property>
+                                                            <property name="active">True</property>
+                                                            <property name="draw_indicator">True</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">True</property>
+                                                            <property name="fill">True</property>
+                                                            <property name="position">0</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
+                                                            <widget class="GtkRadioButton" id="radio_runs_prevent_double_contact_average">
+                                                            <property name="label" translatable="yes">Take average</property>
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">True</property>
+                                                            <property name="receives_default">False</property>
+                                                            <property name="use_action_appearance">False</property>
+                                                            <property name="active">True</property>
+                                                            <property name="draw_indicator">True</property>
+                                                            <property name="group">radio_runs_prevent_double_contact_first</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">True</property>
+                                                            <property name="fill">True</property>
+                                                            <property name="position">1</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
+                                                            <widget class="GtkRadioButton" id="radio_runs_prevent_double_contact_last">
+                                                            <property name="label" translatable="yes">Take last contact</property>
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">True</property>
+                                                            <property name="receives_default">False</property>
+                                                            <property name="use_action_appearance">False</property>
+                                                            <property name="active">True</property>
+                                                            <property name="draw_indicator">True</property>
+                                                            <property name="group">radio_runs_prevent_double_contact_first</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">True</property>
+                                                            <property name="fill">True</property>
+                                                            <property name="position">2</property>
+                                                            </packing>
+                                                            </child>
+                                                            </widget>
+                                                            </child>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">True</property>
+                                                            <property name="fill">True</property>
+                                                            <property name="position">3</property>
+                                                            </packing>
+                                                            </child>
+                                                            </widget>
+                                                            </child>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">True</property>
+                                                            <property name="fill">True</property>
+                                                            <property name="position">1</property>
+                                                            </packing>
+                                                            </child>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="position">3</property>
+                                                            </packing>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">True</property>
diff --git a/src/constants.cs b/src/constants.cs
index 8280d0e..5c53cb3 100644
--- a/src/constants.cs
+++ b/src/constants.cs
@@ -583,4 +583,7 @@ public class Constants
 	//if this name changes, change it in encoder/graph.R
 	public static string EncoderGraphInputMulti = "chronojump-encoder-graph-input-multi.csv"; 
 
+	public enum DoubleContact {
+		FIRST, AVERAGE, LAST
+	}
 }
diff --git a/src/execute/run.cs b/src/execute/run.cs
index b9b2dd9..2b9bd0b 100644
--- a/src/execute/run.cs
+++ b/src/execute/run.cs
@@ -43,14 +43,20 @@ public class RunExecute : EventExecute
 	}
 	protected runPhases runPhase;
 		
+	private bool checkDoubleContact;
+	private int checkDoubleContactTime;
+	private Constants.DoubleContact checkDoubleContactMode;
+		
 	
 	public RunExecute() {
 	}
 
 	//run execution
 	public RunExecute(int personID, int sessionID, string type, double distance,   
-			Chronopic cp, Gtk.TextView event_execute_textview_message, Gtk.Window app, int pDN, bool metersSecondsPreferred, bool volumeOn,
-			double progressbarLimit, ExecutingGraphData egd 
+			Chronopic cp, Gtk.TextView event_execute_textview_message, Gtk.Window app, 
+			int pDN, bool metersSecondsPreferred, bool volumeOn,
+			double progressbarLimit, ExecutingGraphData egd,
+			bool checkDoubleContact, int checkDoubleContactTime, Constants.DoubleContact checkDoubleContactMode
 			)
 	{
 		this.personID = personID;
@@ -67,6 +73,9 @@ public class RunExecute : EventExecute
 		this.volumeOn = volumeOn;
 		this.progressbarLimit = progressbarLimit;
 		this.egd = egd;
+		this.checkDoubleContact = checkDoubleContact;
+		this.checkDoubleContactTime = checkDoubleContactTime;
+		this.checkDoubleContactMode = checkDoubleContactMode;
 		
 		fakeButtonUpdateGraph = new Gtk.Button();
 		fakeButtonEventEnded = new Gtk.Button();
@@ -174,8 +183,12 @@ Log.WriteLine("MANAGE(3)!!!!");
 	protected override void waitEvent ()
 	{
 		double timestamp = 0;
+
+		double timestampDCFlightTimes = -1; //sum of the flight times that happen in small time
+		double timestampDCContactTimes = -1;//sum of the contact times that happen in small time
+		double timestampDCN = 0; //number of flight times
+
 		bool success = false;
-		
 		bool ok;
 
 		do {
@@ -186,6 +199,7 @@ Log.WriteLine("MANAGE(3)!!!!");
 			
 			//if (ok) {
 			if (ok && !cancel) {
+//Log.WriteLine("timestamp:" + timestamp);
 				if (platformState == Chronopic.Plataforma.ON && loggedState == States.OFF) {
 					//has arrived
 					loggedState = States.ON;
@@ -206,44 +220,91 @@ Log.WriteLine("MANAGE(3)!!!!");
 						
 						if(simulated)
 							timestamp = simulatedTimeLast * 1000; //conversion to milliseconds
-						
-						time = timestamp / 1000.0;
-						write();
 
-						success = true;
-						
-						updateProgressBar = new UpdateProgressBar (
-								true, //isEvent
-								true, //percentageMode
-								//percentageToPass
-								3
-								);  
-						needUpdateEventProgressBar = true;
+						//prevent double contact stuff
+						if(checkDoubleContact) {
+							if(timestamp <= checkDoubleContactTime) {
+								/*
+								   when checking double contact
+								   first time that timestamp < checkDoubleContactTime
+								   and we arrived (it's a flight time)
+								   record this time as timestampDCFlightTimes
+								 */
+								timestampDCN ++;
+								timestampDCFlightTimes += timestamp;
+							}
+							else {
+								if(timestampDCN > 0) {
+									if(checkDoubleContactMode == 
+											Constants.DoubleContact.FIRST) {
+										/* user want first flight time,
+										   then add all DC times*/
+										timestamp += timestampDCFlightTimes + 
+											timestampDCContactTimes;
+									}
+									else if(checkDoubleContactMode == 
+											Constants.DoubleContact.LAST) {
+										//user want last flight time, take that
+										timestamp = timestamp;
+									}
+									else {	/* do the avg of all flights and contacts
+										   then add to last timestamp */
+										timestamp += 
+											(timestampDCFlightTimes + 
+											 timestampDCContactTimes) 
+											/ timestampDCN;
+									}
+								}
+								success = true;
+							}
+						}
 						
-						runPhase = runPhases.PLATFORM_END;
+						if(! checkDoubleContact)
+							success = true;
+
+						if(success) {
+							time = timestamp / 1000.0;
+							write();
+
+							//success = true;
+
+							updateProgressBar = new UpdateProgressBar (
+									true, //isEvent
+									true, //percentageMode
+									//percentageToPass
+									3
+									);  
+							needUpdateEventProgressBar = true;
+
+							runPhase = runPhases.PLATFORM_END;
+						}
 					}
 				}
 				else if (platformState == Chronopic.Plataforma.OFF && loggedState == States.ON) {
 					//it's out, was inside (= has abandoned platform)
 					//don't record time
 						
-					initializeTimer();
-						
-					//update event progressbar
-					updateProgressBar = new UpdateProgressBar (
-							true, //isEvent
-							true, //percentageMode
-							2 //normal run, phase 2/3
-							);  
-					needUpdateEventProgressBar = true;
-				
-					feedbackMessage = "";
-					needShowFeedbackMessage = true; 
-					
 					//change the automata state
 					loggedState = States.OFF;
-						
-					runPhase = runPhases.RUNNING;
+
+					if(checkDoubleContact && timestampDCN > 0)
+						timestampDCContactTimes += timestamp;
+					else {
+						initializeTimer();
+
+						//update event progressbar
+						updateProgressBar = new UpdateProgressBar (
+								true, //isEvent
+								true, //percentageMode
+								2 //normal run, phase 2/3
+								);  
+						needUpdateEventProgressBar = true;
+
+						feedbackMessage = "";
+						needShowFeedbackMessage = true; 
+
+						runPhase = runPhases.RUNNING;
+					}
 				}
 			}
 		} while ( ! success && ! cancel );
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index eba4934..e70bc8a 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -473,6 +473,9 @@ public partial class ChronoJumpWindow
 		on_extra_window_jumps_test_changed(new object(), new EventArgs());
 		//changeTestImage("", "", "LOGO");
 
+		//don't know why Glade is not doing this
+		spinbutton_runs_prevent_double_contact.Value=1000;
+
 		//We have no session, mark some widgets as ".Sensitive = false"
 		sensitiveGuiNoSession();
 		definedSession = false;
@@ -3334,6 +3337,15 @@ Console.WriteLine("X");
 	 * ----------------  RUNS EXECUTION (no interval) ----------
 	 *  --------------------------------------------------------
 	 */
+
+	private Constants.DoubleContact getDoubleContactModes() {
+		if(radio_runs_prevent_double_contact_first.Active)
+			return Constants.DoubleContact.FIRST;
+		else if(radio_runs_prevent_double_contact_average.Active)
+			return Constants.DoubleContact.AVERAGE;
+		else
+			return Constants.DoubleContact.LAST;
+	}
 	
 	//suitable for all runs not repetitive
 	private void on_normal_run_activate (object o, EventArgs args) 
@@ -3383,7 +3395,11 @@ Console.WriteLine("X");
 		currentEventExecute = new RunExecute(currentPerson.UniqueID, currentSession.UniqueID, 
 				currentRunType.Name, myDistance, 
 				chronopicWin.CP, event_execute_textview_message, app1, prefsDigitsNumber, metersSecondsPreferred, volumeOn, 
-				progressbarLimit, egd);
+				progressbarLimit, egd,
+				checkbutton_runs_prevent_double_contact.Active, 
+				(int) spinbutton_runs_prevent_double_contact.Value,
+				getDoubleContactModes()
+				);
 		
 		if (!chronopicWin.Connected) 
 			currentEventExecute.SimulateInitValues(rand);
diff --git a/src/gui/run.cs b/src/gui/run.cs
index c4bb771..4c28084 100644
--- a/src/gui/run.cs
+++ b/src/gui/run.cs
@@ -941,9 +941,15 @@ partial class ChronoJumpWindow
 	[Widget] Gtk.Label extra_window_runs_label_distance;
 	[Widget] Gtk.SpinButton extra_window_runs_spinbutton_distance;
 	[Widget] Gtk.Label extra_window_runs_label_distance_units;
-
 	[Widget] Gtk.Label extra_window_label_runs_no_options;
 	
+	[Widget] Gtk.Box vbox_runs_prevent_double_contact;
+	[Widget] Gtk.CheckButton checkbutton_runs_prevent_double_contact;
+	[Widget] Gtk.SpinButton spinbutton_runs_prevent_double_contact;
+	[Widget] Gtk.RadioButton radio_runs_prevent_double_contact_first;
+	[Widget] Gtk.RadioButton radio_runs_prevent_double_contact_average;
+	[Widget] Gtk.RadioButton radio_runs_prevent_double_contact_last;
+	
 	//options runs interval
 	[Widget] Gtk.Label extra_window_runs_interval_label_distance;
 	[Widget] Gtk.SpinButton extra_window_runs_interval_spinbutton_distance;
@@ -1253,6 +1259,9 @@ partial class ChronoJumpWindow
 			extra_window_label_runs_no_options.Visible = ! hasOptions;
 	}
 
+	protected void on_checkbutton_runs_prevent_double_contact_toggled (object o, EventArgs args) {
+		vbox_runs_prevent_double_contact.Visible = checkbutton_runs_prevent_double_contact.Active;
+	}
 
 }
 



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