[chronojump/michrolab] Networks: Multiple jumps upload correctly



commit 3cc6562dce8fd5d581a43494c0e7c2a4cca996cc
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Aug 25 12:12:46 2022 +0200

    Networks: Multiple jumps upload correctly

 src/execute/jump.cs        | 67 +++++++++++++++++++++++++++++++---------------
 src/gui/app1/chronojump.cs | 11 +++++---
 src/json/compujump.cs      | 35 +++++++++++++++---------
 src/json/compujumpJumps.cs | 62 +++++++++++++++++++++++++++++-------------
 src/jump.cs                | 31 +++++++++++++++++++++
 src/treeview/jump.cs       |  9 +++++++
 6 files changed, 161 insertions(+), 54 deletions(-)
---
diff --git a/src/execute/jump.cs b/src/execute/jump.cs
index 6b3a1c1a8..a4fbccd53 100644
--- a/src/execute/jump.cs
+++ b/src/execute/jump.cs
@@ -51,7 +51,7 @@ public class JumpExecute : EventExecute
        private int angle = -1;
        private bool avoidGraph;
        private bool heightPreferred;
-       private bool metersSecondsPreferred;
+       protected bool metersSecondsPreferred;
        protected bool upload;
        protected int uploadStationId;
        protected bool django;
