[chronojump] On compujump runInterval is R calculated as sprint and uploaded



commit 47e8a9149abfb786c9bfef1244154e23bd63817d
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Jul 5 22:17:39 2017 +0200

    On compujump runInterval is R calculated as sprint and uploaded

 src/gui/chronojump.cs |   64 +++++++++++++++++++++++++++++++++++++++++++++---
 src/gui/sprint.cs     |   14 +++++++----
 src/json.cs           |   11 ++++++--
 src/sprint.cs         |    8 ++++++
 4 files changed, 85 insertions(+), 12 deletions(-)
---
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index 204645b..2188906 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -4454,10 +4454,7 @@ public partial class ChronoJumpWindow
 
                        if(configChronojump.Compujump)
                        {
-                               Json js = new Json();
-                               js.UploadSprintData(currentPerson.UniqueID,
-                                               "5;5;5;5", //TODO_ fix this
-                                               currentRunInterval.IntervalTimesString);
+                               calculateSprintAndUpload();
                        }
                }
                else if( currentEventExecute.ChronopicDisconnected )
@@ -4467,6 +4464,65 @@ public partial class ChronoJumpWindow
                Sqlite.DeleteTempEvents("tempRunInterval");
        }
 
+       private void calculateSprintAndUpload()
+       {
+               string positions = getSprintPositions(
+                               currentRunInterval.DistanceInterval, //distanceInterval. == -1 means variable 
distances
+                               currentRunInterval.IntervalTimesString,
+                               currentRunIntervalType.DistancesString  //distancesString
+                               );
+               if(positions == "")
+                       return;
+
+               positions = Util.ChangeChars(positions, ",", ".");
+               positions = "0;" + positions;
+
+               string splitTimes = getSplitTimes(currentRunInterval.IntervalTimesString);
+               splitTimes = Util.ChangeChars(splitTimes, ",", ".");
+               splitTimes = "0;" + splitTimes;
+
+               sprint = new Sprint(positions,
+                               splitTimes,
+                               currentPersonSession.Weight, //TODO: can be more if extra weight
+                               currentPersonSession.Height,
+                               25);
+
+               bool sprintRDoneOk = on_button_sprint_do ();
+               string stringResultsFile = System.IO.Path.GetTempPath() + "sprintResults.csv";
+               string line = "";
+               if(! sprintRDoneOk || ! File.Exists(stringResultsFile))
+                       return;
+
+               string contents = Util.ReadFile(stringResultsFile, false);
+               if (contents == null)
+                       return;
+
+               using (StringReader reader = new StringReader (contents))
+               {
+                       line = reader.ReadLine ();      //headers
+                       if(line == null)
+                               return;
+
+                       line = reader.ReadLine ();      //data
+                       if(line == null)
+                               return;
+               }
+
+               
//"";"Mass";"Height";"Temperature";"Vw";"Ka";"K.fitted";"Vmax.fitted";"amax.fitted";"fmax.fitted";"fmax.rel.fitted";"sfv.fitted";"sfv.rel.fitted";"pmax.fitted";"pmax.rel.fitted";"tpmax.fitted";"F0";"F0.rel";"V0";"sfv.lm";"sfv.rel.lm";"pmax.lm";"pmax.rel.lm"
+               string [] results = line.Split(new char[] {';'});
+               if(results.Length < 14)
+                       return;
+
+               double k = Convert.ToDouble(Util.ChangeDecimalSeparator(results[6])); //K.fitted
+               double vmax = Convert.ToDouble(Util.ChangeDecimalSeparator(results[7])); //Vmax.fitted
+               double amax = Convert.ToDouble(Util.ChangeDecimalSeparator(results[8])); //amax.fitted
+               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(currentPerson.UniqueID, sprint, k, vmax, amax, fmax, pmax);
+       }
+
        /* ---------------------------------------------------------
         * ----------------  REACTION TIMES EXECUTION --------------
         *  --------------------------------------------------------
diff --git a/src/gui/sprint.cs b/src/gui/sprint.cs
index d89987a..147bf39 100644
--- a/src/gui/sprint.cs
+++ b/src/gui/sprint.cs
@@ -193,12 +193,10 @@ public partial class ChronoJumpWindow
                {
                         string positions = (string) model.GetValue(iter, 2);
                         positions = Util.ChangeChars(positions, ",", ".");
-                        //add start TODO: check if needed
                         positions = "0;" + positions;
 
                         string splitTimes = (string) model.GetValue(iter, 3);
                         splitTimes = Util.ChangeChars(splitTimes, ",", ".");
-                        //add start TODO: check if needed
                         splitTimes = "0;" + splitTimes;
 
                         sprint = new Sprint(
@@ -221,18 +219,23 @@ public partial class ChronoJumpWindow
                        return;
                }
 
+               on_button_sprint_do ();
+       }
+
+       private bool on_button_sprint_do ()
+       {
                if(currentPersonSession.Weight == 0)
                {
                        new DialogMessage(Constants.MessageTypes.WARNING,
                                        Catalog.GetString("Error, weight of the person cannot be 0"));
-                       return;
+                       return false;
                }
 
                if(currentPersonSession.Height == 0)
                {
                        new DialogMessage(Constants.MessageTypes.WARNING,
                                        Catalog.GetString("Error, height of the person cannot be 0"));
-                       return;
+                       return false;
                }
 
                Util.FileDelete(UtilEncoder.GetSprintImage());
@@ -246,7 +249,7 @@ public partial class ChronoJumpWindow
                if(! success)
                {
                        new DialogMessage(Constants.MessageTypes.WARNING, Catalog.GetString("This data does 
not seem a sprint."));
-                       return;
+                       return false;
                }
 
                while ( ! Util.FileReadable(UtilEncoder.GetSprintImage()));
@@ -255,6 +258,7 @@ public partial class ChronoJumpWindow
                                UtilEncoder.GetSprintImage(),
                                image_sprint);
                image_sprint.Sensitive = true;
+               return true;
        }
 
 }
diff --git a/src/json.cs b/src/json.cs
index 8a0af95..25d413f 100644
--- a/src/json.cs
+++ b/src/json.cs
@@ -609,7 +609,7 @@ public class Json
                                "", "", 0); //ressitance, description, speed1RM
        }
 
-       public bool UploadSprintData(int personId, string distances, string times)
+       public bool UploadSprintData(int personId, Sprint sprint, double k, double vmax, double amax, double 
fmax, double pmax )
        {
                LogB.Information("calling upload sprint");
                // Create a request using a URL that can receive a post.
@@ -626,8 +626,13 @@ public class Json
                JsonObject json = new JsonObject();
 
                json.Add("personId", personId);
-               json.Add("distances", distances);
-               json.Add("times", times);
+               json.Add("distances", sprint.Positions);
+               json.Add("times", sprint.SplitTimes);
+               json.Add("k", k);
+               json.Add("vmax", vmax);
+               json.Add("amax", amax);
+               json.Add("fmax", fmax);
+               json.Add("pmax", pmax);
 
                // Converts it to a String
                String js = json.ToString();
diff --git a/src/sprint.cs b/src/sprint.cs
index 63ccf5b..3dc3676 100644
--- a/src/sprint.cs
+++ b/src/sprint.cs
@@ -118,4 +118,12 @@ public class Sprint
                writer.Close();
                ((IDisposable)writer).Dispose();
        }
+
+       public string Positions {
+               get { return positions; }
+       }
+
+       public string SplitTimes {
+               get { return splitTimes; }
+       }
 }


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