[chronojump] Compujump upload temp data on person login (UNTESTED)



commit 8ff762da89f49ff79ddac90a613337f717bbf812
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Feb 26 21:28:18 2018 +0100

    Compujump upload temp data on person login (UNTESTED)

 src/gui/chronojump.cs |    1 +
 src/gui/encoder.cs    |    1 +
 src/gui/networks.cs   |   29 +++++++++++++
 src/json.cs           |   46 ++++++++++++++++++++-
 src/sqlite/json.cs    |  107 ++++++++++++++++++++++++++++++++++++++++++++++++-
 5 files changed, 181 insertions(+), 3 deletions(-)
---
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index 562926e..41bd2a4 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -4776,6 +4776,7 @@ public partial class ChronoJumpWindow
                double pmax = Convert.ToDouble(Util.ChangeDecimalSeparator(results[14])); //pmax.rel.fitted
 
                UploadSprintDataObject usdo = new UploadSprintDataObject(
+                               -1, //uniqueID
                                currentPerson.UniqueID,
                                sprint.Positions, sprint.GetSplitTimesAsList(),
                                k, vmax, amax, fmax, pmax);
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 1325cb2..ca5a166 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -6409,6 +6409,7 @@ public partial class ChronoJumpWindow
                                                        LogB.Information("calling Upload");
                                                        Json js = new Json();
                                                        UploadEncoderDataFullObject uedfo = new 
UploadEncoderDataFullObject(
+                                                                       -1, //uniqueID
                                                                        currentPerson.UniqueID,
                                                                        configChronojump.CompujumpStationID,
                                                                        lastEncoderSQLSignal.exerciseID,
diff --git a/src/gui/networks.cs b/src/gui/networks.cs
index 8340ce3..56bf229 100644
--- a/src/gui/networks.cs
+++ b/src/gui/networks.cs
@@ -566,6 +566,35 @@ public partial class ChronoJumpWindow
                        }
                }
 
+               //----- Start upload temp tests
+               //select UploadTemp tests (have not been uploaded by network errors)
+               List<UploadEncoderDataFullObject> listEncoderTemp = SqliteJson.SelectTempEncoder(false);
+               List<UploadSprintDataObject> listSprintTemp = SqliteJson.SelectTempSprint(false);
+
+               //Upload them
+               if(listEncoderTemp.Count > 0)
+               {
+                       foreach(UploadEncoderDataFullObject uedfo in listEncoderTemp)
+                       {
+                               bool success = json.UploadEncoderData(uedfo);
+                               LogB.Information(json.ResultMessage);
+                               if(success)
+                                       SqliteJson.DeleteTempEncoder(false, uedfo.uniqueId); //delete the 
record
+                       }
+               }
+               if(listSprintTemp.Count > 0)
+               {
+                       foreach(UploadSprintDataObject usdo in listSprintTemp)
+                       {
+                               bool success = json.UploadSprintData(usdo);
+                               LogB.Information(json.ResultMessage);
+                               if(success)
+                                       SqliteJson.DeleteTempSprint(false, usdo.uniqueId); //delete the record
+                       }
+               }
+               //----- End upload temp tests
+
+
                if(currentPerson != null && currentPersonWasNull)
                        sensitiveGuiYesPerson();
 
