[chronojump] ForceSensor stiffness better use of * and recalculate



commit b30154129d5c7267baf98be9c2b1f596ec9a053a
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Oct 24 20:09:26 2019 +0200

    ForceSensor stiffness better use of * and recalculate

 diagrams/sqlite/chronojump_sqlite.dia | Bin 19279 -> 19540 bytes
 src/forceSensor.cs                    |  41 +++++++++++++++++++++++++++++-----
 src/gui/forceSensor.cs                |  33 +++++++++++++++++----------
 src/gui/forceSensorElasticBands.cs    |   7 +++---
 src/sqlite/forceSensor.cs             |  31 ++++++++++++++++++-------
 5 files changed, 82 insertions(+), 30 deletions(-)
---
diff --git a/diagrams/sqlite/chronojump_sqlite.dia b/diagrams/sqlite/chronojump_sqlite.dia
index 52926b88..f1feeb83 100644
Binary files a/diagrams/sqlite/chronojump_sqlite.dia and b/diagrams/sqlite/chronojump_sqlite.dia differ
diff --git a/src/forceSensor.cs b/src/forceSensor.cs
index b881c59f..ffe16ea2 100644
--- a/src/forceSensor.cs
+++ b/src/forceSensor.cs
@@ -64,7 +64,7 @@ public class ForceSensor
        private string comments;
        private string videoURL;
        private double stiffness; //on not elastic capture will be -1 (just check if it is negative because 
it's a double and sometimes -1.0 comparisons don't work)
-       private string stiffnessString;
+       private string stiffnessString; //id0*active0;id1*active1
 
        private string exerciseName;
 
@@ -273,7 +273,7 @@ public class ForceSensor
        public double Stiffness
        {
                get { return stiffness; }
-               //set { stiffness = value; }
+               set { stiffness = value; }
        }
        public string StiffnessString
        {
@@ -478,7 +478,7 @@ public class ForceSensorElasticBand
                if(uniqueID != -1)
                        uniqueIDStr = uniqueID.ToString();
 
-               LogB.Information("stiffness is: " + stiffness.ToString());
+               //LogB.Information("stiffness is: " + stiffness.ToString());
                return
                        uniqueIDStr + ", " + active.ToString() +
                        ", \"" + brand + "\", \"" + color + "\", " +
@@ -507,7 +507,7 @@ public class ForceSensorElasticBand
        {
                double sum = 0;
                foreach(ForceSensorElasticBand fseb in list_fseb)
-                       sum += fseb.Stiffness;
+                       sum += fseb.Stiffness * fseb.Active;
 
                return sum;
        }
@@ -517,7 +517,8 @@ public class ForceSensorElasticBand
                string sep = "";
                foreach(ForceSensorElasticBand fseb in list_fseb)
                {
-                       str += sep + fseb.UniqueID.ToString();
+                       LogB.Information("pppp fseb: " + Util.StringArrayToString(fseb.ToStringArray(), ";"));
+                       str += sep + string.Format("{0}*{1}", fseb.UniqueID, fseb.Active);
                        sep = ";";
                }
 
@@ -525,8 +526,36 @@ public class ForceSensorElasticBand
        }
 
        //stiffnessString is the string of a loaded set
-       public static void UpdateBandsStatus (List<ForceSensorElasticBand> list_at_db, string stiffnessString)
+       public static void UpdateBandsStatusToSqlite (List<ForceSensorElasticBand> list_at_db, string 
stiffnessString)
        {
+               List<ForceSensorElasticBand> list_to_db = new List<ForceSensorElasticBand>();
+
+               foreach(ForceSensorElasticBand fseb in list_at_db)
+               {
+                       string [] strAll = stiffnessString.Split(new char[] {';'});
+                       bool found = false;
+                       ForceSensorElasticBand fsebNew = fseb;
+                       //LogB.Information("processing: " + Util.StringArrayToString(fsebNew.ToStringArray(), 
";"));
+                       foreach(string strBand in strAll)
+                       {
+                               string [] strBandWithMult = strBand.Split(new char[] {'*'});
+                               if(strBandWithMult.Length == 2 && Util.IsNumber(strBandWithMult[0], false) &&
+                                               Util.IsNumber(strBandWithMult[1], false) && 
Convert.ToInt32(strBandWithMult[0]) == fseb.UniqueID)
+                               {
+                                       fsebNew.active = Convert.ToInt32(strBandWithMult[1]);
+                                       list_to_db.Add(fsebNew);
+                                       found = true;
+                                       break;
+                               }
+                       }
+
+                       if(! found) {
+                               fsebNew.active = 0;
+                               list_to_db.Add(fsebNew);
+                       }
+
+               }
+               SqliteForceSensorElasticBand.UpdateList(false, list_to_db);
        }
 
        public int UniqueID
