[chronojump] UploadEncoderData with all needed repetition params



commit 99086b1b15a1ca52a0edfa170e929f1a7d84aacd
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed May 17 23:55:48 2017 +0200

    UploadEncoderData with all needed repetition params

 src/gui/chronojump.cs |    4 +-
 src/gui/encoder.cs    |   16 +-------
 src/json.cs           |  103 +++++++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 104 insertions(+), 19 deletions(-)
---
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index df6073c..521226b 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -6367,6 +6367,8 @@ LogB.Debug("X");
        
        private void on_button_carles_clicked (object o, EventArgs args)
        {
+               return;
+               /*
                bool showInWindow = true;
 
                Json js = new Json();
@@ -6388,7 +6390,7 @@ LogB.Debug("X");
                                                Constants.MessageTypes.WARNING,
                                                js.ResultMessage);
                }
-
+*/
                /*
                new DialogMessage(
                                "Chronojump",
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 47af31a..7abd864 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -5953,18 +5953,7 @@ public partial class ChronoJumpWindow
                                                showTriggersAndTab();
 
                                                //2) send the json to server
-
-                                               //get highest meanPower on set
-                                               double meanPowerHighest = 0;
-                                               foreach (EncoderCurve curve in encoderCaptureCurves)
-                                                       if(curve.MeanPowerD > meanPowerHighest)
-                                                               meanPowerHighest = curve.MeanPowerD;
-
-                                               //get reps >= 50 % of highest
-                                               int repsAbove50pBest = 0;
-                                               foreach (EncoderCurve curve in encoderCaptureCurves)
-                                                       if(curve.MeanPowerD >= meanPowerHighest / 2.0)
-                                                               repsAbove50pBest ++;
+                                               UploadEncoderDataObject uo = new 
UploadEncoderDataObject(encoderCaptureCurves);
 
                                                /*
                                                 * problems on Json by accents like "PressiĆ³ sobre banc"
@@ -5977,8 +5966,7 @@ public partial class ChronoJumpWindow
                                                                1,
                                                                
Util.ConvertToPoint(findMass(Constants.MassType.DISPLACED)), //this is only for gravitatory
                                                                
UtilGtk.ComboGetActive(combo_encoder_exercise_capture),
-                                                               Util.ConvertToPoint(meanPowerHighest),
-                                                               repsAbove50pBest);
+                                                               uo);
 
                                                if(! success) {
                                                        LogB.Error(js.ResultMessage);
diff --git a/src/json.cs b/src/json.cs
index 4fbb9e6..b4bb399 100644
--- a/src/json.cs
+++ b/src/json.cs
@@ -24,6 +24,7 @@ using System.Web;
 using System.IO;
 using System.Json;
 using System.Text;
+using System.Collections;
 using System.Collections.Generic; //Dictionary
 using Mono.Unix;
 
@@ -366,12 +367,13 @@ public class Json
                return new Person(Convert.ToInt32(id), player, rfid);
        }
 
-
+       /*
        public bool UploadEncoderData()
        {
                return UploadEncoderData(1, 1, "40.2", "lateral", "8100.5", 8);
        }
-       public bool UploadEncoderData(int personId, int machineId, string resistance, string exerciseName, 
string meanPowerBestRep, int repsAbove50pBest )
+       */
+       public bool UploadEncoderData(int personId, int machineId, string resistance, string exerciseName, 
UploadEncoderDataObject uo)
        {
                // Create a request using a URL that can receive a post.
                WebRequest request = WebRequest.Create (serverUrl + "/uploadEncoderData");
@@ -385,12 +387,25 @@ public class Json
 
                // Creates the json object
                JsonObject json = new JsonObject();
+
                json.Add("personId", personId);
                json.Add("machineId", machineId);
                json.Add("resistance", resistance);
                json.Add("exerciseName", exerciseName);
-               json.Add("meanPowerBestRep", meanPowerBestRep);
-               json.Add("repsAbove50pBest", repsAbove50pBest);
+
+               json.Add("numBySpeed", uo.numBySpeed);
+               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("rangeByPower", uo.rangeByPower);
+               json.Add("vmeanByPower", uo.vmeanByPower);
+               json.Add("vmaxByPower", uo.vmaxByPower);
+               json.Add("pmeanByPower", uo.pmeanByPower);
+               json.Add("pmaxByPower", uo.pmaxByPower);
 
                // Converts it to a String
                String js = json.ToString();
@@ -450,3 +465,83 @@ class JsonUtils
                }
        }
 }
+
+public class UploadEncoderDataObject
+{
+       //variables calculated BySpeed (by best mean speed)
+       public int numBySpeed;
+       public string rangeBySpeed; //strings with . as decimal point
+       public string vmeanBySpeed;
+       public string vmaxBySpeed;
+       public string pmeanBySpeed;
+       public string pmaxBySpeed;
+
+       //variables calculated ByPower (by best mean power)
+       public int numByPower;
+       public string rangeByPower; //strings with . as decimal point
+       public string vmeanByPower;
+       public string vmaxByPower;
+       public string pmeanByPower;
+       public string pmaxByPower;
+
+       public UploadEncoderDataObject(ArrayList curves)
+       {
+               int nSpeed = getRepBySpeed(curves);
+               int nPower = getRepByPower(curves);
+
+               EncoderCurve curveBySpeed = (EncoderCurve) curves[nSpeed];
+               EncoderCurve curveByPower = (EncoderCurve) curves[nPower];
+
+               rangeBySpeed = Util.ConvertToPoint(curveBySpeed.Height);
+               rangeByPower = Util.ConvertToPoint(curveByPower.Height);
+
+               vmeanBySpeed = Util.ConvertToPoint(curveBySpeed.MeanSpeed);
+               vmeanByPower = Util.ConvertToPoint(curveByPower.MeanSpeed);
+               vmaxBySpeed = Util.ConvertToPoint(curveBySpeed.MaxSpeed);
+               vmaxByPower = Util.ConvertToPoint(curveByPower.MaxSpeed);
+
+               pmeanBySpeed = Util.ConvertToPoint(curveBySpeed.MeanPower);
+               pmeanByPower = Util.ConvertToPoint(curveByPower.MeanPower);
+               pmaxBySpeed = Util.ConvertToPoint(curveBySpeed.PeakPower);
+               pmaxByPower = Util.ConvertToPoint(curveByPower.PeakPower);
+
+               //add +1 to show to user
+               numBySpeed = nSpeed + 1;
+               numByPower = nPower + 1;
+       }
+
+       private int getRepBySpeed(ArrayList curves)
+       {
+               int curveNum = 0;
+               int i = 0;
+               double meanSpeedHighest = 0;
+
+               foreach (EncoderCurve curve in curves)
+               {
+                       if(curve.MeanSpeedD > meanSpeedHighest)
+                       {
+                               meanSpeedHighest = curve.MeanSpeedD;
+                               curveNum = i;
+                       }
+                       i ++;
+               }
+               return curveNum;
+       }
+       private int getRepByPower(ArrayList curves)
+       {
+               int curveNum = 0;
+               int i = 0;
+               double meanPowerHighest = 0;
+
+               foreach (EncoderCurve curve in curves)
+               {
+                       if(curve.MeanPowerD > meanPowerHighest)
+                       {
+                               meanPowerHighest = curve.MeanPowerD;
+                               curveNum = i;
+                       }
+                       i ++;
+               }
+               return curveNum;
+       }
+}


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