[chronojump] Fixes on encoder recalculate and previously saved curves (no more meanPower 0)



commit 35195270219895810d1545d500db5b741321ade7
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu May 28 19:27:16 2015 +0200

    Fixes on encoder recalculate and previously saved curves (no more meanPower 0)

 src/gui/chronojump.cs |    2 +-
 src/gui/encoder.cs    |   82 +++++++++++++++++++++++++++++++++---------------
 src/sqlite/main.cs    |   14 ++++----
 3 files changed, 64 insertions(+), 34 deletions(-)
---
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index f6f3663..957a63e 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -6262,7 +6262,7 @@ LogB.Debug("X");
                        List<string> contents = 
Util.ReadFileAsStringList(UtilEncoder.GetEncoderCurvesTempFileName());
                        encoderUpdateTreeViewCapture(contents); //this updates encoderCaptureCurves
                        
-                       findAndMarkSavedCurves();
+                       findAndMarkSavedCurves(false, false); //SQL closed; don't update curve SQL records 
(like future1: meanPower)
                        
                        //also update the bars plot (to show colors depending on bells changes)
                        if(captureCurvesBarsData.Count > 0) {
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 2244386..63b2495 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -5157,15 +5157,16 @@ public partial class ChronoJumpWindow
                                        /*
                                         * (0) open Sqlite
                                         * (1) if found curves of this signal
-                                        *      (1a) this curves are with different eccon
+                                        *      (1a) this curves are with different eccon, or with different 
encoderConfiguration.name
                                         *              (1a1) delete the curves (files)
                                         *              (1a2) delete the curves (encoder table)
                                         *              (1a3) and also delete from (encoderSignalCurves table)
-                                        *      (1b) or different exercise, or different laterality or 
different extraWeight
+                                        *      (1b) or different exercise, or different laterality or 
different extraWeight, 
+                                        *              or different encoderConfiguration (but the name is 
the same)
                                         *              (1b1) update curves with new data
-                                        *                      but delete the future1 (power) because maybe 
has changed (in exerciseID or extraWeight change)
                                         * (2) update analyze labels and combos
-                                        * (3) close Sqlite
+                                        * (3) update meanPower on SQL encoder
+                                        * (4) close Sqlite
                                         */
 
                                        Sqlite.Open(); // (0)
@@ -5185,43 +5186,49 @@ public partial class ChronoJumpWindow
                                        {
                                                if(currentSignalSQL.GetDate(false) == eSQL.GetDate(false))    
          // (1)
                                                {
-                                                       if(findEccon(true) != eSQL.eccon) {                   
          // (1a)
+                                                       // (1a)
+                                                       if(findEccon(true) != eSQL.eccon || 
+                                                                       encoderConfigurationCurrent.name != 
eSQL.encoderConfiguration.name)
+                                                       {
                                                                Util.FileDelete(eSQL.GetFullURL(false));      
                                  // (1a1)
                                                                Sqlite.Delete(true, Constants.EncoderTable, 
Convert.ToInt32(eSQL.uniqueID));    // (1a2)
                                                                
SqliteEncoder.DeleteSignalCurveWithCurveID(true, Convert.ToInt32(eSQL.uniqueID)); // (1a3)
                                                                deletedUserCurves = true;
                                                        } else {                                              
          // (1b)
-                                                               if(
-                                                                               currentSignalSQL.exerciseID 
!= eSQL.exerciseID ||
-                                                                               currentSignalSQL.extraWeight 
!= eSQL.extraWeight ) 
-                                                               {
-                                                                       if(currentSignalSQL.exerciseID != 
eSQL.exerciseID)
-                                                                               Sqlite.Update(true, 
Constants.EncoderTable, "exerciseID",
-                                                                                               "", 
currentSignalSQL.exerciseID.ToString(),
-                                                                                               "uniqueID", 
eSQL.uniqueID.ToString());
-                                                                       
-                                                                       if(currentSignalSQL.extraWeight != 
eSQL.extraWeight)
-                                                                               Sqlite.Update(true, 
Constants.EncoderTable, "extraWeight",
-                                                                                               "", 
currentSignalSQL.extraWeight,
-                                                                                               "uniqueID", 
eSQL.uniqueID.ToString());
-
-                                                                       Sqlite.Update(true, 
Constants.EncoderTable, "future1",
-                                                                                       "", "0",
+                                                               if(currentSignalSQL.exerciseID != 
eSQL.exerciseID)
+                                                                       Sqlite.Update(true, 
Constants.EncoderTable, "exerciseID",
+                                                                                       "", 
currentSignalSQL.exerciseID.ToString(),
                                                                                        "uniqueID", 
eSQL.uniqueID.ToString());
-                                                               }
+
+                                                               if(currentSignalSQL.extraWeight != 
eSQL.extraWeight)
+                                                                       Sqlite.Update(true, 
Constants.EncoderTable, "extraWeight",
+                                                                                       "", 
currentSignalSQL.extraWeight,
+                                                                                       "uniqueID", 
eSQL.uniqueID.ToString());
+
                                                                if(currentSignalSQL.laterality != 
eSQL.laterality)
                                                                        Sqlite.Update(true, 
Constants.EncoderTable, "laterality",
                                                                                        "", 
currentSignalSQL.laterality,
                                                                                        "uniqueID", 
eSQL.uniqueID.ToString());
+                                                               
+                                                               if( 
currentSignalSQL.encoderConfiguration.ToStringOutput(EncoderConfiguration.Outputs.SQL) !=
+                                                                               
eSQL.encoderConfiguration.ToStringOutput(EncoderConfiguration.Outputs.SQL) )
+                                                               {
+                                                                       Sqlite.Update(true, 
Constants.EncoderTable, "encoderConfiguration",
+                                                                                       "", 
currentSignalSQL.encoderConfiguration.ToStringOutput(
+                                                                                               
EncoderConfiguration.Outputs.SQL),
+                                                                                       "uniqueID", 
eSQL.uniqueID.ToString());
+                                                               }
                                                        }
                                                }
                                        }
                                        if(deletedUserCurves)
                                                updateUserCurvesLabelsAndCombo(true);   // (2)
 
-                                       Sqlite.Close();                                         // (3)
+                                       // (3) update meanPower on SQL encoder
+                                       findAndMarkSavedCurves(true, true); //SQL opened; update curve SQL 
records (like future1: meanPower)
+                                       
+                                       Sqlite.Close();                                         // (4)
 
-                                       findAndMarkSavedCurves();
                                }
                                
                                playVideoEncoderPrepare(false); //do not play
@@ -5336,9 +5343,21 @@ public partial class ChronoJumpWindow
                Util.FileDelete(UtilEncoder.GetEncoderStatusTempBaseFileName() + "5.txt");
        }
 
-       private void findAndMarkSavedCurves() {
+       /*
+        * on capture treeview finds which rows are related to saved SQL curves
+        * mark their rows (meaning saved)
+        * also if updateSQLRecords, then update SQL meanPower of the curve
+        *
+        * This method is called by on_repetitive_conditions_closed, and finishPulseBar
+        */
+       private void findAndMarkSavedCurves(bool dbconOpened, bool updateSQLRecords) 
+       {
+               //run this method with SQL opened to not be closing and opening a lot on the following 
foreachs
+               if(! dbconOpened)
+                       Sqlite.Open();
+
                //find the saved curves
-               ArrayList linkedCurves = SqliteEncoder.SelectSignalCurve(false, 
+               ArrayList linkedCurves = SqliteEncoder.SelectSignalCurve(true, 
                                Convert.ToInt32(encoderSignalUniqueID), //signal
                                -1, -1, -1);                            //curve, msStart,msEnd
                //LogB.Information("SAVED CURVES FOUND");
@@ -5367,11 +5386,22 @@ public partial class ChronoJumpWindow
                                {
                                        LogB.Information(curve.Start + " is saved");
                                        encoderCaptureSelectBySavedCurves(esc.msCentral, true);
+
+                                       if(updateSQLRecords) {
+                                               //update the future1
+                                               Sqlite.Update(true, Constants.EncoderTable, "future1",
+                                                               "", curve.MeanPower,
+                                                               "uniqueID", esc.curveID.ToString());
+                                       }
+                                       
                                        break;
                                }
                        }
                        curveCount ++;
                }
+
+               if(! dbconOpened)
+                       Sqlite.Close();
        }
 
        
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index c9af628..8b87fe0 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -1207,7 +1207,7 @@ class Sqlite
 
                                //delete all it's runs
                                Sqlite.Open();
-                               dbcmd.CommandText = "Delete FROM " + Constants.RunIntervalTable +
+                               dbcmd.CommandText = "DELETE FROM " + Constants.RunIntervalTable +
                                        " WHERE type == 'RSA 8-4-R3-5'";
                                LogB.SQL(dbcmd.CommandText.ToString());
                                dbcmd.ExecuteNonQuery();
@@ -2153,7 +2153,7 @@ class Sqlite
 
                Sqlite.Open();
                //dbcmd.CommandText = "Delete FROM tempJumpRj";
-               dbcmd.CommandText = "Delete FROM " + tableName;
+               dbcmd.CommandText = "DELETE FROM " + tableName;
                LogB.SQL(dbcmd.CommandText.ToString());
                dbcmd.ExecuteNonQuery();
                Sqlite.Close();
@@ -2803,7 +2803,7 @@ LogB.SQL("5" + tableName);
                        cond2 = cond2Pre + columnNameCondition2 + " == '" + searchValueCondition2 + "'"; 
                }
 
