[chronojump] Cairo graph races/datetime manages distances on not fixed tests



commit 67bb95052263ac9234957de6fa71383b9eba93d0
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Apr 30 11:50:03 2021 +0200

    Cairo graph races/datetime manages distances on not fixed tests

 glade/app1.glade                   | 44 +++++++++++++++------
 src/gui/app1/chronojump.cs         |  7 ++--
 src/gui/app1/jumpsRunsEvolution.cs | 78 +++++++++++++++++++++++++++++++++++---
 src/jumpsRunsEvolution.cs          | 24 +++++++++++-
 4 files changed, 132 insertions(+), 21 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index 53147410..9123cea8 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -21436,6 +21436,20 @@ Concentric</property>
                                                             <property name="position">1</property>
                                                             </packing>
                                                             </child>
+                                                            <child>
+                                                            <widget class="GtkHBox" 
id="hbox_combo_select_runs_evolution_distance">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="position">2</property>
+                                                            </packing>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
@@ -25339,6 +25353,9 @@ Concentric</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
@@ -31506,18 +31523,6 @@ Concentric</property>
                                                             <property name="can_focus">False</property>
                                                             <property name="spacing">6</property>
                                                             <child>
-                                                            <widget class="GtkLabel" 
id="label_video_encoder_tests_will_be_filmed">
-                                                            <property name="can_focus">False</property>
-                                                            <property name="label" translatable="yes">Tests 
will be filmed</property>
-                                                            </widget>
-                                                            <packing>
-                                                            <property name="expand">False</property>
-                                                            <property name="fill">False</property>
-                                                            <property name="pack_type">end</property>
-                                                            <property name="position">0</property>
-                                                            </packing>
-                                                            </child>
-                                                            <child>
                                                             <widget class="GtkHBox" 
id="hbox_video_encoder_capturing">
                                                             <property name="can_focus">False</property>
                                                             <property name="spacing">4</property>
@@ -31554,6 +31559,18 @@ Concentric</property>
                                                             </packing>
                                                             </child>
                                                             <child>
+                                                            <widget class="GtkLabel" 
id="label_video_encoder_tests_will_be_filmed">
+                                                            <property name="can_focus">False</property>
+                                                            <property name="label" translatable="yes">Tests 
will be filmed</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="pack_type">end</property>
+                                                            <property name="position">0</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
                                                             <widget class="GtkHBox" 
id="hbox_video_encoder_no_capturing">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
@@ -40594,6 +40611,9 @@ then click this button.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
diff --git a/src/gui/app1/chronojump.cs b/src/gui/app1/chronojump.cs
index c9fe22e9..bd0863aa 100644
--- a/src/gui/app1/chronojump.cs
+++ b/src/gui/app1/chronojump.cs
@@ -652,6 +652,7 @@ public partial class ChronoJumpWindow
                combo_jumps_rj_fatigue_divide_in.Active = 0;
                createComboSelectRuns(true);
                createComboSelectRunsEvolution(true);
+               createComboSelectRunsEvolutionDistance();
                createComboSelectRunsInterval(true);
                
                createComboResultJumps();
@@ -1308,7 +1309,7 @@ public partial class ChronoJumpWindow
                        updateGraphRunsSimple();
 
                        if(notebook_analyze.CurrentPage == 
Convert.ToInt32(notebook_analyze_pages.RUNSEVOLUTION))
-                               runsEvolutionDo(true); //calculate data
+                               runsEvolutionDo(true, true); //calculate data
                }
                else if(current_menuitem_mode == Constants.Menuitem_modes.RUNSINTERVALLIC)
                {
@@ -7466,7 +7467,7 @@ LogB.Debug("mc finished 5");
                                if(radio_mode_contacts_runs_evolution.Active)
                                {
                                        notebook_analyze.CurrentPage = 
Convert.ToInt32(notebook_analyze_pages.RUNSEVOLUTION);
-                                       runsEvolutionDo(true);
+                                       runsEvolutionDo(true, true);
                                }
                        }
                }
@@ -7530,7 +7531,7 @@ LogB.Debug("mc finished 5");
                if(radio_mode_contacts_runs_evolution.Active)
                {
                        notebook_analyze.CurrentPage = Convert.ToInt32(notebook_analyze_pages.RUNSEVOLUTION);
-                       runsEvolutionDo(true);
+                       runsEvolutionDo(true, true);
                }
        }
        private void on_radio_mode_contacts_sprint_toggled (object o, EventArgs args)