@@ -119,7 +119,7 @@ public class JumpExecute : EventExecute
        
        public override void SimulateInitValues(Random randSent)
        {
-               LogB.Information("From execute/jump.cs");
+               LogB.Information ("From execute/jump.cs");
 
                rand = randSent; //we send the random, because if we create here, the values will be the same 
for each nbew instance
                simulated = true;
@@ -143,6 +143,7 @@ public class JumpExecute : EventExecute
        
        public override void Manage()
        {
+               LogB.Information("Jumps Manage!");
                //boolean to know if chronopic has been disconnected    
                chronopicDisconnected = false;
 
@@ -197,6 +198,8 @@ public class JumpExecute : EventExecute
 
        public override void ManageFall()
        {
+               LogB.Information ("Jumps ManageFall!, fall: ", fall.ToString ());
+
                //boolean to know if chronopic has been disconnected    
                chronopicDisconnected = false;
 
@@ -500,7 +503,7 @@ public class JumpExecute : EventExecute
                        UploadJumpSimpleDataObject uj = new UploadJumpSimpleDataObject (
                                        uploadStationId, (Jump) eventDone, typeID, personWeight, 
metersSecondsPreferred);
                        JsonCompujump js = new JsonCompujump (django);
-                       if( ! js.UploadJumpSimpleData (uj) )
+                       if( ! js.UploadJumpData (uj, Constants.Modes.JUMPSSIMPLE) )
                        {
                                LogB.Error (js.ResultMessage);
 
@@ -596,19 +599,22 @@ public class JumpRjExecute : JumpExecute
        }
 
        //jump execution
-       public JumpRjExecute(int personID, string personName, 
-                       int sessionID, string type, double fall, double weight, 
+       public JumpRjExecute(int personID, string personName, double personWeight,
+                       int sessionID, int typeID, string type, double fall, double weight,
                        double limitAsDouble, bool jumpsLimited, 
                        Chronopic cp, int pDN, bool allowFinishAfterTime,
                        bool volumeOn, Preferences.GstreamerTypes gstreamer,
-                       FeedbackWindow feedbackWin,
-                       double progressbarLimit, ExecutingGraphData egd
+                       bool metersSecondsPreferred, FeedbackWindow feedbackWin,
+                       double progressbarLimit, ExecutingGraphData egd,
+                       bool upload, int uploadStationId, bool django //upload: configChronojump.Compujump && 
upload (contacts) button active
                        )
        {
                this.personID = personID;
                this.personName = personName;
+               this.personWeight = personWeight; //for Stiffness at upload on compujump
                this.sessionID = sessionID;
                this.type = type;
+               this.typeID = typeID;
                this.fall = fall;
                this.weight = weight;
                this.limitAsDouble = limitAsDouble;
@@ -629,12 +635,17 @@ public class JumpRjExecute : JumpExecute
                this.allowFinishAfterTime = allowFinishAfterTime;
                this.volumeOn = volumeOn;
                this.gstreamer = gstreamer;
+               this.metersSecondsPreferred = metersSecondsPreferred;
                this.feedbackWin = feedbackWin;
                this.progressbarLimit = progressbarLimit;
                this.egd = egd;
        
                if(TypeHasFall) { hasFall = true; } 
                else { hasFall = false; }
+
+               this.upload = upload;
+               this.uploadStationId = uploadStationId;
+               this.django = django;
                
                fakeButtonUpdateGraph = new Gtk.Button();
                fakeButtonThreadDyed = new Gtk.Button();
@@ -1099,6 +1110,11 @@ public class JumpRjExecute : JumpExecute
                                        jumps, Util.GetTotalTime(tcString, tvString), limitString, 
angleString, Util.BoolToNegativeInt(simulated),
                                        datetime);
                else {
+                       if(simulated)
+                               feedbackMessage = Catalog.GetString(Constants.SimulatedMessage());
+                       else
+                               feedbackMessage = "";
+
                        uniqueID = SqliteJumpRj.Insert(false, Constants.JumpRjTable, "NULL", personID, 
sessionID, 
                                        type, Util.GetMax(tvString), Util.GetMax(tcString), 
                                        fall, weight, description,
@@ -1110,22 +1126,31 @@ public class JumpRjExecute : JumpExecute
                        //define the created object
                        eventDone = new JumpRj(uniqueID, personID, sessionID, type, tvString, tcString, fall, 
weight, description, jumps, Util.GetTotalTime(tcString, tvString), limitString, angleString, 
Util.BoolToNegativeInt(simulated), datetime);
 
+                       if(upload)
+                       {
+                               /* debug
+                               LogB.Information ("upload will start");
+                               LogB.Information (string.Format (
+                                                       "uploadStationId: {0}, (JumpRj) eventDone {1}, typeID 
{2}, personWeight {3}, metersSecondsPreferred {4}",
+                                                       uploadStationId, (JumpRj) eventDone, typeID, 
personWeight, metersSecondsPreferred));
+                                */
+
+                               UploadJumpReactiveDataObject uj = new UploadJumpReactiveDataObject (
+                                               uploadStationId, (JumpRj) eventDone, typeID, personWeight, 
metersSecondsPreferred);
+                               LogB.Information ("uj: " + uj.ToString ());
+
+                               JsonCompujump js = new JsonCompujump (django);
+                               if( ! js.UploadJumpData (uj, Constants.Modes.JUMPSREACTIVE) )
+                               {
+                                       LogB.Error (js.ResultMessage);
+
+                                       feedbackMessageOnDialog = true;
+                                       feedbackMessage = js.ResultMessage;
+                               }
+                       }
 
-                       //event will be raised, and managed in chronojump.cs
-                       /*
-                       string myStringPush =   
-                               //Catalog.GetString("Last jump: ") + 
-                               personName + " " + 
-                               type + " (" + limitString + ") " +
-                               " " + Catalog.GetString("AVG TF") + ": " + Util.TrimDecimals( Util.GetAverage 
(tvString).ToString(), pDN ) +
-                               " " + Catalog.GetString("AVG TC") + ": " + Util.TrimDecimals( Util.GetAverage 
(tcString).ToString(), pDN ) ;
-                       */
-                       if(simulated)
-                               feedbackMessage = Catalog.GetString(Constants.SimulatedMessage());
-                       else
-                               feedbackMessage = "";
                        needShowFeedbackMessage = true; 
-               
+
                        needEndEvent = true; //used for hiding some buttons on eventWindow, and also for 
updateTimeProgressBar here
                }
        }
diff --git a/src/gui/app1/chronojump.cs b/src/gui/app1/chronojump.cs
index c18a5416d..7571015a9 100644
--- a/src/gui/app1/chronojump.cs
+++ b/src/gui/app1/chronojump.cs
@@ -5491,13 +5491,18 @@ public partial class ChronoJumpWindow
                event_execute_ButtonCancel.Clicked += new EventHandler(on_cancel_clicked);
                event_execute_ButtonFinish.Clicked += new EventHandler(on_finish_clicked);
 
-               currentEventExecute = new JumpRjExecute(currentPerson.UniqueID, currentPerson.Name, 
-                               currentSession.UniqueID, currentJumpRjType.Name, myFall, jumpWeight, 
+               currentEventExecute = new JumpRjExecute(
+                               currentPerson.UniqueID, currentPerson.Name, currentPersonSession.Weight,
+                               currentSession.UniqueID, currentJumpRjType.UniqueID, currentJumpRjType.Name,
+                               myFall, jumpWeight,
                                progressbarLimit, currentJumpRjType.JumpsLimited, 
                                cp2016.CP, preferences.digitsNumber,
                                checkbutton_allow_finish_rj_after_time.Active,
                                preferences.volumeOn, preferences.gstreamer,
-                               feedbackWin, progressbarLimit, egd);
+                               preferences.metersSecondsPreferred,
+                               feedbackWin, progressbarLimit, egd,
+                               (configChronojump.Compujump && check_contacts_networks_upload.Active),
+                               configChronojump.CompujumpStationID, configChronojump.CompujumpDjango);
                
                //suitable for limited by jump and time
                //simulated always simulate limited by jumps
diff --git a/src/json/compujump.cs b/src/json/compujump.cs
index 3cae58ac3..4853c0b52 100644
--- a/src/json/compujump.cs
+++ b/src/json/compujump.cs
@@ -407,9 +407,9 @@ public class JsonCompujump : Json
        }
        */
 
-       public bool UploadJumpSimpleData (UploadJumpSimpleDataObject o)
+       public bool UploadJumpData (UploadJumpDataObject o, Constants.Modes m)
        {
-               LogB.Information("calling upload jump simple");
+               LogB.Information("calling jump upload, mode = " + m.ToString());
                // Create a request using a URL that can receive a post.
                if (! createWebRequest(requestType.AUTHENTICATED, "/api/v1/client/uploadJump"))
                        return false;
@@ -421,26 +421,37 @@ public class JsonCompujump : Json
                // debug reading on server /var/log/chronojump/debug.log
 
                JsonObject json = new JsonObject();
-               json.Add("player_id", o.jump.PersonID);
                json.Add("station_id", o.stationId);
                json.Add("exercise_id", o.ExerciseIdStr);
-               json.Add("multiple", 0);
                json.Add("comment", "");
-               json.Add("contact_time", Util.ConvertToPoint (o.jump.Tc));
-               json.Add("flight_time", Util.ConvertToPoint (o.jump.Tv));
-               json.Add("extra_weight", Util.ConvertToPoint (o.jump.Weight));
-               json.Add("fall", Util.ConvertToPoint (o.jump.Fall));
+               if (m == Constants.Modes.JUMPSSIMPLE)
+               {
+                       json.Add("player_id", o.jump.PersonID);
+                       json.Add("multiple", 0);
+                       json.Add("contact_time", Util.ConvertToPoint (o.jump.Tc));
+                       json.Add("flight_time", Util.ConvertToPoint (o.jump.Tv));
+                       json.Add("extra_weight", Util.ConvertToPoint (o.jump.Weight));
+                       json.Add("fall", Util.ConvertToPoint (o.jump.Fall));
+               } else // if (m == Constants.Modes.JUMPSREACTIVE)
+               {
+                       json.Add("player_id", o.jumpRj.PersonID);
+                       json.Add("multiple", 1);
+                       json.Add("contact_time", Util.ConvertToPoint (o.jumpRj.TcAvg));
+                       json.Add("flight_time", Util.ConvertToPoint (o.jumpRj.TvAvg));
+                       json.Add("extra_weight", Util.ConvertToPoint (o.jumpRj.Weight));
+                       json.Add("fall", Util.ConvertToPoint (o.jumpRj.Fall));
+               }
                json.Add("power", o.PowerStr);
                json.Add("stiffness", o.StiffnessStr);
                json.Add("initial_speed", o.InitialSpeedStr);
 
                // Converts it to a String
                String js = json.ToString();
-               LogB.Information("json UploadJumpSimpleData: ", js);
+               LogB.Information("json UploadJumpData: ", js);
 
                // Writes the json object into the request dataStream
                Stream dataStream;
-               if(! getWebRequestStream (request, out dataStream, "Could not upload jump simple data."))
+               if(! getWebRequestStream (request, out dataStream, "Could not upload jump data."))
                        return false;
 
                dataStream.Write (Encoding.UTF8.GetBytes(js), 0, js.Length);
@@ -448,7 +459,7 @@ public class JsonCompujump : Json
 
                // Get the response.
                WebResponse response;
-               if(! getWebResponse (request, out response, "Could not upload jump simple data."))
+               if(! getWebResponse (request, out response, "Could not upload jump data."))
                        return false;
 
                // Display the status (will be 202, CREATED)
@@ -458,7 +469,7 @@ public class JsonCompujump : Json
                dataStream.Close ();
                response.Close ();
 
-               this.ResultMessage = "Jump simple data sent.";
+               this.ResultMessage = "Jump data sent.";
                return true;
        }
 
diff --git a/src/json/compujumpJumps.cs b/src/json/compujumpJumps.cs
index 561015879..067e26099 100644
--- a/src/json/compujumpJumps.cs
+++ b/src/json/compujumpJumps.cs
@@ -143,30 +143,24 @@ public class JsonCompujumpJumps : JsonCompujump
        }
 }
 
-public class UploadJumpSimpleDataObject
+public abstract class UploadJumpDataObject
 {
-       public int stationId;
        public Jump jump;
+       public JumpRj jumpRj;
 
-       private int exerciseId;
-
-       private double power;
-       private double stiffness;
-       private double initialSpeed;
+       public int stationId;
 
-       public UploadJumpSimpleDataObject (int stationId, Jump jump, int exerciseId, double personMassInKg, 
bool metersSecondsPreferred)
-       {
-               this.stationId = stationId;
-               this.jump = jump;
-               this.exerciseId = exerciseId;
+       protected int exerciseId;
 
-               if (jump.Tc > 0)
-                       this.power = Jump.GetDjPower (jump.Tc, jump.Tv, personMassInKg + jump.Weight, 
jump.Fall);
-               else
-                       this.power = Jump.GetPower (jump.Tv, personMassInKg, jump.Weight);
+       protected double power;
+       protected double stiffness;
+       protected double initialSpeed;
 
-               this.stiffness = jump.Stiffness (personMassInKg, jump.Weight);
-               this.initialSpeed = jump.GetInitialSpeedJumpSimple (metersSecondsPreferred);
+       //debug
+       public override string ToString ()
+       {
+               return string.Format ("power: {0}, stiffness: {1}, initialSpeed: {2}",
+                               power, stiffness, initialSpeed);
        }
 
        public string ExerciseIdStr
@@ -187,3 +181,35 @@ public class UploadJumpSimpleDataObject
        }
 }
 
+public class UploadJumpSimpleDataObject : UploadJumpDataObject
+{
+       public UploadJumpSimpleDataObject (int stationId, Jump jump, int exerciseId, double personMassInKg, 
bool metersSecondsPreferred)
+       {
+               this.stationId = stationId;
+               this.jump = jump;
+               this.exerciseId = exerciseId;
+
+               if (jump.Tc > 0)
+                       this.power = Jump.GetDjPower (jump.Tc, jump.Tv, personMassInKg + jump.Weight, 
jump.Fall);
+               else
+                       this.power = Jump.GetPower (jump.Tv, personMassInKg, jump.Weight);
+
+               this.stiffness = jump.Stiffness (personMassInKg, jump.Weight);
+               this.initialSpeed = jump.GetInitialSpeedJumpSimple (metersSecondsPreferred);
+       }
+}
+
+public class UploadJumpReactiveDataObject : UploadJumpDataObject
+{
+       public UploadJumpReactiveDataObject (int stationId, JumpRj jumpRj, int exerciseId, double 
personMassInKg, bool metersSecondsPreferred)
+       {
+               this.stationId = stationId;
+               this.jumpRj = jumpRj;
+               this.exerciseId = exerciseId;
+
+               this.power = jumpRj.PowerAverage (personMassInKg);
+               this.stiffness = jumpRj.Stiffness (personMassInKg, jumpRj.Weight);
+               this.initialSpeed = Jump.GetInitialSpeed (jumpRj.TvAvg, metersSecondsPreferred);
+       }
+}
+
diff --git a/src/jump.cs b/src/jump.cs
index 636282d6d..1e379f1df 100644
--- a/src/jump.cs
+++ b/src/jump.cs
@@ -332,6 +332,37 @@ public class JumpRj : Jump
                                angleString, simulated, datetime);
        }
 
