[chronojump] RunEncoderExercise, also on import. Note DB 1.69-1.70 changed
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] RunEncoderExercise, also on import. Note DB 1.69-1.70 changed
- Date: Tue, 17 Sep 2019 15:15:26 +0000 (UTC)
commit 3fe62caf9ec6944f8663d5af3a76f80636e99787
Author: Xavier de Blas <xaviblas gmail com>
Date: Tue Sep 17 17:14:46 2019 +0200
RunEncoderExercise, also on import. Note DB 1.69-1.70 changed
glade/app1.glade | 96 +++++++++++++++++++++++++++++-
src/constants.cs | 2 +-
src/gui/chronojump.cs | 1 +
src/gui/chronojumpIcons.cs | 4 ++
src/gui/runEncoder.cs | 50 ++++++++++++++++
src/runEncoder.cs | 84 ++++++++++++++++++++++----
src/sqlite/main.cs | 6 +-
src/sqlite/runEncoder.cs | 143 ++++++++++++++++++++++++++++++++++++++++++++-
8 files changed, 368 insertions(+), 18 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index a116657e..0744299e 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -7088,10 +7088,104 @@ EncoderInertialCapture</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
+ <widget class="GtkHBox" id="hbox_run_encoder">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">20</property>
+ <child>
+ <widget class="GtkHBox" id="hbox332">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">8</property>
+ <child>
<widget class="GtkLabel" id="label368">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="label">Race analyzer - SOON
AVAILABLE</property>
+ <property name="label"
translatable="yes">Test</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="hbox_combo_run_encoder_exercise">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <placeholder/>
+ </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">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkHBox" id="hbox333">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">8</property>
+ <child>
+ <widget class="GtkButton"
id="button_run_encoder_exercise_edit">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="has_tooltip">True</property>
+ <property name="tooltip" translatable="yes">Edit
exercise type</property>
+ <child>
+ <widget class="GtkImage"
id="image_run_encoder_exercise_edit">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="stock">gtk-new</property>
+ <property name="icon-size">2</property>
+ </widget>
+ </child>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkButton"
id="button_run_encoder_exercise_add">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="has_tooltip">True</property>
+ <property name="tooltip" translatable="yes">Add
exercise type</property>
+ <child>
+ <widget class="GtkImage"
id="image_run_encoder_exercise_add">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="stock">gtk-new</property>
+ <property name="icon-size">2</property>
+ </widget>
+ </child>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
</widget>
<packing>
<property name="expand">False</property>
diff --git a/src/constants.cs b/src/constants.cs
index 8a0dbef1..191eaf22 100644
--- a/src/constants.cs
+++ b/src/constants.cs
@@ -161,7 +161,7 @@ public class Constants
public const string ForceSensorExerciseTable = "forceSensorExercise";
public const string ForceRFDTable = "forceRFD";
public const string RunEncoderTable = "runEncoder";
- //public const string RunEncoderExerciseTable = "runEncoderExercise";
+ public const string RunEncoderExerciseTable = "runEncoderExercise";
// Dummy variables that exists for translating purposes
// pragma warning is to avoid warnings of "defined and not used" for these variables.
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index 05cef1d8..3b6f363e 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -621,6 +621,7 @@ public partial class ChronoJumpWindow
rfdList = SqliteForceSensorRFD.SelectAll(false);
impulse = SqliteForceSensorRFD.SelectImpulse(false);
initForceSensor();
+ initRunEncoder();
createComboSelectJumps(true);
diff --git a/src/gui/chronojumpIcons.cs b/src/gui/chronojumpIcons.cs
index 778b4bd5..4e25772d 100644
--- a/src/gui/chronojumpIcons.cs
+++ b/src/gui/chronojumpIcons.cs
@@ -181,6 +181,8 @@ public partial class ChronoJumpWindow
[Widget] Gtk.Image image_race_encoder_open_folder;
[Widget] Gtk.Image image_race_encoder_capture_load;
[Widget] Gtk.Image image_race_encoder_capture_recalculate;
+ [Widget] Gtk.Image image_run_encoder_exercise_edit;
+ [Widget] Gtk.Image image_run_encoder_exercise_add;
//video play icons
[Widget] Gtk.Image image_video_play_this_test;
@@ -339,6 +341,7 @@ public partial class ChronoJumpWindow
image_add_test3.Pixbuf = pixbuf;
image_add_test4.Pixbuf = pixbuf;
image_add_test5.Pixbuf = pixbuf;
+ image_run_encoder_exercise_add.Pixbuf = pixbuf;
pixbuf = new Pixbuf (null, Util.GetImagePath(false) + "image_test_inspect.png");
image_test_inspect.Pixbuf = pixbuf;
@@ -394,6 +397,7 @@ public partial class ChronoJumpWindow
pixbuf = new Pixbuf (null, Util.GetImagePath(false) + "image_edit.png");
image_encoder_exercise_edit.Pixbuf = pixbuf;
image_force_sensor_exercise_edit.Pixbuf = pixbuf;
+ image_run_encoder_exercise_edit.Pixbuf = pixbuf;
image_edit_current_person.Pixbuf = pixbuf;
image_edit_current_person_h.Pixbuf = pixbuf;
image_session_edit.Pixbuf = pixbuf;
diff --git a/src/gui/runEncoder.cs b/src/gui/runEncoder.cs
index e1b95490..ae4efa89 100644
--- a/src/gui/runEncoder.cs
+++ b/src/gui/runEncoder.cs
@@ -34,6 +34,9 @@ using Mono.Unix;
public partial class ChronoJumpWindow
{
[Widget] Gtk.MenuItem menuitem_race_encoder_open_folder;
+
+ [Widget] Gtk.HBox hbox_combo_run_encoder_exercise;
+ [Widget] Gtk.ComboBox combo_run_encoder_exercise;
[Widget] Gtk.SpinButton race_analyzer_spinbutton_distance;
[Widget] Gtk.SpinButton race_analyzer_spinbutton_temperature;
[Widget] Gtk.SpinButton race_analyzer_spinbutton_graph_width;
@@ -221,6 +224,11 @@ public partial class ChronoJumpWindow
currentRunEncoder = new RunEncoder();
}
+ private void initRunEncoder ()
+ {
+ createRunEncoderExerciseCombo();
+ }
+
private void raceEncoderReadWidgets()
{
race_analyzer_distance = Convert.ToInt32(race_analyzer_spinbutton_distance.Value);
@@ -901,4 +909,46 @@ LogB.Information(" fc R ");
new DialogMessage(Constants.MessageTypes.WARNING, Constants.DirectoryCannotOpenStr());
}
+ // -------------------------------- exercise stuff --------------------
+
+
+ string [] runEncoderComboExercisesString; //id:name (no translations, use user language)
+
+ private void createRunEncoderExerciseCombo ()
+ {
+ //run_encoder_exercise
+
+ combo_run_encoder_exercise = ComboBox.NewText ();
+ fillRunEncoderExerciseCombo("");
+
+// combo_run_encoder_exercise.Changed += new EventHandler
(on_combo_run_encoder_exercise_changed);
+ hbox_combo_run_encoder_exercise.PackStart(combo_run_encoder_exercise, true, true, 0);
+ hbox_combo_run_encoder_exercise.ShowAll();
+ }
+
+ private void fillRunEncoderExerciseCombo(string name)
+ {
+ ArrayList runEncoderExercises = SqliteRunEncoderExercise.Select (false, -1, false);
+ if(runEncoderExercises.Count == 0)
+ {
+ runEncoderComboExercisesString = new String [0];
+ return;
+ }
+
+ runEncoderComboExercisesString = new String [runEncoderExercises.Count];
+ string [] exerciseNamesToCombo = new String [runEncoderExercises.Count];
+ int i =0;
+ foreach(RunEncoderExercise ex in runEncoderExercises)
+ {
+ exerciseNamesToCombo[i] = ex.Name;
+ runEncoderComboExercisesString[i] = ex.UniqueID + ":" + ex.Name;
+ i++;
+ }
+
+ UtilGtk.ComboUpdate(combo_run_encoder_exercise, exerciseNamesToCombo, "");
+ if(name == "")
+ combo_run_encoder_exercise.Active = 0;
+ else
+ combo_run_encoder_exercise.Active =
UtilGtk.ComboMakeActive(combo_run_encoder_exercise, name);
+ }
}
diff --git a/src/runEncoder.cs b/src/runEncoder.cs
index 2ff5c805..a7e99323 100644
--- a/src/runEncoder.cs
+++ b/src/runEncoder.cs
@@ -197,6 +197,47 @@ public class RunEncoder
}
}
+public class RunEncoderExercise
+{
+ private int uniqueID;
+ private string name;
+ private string description;
+
+ public RunEncoderExercise()
+ {
+ }
+
+ public RunEncoderExercise(string name)
+ {
+ this.name = name;
+ }
+
+ public RunEncoderExercise(int uniqueID, string name, string description)
+ {
+ this.uniqueID = uniqueID;
+ this.name = name;
+ this.description = description;
+ }
+
+ public override string ToString()
+ {
+ return uniqueID.ToString() + ":" + name + ":" + description + ":";
+ }
+
+ public int UniqueID
+ {
+ get { return uniqueID; }
+ }
+ public string Name
+ {
+ get { return name; }
+ }
+ public string Description
+ {
+ get { return description; }
+ }
+}
+
public class RunEncoderGraph
{
private int testLength;
@@ -266,22 +307,26 @@ public class RunEncoderGraph
}
}
-public class RunEncoderLoadTryToAssignPerson
+public class RunEncoderLoadTryToAssignPersonAndComment
{
private bool dbconOpened;
private string filename; //filename comes without extension
private int currentSessionID; //we get a person if already exists on that session
- public RunEncoderLoadTryToAssignPerson(bool dbconOpened, string filename, int currentSessionID)
+ public string Comment;
+
+ public RunEncoderLoadTryToAssignPersonAndComment(bool dbconOpened, string filename, int
currentSessionID)
{
this.dbconOpened = dbconOpened;
this.filename = filename;
this.currentSessionID = currentSessionID;
+
+ Comment = "";
}
public Person GetPerson()
{
- string personName = getName();
+ string personName = getNameAndComment();
if(personName == "")
return new Person(-1);
@@ -292,19 +337,36 @@ public class RunEncoderLoadTryToAssignPerson
return new Person(-1);
}
- private string getName()
+ private string getNameAndComment()
{
+ string name = "";
+
string [] strFull = filename.Split(new char[] {'_'});
/*
* first filename was: personName_date_hour
- * Later filename was: uniqueID_personName_date_hour
+ * but we have lots of files with comments added manually like:
+ * first filename was: personName_date_hour_comment
+ * first filename was: personName_date_hour_comment_long_with_underscores
*/
- if(strFull.Length == 3)
- return strFull[0];
- else if(strFull.Length == 4)
- return strFull[1];
-
- return "";
+ if(strFull.Length >= 3)
+ name = strFull[0];
+
+ if(strFull.Length == 4) //with one comment
+ Comment = strFull[3];
+ else if(strFull.Length > 4) //with comments separated by underscores
+ {
+ string myComment = "";
+ string sep = "";
+ for(int i = 3; i <= strFull.Length -3; i ++)
+ {
+ myComment += sep + strFull[i];
+ sep = "_";
+ }
+
+ Comment = myComment;
+ }
+
+ return name;
}
}
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index a5c1cb2b..b1babd80 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -2442,9 +2442,10 @@ class Sqlite
}
if(currentVersion == "1.69")
{
- LogB.SQL("Created table: RunEncoder");
+ LogB.SQL("Created tables: RunEncoder, RunEncoderExercise");
SqliteRunEncoder.createTable();
+ SqliteRunEncoderExercise.createTable();
currentVersion = updateVersion("1.70");
}
@@ -2637,6 +2638,7 @@ class Sqlite
//runEncoder
SqliteRunEncoder.createTable();
+ SqliteRunEncoderExercise.createTable();
creationRate ++;
SqlitePreferences.createTable();
@@ -2649,7 +2651,7 @@ class Sqlite
//changes [from - to - desc]
//1.70 - 1.71 Converted DB to 1.71 Imported run encoder text files into SQL
- //1.69 - 1.70 Converted DB to 1.70 Created table: RunEncoder
+ //1.69 - 1.70 Converted DB to 1.70 Created tables: RunEncoder, RunEncoderExercise
//1.68 - 1.69 Converted DB to 1.69 Imported force sensor text files into SQL
//1.67 - 1.68 Converted DB to 1.68 Created table: ForceSensor
//1.66 - 1.67 Converted DB to 1.67 ALTER TABLE Constants.ForceSensorExerciseTable ADD COLUMN
tareBeforeCapture INT
diff --git a/src/sqlite/runEncoder.cs b/src/sqlite/runEncoder.cs
index 23859689..3975b0f9 100644
--- a/src/sqlite/runEncoder.cs
+++ b/src/sqlite/runEncoder.cs
@@ -203,8 +203,8 @@ class SqliteRunEncoder : Sqlite
continue;
string fileWithoutExtension =
Util.RemoveExtension(Util.GetLastPartOfPath(file.Name));
- RunEncoderLoadTryToAssignPerson relt =
- new RunEncoderLoadTryToAssignPerson(true, fileWithoutExtension,
Convert.ToInt32(session.Name));
+ RunEncoderLoadTryToAssignPersonAndComment relt =
+ new RunEncoderLoadTryToAssignPersonAndComment(true,
fileWithoutExtension, Convert.ToInt32(session.Name));
Person p = relt.GetPerson();
if(p.UniqueID == -1)
@@ -235,7 +235,7 @@ class SqliteRunEncoder : Sqlite
RunEncoder.Devices.MANUAL, distance, temperature,
myFilename,
Util.MakeURLrelative(Util.GetRunEncoderSessionDir(Convert.ToInt32(session.Name))),
- parsedDate, "", "");
+ parsedDate, relt.Comment, "");
runEncoder.InsertSQL(true);
}
}
@@ -245,3 +245,140 @@ class SqliteRunEncoder : Sqlite
}
}
+
+class SqliteRunEncoderExercise : Sqlite
+{
+ private static string table = Constants.RunEncoderExerciseTable;
+
+ public SqliteRunEncoderExercise() {
+ }
+
+ ~SqliteRunEncoderExercise() {}
+
+ /*
+ * create and initialize tables
+ */
+
+ protected internal static void createTable()
+ {
+ dbcmd.CommandText =
+ "CREATE TABLE " + table + " ( " +
+ "uniqueID INTEGER PRIMARY KEY, " +
+ "name TEXT, " +
+ "description TEXT)";
+ LogB.SQL(dbcmd.CommandText.ToString());
+ dbcmd.ExecuteNonQuery();
+ }
+
+ //undefined defaultAngle will be 1000
+ //note execution can have a different angle than the default angle
+ public static int Insert (bool dbconOpened, int uniqueID, string name, string description)
+ {
+ if(! dbconOpened)
+ Sqlite.Open();
+
+ string uniqueIDStr = "NULL";
+ if(uniqueID != -1)
+ uniqueIDStr = uniqueID.ToString();
+
+ dbcmd.CommandText = "INSERT INTO " + table +
+ " (uniqueID, name, description) VALUES (" +
+ uniqueIDStr + ", \"" + name + "\", \"" + description + "\")";
+ LogB.SQL(dbcmd.CommandText.ToString());
+ dbcmd.ExecuteNonQuery();
+
+ string myString = @"select last_insert_rowid()";
+ dbcmd.CommandText = myString;
+ int myLast = Convert.ToInt32(dbcmd.ExecuteScalar()); // Need to type-cast since
`ExecuteScalar` returns an object.
+
+ if(! dbconOpened)
+ Sqlite.Close();
+
+ return myLast;
+ }
+
+ public static void Update (bool dbconOpened, RunEncoderExercise ex)
+ {
+ if(! dbconOpened)
+ Sqlite.Open();
+
+ /*
+ string uniqueIDStr = "NULL";
+ if(ex.UniqueID != -1)
+ uniqueIDStr = ex.UniqueID.ToString();
+ */
+
+ dbcmd.CommandText = "UPDATE " + table + " SET " +
+ " name = \"" + ex.Name +
+ "\", description = \"" + ex.Description +
+ "\", WHERE uniqueID = " + ex.UniqueID;
+
+ LogB.SQL(dbcmd.CommandText.ToString());
+ dbcmd.ExecuteNonQuery();
+
+ if(! dbconOpened)
+ Sqlite.Close();
+ }
+
+ public static void Delete (bool dbconOpened, int uniqueID)
+ {
+ openIfNeeded(dbconOpened);
+
+ dbcmd.CommandText = "DELETE FROM " + table + " WHERE uniqueID = " + uniqueID;
+
+ LogB.SQL(dbcmd.CommandText.ToString());
+ dbcmd.ExecuteNonQuery();
+
+ closeIfNeeded(dbconOpened);
+ }
+
+
+ public static ArrayList Select (bool dbconOpened, int uniqueID, bool onlyNames)
+ {
+ if(! dbconOpened)
+ Sqlite.Open();
+
+ string uniqueIDStr = "";
+ if(uniqueID != -1)
+ uniqueIDStr = " WHERE " + table + ".uniqueID = " + uniqueID;
+
+ if(onlyNames)
+ dbcmd.CommandText = "SELECT name FROM " + table + uniqueIDStr;
+ else
+ dbcmd.CommandText = "SELECT * FROM " + table + uniqueIDStr;
+
+ LogB.SQL(dbcmd.CommandText.ToString());
+ dbcmd.ExecuteNonQuery();
+
+ SqliteDataReader reader;
+ reader = dbcmd.ExecuteReader();
+
+ ArrayList array = new ArrayList(1);
+ RunEncoderExercise ex = new RunEncoderExercise();
+
+ if(onlyNames) {
+ while(reader.Read()) {
+ ex = new RunEncoderExercise (reader[0].ToString());
+ array.Add(ex);
+ }
+ } else {
+ while(reader.Read()) {
+ int angleDefault = 0;
+
+ ex = new RunEncoderExercise (
+ Convert.ToInt32(reader[0].ToString()), //uniqueID
+ reader[1].ToString(), //name
+ reader[2].ToString() //description
+ );
+ array.Add(ex);
+ }
+ }
+
+ reader.Close();
+ if(! dbconOpened)
+ Sqlite.Close();
+
+ return array;
+ }
+
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]