[chronojump/michrolab] Missing on last commit



commit dd88549ed539c050b72130eb895ac24077e531a1
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Sep 23 20:41:10 2022 +0200

    Missing on last commit

 src/gui/app1/jumpsAsymmetry.cs     | 238 +++++++++++++++++++++++++++++++++++++
 src/gui/app1/jumpsRunsEvolution.cs |   2 +
 src/jumpsAsymmetry.cs              | 204 +++++++++++++++++++++++++++++++
 3 files changed, 444 insertions(+)
---
diff --git a/src/gui/app1/jumpsAsymmetry.cs b/src/gui/app1/jumpsAsymmetry.cs
new file mode 100644
index 000000000..c62938271
--- /dev/null
+++ b/src/gui/app1/jumpsAsymmetry.cs
@@ -0,0 +1,238 @@
+/*
+ * 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) 2022   Xavier de Blas <xaviblas gmail com> 
+ */
+
+
+using System;
+using System.Collections.Generic; //List
+using Gtk;
+using Glade;
+
+public partial class ChronoJumpWindow 
+{
+       [Widget] Gtk.DrawingArea drawingarea_jumps_asymmetry;
+       [Widget] Gtk.Image image_tab_jumps_asymmetry;
+       [Widget] Gtk.Image image_jumps_asymmetry_save;
+       [Widget] Gtk.Button button_jumps_asymmetry_save_image;
+
+       [Widget] Gtk.RadioButton radio_jumps_asymmetry_bilateral;
+       [Widget] Gtk.RadioButton radio_jumps_asymmetry_asymmetry;
+
+       [Widget] Gtk.HBox hbox_combo_select_jumps_asymmetry_bilateral;
+       [Widget] Gtk.ComboBox combo_select_jumps_asymmetry_bilateral;
+       [Widget] Gtk.HBox hbox_combo_select_jumps_asymmetry_1;
+       [Widget] Gtk.ComboBox combo_select_jumps_asymmetry_1;
+       [Widget] Gtk.HBox hbox_combo_select_jumps_asymmetry_2;
+       [Widget] Gtk.ComboBox combo_select_jumps_asymmetry_2;
+       [Widget] Gtk.Label label_jumps_asymmetry_bilateral;
+
+       //TODO: need max/avg controls
+
+       JumpsAsymmetry jumpsAsymmetry;
+       CjComboSelectJumps comboSelectJumpsAsymmetryBilateral;
+       CjComboSelectJumps comboSelectJumpsAsymmetry1;
+       CjComboSelectJumps comboSelectJumpsAsymmetry2;
+
+       private void createComboSelectJumpsAsymmetry (bool create)
+       {
+               if(create)
+               {
+                       comboSelectJumpsAsymmetryBilateral = new CjComboSelectJumps 
(combo_select_jumps_asymmetry_bilateral, hbox_combo_select_jumps_asymmetry_bilateral, false);
+                       combo_select_jumps_asymmetry_bilateral = comboSelectJumpsAsymmetryBilateral.Combo;
+                       combo_select_jumps_asymmetry_bilateral.Active = UtilGtk.ComboMakeActive 
(combo_select_jumps_asymmetry_bilateral, "CMJ");
+                       combo_select_jumps_asymmetry_bilateral.Changed += new EventHandler 
(on_combo_select_jumps_asymmetry_bilateral_changed);
+
+                       comboSelectJumpsAsymmetry1 = new CjComboSelectJumps (combo_select_jumps_asymmetry_1, 
hbox_combo_select_jumps_asymmetry_1, false);
+                       combo_select_jumps_asymmetry_1 = comboSelectJumpsAsymmetry1.Combo;
+                       combo_select_jumps_asymmetry_1.Active = UtilGtk.ComboMakeActive 
(combo_select_jumps_asymmetry_1, "slCMJleft");
+                       combo_select_jumps_asymmetry_1.Changed += new EventHandler 
(on_combo_select_jumps_asymmetry_1_changed);
+
+                       comboSelectJumpsAsymmetry2 = new CjComboSelectJumps (combo_select_jumps_asymmetry_2, 
hbox_combo_select_jumps_asymmetry_2, false);
+                       combo_select_jumps_asymmetry_2 = comboSelectJumpsAsymmetry2.Combo;
+                       combo_select_jumps_asymmetry_2.Active = UtilGtk.ComboMakeActive 
(combo_select_jumps_asymmetry_2, "slCMJright");
+                       combo_select_jumps_asymmetry_2.Changed += new EventHandler 
(on_combo_select_jumps_asymmetry_2_changed);
+               } else {
+                       comboSelectJumpsAsymmetryBilateral.Fill();
+                       comboSelectJumpsAsymmetry1.Fill();
+                       comboSelectJumpsAsymmetry2.Fill();
+
+                       combo_select_jumps_asymmetry_bilateral = comboSelectJumpsAsymmetryBilateral.Combo;
+                       combo_select_jumps_asymmetry_1 = comboSelectJumpsAsymmetry1.Combo;
+                       combo_select_jumps_asymmetry_2 = comboSelectJumpsAsymmetry2.Combo;
+               }
+
+               combo_select_jumps_asymmetry_bilateral.Sensitive = true;
+               combo_select_jumps_asymmetry_1.Sensitive = true;
+               combo_select_jumps_asymmetry_2.Sensitive = true;
+       }
+
+       private void on_radio_jumps_asymmetry_bilateral_toggled (object o, EventArgs args)
+       {
+               combo_select_jumps_asymmetry_bilateral.Visible = true;
+               label_jumps_asymmetry_bilateral.Visible = true;
+
+               jumpsAsymmetryDo (true);
+       }
+       private void on_radio_jumps_asymmetry_asymmetry_toggled (object o, EventArgs args)
+       {
+               combo_select_jumps_asymmetry_bilateral.Visible = false;
+               label_jumps_asymmetry_bilateral.Visible = false;
+
+               jumpsAsymmetryDo (true);
+       }
+
+       private void on_combo_select_jumps_asymmetry_bilateral_changed (object o, EventArgs args)
+       {
+               jumpsAsymmetryDo (true);
+       }
+       private void on_combo_select_jumps_asymmetry_1_changed (object o, EventArgs args)
+       {
+               jumpsAsymmetryDo (true);
+       }
+       private void on_combo_select_jumps_asymmetry_2_changed (object o, EventArgs args)
+       {
+               jumpsAsymmetryDo (true);
+       }
+
+       JumpsAsymmetryGraph jumpsAsymmetryGraph;
+
+       private void jumpsAsymmetryDo (bool calculateData)
+       {
+               button_jumps_asymmetry_save_image.Sensitive = false;
+
+               if (currentPerson == null || currentSession == null ||
+                               drawingarea_jumps_asymmetry == null || drawingarea_jumps_asymmetry.GdkWindow 
== null) //it happens at start on click on analyze
+               {
+                       button_jumps_asymmetry_save_image.Sensitive = false;
+                       return;
+               }
+
+               if (jumpsAsymmetry == null) {
+                       jumpsAsymmetry = new JumpsAsymmetry();
+                       calculateData = true;
+               }
+
+               if(calculateData)
+                       jumpsAsymmetry.Calculate (
+                                       currentPerson.UniqueID, currentSession.UniqueID,
+                                       radio_jumps_asymmetry_bilateral.Active,
+                                       //TODO: max/avg
+                                       UtilGtk.ComboGetActive (combo_select_jumps_asymmetry_bilateral),
+                                       UtilGtk.ComboGetActive (combo_select_jumps_asymmetry_1),
+                                       UtilGtk.ComboGetActive (combo_select_jumps_asymmetry_2)
+                                       );
+
+               bool bars = false;
+               if (jumpsAsymmetry.Jad_l.Count == 0)
+               {
+                       if (bars) {
+                               //constructor for showing blank screen with a message
+                               CairoBars cb = new CairoBars1Series (drawingarea_jumps_asymmetry, 
CairoBars.Type.NORMAL, preferences.fontType.ToString(), "Need more data"); //TODO: change message
+                       } else {
+                               new JumpsAsymmetryGraph (drawingarea_jumps_asymmetry, 
+                                               //JumpsEvolutionGraph.Error.NEEDJUMP,
+                                               "el meu salt", preferences.fontType.ToString());
+                       }
+
+                       button_jumps_asymmetry_save_image.Sensitive = false;
+                       return;
+               } else {
+                       if (bars) {
+                               CairoBars cb = new CairoBars1Series (drawingarea_jumps_asymmetry, 
CairoBars.Type.NORMAL, false, true, false);
+                               cb.GraphInit (preferences.fontType.ToString (), false, false);
+
+                               List<PointF> point_l = new List<PointF>();
+                               List<string> names_l = new List<string>();
+                               int count = 1; //TODO: or 0 or start at max and go backwards?
+                               foreach (JumpsAsymmetryDay jad in jumpsAsymmetry.Jad_l)
+                               {
+                                       point_l.Add (new PointF (count ++, jad.GetIndex ()));
+                                       names_l.Add (count.ToString ());
+                               }
+
+                               cb.PassData1Serie (point_l,
+                                               new List<Cairo.Color>(), names_l,
+                                               -1, 14, 10, "hola");
+                               cb.GraphDo();
+                       } else {
+                               //regular constructor
+                               jumpsAsymmetryGraph = new JumpsAsymmetryGraph (
+                                               jumpsAsymmetry.Point_l,
+                                               jumpsAsymmetry.Dates_l,
+                                               0,
+                                               0,
+                                               drawingarea_jumps_asymmetry, "title",
+                                               "el meu salt", currentSession.DateShort, false, true);
+                               jumpsAsymmetryGraph.Do (preferences.fontType.ToString());
+                       }
+
+                       button_jumps_asymmetry_save_image.Sensitive = true;
+               }
+       }
+
+
+       private void on_drawingarea_jumps_asymmetry_button_press_event (object o, ButtonPressEventArgs args)
+       {
+               //if there is no data and nothing to show, nothing to press, and also this is null
+               // without jumpsAsymmetry.Point_l.Count == 0 condition, it will show graph/data on mouse 
(with data of previous person/graph)
+               if(jumpsAsymmetryGraph == null || jumpsAsymmetry.Point_l.Count == 0)
+                       return;
+
+               LogB.Information("Button press done!");
+
+               //redo the graph to delete previous rectangles of previous mouse clicks
+               jumpsAsymmetryGraph.PassMouseXY (args.Event.X, args.Event.Y);
+               jumpsAsymmetryGraph.Do (preferences.fontType.ToString());
+       }
+       private void on_drawingarea_jumps_asymmetry_expose_event (object o, ExposeEventArgs args)
+       {
+               jumpsAsymmetryDo (false); //do not calculate data
+               //data is calculated on switch page (at notebook_capture_analyze) or on change person
+       }
+
+
+       /*
+       private void on_button_jumps_profile_save_image_clicked (object o, EventArgs args)
+       {
+               checkFile(Constants.CheckFileOp.JUMPS_PROFILE_SAVE_IMAGE);
+       }
+
+       private void on_button_jumps_profile_save_image_selected (string destination)
+       {
+               if(drawingarea_jumps_profile == null)
+                       return;
+
+               Gdk.Pixbuf pixbuf = Gdk.Pixbuf.FromDrawable(drawingarea_jumps_profile.GdkWindow, 
Gdk.Colormap.System,
+                               0, 0, 0, 0,
+                               UtilGtk.WidgetWidth(drawingarea_jumps_profile),
+                               UtilGtk.WidgetHeight(drawingarea_jumps_profile) );
+
+               LogB.Information("Saving");
+               pixbuf.Save(destination,"png");
+       }
+       private void on_overwrite_file_jumps_profile_save_image_accepted (object o, EventArgs args)
+       {
+               on_button_jumps_profile_save_image_selected (exportFileName);
+
+               string myString = string.Format(Catalog.GetString("Saved to {0}"), exportFileName);
+               new DialogMessage(Constants.MessageTypes.INFO, myString);
+       }
+       */
+
+}
diff --git a/src/gui/app1/jumpsRunsEvolution.cs b/src/gui/app1/jumpsRunsEvolution.cs
index 52566d9f8..7021d4ba9 100644
--- a/src/gui/app1/jumpsRunsEvolution.cs
+++ b/src/gui/app1/jumpsRunsEvolution.cs
@@ -121,6 +121,7 @@ public partial class ChronoJumpWindow
                        //regular constructor
                        jumpsEvolutionGraph = new JumpsEvolutionGraph(
                                        jumpsEvolution.Point_l,
+                                       jumpsEvolution.Dates_l,
                                        jumpsEvolution.Slope,
                                        jumpsEvolution.Intercept,
                                        drawingarea_jumps_evolution,
@@ -334,6 +335,7 @@ public partial class ChronoJumpWindow
                        //regular constructor
                        runsEvolutionGraph = new RunsEvolutionGraph(
                                        runsEvolution.Point_l,
+                                       runsEvolution.Dates_l,
                                        runsEvolution.Slope,
                                        runsEvolution.Intercept,
                                        drawingarea_runs_evolution,
diff --git a/src/jumpsAsymmetry.cs b/src/jumpsAsymmetry.cs
new file mode 100644
index 000000000..ce440e96f
--- /dev/null
+++ b/src/jumpsAsymmetry.cs
@@ -0,0 +1,204 @@
+/*
+ * 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) 2022   Xavier de Blas <xaviblas gmail com>
+ */
+
+using System;
+using System.Collections.Generic; //List
+
+public class JumpsAsymmetry
+{
+       private List<JumpsAsymmetryDay> jad_l;
+       private List<PointF> point_l; //to cairo points graph
+       protected List<DateTime> dates_l; //used on button press to know day date instead of date as double
+
+       //constructor
+       public JumpsAsymmetry ()
+       {
+       }
+       
+       public void Calculate (int personID, int sessionID, bool bilateral, //TODO: max,avg
+                       string jumpBilateralStr, string j1Str, string j2Str)
+       {
+               List<string> jumpTypes_l = new List<string> ();
+               if (bilateral)
+                       jumpTypes_l.Add (jumpBilateralStr);
+               jumpTypes_l.Add (j1Str);
+               jumpTypes_l.Add (j2Str);
+
+               //1 get data
+                List<SqliteStruct.DateTypeResult> sdtr_l = SqliteJump.SelectJumpsStatsByDay (personID, 
jumpTypes_l, Sqlite.StatType.MAX);
+
+               point_l = new List<PointF> ();
+               dates_l = new List<DateTime> ();
+               jad_l = new List<JumpsAsymmetryDay> ();
+               JumpsAsymmetryDay jad = new JumpsAsymmetryDay (bilateral);
+               string currentDate = "";
+               bool jadAdded = false; //to know if at end of bucle we need to check for completion
+
+               foreach (SqliteStruct.DateTypeResult sdtr in sdtr_l)
+               {
+                       LogB.Information (string.Format ("-MMMM {0} {1} {2}", sdtr.date, sdtr.type, 
sdtr.result));
+
+                       if (sdtr.date != currentDate)
+                       {
+                               if (jad.Complete ())
+                               {
+                                       jad.AddDate (currentDate);
+                                       jad_l.Add (jad);
+                                       //LogB.Information ("currentDate: " + currentDate);
+
+                                       //add time to be able to graph
+                                       DateTime dt = UtilDate.FromFile (currentDate + "_00-00-01");
+                                       double dtDouble = UtilDate.DateTimeYearDayAsDouble (dt);
+                                       point_l.Add (new PointF(dtDouble, jad.GetIndex ()));
+                                       dates_l.Add (dt);
+                               }
+
+                               //If new new date, create a new jad, even if previous was complete or not
+                               jad = new JumpsAsymmetryDay (bilateral);
+                       }
+
+                       if (bilateral && sdtr.type == jumpBilateralStr)
+                               jad.AddBilateral (sdtr.type, sdtr.result);
+                       else if (sdtr.type == j1Str)
+                               jad.AddAsymmetry1 (sdtr.type, sdtr.result);
+                       else if (sdtr.type == j2Str)
+                               jad.AddAsymmetry2 (sdtr.type, sdtr.result);
+
+                       currentDate = sdtr.date;
+               }
+               
+               if (jad.Complete ())
+               {
+                       jad.AddDate (currentDate);
+                       jad_l.Add (jad);
+
+                       //add time to be able to graph
+                       DateTime dt = UtilDate.FromFile (currentDate + "_00-00-01");
+                       double dtDouble = UtilDate.DateTimeYearDayAsDouble (dt);
+                       point_l.Add (new PointF(dtDouble, jad.GetIndex ()));
+                       dates_l.Add (dt);
+               }
+
+               /* debug
+               LogB.Information ("jads: " + jad_l.Count.ToString ());
+               foreach (JumpsAsymmetryDay jadDebug in jad_l)
+                       LogB.Information (jadDebug.ToString ());
+                       */
+       }
+
+       public List<JumpsAsymmetryDay> Jad_l
+       {
+               get { return jad_l; }
+       }
+       public List<PointF> Point_l
+       {
+               get { return point_l; }
+       }
+       public List<DateTime> Dates_l
+       {
+               get { return dates_l; }
+       }
+
+}
+       
+public class JumpsAsymmetryDay
+{
+       private bool bilateral;
+
+       public string date;
+       public string bilateralType;
+       public double bilateralResult;
+       public string asymmetry1Type;
+       public double asymmetry1Result;
+       public string asymmetry2Type;
+       public double asymmetry2Result;
+
+       public JumpsAsymmetryDay (bool bilateral)
+       {
+               this.bilateral = bilateral;
+
+               date = "";
+               bilateralType = "";
+               asymmetry1Type = "";
+               asymmetry2Type = "";
+       }
+
+       public void AddBilateral (string type, double result)
+       {
+               bilateralType = type;
+               bilateralResult = result;
+       }
+
+       public void AddAsymmetry1 (string type, double result)
+       {
+               asymmetry1Type = type;
+               asymmetry1Result = result;
+       }
+
+       public void AddAsymmetry2 (string type, double result)
+       {
+               asymmetry2Type = type;
+               asymmetry2Result = result;
+       }
+
+       public void AddDate (string date)
+       {
+               this.date = date;
+       }
+
+       public bool Complete ()
+       {
+               //LogB.Information (string.Format ("complete? bilateral: {0}, bilateral ({1}): {2}, a1: 
({3}): {4}, a2: ({5}): {6}", 
+               //              bilateral, bilateralType, bilateralResult, asymmetry1Type, asymmetry1Result, 
asymmetry2Type, asymmetry2Result));
+
+               if (bilateral && bilateralType != "" && asymmetry1Type != "" && asymmetry2Type != "")
+                       return true;
+               else if (! bilateral && asymmetry1Type != "" && asymmetry2Type != "")
+                       return true;
+
+               return false;
+       }
+       
+       //TODO: flight time or heights?
+       public double GetIndex ()
+       {
+               if (bilateral) {
+                       //CMJ-(slcmjR+slcmjL)
+                       return bilateralResult - (asymmetry1Result + asymmetry2Result);
+               } else {
+                       //100*(tfG-tfB)/tfG (being tfG the flight time of the "good" leg, and tfB of the 
"bad" leg). Good and bad will be related to the results of each day.
+                       double good = asymmetry1Result;
+                       double bad = asymmetry2Result;
+                       if (bad > good)
+                       {
+                               good = asymmetry2Result;
+                               bad = asymmetry1Result;
+                       }
+                       return 100.0 * UtilAll.DivideSafe (good-bad, good);
+               }
+       }
+
+       //debug
+       public override string ToString ()
+       {
+               return string.Format ("bilateral ({0}): {1}, a1: ({2}): {3}, a2: ({4}): {5}", 
+                               bilateralType, bilateralResult, asymmetry1Type, asymmetry1Result, 
asymmetry2Type, asymmetry2Result);
+       }
+}


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