diff --git a/src/gui/forceSensor.cs b/src/gui/forceSensor.cs
index 36a1ee9b..11cfc720 100644
--- a/src/gui/forceSensor.cs
+++ b/src/gui/forceSensor.cs
@@ -1056,14 +1056,9 @@ LogB.Information(" fs C ");
                                {
                                        event_execute_label_message.Text = "Saved.";
 
-                                       double stiffness = -1;
-                                       string stiffnessString = "";
-                                       if(currentForceSensorExercise.ComputeAsElastic)
-                                       {
-                                               List<ForceSensorElasticBand> list_fseb = 
SqliteForceSensorElasticBand.SelectAll(false, true); //not opened, onlyActive
-                                               stiffness = 
ForceSensorElasticBand.GetStiffnessOfActiveBands(list_fseb);
-                                               stiffnessString = 
ForceSensorElasticBand.GetIDsOfActiveBands(list_fseb);
-                                       }
+                                       double stiffness;
+                                       string stiffnessString;
+                                       getStiffnessAndStiffnessStringFromSQL(out stiffness, out 
stiffnessString);
 
                                        currentForceSensor = new ForceSensor(-1, currentPerson.UniqueID, 
currentSession.UniqueID,
                                                        currentForceSensorExercise.UniqueID, 
getForceSensorCaptureOptions(),
@@ -1550,6 +1545,8 @@ LogB.Information(" fs R ");
                        button_force_sensor_stiffness.Visible = false;
                }
                // stiffness 2: update elastic bands table
+               ForceSensorElasticBand.UpdateBandsStatusToSqlite (
+                               SqliteForceSensorElasticBand.SelectAll(false, false), fs.StiffnessString);
 
 
                forceSensorCopyTempAndDoGraphs();
@@ -1719,6 +1716,12 @@ LogB.Information(" fs R ");
                currentForceSensor.Laterality = getLaterality(false);
                currentForceSensor.Comments = 
UtilGtk.TextViewGetCommentValidSQL(textview_force_sensor_capture_comment);
 
+               double stiffness;
+               string stiffnessString;
+               getStiffnessAndStiffnessStringFromSQL(out stiffness, out stiffnessString);
+               currentForceSensor.Stiffness = stiffness;
+               currentForceSensor.StiffnessString = stiffnessString;
+
                currentForceSensor.UpdateSQL(false);
        }
 
@@ -2408,12 +2411,18 @@ LogB.Information(" fs R ");
 
        // -------------------------------- elastic band stuff -----------------------
 
-       /*
-       private string getForceSensorStiffnessString()
+       private void getStiffnessAndStiffnessStringFromSQL(out double stiffness, out string stiffnessString)
        {
-               return "";
+               stiffness = -1;
+               stiffnessString = "";
+
+               if(currentForceSensorExercise.ComputeAsElastic)
+               {
+                       List<ForceSensorElasticBand> list_fseb = 
SqliteForceSensorElasticBand.SelectAll(false, true); //not opened, onlyActive
+                       stiffness = ForceSensorElasticBand.GetStiffnessOfActiveBands(list_fseb);
+                       stiffnessString = ForceSensorElasticBand.GetIDsOfActiveBands(list_fseb);
+               }
        }
-       */
 
        private void on_button_force_sensor_stiffness_clicked (object o, EventArgs args)
        {
diff --git a/src/gui/forceSensorElasticBands.cs b/src/gui/forceSensorElasticBands.cs
index f2f61e1d..c69d0282 100644
--- a/src/gui/forceSensorElasticBands.cs
+++ b/src/gui/forceSensorElasticBands.cs
@@ -127,8 +127,8 @@ public class ForceSensorElasticBandsWindow
                                Convert.ToInt32(store.GetValue (iter, 0)),
                                //(bool) store.GetValue (iter, 1),
                                Convert.ToInt32(store.GetValue (iter, 1)), //active
-                               store.GetValue (iter, 2).ToString(), //brand
-                               store.GetValue (iter, 3).ToString(), //color
+                               store.GetValue (iter, 3).ToString(), //brand
+                               store.GetValue (iter, 4).ToString(), //color
                                Convert.ToDouble(store.GetValue (iter, stiffnessColumn)),
                                store.GetValue (iter, 5).ToString() //comments
                                );
