[chronojump] Networks: Simple jumps upload correctly



commit e8bfb0fb4b0dfa51dbbff31c417528e836a989af
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Aug 23 16:25:05 2022 +0200

    Networks: Simple jumps upload correctly

 src/execute/event.cs       |  9 +++++++-
 src/execute/jump.cs        | 48 +++++++++++++++++++++++++++++++++++-----
 src/gui/app1/chronojump.cs | 11 ++++++----
 src/gui/app1/jump.cs       | 12 ++++++----
 src/json/compujump.cs      | 55 ++++++++++++++++++++++++++++++++++++++++++++++
 src/json/compujumpJumps.cs | 45 +++++++++++++++++++++++++++++++++++++
 6 files changed, 165 insertions(+), 15 deletions(-)
---
diff --git a/src/execute/event.cs b/src/execute/event.cs
index 728ac4f58..54b867a33 100644
--- a/src/execute/event.cs
+++ b/src/execute/event.cs
@@ -15,7 +15,7 @@
  *  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) 2004-2020   Xavier de Blas <xaviblas gmail com> 
+ * Copyright (C) 2004-2022   Xavier de Blas <xaviblas gmail com>
  */
 
 using System;
@@ -33,6 +33,7 @@ public class EventExecute
        protected string personName;
        protected int sessionID;
        protected int uniqueID;
+       protected int typeID; //to upload to networks
        protected string type;
        protected string description;
 
@@ -65,6 +66,7 @@ public class EventExecute
        //protected bool needShowSyncMessage;
        protected string feedbackMessage;
        protected bool needShowFeedbackMessage;
+       protected bool feedbackMessageOnDialog;
 
        //instances with the info to create
        public PrepareEventGraphJumpSimple PrepareEventGraphJumpSimpleObject; 
@@ -366,6 +368,11 @@ public class EventExecute
                } 
                else if(needShowFeedbackMessage) 
                {
+                       if (feedbackMessageOnDialog)
+                       {
+                               new DialogMessage(Constants.MessageTypes.WARNING, feedbackMessage);
+                               feedbackMessageOnDialog = false;
+                       }
                        UtilGtk.PrintLabelWithTooltip(egd.Label_message, feedbackMessage);
                        needShowFeedbackMessage = false;
                }