diff --git a/src/gui/app1/jumpsRunsEvolution.cs b/src/gui/app1/jumpsRunsEvolution.cs
index c94daa55..49be013f 100644
--- a/src/gui/app1/jumpsRunsEvolution.cs
+++ b/src/gui/app1/jumpsRunsEvolution.cs
@@ -175,6 +175,8 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.Image image_runs_evolution_analyze_image_save;
        [Widget] Gtk.HBox hbox_combo_select_runs_evolution;
        [Widget] Gtk.ComboBox combo_select_runs_evolution;
+       [Widget] Gtk.HBox hbox_combo_select_runs_evolution_distance;
+       [Widget] Gtk.ComboBox combo_select_runs_evolution_distance;
        [Widget] Gtk.Button button_runs_evolution_save_image;
        [Widget] Gtk.CheckButton check_runs_evolution_only_best_in_session;
        [Widget] Gtk.CheckButton check_runs_evolution_show_time;
@@ -203,37 +205,72 @@ public partial class ChronoJumpWindow
                if (o == null)
                        return;
 
-               runsEvolutionDo(true);
+               runsEvolutionDo(true, true);
+       }
+       // combo (end)
+
+       // combo (start)
+       private bool combo_select_runs_evolution_distance_follow_signals;
+       private void createComboSelectRunsEvolutionDistance()
+       {
+               combo_select_runs_evolution_distance = ComboBox.NewText();
+               //UtilGtk.ComboUpdate (combo_select_runs_evolution_distance, Catalog.GetString("All"));
+               //combo_select_runs_evolution_distance.Active = 0;
+               hbox_combo_select_runs_evolution_distance.PackStart(combo_select_runs_evolution_distance, 
true, true, 0);
+
+               combo_select_runs_evolution_distance_follow_signals = false;
+               combo_select_runs_evolution_distance.Changed += new EventHandler 
(on_combo_select_runs_evolution_distance_changed);
+               combo_select_runs_evolution_distance_follow_signals = true;
+
+               combo_select_runs_evolution_distance.Sensitive = true;
+               combo_select_runs_evolution_distance.Visible = true;
+               hbox_combo_select_runs_evolution_distance.Visible = true;
+       }
+       private void on_combo_select_runs_evolution_distance_changed(object o, EventArgs args)
+       {
+               if(! combo_select_runs_evolution_distance_follow_signals)
+                       return;
+
+               ComboBox combo = o as ComboBox;
+               if (o == null)
+                       return;
+
+               runsEvolutionDo(false, true);
        }
        // combo (end)
 
        private void on_check_runs_evolution_only_best_in_session_clicked (object o, EventArgs args)
        {
-               runsEvolutionDo(true);
+               runsEvolutionDo(false, true);
 
                SqlitePreferences.Update(SqlitePreferences.RunsEvolutionOnlyBestInSession,
                                check_runs_evolution_only_best_in_session.Active, false);
        }
        private void on_check_runs_evolution_show_time_clicked (object o, EventArgs args)
        {
-               runsEvolutionDo(true);
+               runsEvolutionDo(false, true);
 
                SqlitePreferences.Update(SqlitePreferences.RunsEvolutionShowTime,
                                check_runs_evolution_show_time.Active, false);
        }
 
