[chronojump] Experimental raceEncoder file load
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Experimental raceEncoder file load
- Date: Mon, 16 Sep 2019 17:58:32 +0000 (UTC)
commit 71b2ec40994bb2929272907f782c33cb4a145903
Author: Xavier de Blas <xaviblas gmail com>
Date: Mon Sep 16 19:57:45 2019 +0200
Experimental raceEncoder file load
is not very useful without DB because need to know:
- captured device
- distance
glade/app1.glade | 68 +++++++++++++++++++++++++++++-------
src/gui/chronojumpIcons.cs | 2 ++
src/gui/runEncoder.cs | 86 +++++++++++++++++++++++++++++++++++++++-------
src/runEncoder.cs | 43 +++++++++++++++++++++++
4 files changed, 174 insertions(+), 25 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index f5ddcc63..9fe40c65 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -10465,6 +10465,37 @@ Inverted values</property>
</packing>
</child>
<child>
+ <widget class="GtkHBox" id="hbox331">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">12</property>
+ <child>
+ <widget class="GtkButton"
id="button_run_encoder_load">
+ <property name="width_request">60</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="can_default">True</property>
+ <property name="receives_default">True</property>
+ <property name="has_tooltip">True</property>
+ <property name="relief">half</property>
+ <property name="use_underline">True</property>
+ <signal name="clicked"
handler="on_button_run_encoder_load_clicked" swapped="no"/>
+ <child>
+ <widget class="GtkImage"
id="image_race_encoder_capture_load">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property
name="stock">gtk-missing-image</property>
+ <property name="icon-size">2</property>
+ </widget>
+ </child>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
<widget class="GtkButton"
id="button_run_encoder_recalculate">
<property name="width_request">60</property>
<property name="visible">True</property>
@@ -10487,6 +10518,13 @@ Inverted values</property>
</child>
</widget>
<packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
<property name="expand">True</property>
<property name="fill">False</property>
<property name="position">4</property>
@@ -21814,6 +21852,9 @@ Concentric</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
<packing>
<property name="expand">False</property>
@@ -23774,6 +23815,18 @@ Concentric</property>
<property name="can_focus">False</property>
<property name="spacing">6</property>
<child>
+ <widget class="GtkLabel"
id="label_video_encoder_tests_will_be_filmed">
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Tests
will be filmed</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="pack_type">end</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
<widget class="GtkHBox"
id="hbox_video_encoder_capturing">
<property name="can_focus">False</property>
<property name="spacing">4</property>
@@ -23810,18 +23863,6 @@ Concentric</property>
</packing>
</child>
<child>
- <widget class="GtkLabel"
id="label_video_encoder_tests_will_be_filmed">
- <property name="can_focus">False</property>
- <property name="label" translatable="yes">Tests
will be filmed</property>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="pack_type">end</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
<widget class="GtkHBox"
id="hbox_video_encoder_no_capturing">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -30693,6 +30734,9 @@ then click this button.</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
<packing>
<property name="expand">False</property>
diff --git a/src/gui/chronojumpIcons.cs b/src/gui/chronojumpIcons.cs
index 9987f9f7..778b4bd5 100644
--- a/src/gui/chronojumpIcons.cs
+++ b/src/gui/chronojumpIcons.cs
@@ -179,6 +179,7 @@ public partial class ChronoJumpWindow
//race encoder
[Widget] Gtk.Image image_race_encoder_open_folder;
+ [Widget] Gtk.Image image_race_encoder_capture_load;
[Widget] Gtk.Image image_race_encoder_capture_recalculate;
//video play icons
@@ -375,6 +376,7 @@ public partial class ChronoJumpWindow
image_encoder_capture_open1.Pixbuf = pixbuf;
image_force_sensor_capture_load.Pixbuf = pixbuf;
image_force_sensor_analyze_load.Pixbuf = pixbuf;
+ image_race_encoder_capture_load.Pixbuf = pixbuf;
pixbuf = new Pixbuf (null, Util.GetImagePath(false) + "zero.png");
image_force_sensor_tare.Pixbuf = pixbuf;
diff --git a/src/gui/runEncoder.cs b/src/gui/runEncoder.cs
index 17d6ef93..fabcb859 100644
--- a/src/gui/runEncoder.cs
+++ b/src/gui/runEncoder.cs
@@ -55,7 +55,7 @@ public partial class ChronoJumpWindow
static bool runEncoderProcessError;
static string lastRunEncoderFile = "";
- static string lastRunEncoderFullPath = "";
+ //static string lastRunEncoderFullPath = "";
//int usbDisconnectedCount;
//int usbDisconnectedLastTime;
@@ -198,7 +198,7 @@ public partial class ChronoJumpWindow
return;
}
- forceSensorReadWidgets();
+ raceEncoderReadWidgets();
runEncoderButtonsSensitive(false);
button_run_encoder_recalculate.Sensitive = false;
@@ -207,7 +207,7 @@ public partial class ChronoJumpWindow
runEncoderButtonsSensitive(true);
}
- private void forceSensorReadWidgets()
+ private void raceEncoderReadWidgets()
{
race_analyzer_distance = Convert.ToInt32(race_analyzer_spinbutton_distance.Value);
race_analyzer_temperature = Convert.ToInt32(race_analyzer_spinbutton_temperature.Value);
@@ -301,13 +301,13 @@ public partial class ChronoJumpWindow
Util.CreateRaceAnalyzerSessionDirIfNeeded (currentSession.UniqueID);
- string nameDate = currentPerson.Name + "_" + UtilDate.ToFile(DateTime.Now);
+ string idNameDate = currentPerson.UniqueID + "_" + currentPerson.Name + "_" +
UtilDate.ToFile(DateTime.Now);
//fileName to save the csv
- string fileName = Util.GetRaceAnalyzerSessionDir(currentSession.UniqueID) +
Path.DirectorySeparatorChar + nameDate + ".csv";
+ string fileName = Util.GetRaceAnalyzerSessionDir(currentSession.UniqueID) +
Path.DirectorySeparatorChar + idNameDate + ".csv";
//lastRunEncoderFile to save the images
- lastRunEncoderFile = nameDate;
+ lastRunEncoderFile = idNameDate;
TextWriter writer = File.CreateText(fileName);
@@ -401,20 +401,79 @@ public partial class ChronoJumpWindow
else {
//call graph. Prepare data
File.Copy(fileName, UtilEncoder.GetRaceAnalyzerCSVFileName(), true); //can be
overwritten
- lastRunEncoderFullPath = fileName;
+ //lastRunEncoderFullPath = fileName;
- forceSensorCaptureGraphDo();
+ raceEncoderCaptureGraphDo();
capturingRunEncoder = arduinoCaptureStatus.COPIED_TO_TMP;
}
}
+ private void on_button_run_encoder_load_clicked (object o, EventArgs args)
+ {
+ if (currentSession == null)
+ return;
+
+ Gtk.FileChooserDialog filechooser = new Gtk.FileChooserDialog ("Choose file",
+ app1, FileChooserAction.Open,
+ "Cancel",ResponseType.Cancel,
+ "Choose",ResponseType.Accept);
+ string dataDir = RunEncoderGraph.GetDataDir(currentSession.UniqueID);
+ filechooser.SetCurrentFolder(dataDir);
+
+ filechooser.Filter = new FileFilter();
+ filechooser.Filter.AddPattern ("*.csv");
+
+ lastRunEncoderFile = "";
+ if (filechooser.Run () == (int)ResponseType.Accept)
+ {
+ lastRunEncoderFile =
Util.RemoveExtension(Util.GetLastPartOfPath(filechooser.Filename));
+
+ //try to change currentPerson on loading set
+ RaceEncoderLoadTryToAssignPerson relt = new RaceEncoderLoadTryToAssignPerson(false,
lastRunEncoderFile, currentSession.UniqueID);
+ Person p = relt.GetPerson();
+ if(p.UniqueID != -1)
+ {
+ currentPerson = p;
+ currentPersonSession = SqlitePersonSession.Select(currentPerson.UniqueID,
currentSession.UniqueID);
+
+ int rowToSelect = myTreeViewPersons.FindRow(p.UniqueID);
+ if(rowToSelect != -1) {
+ //this will update also currentPerson
+ selectRowTreeView_persons(treeview_persons, rowToSelect);
+ }
+
+ label_person_change();
+ personChanged();
+ }
+
+ //lastRunEncoderFullPath = filechooser.Filename; //used on recalculate
+
+ //call graph. Prepare data
+ File.Copy(filechooser.Filename, UtilEncoder.GetRaceAnalyzerCSVFileName(), true);
//can be overwritten
+
+ raceEncoderReadWidgets(); //needed to be able to do R graph
+ raceEncoderCaptureGraphDo();
+
+ Thread.Sleep (250); //Wait a bit to ensure is copied
+
+ runEncoderAnalyzeOpenImage();
+ notebook_analyze.CurrentPage = Convert.ToInt32(notebook_analyze_pages.RACEENCODER);
+ radio_mode_contacts_analyze.Active = true;
+ button_run_encoder_recalculate.Sensitive = true;
+
+ event_execute_label_message.Text = "Loaded: " +
Util.GetLastPartOfPath(filechooser.Filename);
+ }
+ filechooser.Destroy ();
+ }
+
+
private void on_button_run_encoder_recalculate_clicked (object o, EventArgs args)
{
- forceSensorReadWidgets();
- button_run_encoder_recalculate.Sensitive = false;
+ button_run_encoder_recalculate.Sensitive = false; //to not be called two times
+ raceEncoderReadWidgets();
- forceSensorCaptureGraphDo();
+ raceEncoderCaptureGraphDo();
event_execute_label_message.Text = "Recalculated.";
Thread.Sleep (250); //Wait a bit to ensure is copied
@@ -422,9 +481,10 @@ public partial class ChronoJumpWindow
runEncoderAnalyzeOpenImage();
notebook_analyze.CurrentPage = Convert.ToInt32(notebook_analyze_pages.RACEENCODER);
radio_mode_contacts_analyze.Active = true;
+ button_run_encoder_recalculate.Sensitive = true;
}
- private void forceSensorCaptureGraphDo()
+ private void raceEncoderCaptureGraphDo()
{
//create graph
RunEncoderGraph reg = new RunEncoderGraph(
@@ -449,7 +509,7 @@ public partial class ChronoJumpWindow
try {
File.Copy(UtilEncoder.GetSprintEncoderImage(),
Util.GetRaceAnalyzerSessionDir(currentSession.UniqueID) +
Path.DirectorySeparatorChar +
- lastRunEncoderFile + //nameDate
+ lastRunEncoderFile + //idNameDate
".png",
true); //can be overwritten
captureEndedMessage += " (png too)";
diff --git a/src/runEncoder.cs b/src/runEncoder.cs
index 3e586b7b..2e2150d6 100644
--- a/src/runEncoder.cs
+++ b/src/runEncoder.cs
@@ -92,3 +92,46 @@ public class RunEncoderGraph
return "";
}
}
+
+public class RaceEncoderLoadTryToAssignPerson
+{
+ private bool dbconOpened;
+ private string filename; //filename comes without extension
+ private int currentSessionID; //we get a person if already exists on that session
+
+ public RaceEncoderLoadTryToAssignPerson(bool dbconOpened, string filename, int currentSessionID)
+ {
+ this.dbconOpened = dbconOpened;
+ this.filename = filename;
+ this.currentSessionID = currentSessionID;
+ }
+
+ public Person GetPerson()
+ {
+ string personName = getName();
+ if(personName == "")
+ return new Person(-1);
+
+ Person p = SqlitePerson.SelectByName(dbconOpened, personName);
+ if(SqlitePersonSession.PersonSelectExistsInSession(dbconOpened, p.UniqueID, currentSessionID))
+ return p;
+
+ return new Person(-1);
+ }
+
+ private string getName()
+ {
+ string [] strFull = filename.Split(new char[] {'_'});
+
+ /*
+ * first filename was: personName_date_hour
+ * Later filename was: uniqueID_personName_date_hour
+ */
+ if(strFull.Length == 3)
+ return strFull[0];
+ else if(strFull.Length == 4)
+ return strFull[1];
+
+ return "";
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]