diff --git a/src/json.cs b/src/json.cs
index 1eb2c42..39ca89a 100644
--- a/src/json.cs
+++ b/src/json.cs
@@ -994,6 +994,7 @@ class JsonUtils
 
 public class UploadSprintDataObject
 {
+       public int uniqueId; //used for SQL load and delete
        public int personId;
        public string sprintPositions;
        public List<double> splitTimesL;
@@ -1003,9 +1004,10 @@ public class UploadSprintDataObject
        public double fmax;
        public double pmax;
 
-       public UploadSprintDataObject (int personId, string sprintPositions, List<double> splitTimesL,
+       public UploadSprintDataObject (int uniqueId, int personId, string sprintPositions, List<double> 
splitTimesL,
                        double k, double vmax, double amax, double fmax, double pmax)
        {
+               this.uniqueId = uniqueId;
                this.personId = personId;
                this.sprintPositions = sprintPositions;
                this.splitTimesL = splitTimesL;
@@ -1030,6 +1032,19 @@ public class UploadSprintDataObject
                        Util.ConvertToPoint(pmax) + ")";
        }
 
+       public static List<double> SplitTimesStringToList(string sqlSelectSplitTimes)
+       {
+               List<double> l = new List<double>();
+               if(sqlSelectSplitTimes == null || sqlSelectSplitTimes == "")
+                       return l;
+
+               string [] myStringFull = sqlSelectSplitTimes.Split(new char[] {';'});
+               foreach (string time in myStringFull)
+                       l.Add(Convert.ToDouble(Util.ChangeDecimalSeparator(time)));
+
+               return l;
+       }
+
        private string splitTimesLToString()
        {
                string str = "";
@@ -1046,6 +1061,7 @@ public class UploadSprintDataObject
 
 public class UploadEncoderDataFullObject
 {
+       public int uniqueId; //used for SQL load and delete
        public int personId;
        public int stationId;
        public int exerciseId;
@@ -1053,9 +1069,10 @@ public class UploadEncoderDataFullObject
        public string resistance;
        public UploadEncoderDataObject uo;
 
-       public UploadEncoderDataFullObject(int personId, int stationId, int exerciseId,
+       public UploadEncoderDataFullObject(int uniqueId, int personId, int stationId, int exerciseId,
                        string laterality, string resistance, UploadEncoderDataObject uo)
        {
+               this.uniqueId = uniqueId;
                this.personId = personId;
                this.stationId = stationId;
                this.exerciseId = exerciseId;
@@ -1116,6 +1133,7 @@ public class UploadEncoderDataObject
        public string pmeanByPower;
        public string pmaxByPower;
 
+       //constructor called after capture
        public UploadEncoderDataObject(ArrayList curves)
        {
                repetitions = curves.Count; //TODO: on ecc-con divide by 2
@@ -1147,6 +1165,30 @@ public class UploadEncoderDataObject
                lossByPower = getLoss(curves, byTypes.POWER);
        }
 
+       //constructor called on SQL load
+       public UploadEncoderDataObject(int repetitions,
+                       int numBySpeed, int lossBySpeed, string rangeBySpeed,
+                       string vmeanBySpeed, string vmaxBySpeed, string pmeanBySpeed, string pmaxBySpeed,
+                       int numByPower, int lossByPower, string rangeByPower,
+                       string vmeanByPower, string vmaxByPower, string pmeanByPower, string pmaxByPower)
+       {
+               this.repetitions = repetitions;
+               this.numBySpeed = numBySpeed;
+               this.lossBySpeed = lossBySpeed;
+               this.rangeBySpeed = rangeBySpeed;
+               this.vmeanBySpeed = vmeanBySpeed;
+               this.vmaxBySpeed = vmaxBySpeed;
+               this.pmeanBySpeed = pmeanBySpeed;
+               this.pmaxBySpeed = pmaxBySpeed;
+               this.numByPower = numByPower;
+               this.lossByPower = lossByPower;
+               this.rangeByPower = rangeByPower;
+               this.vmeanByPower = vmeanByPower;
+               this.vmaxByPower = vmaxByPower;
+               this.pmeanByPower = pmeanByPower;
+               this.pmaxByPower = pmaxByPower;
+       }
+
        //TODO: on ecc-con should count [ecc-count] reps
        //this calculation should be the same than the client gui
        private int getBestRep(ArrayList curves, byTypes by)
diff --git a/src/sqlite/json.cs b/src/sqlite/json.cs
index e033515..70b3bce 100644
--- a/src/sqlite/json.cs
+++ b/src/sqlite/json.cs
@@ -19,7 +19,7 @@
  */
 
 using System;
-//using System.Collections.Generic; //List<T>
+using System.Collections.Generic; //List<T>
 using Mono.Data.Sqlite;
 
 class SqliteJson : Sqlite
@@ -88,6 +88,66 @@ class SqliteJson : Sqlite
                closeIfNeeded(dbconOpened);
        }
 
+       public static List<UploadEncoderDataFullObject> SelectTempEncoder(bool dbconOpened)
+       {
+               openIfNeeded(dbconOpened);
+
+               dbcmd.CommandText = "SELECT * FROM " + tableEncoder;
+               LogB.SQL(dbcmd.CommandText.ToString());
+               dbcmd.ExecuteNonQuery();
+
+               SqliteDataReader reader = dbcmd.ExecuteReader();
+
+               List<UploadEncoderDataFullObject> l = new List<UploadEncoderDataFullObject>();
+               while(reader.Read())
+               {
+                       UploadEncoderDataObject uo = new UploadEncoderDataObject(
+                                       Convert.ToInt32(reader[6]),             //repetitions
+                                       Convert.ToInt32(reader[7]),             //numBySpeed
+                                       Convert.ToInt32(reader[8]),             //lossBySpeed
+                                       reader[9].ToString(),                   //rangeBySpeed
+                                       reader[10].ToString(),                  //vmeanBySpeed
+                                       reader[11].ToString(),                  //vmaxBySpeed
+                                       reader[12].ToString(),                  //pmeanBySpeed
+                                       reader[13].ToString(),                  //pmaxBySpeed
+                                       Convert.ToInt32(reader[14]),            //numByPower
+                                       Convert.ToInt32(reader[15]),            //lossByPower
+                                       reader[16].ToString(),                  //rangeByPower
+                                       reader[17].ToString(),                  //vmeanByPower
+                                       reader[18].ToString(),                  //vmaxByPower
+                                       reader[19].ToString(),                  //pmeanByPower
+                                       reader[20].ToString()                   //pmaxByPower
+                                               );
+
+                       UploadEncoderDataFullObject o = new UploadEncoderDataFullObject(
+                                       Convert.ToInt32(reader[0]),             //uniqueID
+                                       Convert.ToInt32(reader[1]),             //personID
+                                       Convert.ToInt32(reader[2]),             //stationID
+                                       Convert.ToInt32(reader[3]),             //exerciseID
+                                       reader[4].ToString(),                   //laterality
+                                       reader[5].ToString(),                   //resistance
+                                       uo);
+
+                       l.Add(o);
+               }
+
+               reader.Close();
+               closeIfNeeded(dbconOpened);
+
+               return l;
+       }
+
+       public static void DeleteTempEncoder(bool dbconOpened, int uniqueID)
+       {
+               openIfNeeded(dbconOpened);
+
+               dbcmd.CommandText = "Delete FROM " + tableEncoder + " WHERE uniqueID = " + uniqueID;
+               LogB.SQL(dbcmd.CommandText.ToString());
+               dbcmd.ExecuteNonQuery();
+
+               closeIfNeeded(dbconOpened);
+       }
+
 
        /*
         * SPRINT
@@ -124,5 +184,50 @@ class SqliteJson : Sqlite
                closeIfNeeded(dbconOpened);
        }
 
+       public static List<UploadSprintDataObject> SelectTempSprint (bool dbconOpened)
+       {
+               openIfNeeded(dbconOpened);
+
+               dbcmd.CommandText = "SELECT * FROM " + tableSprint;
+               LogB.SQL(dbcmd.CommandText.ToString());
+               dbcmd.ExecuteNonQuery();
+
+               SqliteDataReader reader = dbcmd.ExecuteReader();
+
+               List<UploadSprintDataObject> l = new List<UploadSprintDataObject>();
+               while(reader.Read())
+               {
+                       UploadSprintDataObject o = new UploadSprintDataObject(
+                                       Convert.ToInt32(reader[0]),             //uniqueID
+                                       Convert.ToInt32(reader[1]),             //personID
+                                       reader[2].ToString(),                           //sprintPositions
+                                       UploadSprintDataObject.SplitTimesStringToList(reader[3].ToString()), 
//splitTimes
+                                       Convert.ToDouble(Util.ChangeDecimalSeparator(reader[4].ToString())), 
//k
+                                       Convert.ToDouble(Util.ChangeDecimalSeparator(reader[5].ToString())), 
//vmax
+                                       Convert.ToDouble(Util.ChangeDecimalSeparator(reader[6].ToString())), 
//amax
+                                       Convert.ToDouble(Util.ChangeDecimalSeparator(reader[7].ToString())), 
//fmax
+                                       Convert.ToDouble(Util.ChangeDecimalSeparator(reader[8].ToString())) 
//pmax
+                                       );
+
+                       l.Add(o);
+               }
+
+               reader.Close();
+               closeIfNeeded(dbconOpened);
+
+               return l;
+       }
+
+       public static void DeleteTempSprint(bool dbconOpened, int uniqueID)
+       {
+               openIfNeeded(dbconOpened);
+
+               dbcmd.CommandText = "Delete FROM " + tableSprint + " WHERE uniqueID = " + uniqueID;
+               LogB.SQL(dbcmd.CommandText.ToString());
+               dbcmd.ExecuteNonQuery();
+
+               closeIfNeeded(dbconOpened);
+       }
+
 }
 


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