-       private void runsEvolutionDo (bool calculateData)
+       //if exerciseChanged, distances can change
+       private void runsEvolutionDo (bool exerciseChanged, bool calculateData)
        {
+               LogB.Information("runsEvolutionDo, calculateData: " + calculateData.ToString());
                if(currentPerson == null || currentSession == null ||
                                drawingarea_runs_evolution == null || drawingarea_runs_evolution.GdkWindow == 
null) //it happens at start on click on analyze
                {
                        button_runs_evolution_save_image.Sensitive = false;
+                       LogB.Information("runsEvolutionDo: exit early");
                        return;
                }
 
+               bool runsEvolutionJustCreated = false;
                if(runsEvolution == null) {
                        runsEvolution = new RunsEvolution();
                        calculateData = true;
+                       runsEvolutionJustCreated = true;
                }
 
                string runType = comboSelectRunsEvolution.GetSelectedNameEnglish();
@@ -241,7 +278,37 @@ public partial class ChronoJumpWindow
                if(calculateData)
                {
                        runsEvolution.PassParameters(check_runs_evolution_show_time.Active, 
preferences.metersSecondsPreferred);
+
+                       // 1 get distance on the combo
+                       double distanceAtCombo = -1;
+                       if(exerciseChanged)
+                               distanceAtCombo = -1; //changing exercise will always select ----
+                       else if(combo_select_runs_evolution_distance != null && 
Util.IsNumber(UtilGtk.ComboGetActive(combo_select_runs_evolution_distance), true))
+                               distanceAtCombo = 
Convert.ToDouble(UtilGtk.ComboGetActive(combo_select_runs_evolution_distance));
+
+                       // 2 calculate (using distance)
+                       runsEvolution.distanceAtCombo = distanceAtCombo;
                        runsEvolution.Calculate(currentPerson.UniqueID, runType, 
check_runs_evolution_only_best_in_session.Active);
+
+                       // 3 modify the distances combo, but only if exercise change or on creation of 
runsEvolution (first expose_event)
+                       if(exerciseChanged || runsEvolutionJustCreated)
+                       {
+                               if(runsEvolution.distance_l.Count > 0)
+                               {
+                                       if(runsEvolution.distance_l.Count > 1)
+                                               runsEvolution.distance_l.Insert(0, "----");
+
+                                       combo_select_runs_evolution_distance_follow_signals = false;
+
+                                       UtilGtk.ComboUpdate(combo_select_runs_evolution_distance, 
runsEvolution.distance_l);
+
+                                       combo_select_runs_evolution_distance.Active = 0;
+                                       combo_select_runs_evolution_distance.Visible = true;
+
+                                       combo_select_runs_evolution_distance_follow_signals = true;
+                               } else
+                                       combo_select_runs_evolution_distance.Visible = false;
+                       }
                }
 
                if(runsEvolution.Point_l.Count == 0)
@@ -265,6 +332,7 @@ public partial class ChronoJumpWindow
 
                        button_runs_evolution_save_image.Sensitive = true;
                }
+               LogB.Information("runsEvolutionDo: ended!");
        }
        private void on_drawingarea_runs_evolution_expose_event (object o, ExposeEventArgs args)
        {
@@ -272,7 +340,7 @@ public partial class ChronoJumpWindow
 //             drawingarea_runs_evolution.AddEvents((int) (Gdk.EventMask.ButtonPressMask | 
Gdk.EventMask.ButtonReleaseMask));
                drawingarea_runs_evolution.AddEvents((int) Gdk.EventMask.ButtonPressMask);
 
-               runsEvolutionDo(false); //do not calculate data
+               runsEvolutionDo(false, false); //do not calculate data
                //data is calculated on switch page (at notebook_capture_analyze) or on change person
        }
 
diff --git a/src/jumpsRunsEvolution.cs b/src/jumpsRunsEvolution.cs
index 3169b65f..7d971732 100644
--- a/src/jumpsRunsEvolution.cs
+++ b/src/jumpsRunsEvolution.cs
@@ -108,6 +108,8 @@ public class RunsEvolution : JumpsRunsEvolution
 {
        private bool showTime;
        private bool metersSecondsPreferred;
+       public List<string> distance_l; //distances of selected runType
+       public double distanceAtCombo;
 
        //constructor
        public RunsEvolution()
@@ -126,12 +128,31 @@ public class RunsEvolution : JumpsRunsEvolution
                 List<Run> run_l = SqliteRun.SelectRuns (false, -1, personID, runType,
                                Sqlite.Orders_by.DEFAULT, -1, false, onlyBestInSession);
 
-               //2 convert to list of PointF
+               //2 convert to list of PointF, and also create distance_l
                point_l = new List<PointF>();
+               distance_l = new List<string>();
                int currentSession = -1;
                 foreach(Run r in run_l)
                {
+                       // 1 if a distance is selected and this run does not match, continue
+                       if(distanceAtCombo > 0 && r.Distance != distanceAtCombo)
+                               continue;
+
+                       // 2 if not done previously, save the distance for distance_l
+                       bool found = false;
+                       foreach(string dStr in distance_l)
+                               if(dStr == Util.TrimDecimals(r.Distance, 1))
+                               {
+                                       found = true;
+                                       break;
+                               }
+                       if(! found)
+                       {
+                               distance_l.Add(Util.TrimDecimals(r.Distance, 1));
+                               //LogB.Information("Added distance: " + r.Distance);
+                       }
 
+                       // 3 if only best, only show the best (first one of each session, also according 
previous to distance)
                        if(onlyBestInSession)
                        {
                                //at onlyBestInSession they return ordered by sessionID, 
run.distance/run.time DESC
@@ -141,6 +162,7 @@ public class RunsEvolution : JumpsRunsEvolution
                                        currentSession = r.SessionID;
                        }
 
+                       // 4 store the point at point_l
                        DateTime dt = UtilDate.FromFile(r.Datetime);
                        double dtDouble = UtilDate.DateTimeYearDayAsDouble(dt);
 


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