@@ -164,9 +164,8 @@ public class ForceSensorElasticBandsWindow
        private void setTreeview() 
        {
                string [] columnsString = new string [] {
-                       //Catalog.GetString("ID"),
                        "ID",
-                       Catalog.GetString("Active"),    //checkboxes
+                       Catalog.GetString("Active units"),
                        Catalog.GetString("Stiffness"),
                        Catalog.GetString("Brand"),
                        Catalog.GetString("Color"),
diff --git a/src/sqlite/forceSensor.cs b/src/sqlite/forceSensor.cs
index 630eacec..df40929c 100644
--- a/src/sqlite/forceSensor.cs
+++ b/src/sqlite/forceSensor.cs
@@ -57,7 +57,7 @@ class SqliteForceSensor : Sqlite
                        "comments TEXT, " +
                        "videoURL TEXT, " +     //URL of video of signals. stored as relative
                        "stiffness FLOAT DEFAULT -1, " +        //this is the important, next one is needed 
for recalculate, but note that some bands can have changed or being deleted
-                       "stiffnessString TEXT)"; //uniqueID of ElasticBand separated by ';' or empty if 
exerciseID ! elastic
+                       "stiffnessString TEXT)"; //uniqueID*active of ElasticBand separated by ';' or empty 
if exerciseID ! elastic
                LogB.SQL(dbcmd.CommandText.ToString());
                dbcmd.ExecuteNonQuery();
        }
@@ -662,8 +662,7 @@ class SqliteForceSensorElasticBand : Sqlite
 
        public static void Update (bool dbconOpened, ForceSensorElasticBand eb)
        {
-               if(! dbconOpened)
-                       Sqlite.Open();
+               openIfNeeded(dbconOpened);
 
                dbcmd.CommandText = "UPDATE " + table + " SET " +
                        " active = " + eb.Active.ToString() +
@@ -676,8 +675,16 @@ class SqliteForceSensorElasticBand : Sqlite
                LogB.SQL(dbcmd.CommandText.ToString());
                dbcmd.ExecuteNonQuery();
 
-               if(! dbconOpened)
-                       Sqlite.Close();
+               closeIfNeeded(dbconOpened);
+       }
+       public static void UpdateList (bool dbconOpened, List<ForceSensorElasticBand> list_fseb)
+       {
+               openIfNeeded(dbconOpened);
+
+               foreach(ForceSensorElasticBand fseb in list_fseb)
+                       Update (true, fseb);
+
+               closeIfNeeded(dbconOpened);
        }
 
        public static void Delete (bool dbconOpened, int uniqueID)
@@ -733,8 +740,11 @@ class SqliteForceSensorElasticBand : Sqlite
                if(stiffnessString == "")
                        return 0;
 
-               //return 0 if there is only one value and is not a integer
                string [] strFull = stiffnessString.Split(new char[] {';'});
+               /*
+                * TODO: fix this comprovations knowing that values come as "id*active;..."
+                *
+               //return 0 if there is only one value and is not a integer
                if(strFull.Length == 1) //there is just one value (there are no ';')
                        if(! Util.IsNumber(strFull[0], false))
                                return 0;
@@ -743,6 +753,7 @@ class SqliteForceSensorElasticBand : Sqlite
                foreach(string s in strFull)
                        if(! Util.IsNumber(s, false))
                                return 0;
+                               */
 
                return getStiffnessOfACaptureDo (dbconOpened, strFull);
        }
@@ -765,8 +776,12 @@ class SqliteForceSensorElasticBand : Sqlite
                while(reader.Read())
                {
                        string id = reader[0].ToString();
-                       if(Util.FoundInStringArray(stiffnessStrArray, id))
-                               sum += Convert.ToDouble(Util.ChangeDecimalSeparator(reader[1].ToString()));
+                       foreach(string str in stiffnessStrArray)
+                       {
+                               string [] strFull = str.Split(new char[] {'*'});
+                               if(strFull[0] == id)
+                                       sum += 
Convert.ToDouble(Util.ChangeDecimalSeparator(reader[1].ToString())) * Convert.ToInt32(strFull[1]);
+                       }
                }
 
                reader.Close();


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