[chronojump] Moving to DB 1.06:"connect signal with curves" 40%



commit 6bb5d16891f8cd7c38dd466be6e1f49f814baea4
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri May 16 16:54:08 2014 +0200

    Moving to DB 1.06:"connect signal with curves" 40%

 src/constants.cs      |    1 +
 src/sqlite/encoder.cs |   55 +++++++++++++++++++++++++++++++++++++++++++++++-
 src/sqlite/main.cs    |   17 ++++++++++++++-
 3 files changed, 70 insertions(+), 3 deletions(-)
---
diff --git a/src/constants.cs b/src/constants.cs
index a4c872f..dc566e8 100644
--- a/src/constants.cs
+++ b/src/constants.cs
@@ -125,6 +125,7 @@ public class Constants
        public const string MultiChronopicTable = "multiChronopic";
        public const string TempMultiChronopicTable = "tempMultiChronopic"; //TODO
        public const string EncoderTable = "encoder";
+       public const string EncoderSignalCurveTable = "encoderSignalCurve";
        public const string EncoderExerciseTable = "encoderExercise";
        public const string Encoder1RMTable = "encoder1RM";
 
diff --git a/src/sqlite/encoder.cs b/src/sqlite/encoder.cs
index 819692a..764bc01 100644
--- a/src/sqlite/encoder.cs
+++ b/src/sqlite/encoder.cs
@@ -295,6 +295,34 @@ class SqliteEncoder : Sqlite
        }
 
        
+       protected internal static void createTableEncoderSignalCurve()
+       {
+               dbcmd.CommandText = 
+                       "CREATE TABLE " + Constants.EncoderSignalCurveTable + " ( " +
+                       "signalID INT, " +
+                       "curveID INT, " +
+                       "eccon TEXT, " +        //"c", "ecS", "ceS"
+                       "msCentral INT, " +
+                       "future1 TEXT )";
+               dbcmd.ExecuteNonQuery();
+       }
+       
+       public static void SignalCurveInsert(bool dbconOpened, int signalID, int curveID, string eccon, int 
msCentral)
+       {
+               if(! dbconOpened)
+                       dbcon.Open();
+
+               dbcmd.CommandText = "INSERT INTO " + Constants.EncoderSignalCurveTable +  
+                       " (signalID, curveID, eccon, msCentral, future1) VALUES (" + 
+                       signalID + ", " + curveID + ", '" + eccon + "', " + msCentral + ", '')";
+               Log.WriteLine(dbcmd.CommandText.ToString());
+               dbcmd.ExecuteNonQuery();
+               
+               if(! dbconOpened)
+                       dbcon.Close();
+       }
+       
+       
 
        /*
         * EncoderExercise stuff
@@ -624,10 +652,10 @@ class SqliteEncoder : Sqlite
 
                int c;
                for(int s=0; s < signalInts.Length; s ++) {
-                       for(c=0; c < curveInts.Length; c ++) {
+                       for(c=0; c < curveInts.Length && (s + c < signalInts.Length); c ++)
                                if(signalInts[s + c] != curveInts[c])
                                        break;
-                       }
+                       
                        if(c == curveInts.Length) {
                                Log.WriteLine("Start at: " + s);
                                Log.WriteLine("Middle at: " + s + Convert.ToInt32(c / 2));
@@ -637,6 +665,29 @@ class SqliteEncoder : Sqlite
 
                return -1;
        }
+
+       public static void ConvertTo1_06()
+       {
+               //TODO: do it on sqlite main in order to see the conversion progressbar
+               ArrayList signals = Select(true, -1, -1, -1, "signal", false);
+               ArrayList curves = Select(true, -1, -1, -1, "curve", false);
+
+               //in 1.05 curves can be related to signals only by date
+               foreach(EncoderSQL c in curves) {
+                       foreach(EncoderSQL s in signals) {
+                               if(s.GetDate(false) == c.GetDate(false)) {
+                                        Log.WriteLine(s.sessionID.ToString() + "-" + c.sessionID.ToString());
+                                        int msCentral = FindCurveInSignal(s.GetFullURL(false), 
c.GetFullURL(false));
+                                        if(msCentral == -1)
+                                                Log.WriteLine("TODO: NEED CREATE SIGNAL: " + 
s.GetDate(false));
+                                        else
+                                                Log.WriteLine(msCentral.ToString());
+                               }
+                       }
+               }
+               
+               //when insert, check duplicates, orphanes and merge curves commentaries
+       }
        
 
 }
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index a25d464..43e25c2 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -74,7 +74,7 @@ class Sqlite
         * Important, change this if there's any update to database
         * Important2: if database version get numbers higher than 1, check if the comparisons with 
currentVersion works ok
         */
-       static string lastChronojumpDatabaseVersion = "1.05";
+       static string lastChronojumpDatabaseVersion = "1.06";
 
        public Sqlite() {
        }
@@ -1492,6 +1492,19 @@ class Sqlite
 
                                currentVersion = "1.05";
                        }
+                       if(currentVersion == "1.05") {
+                               dbcon.Open();
+
+                               SqliteEncoder.ConvertTo1_06();
+
+                               //Log.WriteLine("Curves are now related to signals ");
+                               //SqlitePreferences.Update ("databaseVersion", "1.06", true); 
+                               
+                               dbcon.Close();
+
+                               //currentVersion = "1.06";
+                       }
+               
                
 
                                
@@ -1609,6 +1622,7 @@ class Sqlite
                //encoder       
                creationRate ++;
                SqliteEncoder.createTableEncoder();
+               SqliteEncoder.createTableEncoderSignalCurve();
                SqliteEncoder.createTableEncoderExercise();
                SqliteEncoder.initializeTableEncoderExercise();
                SqliteEncoder.createTable1RM();
@@ -1634,6 +1648,7 @@ class Sqlite
                SqliteCountry.initialize();
                
                //changes [from - to - desc]
+               //1.05 - 1-06 Converted DB to 1.06 Curves are now related to signals
                //1.04 - 1-05 Converted DB to 1.05 Removed inertial curves, because sign was not checked on 
1.04 when saving curves
                //1.03 - 1-04 Converted DB to 1.04 Encoder table improved
                //1.02 - 1-03 Converted DB to 1.03 Updated encoder exercise, angle is now on encoder 
configuration


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