diff --git a/src/execute/jump.cs b/src/execute/jump.cs
index fa0b25ec2..6b3a1c1a8 100644
--- a/src/execute/jump.cs
+++ b/src/execute/jump.cs
@@ -28,6 +28,7 @@ using Mono.Unix;
 
 public class JumpExecute : EventExecute
 {
+       protected double personWeight;
        protected double tv;
        protected double tc;
        protected double fall;
@@ -50,22 +51,32 @@ public class JumpExecute : EventExecute
        private int angle = -1;
        private bool avoidGraph;
        private bool heightPreferred;
-       
+       private bool metersSecondsPreferred;
+       protected bool upload;
+       protected int uploadStationId;
+       protected bool django;
+
        public JumpExecute() {
        }
 
        //jump execution
-       public JumpExecute(int personID, string personName, int sessionID, string type, double fall, double 
weight,  
+       public JumpExecute (
+                       int personID, string personName, double personWeight,
+                       int sessionID, int typeID, string type, double fall, double weight,
                        Chronopic cp, int pDN,
                        bool volumeOn, Preferences.GstreamerTypes gstreamer,
                        double progressbarLimit, ExecutingGraphData egd, string description,
                        bool avoidGraph, //on configChronojump.Exhibition do not show graph because it gets 
too slow with big database
-                       bool heightPreferred, int graphLimit, bool graphAllTypes, bool graphAllPersons
+                       bool heightPreferred, bool metersSecondsPreferred,
+                       int graphLimit, bool graphAllTypes, bool graphAllPersons,
+                       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.typeID = typeID;
                this.type = type;
                this.fall = fall; //-1 means has to be calculated with a previous jump
                this.weight = weight;
@@ -80,10 +91,14 @@ public class JumpExecute : EventExecute
                this.description = description;
                this.avoidGraph = avoidGraph;
                this.heightPreferred = heightPreferred;
+               this.metersSecondsPreferred = metersSecondsPreferred;
                this.graphLimit = graphLimit;
                this.graphAllTypes = graphAllTypes;
                this.graphAllPersons = graphAllPersons;
-       
+               this.upload = upload;
+               this.uploadStationId = uploadStationId;
+               this.django = django;
+
                if(TypeHasFall) {
                        hasFall = true;
                } else {
@@ -467,8 +482,7 @@ public class JumpExecute : EventExecute
                        feedbackMessage = Catalog.GetString(Constants.SimulatedMessage());
                else
                        feedbackMessage = "";
-               needShowFeedbackMessage = true; 
-               
+
                string table = Constants.JumpTable;
                string datetime = UtilDate.ToFile(DateTime.Now);
 
@@ -481,6 +495,28 @@ public class JumpExecute : EventExecute
                eventDone = new Jump(uniqueID, personID, sessionID, type, tv, tc, fall, 
                                weight, description, angle, Util.BoolToNegativeInt(simulated), datetime);
 
+               if(upload)
+               {
+                       UploadJumpSimpleDataObject uj = new UploadJumpSimpleDataObject (
+                                       uploadStationId, (Jump) eventDone, typeID, personWeight, 
metersSecondsPreferred);
+                       JsonCompujump js = new JsonCompujump (django);
+                       if( ! js.UploadJumpSimpleData (uj) )
+                       {
+                               LogB.Error (js.ResultMessage);
+
+                               /*
+                                  feedbackMessage will be shown on a DialogMessage to not being erased by 
updateGraphJumpsSimple -> event_execute_initializeVariables
+                                  the dialog cannot be called here to avoid gtk crash
+                                  */
+                               feedbackMessageOnDialog = true;
+                               feedbackMessage = js.ResultMessage;
+
+                               //since 2.1.3 do not store in Temp, if there are network errors, it is not 
going to be uploaded later, because wristbands can be re-assigned
+                               //SqliteJson.InsertTempSprint(false, usdo); //insert only if couldn't be 
uploaded
+                       }
+               }
+               needShowFeedbackMessage = true;
+
                if(! avoidGraph)
                {
                        if(graphAllTypes)
diff --git a/src/gui/app1/chronojump.cs b/src/gui/app1/chronojump.cs
index 2c2ee3de7..92ec1a39a 100644
--- a/src/gui/app1/chronojump.cs
+++ b/src/gui/app1/chronojump.cs
@@ -5196,14 +5196,17 @@ public partial class ChronoJumpWindow
                event_execute_ButtonCancel.Clicked += new EventHandler(on_cancel_clicked);
                event_execute_ButtonFinish.Clicked += new EventHandler(on_finish_clicked);
 
-               currentEventExecute = new JumpExecute(currentPerson.UniqueID, currentPerson.Name, 
-                               currentSession.UniqueID, currentJumpType.Name, myFall, jumpWeight,
+               currentEventExecute = new JumpExecute (
+                               currentPerson.UniqueID, currentPerson.Name, currentPersonSession.Weight,
+                               currentSession.UniqueID, currentJumpType.UniqueID, currentJumpType.Name, 
myFall, jumpWeight,
                                cp2016.CP, preferences.digitsNumber,
                                preferences.volumeOn, preferences.gstreamer,
                                progressbarLimit, egd, description, configChronojump.Exhibition,
-                               preferences.heightPreferred,
+                               preferences.heightPreferred, preferences.metersSecondsPreferred,
                                Convert.ToInt32(spin_contacts_graph_last_limit.Value),
-                               radio_contacts_graph_allTests.Active, radio_contacts_graph_allPersons.Active);
+                               radio_contacts_graph_allTests.Active, radio_contacts_graph_allPersons.Active,
+                               (configChronojump.Compujump && check_contacts_networks_upload.Active),
+                               configChronojump.CompujumpStationID, configChronojump.CompujumpDjango);
 
 
                //UtilGtk.ChronopicColors(viewport_chronopics, label_chronopics, label_connected_chronopics, 
chronopicWin.Connected);
diff --git a/src/gui/app1/jump.cs b/src/gui/app1/jump.cs
index 34c35bd9b..98e697a92 100644
--- a/src/gui/app1/jump.cs
+++ b/src/gui/app1/jump.cs
@@ -15,7 +15,7 @@
  *  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) 2004-2020   Xavier de Blas <xaviblas gmail com> 
+ * Copyright (C) 2004-2022   Xavier de Blas <xaviblas gmail com>
  */
 
 using System;
@@ -107,10 +107,13 @@ public partial class ChronoJumpWindow
        
        //creates and if is not predefined, checks database to gather all the data
        //simple == true  for simple jumps, and false for reactive
-       private JumpType createJumpType(string name, bool simple) {
+       private JumpType createJumpType(string name, bool simple)
+       {
                JumpType t = new JumpType(name);
-               
-               if(! t.IsPredefined) {
+
+               //on networks need the uniquedID, so we need to do the SQL selection
+               if(! t.IsPredefined || configChronojump.Compujump)
+               {
                        if(simple) {
                                t = SqliteJumpType.SelectAndReturnJumpType(name, false);
                                t.ImageFileName = SqliteEvent.GraphLinkSelectFileName(Constants.JumpTable, 
name);
@@ -119,6 +122,7 @@ public partial class ChronoJumpWindow
                                t.ImageFileName = SqliteEvent.GraphLinkSelectFileName(Constants.JumpRjTable, 
name);
                        }
                }
+
                return t;
        }
 
diff --git a/src/json/compujump.cs b/src/json/compujump.cs
index 2d05dcaee..3cae58ac3 100644
--- a/src/json/compujump.cs
+++ b/src/json/compujump.cs
@@ -407,6 +407,61 @@ public class JsonCompujump : Json
        }
        */
 
+       public bool UploadJumpSimpleData (UploadJumpSimpleDataObject o)
+       {
+               LogB.Information("calling upload jump simple");
+               // Create a request using a URL that can receive a post.
+               if (! createWebRequest(requestType.AUTHENTICATED, "/api/v1/client/uploadJump"))
+                       return false;
+
+               // Set the Method property of the request to POST.
+               request.Method = "POST";
+
+               // Creates the json object
+               // 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));
+               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);
+
+               // Writes the json object into the request dataStream
+               Stream dataStream;
+               if(! getWebRequestStream (request, out dataStream, "Could not upload jump simple data."))
+                       return false;
+
+               dataStream.Write (Encoding.UTF8.GetBytes(js), 0, js.Length);
+               dataStream.Close ();
+
+               // Get the response.
+               WebResponse response;
+               if(! getWebResponse (request, out response, "Could not upload jump simple data."))
+                       return false;
+
+               // Display the status (will be 202, CREATED)
+               Console.WriteLine (((HttpWebResponse)response).StatusDescription);
+
+               // Clean up the streams.
+               dataStream.Close ();
+               response.Close ();
+
+               this.ResultMessage = "Jump simple data sent.";
+               return true;
+       }
+
        public bool UploadSprintData (UploadSprintDataObject o)
        {
                LogB.Information("calling upload sprint");
diff --git a/src/json/compujumpJumps.cs b/src/json/compujumpJumps.cs
index 5fe0b094d..561015879 100644
--- a/src/json/compujumpJumps.cs
+++ b/src/json/compujumpJumps.cs
@@ -142,3 +142,48 @@ public class JsonCompujumpJumps : JsonCompujump
                }
        }
 }
+
+public class UploadJumpSimpleDataObject
+{
+       public int stationId;
+       public Jump jump;
+
+       private int exerciseId;
+
+       private double power;
+       private double stiffness;
+       private double initialSpeed;
+
+       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 string ExerciseIdStr
+       {
+               get { return exerciseId.ToString(); }
+       }
+       public string PowerStr
+       {
+               get { return Util.ConvertToPoint (power); }
+       }
+       public string StiffnessStr
+       {
+               get { return Util.ConvertToPoint (stiffness); }
+       }
+       public string InitialSpeedStr
+       {
+               get { return Util.ConvertToPoint (initialSpeed); }
+       }
+}
+


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