+       // based on treeviewJump printAVG
+       public double PowerAverage (double personMassInKg)
+       {
+               double powerSum = 0;
+               for (int i = 0; i < tcList.Count; i ++)
+               {
+                       double tc = tcList[i];
+                       double tv = tvList[i];
+                       double myfall = 0;
+                       if (tcList[i] == -1) //startIn at first jump tc is 0, better check like this (string)
+                               powerSum += GetPower (tv, personMassInKg, weight);
+                       else {
+                               if (i == 0)
+                                       myfall = fall;
+                               else
+                                       myfall = Util.GetHeightInCentimeters (tvList[i-1]);
+
+                               powerSum += Jump.GetDjPower (tc, tv,
+                                               (personMassInKg + weight), myfall);
+
+                               /* debug
+                               LogB.Information (string.Format (
+                                                       "at jumpRj.PowerAverage, tc: {0}, tv: {1}, 
(personMassInKg + weight): {2}, myfall: {3}, powerSum: {4}",
+                                                       tc, tv, (personMassInKg + weight), myfall, powerSum));
+                               */
+
+                               //LogB.Information ("at jumpRj.PowerAverage, powerSum = ", 
powerSum.ToString());
+                       }
+               }
+               return UtilAll.DivideSafe (powerSum, tcList.Count);
+       }
 
        public override double Stiffness(double personMassInKg, double extraMass) 
        {
diff --git a/src/treeview/jump.cs b/src/treeview/jump.cs
index f2afa8d1f..28df7dab8 100644
--- a/src/treeview/jump.cs
+++ b/src/treeview/jump.cs
@@ -539,11 +539,20 @@ public class TreeViewJumpsRj : TreeViewJumps
                                                fall = newJumpRj.Fall;
                                        else
                                                fall = 
Util.GetHeightInCentimeters(Convert.ToDouble(tv_array[i-1]));
+
                                        powerSum += Jump.GetDjPower (tc, tv,
                                                        (personWeight + weightInKg), fall);
+
+                                       /* debug
+                                       LogB.Information (string.Format (
+                                                               "at treeviewJump, tc: {0}, tv: {1}, 
(personWeight + weightInKg): {2}, fall: {3}, powerSum: {4}",
+                                                       tc, tv, (personWeight + weightInKg), fall, powerSum));
+                                                       */
+
                                        stiffnessSum += Util.GetStiffness(personWeight, weightInKg, tv, tc);
                                        stiffnessCount ++;
                                }
+                               //LogB.Information ("at treeviewJump, powerSum = ", powerSum.ToString());
                                powerCount ++;
                        }
                        if (preferences.showPower)


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