-               dbcmd.CommandText = "Update " + tableName +
+               dbcmd.CommandText = "UPDATE " + tableName +
                        " SET " + columnName + " = '" + newValue + "'" +  
                        cond1 +
                        cond2
@@ -2820,7 +2820,7 @@ LogB.SQL("5" + tableName);
                if( ! dbconOpened)
                        Sqlite.Open();
 
-               dbcmd.CommandText = "Delete FROM " + tableName +
+               dbcmd.CommandText = "DELETE FROM " + tableName +
                        " WHERE uniqueID == " + uniqueID.ToString();
                LogB.SQL(dbcmd.CommandText.ToString());
                dbcmd.ExecuteNonQuery();
@@ -2834,7 +2834,7 @@ LogB.SQL("5" + tableName);
                if( ! dbconOpened)
                        Sqlite.Open();
 
-               dbcmd.CommandText = "Delete FROM " + tableName +
+               dbcmd.CommandText = "DELETE FROM " + tableName +
                        " WHERE " + fieldName + " == " + id;
                LogB.SQL(dbcmd.CommandText.ToString());
                dbcmd.ExecuteNonQuery();
@@ -2849,7 +2849,7 @@ LogB.SQL("5" + tableName);
                if( ! dbconOpened)
                        Sqlite.Open();
 
-               dbcmd.CommandText = "Delete FROM " + tableName +
+               dbcmd.CommandText = "DELETE FROM " + tableName +
                        " WHERE name == '" + name + "'";
                LogB.SQL(dbcmd.CommandText.ToString());
                dbcmd.ExecuteNonQuery();
@@ -2863,7 +2863,7 @@ LogB.SQL("5" + tableName);
                if( ! dbconOpened)
                        Sqlite.Open();
 
-               dbcmd.CommandText = "Delete FROM " + tableName +
+               dbcmd.CommandText = "DELETE FROM " + tableName +
                        " WHERE " + colName + " == " + id;
                LogB.SQL(dbcmd.CommandText.ToString());
                dbcmd.ExecuteNonQuery();


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