[chronojump] DB:1.38 encoderConfiguration always 12 params. Lots of fixes to avoid have multiple records of encod
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] DB:1.38 encoderConfiguration always 12 params. Lots of fixes to avoid have multiple records of encod
- Date: Thu, 16 Mar 2017 17:18:20 +0000 (UTC)
commit 740ebf70744d8aaf3676d58944ba1a93abbc1b8b
Author: Xavier de Blas <xaviblas gmail com>
Date: Thu Mar 16 17:48:15 2017 +0100
DB:1.38 encoderConfiguration always 12 params. Lots of fixes to avoid have multiple records of
encoderConfiguration
glade/app1.glade | 4 +-
src/encoder.cs | 197 +++++++++++++++++++++++----------------
src/encoderRProc.cs | 8 +-
src/gui/encoder.cs | 6 +-
src/gui/encoderConfiguration.cs | 32 ++++---
src/sqlite/main.cs | 77 +++++++++++++++-
6 files changed, 221 insertions(+), 103 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index 5ad5b1f..241e200 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -14016,8 +14016,8 @@ Concentric</property>
</packing>
</child>
<child>
- <widget class="GtkLabel"
id="label_encoder_selected">
- <property name="visible">True</property>
+ <widget class="GtkLabel"
id="label_encoder_selected">
+ <property name="visible">True</property>
<property name="can_focus">False</property>
</widget>
<packing>
diff --git a/src/encoder.cs b/src/encoder.cs
index 2a012b3..db143a3 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -111,7 +111,7 @@ public class EncoderParams
public string Analysis {
get { return analysis; }
}
-
+
~EncoderParams() {}
}
@@ -1210,54 +1210,32 @@ public class EncoderConfiguration
public int extraWeightGrams; //weight of each extra weight (inertia)
public double extraWeightLength; //length from center to center (cm) (inertia)
- public List<double> list_d; //list of diameters depending on the anchorage position
+ public List_d list_d; //object managing a list of diameters depending on the anchorage position
public string textDefault = Catalog.GetString("Linear encoder attached to a barbell.") + "\n" +
Catalog.GetString("Also common gym tests like jumps or chin-ups.");
//this is the default values
- public EncoderConfiguration() {
+ public EncoderConfiguration()
+ {
name = Constants.EncoderConfigurationNames.LINEAR;
type = Constants.EncoderType.LINEAR;
position = 0;
image = Constants.FileNameEncoderLinearFreeWeight;
code = Constants.DefaultEncoderConfigurationCode;
text = textDefault;
- has_d = false;
- has_D = false;
- has_angle_push = false;
- has_angle_weight = false;
- has_inertia = false;
- has_gearedDown = false; //gearedDown can be changed by user
- rotaryFrictionOnAxis = false;
- d = -1;
- D = -1;
- anglePush = -1;
- angleWeight = -1;
- inertiaMachine = -1;
- gearedDown = 1;
- inertiaTotal = -1;
- extraWeightN = 0;
- extraWeightGrams = 0;
- extraWeightLength = 1;
- list_d = new List<double>();
+
+ setDefaultOptions();
}
// note: if this changes, change also in:
// UtilEncoder.EncoderConfigurationList(enum encoderType)
- public EncoderConfiguration(Constants.EncoderConfigurationNames name) {
+ public EncoderConfiguration(Constants.EncoderConfigurationNames name)
+ {
this.name = name;
- has_d = false;
- has_D = false;
- has_angle_push = false;
- has_angle_weight = false;
- has_inertia = false;
- has_gearedDown = false; //gearedDown can be changed by user
- rotaryFrictionOnAxis = false;
- gearedDown = 1;
- list_d = new List<double>();
+ setDefaultOptions();
// ---- LINEAR ----
// ---- not inertial
@@ -1557,12 +1535,35 @@ public class EncoderConfiguration
}
}
- public void SetInertialDefaultOptions() {
+ private void setDefaultOptions()
+ {
+ has_d = false;
+ has_D = false;
+ has_angle_push = false;
+ has_angle_weight = false;
+ has_inertia = false;
+ has_gearedDown = false; //gearedDown can be changed by user
+ rotaryFrictionOnAxis = false;
+ d = -1;
+ D = -1;
+ anglePush = -1;
+ angleWeight = -1;
+ inertiaMachine = -1;
+ gearedDown = 1;
+ inertiaTotal = -1;
+ extraWeightN = 0;
+ extraWeightGrams = 0;
+ extraWeightLength = 1;
+ list_d = new List_d();
+ }
+
+ public void SetInertialDefaultOptions()
+ {
//after creating Constants.EncoderConfigurationNames.ROTARYAXISINERTIAL
inertiaMachine = 900;
d = 5;
- list_d = new List<double>();
- list_d.Add(d);
+ list_d = new List_d(d);
+ inertiaTotal = UtilEncoder.CalculeInertiaTotal(this);
}
public void ReadParamsFromSQL (string [] strFull)
@@ -1574,40 +1575,11 @@ public class EncoderConfiguration
this.angleWeight = Convert.ToInt32(strFull[4]);
this.inertiaMachine = Convert.ToInt32(strFull[5]);
this.gearedDown = Convert.ToInt32(strFull[6]);
-
- //this params started at 1.5.1
- if(strFull.Length > 7) {
- this.inertiaTotal = Convert.ToInt32(strFull[7]);
- this.extraWeightN = Convert.ToInt32(strFull[8]);
- this.extraWeightGrams = Convert.ToInt32(strFull[9]);
- this.extraWeightLength = Convert.ToDouble(Util.ChangeDecimalSeparator(strFull[10]));
- if(strFull.Length > 11) //this param starts at 1.5.3
- this.list_d = readList_d(strFull[11]);
- } else {
- this.inertiaTotal = inertiaMachine;
- this.extraWeightN = 0;
- this.extraWeightGrams = 0;
- this.extraWeightLength = 1;
- }
-
- //if we load a signal previous to 1.5.3, put d in list_d to have something to be sent to R
- if(this.list_d.Count == 0)
- this.list_d.Add(d);
- else if (this.list_d.Count == 1 && this.list_d[0] == 0) {
- //check if diameter is zero is safest because some tests have been done while list_d
has been completely implemented
- this.list_d[0] = this.d;
- }
- }
- //list_d contains the different diameters (byt eh anchorages). They are stored as '_'
- private List<double> readList_d(string listFromSQL)
- {
- List<double> l = new List<double>();
- string [] strFull = listFromSQL.Split(new char[] {'_'});
- foreach (string s in strFull) {
- double d = Convert.ToDouble(Util.ChangeDecimalSeparator(s));
- l.Add(d);
- }
- return l;
+ this.inertiaTotal = Convert.ToInt32(strFull[7]);
+ this.extraWeightN = Convert.ToInt32(strFull[8]);
+ this.extraWeightGrams = Convert.ToInt32(strFull[9]);
+ this.extraWeightLength = Convert.ToDouble(Util.ChangeDecimalSeparator(strFull[10]));
+ this.list_d.ReadFromSQL(strFull[11]);
}
public enum Outputs { ROPTIONS, RCSV, SQL, SQLECWINCOMPARE}
@@ -1673,20 +1645,10 @@ public class EncoderConfiguration
my_str_extraWeightN + sep +
extraWeightGrams.ToString() + sep +
extraWeightLength.ToString() + sep +
- writeList_d(list_d)
- ;
+ list_d.ToString();
}
}
- private string writeList_d(List<double> l) {
- string str = "";
- string sep = "";
- foreach(double d in l) {
- str += sep + Util.ConvertToPoint(d);
- sep = "_";
- }
- return str;
- }
-
+
//just to show on a treeview
public string ToStringPretty() {
string sep = "; ";
@@ -1774,6 +1736,81 @@ public class EncoderConfiguration
}
}
+/*
+ * class that manages list of diameters on encoderConfiguration
+ * read_list_d returns a List<double>. when reading a "" value from SQL is usually converted to 0 here
+ * and then a list_d Add will add a new value
+ * control list_d values with this class
+ * if there are no diameters, list_d has one value: 0
+ */
+public class List_d
+{
+ private List<double> l;
+
+ //default constructor
+ public List_d()
+ {
+ l = new List<double>();
+ l.Add(0);
+ }
+ //constructor with a default value
+ public List_d(double d)
+ {
+ l = new List<double>();
+ l.Add(d);
+ }
+
+ //list_d contains the different diameters (anchorages). They are stored as '_'
+ public void ReadFromSQL(string listFromSQL)
+ {
+ l = new List<double>();
+ string [] strFull = listFromSQL.Split(new char[] {'_'});
+ foreach (string s in strFull) {
+ double d = Convert.ToDouble(Util.ChangeDecimalSeparator(s));
+ l.Add(d);
+ }
+
+ if(l.Count == 0)
+ l.Add(0);
+ }
+
+ public void Add(double d)
+ {
+ if(l.Count == 1 && l[0] == 0)
+ l[0] = d;
+ else
+ l.Add(d);
+ }
+
+ public override string ToString()
+ {
+ string str = "";
+ string sep = "";
+ foreach(double d in l) {
+ str += sep + Util.ConvertToPoint(d);
+ sep = "_";
+ }
+
+ if(str == "")
+ str = "0";
+
+ return str;
+ }
+
+ public bool IsEmpty()
+ {
+ if(l == null || l.Count == 0 || (l.Count == 1 && l[0] == 0) )
+ return true;
+
+ return false;
+ }
+
+ public List<double> L
+ {
+ get { return l; }
+ }
+
+}
public class EncoderAnalyzeInstant
{
diff --git a/src/encoderRProc.cs b/src/encoderRProc.cs
index cfdc9b3..ec0e423 100644
--- a/src/encoderRProc.cs
+++ b/src/encoderRProc.cs
@@ -79,7 +79,7 @@ public abstract class EncoderRProc
LogB.Information("pBin:", pBin);
return pBin;
}
-
+
protected virtual void writeOptionsFile()
{
}
@@ -224,12 +224,12 @@ public class EncoderRProcCapture : EncoderRProc
p.StandardInput.WriteLine(curveCompressed); //this will send some lines because
compressed data comes with '\n's
p.StandardInput.WriteLine("E"); //this will mean the 'E'nd of the curve. Then data
can be uncompressed on R
- }
-
+ }
+
protected override void writeOptionsFile()
{
optionsFile = Path.GetTempPath() + "Roptions.txt";
-
+
string scriptOptions = UtilEncoder.PrepareEncoderGraphOptions(
"none", //title
es,
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index af92b4e..da56a95 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -492,7 +492,7 @@ public partial class ChronoJumpWindow
{
if(encoderConfigurationCurrent.has_inertia) {
if(combo_encoder_anchorage_should_update) {
- UtilGtk.ComboUpdate(combo_encoder_anchorage,
encoderConfigurationCurrent.list_d);
+ UtilGtk.ComboUpdate(combo_encoder_anchorage,
encoderConfigurationCurrent.list_d.L);
combo_encoder_anchorage.Active = UtilGtk.ComboMakeActive(
combo_encoder_anchorage,
encoderConfigurationCurrent.d.ToString()
@@ -1522,9 +1522,9 @@ public partial class ChronoJumpWindow
label_encoder_exercise_inertia.Visible = true;
vbox_encoder_exercise_inertia.Visible = true;
- if(encoderConfigurationCurrent.list_d != null &&
encoderConfigurationCurrent.list_d.Count > 0)
+ if(! encoderConfigurationCurrent.list_d.IsEmpty())
{
- UtilGtk.ComboUpdate(combo_encoder_anchorage,
encoderConfigurationCurrent.list_d);
+ UtilGtk.ComboUpdate(combo_encoder_anchorage,
encoderConfigurationCurrent.list_d.L);
combo_encoder_anchorage.Active = UtilGtk.ComboMakeActive(
combo_encoder_anchorage,
encoderConfigurationCurrent.d.ToString()
diff --git a/src/gui/encoderConfiguration.cs b/src/gui/encoderConfiguration.cs
index 0ff55ea..736096d 100644
--- a/src/gui/encoderConfiguration.cs
+++ b/src/gui/encoderConfiguration.cs
@@ -291,19 +291,19 @@ public class EncoderConfigurationWindow
showHideSide(sideModes.HIDDEN);
}
- private void putValuesStoredPreviously(double d, List<double> list_d, double D, int anglePush, int
angleWeight,
- int inertia, int extraWeightGrams, double extraWeightLength,
- bool has_gearedDown, string gearedUpDisplay)
+ private void putValuesStoredPreviously(double d, List_d list_d, double D, int anglePush, int
angleWeight,
+ int inertia, int extraWeightGrams, double extraWeightLength,
+ bool has_gearedDown, string gearedUpDisplay)
{
if(d != -1)
spin_d.Value = d;
- if(list_d != null && list_d.Count > 0) {
+ if(! list_d.IsEmpty()) {
//when there's 1 value in list_d, first value (0) in combo should be selected
- combo_d_num.Active = list_d.Count -1; //this will perform a reset on spinbuttons
+ combo_d_num.Active = list_d.L.Count -1; //this will perform a reset on spinbuttons
int i = 0;
foreach(Gtk.SpinButton sp in hbox_list_d.Children)
- sp.Value = list_d[i ++];
+ sp.Value = list_d.L[i ++];
}
if(D != -1)
@@ -395,14 +395,15 @@ public class EncoderConfigurationWindow
hbox_list_d.ShowAll();
}
- private List<double> get_list_d () {
- List<double> l = new List<double>();
+ private List_d get_list_d()
+ {
+ List_d list_d = new List_d();
double d = new double();
foreach(Gtk.SpinButton sp in hbox_list_d.Children) {
d = (double) sp.Value;
- l.Add(d);
+ list_d.Add(d);
}
- return l;
+ return list_d;
}
/*
@@ -416,11 +417,16 @@ public class EncoderConfigurationWindow
EncoderConfiguration ec = (EncoderConfiguration) list[listCurrent];
ec.d = -1;
- ec.list_d = new List<double>();
+ ec.list_d = new List_d();
ec.D = -1;
ec.anglePush = -1;
ec.angleWeight = -1;
ec.inertiaMachine = -1;
+ ec.gearedDown = 1;
+ ec.inertiaTotal = -1;
+ ec.extraWeightN = 0;
+ ec.extraWeightGrams = 0;
+ ec.extraWeightLength = 1;
if(ec.has_d) {
if(ec.has_inertia)
@@ -432,7 +438,7 @@ public class EncoderConfigurationWindow
{
LogB.Information("main_gui_anchorage = " + main_gui_anchorage_str);
double guiAnchorage = Convert.ToDouble(main_gui_anchorage_str);
- foreach(double d in ec.list_d) {
+ foreach(double d in ec.list_d.L) {
LogB.Information("d = " + d.ToString());
if(d == guiAnchorage) {
ec.d = guiAnchorage;
@@ -443,7 +449,7 @@ public class EncoderConfigurationWindow
}
if(! found)
- ec.d = ec.list_d[0];
+ ec.d = ec.list_d.L[0];
}
else
ec.d = (double) spin_d.Value;
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index a3de4eb..ec866fd 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -125,7 +125,7 @@ class Sqlite
/*
* Important, change this if there's any update to database
*/
- static string lastChronojumpDatabaseVersion = "1.37";
+ static string lastChronojumpDatabaseVersion = "1.38";
public Sqlite() {
}
@@ -2079,6 +2079,71 @@ class Sqlite
currentVersion = updateVersion("1.37");
}
+ if(currentVersion == "1.37")
+ {
+ /*
+ * encoderConfiguration has 7 values, 11 at 1.5.1 and 12 from 1.5.3.
+ * I't safe to convert everything to 12
+ * Example of checking the number of values using the separator (colon)
character
+ * SELECT LENGTH(encoderConfiguration) - LENGTH(REPLACE(encoderConfiguration,
":", "")) AS colons, count(*) FROM encoder GROUP BY colons;
+ * 6|2149
+ * 10|74
+ * 11|1505
+ * */
+
+ //encoderConfiguration table. Update fields with 6 ':'
+ executeSQL("UPDATE encoderConfiguration " +
+ "SET encoderConfiguration = encoderConfiguration ||
\":-1:0:0:1:0\" " +
+ "WHERE LENGTH(encoderConfiguration) -
LENGTH(REPLACE(encoderConfiguration, \":\", \"\")) = 6");
+
+ //encoderConfiguration table. Update fields with 10 ':'
+ executeSQL("UPDATE encoderConfiguration " +
+ "SET encoderConfiguration = encoderConfiguration || \":0\" " +
+ "WHERE LENGTH(encoderConfiguration) -
LENGTH(REPLACE(encoderConfiguration, \":\", \"\")) = 10");
+
+ //encoder table. Update fields with 6 ':'
+ executeSQL("UPDATE encoder " +
+ "SET encoderConfiguration = encoderConfiguration ||
\":-1:0:0:1:0\" " +
+ "WHERE LENGTH(encoderConfiguration) -
LENGTH(REPLACE(encoderConfiguration, \":\", \"\")) = 6");
+
+ //encoder table. Update fields with 10 ':'
+ executeSQL("UPDATE encoder " +
+ "SET encoderConfiguration = encoderConfiguration || \":0\" " +
+ "WHERE LENGTH(encoderConfiguration) -
LENGTH(REPLACE(encoderConfiguration, \":\", \"\")) = 10");
+
+
+ /*
+ * encoderConfiguration last parameter: list_d when is not used, sometimes is
":" or ":0" or ":-1"
+ * Convert all to ":0" that's how is going to be always when there are empty
vales, from now on
+ *
+ * Don't use REPLACE because it will change all the -1 and not just the last
one
+ */
+
+ // A) encoderConfiguration table
+ // If ends with ":" convert to ":0"
+ executeSQL("UPDATE encoderConfiguration " +
+ "SET encoderConfiguration = encoderConfiguration || \"0\" " +
+ "WHERE SUBSTR(encoderConfiguration, -1, 1) = \":\"");
+
+ // If ends with ":-1" convert to ":0"
+ executeSQL("UPDATE encoderConfiguration " +
+ "SET encoderConfiguration = SUBSTR(encoderConfiguration, 0,
LENGTH(encoderConfiguration) +1 -2) || \"0\" " +
+ "WHERE SUBSTR(encoderConfiguration, -3, 3) = \":-1\"");
+
+ // B) encoder table
+ // If ends with ":" convert to ":0"
+ executeSQL("UPDATE encoder " +
+ "SET encoderConfiguration = encoderConfiguration || \"0\" " +
+ "WHERE SUBSTR(encoderConfiguration, -1, 1) = \":\"");
+
+ // If ends with ":-1" convert to ":0"
+ executeSQL("UPDATE encoder " +
+ "SET encoderConfiguration = SUBSTR(encoderConfiguration, 0,
LENGTH(encoderConfiguration) +1 -2) || \"0\" " +
+ "WHERE SUBSTR(encoderConfiguration, -3, 3) = \":-1\"");
+
+ currentVersion = updateVersion("1.38");
+ }
+
// --- add more updates here
@@ -2097,6 +2162,13 @@ class Sqlite
return returnSoftwareIsNew;
}
+ private static void executeSQL(string command)
+ {
+ dbcmd.CommandText = command;
+ LogB.SQL(dbcmd.CommandText.ToString());
+ dbcmd.ExecuteNonQuery();
+ }
+
private static string updateVersion(string newVersion) {
SqlitePreferences.Update ("databaseVersion", newVersion, true);
return newVersion;
@@ -2248,6 +2320,9 @@ class Sqlite
SqliteChronopicRegister.createTableChronopicRegister();
//changes [from - to - desc]
+ //1.37 - 1.38 Converted DB to 1.38 encoderConfiguration always with 12 values. Empty
encoderConfiguration list_d as '' instead of '-1' or '0'
+ //1.36 - 1.37 Converted DB to 1.37 Deleted encoderConfiguration variable. Added
encoderConfiguration table (1.36)
+ //1.35 - 1.36 Converted DB to 1.36 Deleted encoderConfiguration table
//1.34 - 1.35 Converted DB to 1.35 Added encoderConfiguration table
//1.33 - 1.34 Converted DB to 1.34 Added thresholdJumps, thresholdRuns, thresholdOther to
preferences
//1.32 - 1.33 Converted DB to 1.33 Added chronopicRegister table
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]