[chronojump] DB: 1.57 Compujump upload data (if no network) stored on temp tables
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] DB: 1.57 Compujump upload data (if no network) stored on temp tables
- Date: Mon, 26 Feb 2018 17:01:21 +0000 (UTC)
commit 1aaf52d930734bf1f74164de0c7e89c2c6e18f2b
Author: Xavier de Blas <xaviblas gmail com>
Date: Mon Feb 26 18:00:22 2018 +0100
DB: 1.57 Compujump upload data (if no network) stored on temp tables
src/Makefile.am | 1 +
src/constants.cs | 4 +
src/gui/chronojump.cs | 12 +++-
src/gui/encoder.cs | 7 ++-
src/json.cs | 179 +++++++++++++++++++++++++++++++++++++-----------
src/sqlite/json.cs | 128 +++++++++++++++++++++++++++++++++++
src/sqlite/main.cs | 16 ++++-
7 files changed, 301 insertions(+), 46 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 983cab6..e46b219 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -122,6 +122,7 @@ SOURCES = \
sqlite/reactionTime.cs\
sqlite/multiChronopic.cs\
sqlite/event.cs\
+ sqlite/json.cs\
sqlite/sport.cs\
sqlite/speciallity.cs\
sqlite/trigger.cs\
diff --git a/src/constants.cs b/src/constants.cs
index 75609de..3b654ac 100644
--- a/src/constants.cs
+++ b/src/constants.cs
@@ -172,6 +172,10 @@ public class Constants
public const string ReactionTimeTypeTable = "reactionTimeType";
public const string GraphLinkTable = "graphLinkTable";
+ //json temp tables
+ public const string UploadEncoderDataTempTable = "uploadEncoderDataTemp";
+ public const string UploadSprintDataTempTable = "uploadSprintDataTemp";
+
public const string UndefinedDefault = "Undefined";
public const string Any = "Any";
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index 848201a..562926e 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -4775,11 +4775,17 @@ public partial class ChronoJumpWindow
double fmax = Convert.ToDouble(Util.ChangeDecimalSeparator(results[10])); //fmax.rel.fitted
double pmax = Convert.ToDouble(Util.ChangeDecimalSeparator(results[14])); //pmax.rel.fitted
- Json js = new Json();
- js.UploadSprintData(
+ UploadSprintDataObject usdo = new UploadSprintDataObject(
currentPerson.UniqueID,
- sprint, sprint.GetSplitTimesAsList(),
+ sprint.Positions, sprint.GetSplitTimesAsList(),
k, vmax, amax, fmax, pmax);
+
+ Json js = new Json();
+ if( ! js.UploadSprintData(usdo) )
+ {
+ LogB.Error(js.ResultMessage);
+ SqliteJson.InsertTempSprint(false, usdo); //insert only if could'nt be uploaded
+ }
}
/* ---------------------------------------------------------
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 2909541..1325cb2 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -6408,18 +6408,23 @@ public partial class ChronoJumpWindow
LogB.Information("calling Upload");
Json js = new Json();
- bool success = js.UploadEncoderData(
+ UploadEncoderDataFullObject uedfo = new
UploadEncoderDataFullObject(
currentPerson.UniqueID,
configChronojump.CompujumpStationID,
lastEncoderSQLSignal.exerciseID,
lastEncoderSQLSignal.LateralityToEnglish(),
Util.ConvertToPoint(findMass(Constants.MassType.EXTRA)), //this is only for gravitatory
uo);
+ bool success = js.UploadEncoderData(uedfo);
+
LogB.Information(js.ResultMessage);
LogB.Information("called Upload");
if(! success) {
LogB.Error(js.ResultMessage);
+
+ SqliteJson.InsertTempEncoder(false, uedfo);
+
bool showInWindow = false;
if(showInWindow)
new DialogMessage(
diff --git a/src/json.cs b/src/json.cs
index 5a33a27..1eb2c42 100644
--- a/src/json.cs
+++ b/src/json.cs
@@ -795,8 +795,7 @@ public class Json
}
*/
- public bool UploadSprintData(int personId, Sprint sprint, List<double> splitTimesL,
- double k, double vmax, double amax, double fmax, double pmax )
+ public bool UploadSprintData (UploadSprintDataObject o)
{
LogB.Information("calling upload sprint");
// Create a request using a URL that can receive a post.
@@ -819,32 +818,31 @@ public class Json
// Creates the json object
JsonObject json = new JsonObject();
- json.Add("personId", personId);
- json.Add("distances", sprint.Positions);
- //json.Add("times", sprint.SplitTimes);
- json.Add("t1", splitTimesL[1]);
+ json.Add("personId", o.personId);
+ json.Add("distances", o.sprintPositions);
+ json.Add("t1", o.splitTimesL[1]);
//splitTimesL starts with a 0 that is not passed
- if(splitTimesL.Count >= 3)
- json.Add("t2", splitTimesL[2] - splitTimesL[1]); //return lap (partial time) and not
split (accumulated time)
+ if(o.splitTimesL.Count >= 3)
+ json.Add("t2", o.splitTimesL[2] - o.splitTimesL[1]); //return lap (partial time) and
not split (accumulated time)
else
json.Add("t2", "");
- if(splitTimesL.Count >= 4)
- json.Add("t3", splitTimesL[3] - splitTimesL[2]);
+ if(o.splitTimesL.Count >= 4)
+ json.Add("t3", o.splitTimesL[3] - o.splitTimesL[2]);
else
json.Add("t3", "");
- if(splitTimesL.Count >= 5)
- json.Add("t4", splitTimesL[4] - splitTimesL[3]);
+ if(o.splitTimesL.Count >= 5)
+ json.Add("t4", o.splitTimesL[4] - o.splitTimesL[3]);
else
json.Add("t4", "");
- json.Add("k", k);
- json.Add("vmax", vmax);
- json.Add("amax", amax);
- json.Add("fmax", fmax);
- json.Add("pmax", pmax);
+ json.Add("k", o.k);
+ json.Add("vmax", o.vmax);
+ json.Add("amax", o.amax);
+ json.Add("fmax", o.fmax);
+ json.Add("pmax", o.pmax);
// Converts it to a String
String js = json.ToString();
@@ -893,7 +891,7 @@ public class Json
return UploadEncoderData(1, 1, "40.2", "lateral", "8100.5", 8);
}
*/
- public bool UploadEncoderData(int personId, int stationId, int exerciseId, string laterality, string
resistance, UploadEncoderDataObject uo)
+ public bool UploadEncoderData(UploadEncoderDataFullObject o)
{
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create (serverUrl + "/uploadEncoderData");
@@ -908,29 +906,29 @@ public class Json
// Creates the json object
JsonObject json = new JsonObject();
- json.Add("personId", personId);
- json.Add("stationId", stationId);
+ json.Add("personId", o.personId);
+ json.Add("stationId", o.stationId);
//json.Add("exerciseName", exerciseName);
- json.Add("exerciseId", exerciseId);
- json.Add("laterality", laterality);
- json.Add("resistance", resistance);
- json.Add("repetitions", uo.repetitions);
-
- json.Add("numBySpeed", uo.numBySpeed);
- json.Add("lossBySpeed", uo.lossBySpeed);
- json.Add("rangeBySpeed", uo.rangeBySpeed);
- json.Add("vmeanBySpeed", uo.vmeanBySpeed);
- json.Add("vmaxBySpeed", uo.vmaxBySpeed);
- json.Add("pmeanBySpeed", uo.pmeanBySpeed);
- json.Add("pmaxBySpeed", uo.pmaxBySpeed);
-
- json.Add("numByPower", uo.numByPower);
- json.Add("lossByPower", uo.lossByPower);
- json.Add("rangeByPower", uo.rangeByPower);
- json.Add("vmeanByPower", uo.vmeanByPower);
- json.Add("vmaxByPower", uo.vmaxByPower);
- json.Add("pmeanByPower", uo.pmeanByPower);
- json.Add("pmaxByPower", uo.pmaxByPower);
+ json.Add("exerciseId", o.exerciseId);
+ json.Add("laterality", o.laterality);
+ json.Add("resistance", o.resistance);
+ json.Add("repetitions", o.uo.repetitions);
+
+ json.Add("numBySpeed", o.uo.numBySpeed);
+ json.Add("lossBySpeed", o.uo.lossBySpeed);
+ json.Add("rangeBySpeed", o.uo.rangeBySpeed);
+ json.Add("vmeanBySpeed", o.uo.vmeanBySpeed);
+ json.Add("vmaxBySpeed", o.uo.vmaxBySpeed);
+ json.Add("pmeanBySpeed", o.uo.pmeanBySpeed);
+ json.Add("pmaxBySpeed", o.uo.pmaxBySpeed);
+
+ json.Add("numByPower", o.uo.numByPower);
+ json.Add("lossByPower", o.uo.lossByPower);
+ json.Add("rangeByPower", o.uo.rangeByPower);
+ json.Add("vmeanByPower", o.uo.vmeanByPower);
+ json.Add("vmaxByPower", o.uo.vmaxByPower);
+ json.Add("pmeanByPower", o.uo.pmeanByPower);
+ json.Add("pmaxByPower", o.uo.pmaxByPower);
// Converts it to a String
String js = json.ToString();
@@ -994,6 +992,106 @@ class JsonUtils
}
}
+public class UploadSprintDataObject
+{
+ public int personId;
+ public string sprintPositions;
+ public List<double> splitTimesL;
+ public double k;
+ public double vmax;
+ public double amax;
+ public double fmax;
+ public double pmax;
+
+ public UploadSprintDataObject (int personId, string sprintPositions, List<double> splitTimesL,
+ double k, double vmax, double amax, double fmax, double pmax)
+ {
+ this.personId = personId;
+ this.sprintPositions = sprintPositions;
+ this.splitTimesL = splitTimesL;
+ this.k = k;
+ this.vmax = vmax;
+ this.amax = amax;
+ this.fmax = fmax;
+ this.pmax = pmax;
+ }
+
+ public string ToSQLInsertString ()
+ {
+ return
+ "NULL, " +
+ personId.ToString() + ", " +
+ "\"" + sprintPositions + "\", " +
+ "\"" + splitTimesLToString() + "\", " +
+ Util.ConvertToPoint(k) + ", " +
+ Util.ConvertToPoint(vmax) + ", " +
+ Util.ConvertToPoint(amax) + ", " +
+ Util.ConvertToPoint(fmax) + ", " +
+ Util.ConvertToPoint(pmax) + ")";
+ }
+
+ private string splitTimesLToString()
+ {
+ string str = "";
+ string sep = "";
+ foreach(double d in splitTimesL)
+ {
+ str += sep + Util.ConvertToPoint(d);
+ sep = ";";
+ }
+
+ return str;
+ }
+}
+
+public class UploadEncoderDataFullObject
+{
+ public int personId;
+ public int stationId;
+ public int exerciseId;
+ public string laterality;
+ public string resistance;
+ public UploadEncoderDataObject uo;
+
+ public UploadEncoderDataFullObject(int personId, int stationId, int exerciseId,
+ string laterality, string resistance, UploadEncoderDataObject uo)
+ {
+ this.personId = personId;
+ this.stationId = stationId;
+ this.exerciseId = exerciseId;
+ this.laterality = laterality;
+ this.resistance = resistance;
+ this.uo = uo;
+ }
+
+ public string ToSQLInsertString ()
+ {
+ return
+ "NULL, " +
+ personId.ToString() + ", " +
+ stationId.ToString() + ", " +
+ exerciseId.ToString() + ", " +
+ "\"" + laterality + "\", " +
+ "\"" + resistance + "\", " +
+ uo.repetitions.ToString() + ", " +
+ uo.numBySpeed.ToString() + ", " +
+ uo.lossBySpeed.ToString() + ", " +
+ "\"" + uo.rangeBySpeed.ToString() + "\", " +
+ "\"" + uo.vmeanBySpeed.ToString() + "\"," +
+ "\"" + uo.vmaxBySpeed.ToString() + "\"," +
+ "\"" + uo.pmeanBySpeed.ToString() + "\"," +
+ "\"" + uo.pmaxBySpeed.ToString() + "\"," +
+ uo.numByPower.ToString() + ", " +
+ uo.lossByPower.ToString() + ", " +
+ "\"" + uo.rangeByPower.ToString() + "\", " +
+ "\"" + uo.vmeanByPower.ToString() + "\"," +
+ "\"" + uo.vmaxByPower.ToString() + "\"," +
+ "\"" + uo.pmeanByPower.ToString() + "\"," +
+ "\"" + uo.pmaxByPower.ToString() + "\")";
+ }
+
+}
+
public class UploadEncoderDataObject
{
private enum byTypes { SPEED, POWER }
@@ -1072,7 +1170,6 @@ public class UploadEncoderDataObject
}
return curveNum;
}
-
//TODO: on ecc-con should count [ecc-count] reps
//this calculation should be the same than the client gui
private int getLoss(ArrayList curves, byTypes by)
diff --git a/src/sqlite/json.cs b/src/sqlite/json.cs
new file mode 100644
index 0000000..e033515
--- /dev/null
+++ b/src/sqlite/json.cs
@@ -0,0 +1,128 @@
+/*
+ * This file is part of ChronoJump
+ *
+ * ChronoJump is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * ChronoJump is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Copyright (C) 2018 Xavier de Blas <xaviblas gmail com>
+ */
+
+using System;
+//using System.Collections.Generic; //List<T>
+using Mono.Data.Sqlite;
+
+class SqliteJson : Sqlite
+{
+ private static string tableEncoder = Constants.UploadEncoderDataTempTable;
+ private static string tableSprint = Constants.UploadSprintDataTempTable;
+
+ public SqliteJson() {
+ }
+
+ ~SqliteJson() {}
+
+ /*
+ * create and initialize tables
+ */
+
+ /*
+ * ENCODER
+ */
+
+ protected internal static void createTableUploadEncoderDataTemp()
+ {
+ dbcmd.CommandText =
+ "CREATE TABLE " + tableEncoder + " ( " +
+ "uniqueID INTEGER PRIMARY KEY, " +
+ "personId INT, " +
+ "stationId INT, " +
+ "exerciseId INT, " +
+ "laterality TEXT, " +
+ "resistance TEXT, " +
+ "repetitions INT, " +
+ //BySpeed stuff
+ "numBySpeed INT, " +
+ "lossBySpeed INT, " +
+ "rangeBySpeed TEXT, " +
+ "vmeanBySpeed TEXT, " +
+ "vmaxBySpeed TEXT, " +
+ "pmeanBySpeed TEXT, " +
+ "pmaxBySpeed TEXT, " +
+ //ByPower stuff
+ "numByPower INT, " +
+ "lossByPower INT, " +
+ "rangeByPower TEXT, " +
+ "vmeanByPower TEXT, " +
+ "vmaxByPower TEXT, " +
+ "pmeanByPower TEXT, " +
+ "pmaxByPower TEXT )";
+ dbcmd.ExecuteNonQuery();
+ }
+
+ public static void InsertTempEncoder (bool dbconOpened, UploadEncoderDataFullObject o)
+ {
+ openIfNeeded(dbconOpened);
+
+ dbcmd.CommandText = "INSERT INTO " + tableEncoder +
+ " (uniqueID, personID, stationID, exerciseID, laterality, resistance, " +
+ "repetitions, " +
+ "numBySpeed, lossBySpeed, rangeBySpeed, vmeanBySpeed, vmaxBySpeed, pmeanBySpeed,
pmaxBySpeed, " +
+ "numByPower, lossByPower, rangeByPower, vmeanByPower, vmaxByPower, pmeanByPower,
pmaxByPower) " +
+ " VALUES (" +
+ o.ToSQLInsertString();
+ LogB.SQL(dbcmd.CommandText.ToString());
+
+ dbcmd.ExecuteNonQuery();
+
+ closeIfNeeded(dbconOpened);
+ }
+
+
+ /*
+ * SPRINT
+ */
+
+ protected internal static void createTableUploadSprintDataTemp()
+ {
+ dbcmd.CommandText =
+ "CREATE TABLE " + tableSprint + " ( " +
+ "uniqueID INTEGER PRIMARY KEY, " +
+ "personId INT, " +
+ "sprintPositions TEXT, " +
+ "splitTimes TEXT, " +
+ "k FLOAT, " +
+ "vmax FLOAT, " +
+ "amax FLOAT, " +
+ "fmax FLOAT, " +
+ "pmax FLOAT )";
+ dbcmd.ExecuteNonQuery();
+ }
+
+ public static void InsertTempSprint (bool dbconOpened, UploadSprintDataObject o)
+ {
+ openIfNeeded(dbconOpened);
+
+ dbcmd.CommandText = "INSERT INTO " + tableSprint +
+ " (uniqueID, personID, sprintPositions, splitTimes, " +
+ " k, vmax, amax, fmax, pmax) VALUES (" +
+ o.ToSQLInsertString();
+ LogB.SQL(dbcmd.CommandText.ToString());
+
+ dbcmd.ExecuteNonQuery();
+
+ closeIfNeeded(dbconOpened);
+ }
+
+}
+
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index 31bb8e2..ca8d747 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.56";
+ static string lastChronojumpDatabaseVersion = "1.57";
public Sqlite() {
}
@@ -2337,6 +2337,15 @@ class Sqlite
currentVersion = updateVersion("1.56");
}
+ if(currentVersion == "1.56")
+ {
+ LogB.SQL("Created table UploadEncoderDataTemp, UploadSprintDataTemp");
+
+ SqliteJson.createTableUploadEncoderDataTemp ();
+ SqliteJson.createTableUploadSprintDataTemp ();
+
+ currentVersion = updateVersion("1.57");
+ }
@@ -2520,7 +2529,12 @@ class Sqlite
SqlitePreferences.createTable();
SqlitePreferences.initializeTable(lastChronojumpDatabaseVersion, creatingBlankDatabase);
+ //compujump json temp tables
+ SqliteJson.createTableUploadEncoderDataTemp ();
+ SqliteJson.createTableUploadSprintDataTemp ();
+
//changes [from - to - desc]
+ //1.56 - 1.57 Converted DB to 1.57 Created table UploadEncoderDataTemp, UploadSprintDateTemp
//1.55 - 1.56 Converted DB to 1.56 Added encoder rhythm restAfterEcc
//1.54 - 1.55 Converted DB to 1.55 Added preferences: personPhoto
//1.53 - 1.54 Converted DB to 1.54 Added encoderRhythm variables: repOrPhases, repSeconds
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]