[chronojump] Race analyzer capture tab graphs with smoothing slider



commit 3351d92140ff17e3c860772b66676d53bd5bc2a6
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu May 5 20:21:44 2022 +0200

    Race analyzer capture tab graphs with smoothing slider

 glade/app1.glade              | 77 ++++++++++++++++++++++++++++++++++++-------
 src/gui/app1/runEncoder.cs    | 33 +++++++++++++++++--
 src/gui/cairo/raceAnalyzer.cs | 16 +++++++--
 src/gui/cairo/xy.cs           |  6 ++--
 src/utilMath.cs               |  5 +++
 5 files changed, 116 insertions(+), 21 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index 8aa74e7dc..a7388652a 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -7922,6 +7922,53 @@ device</property>
                                                             <property name="position">1</property>
                                                             </packing>
                                                             </child>
+                                                            <child>
+                                                            <widget class="GtkAlignment" id="alignment11">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="left_padding">30</property>
+                                                            <child>
+                                                            <widget class="GtkHBox" id="hbox150">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="spacing">6</property>
+                                                            <child>
+                                                            <widget class="GtkHScale" 
id="hscale_race_analyzer_capture_smooth_graphs">
+                                                            <property name="width_request">100</property>
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">True</property>
+                                                            <property name="adjustment">0 0 7 1 1 
0</property>
+                                                            <property name="round_digits">0</property>
+                                                            <property name="digits">0</property>
+                                                            <property name="draw_value">False</property>
+                                                            <signal name="value_changed" 
handler="on_hscale_race_analyzer_capture_smooth_graphs_value_changed" swapped="no"/>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">True</property>
+                                                            <property name="fill">True</property>
+                                                            <property name="position">0</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
+                                                            <widget class="GtkLabel" 
id="label_race_analyzer_capture_smooth_graphs">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">True</property>
+                                                            <property name="fill">True</property>
+                                                            <property name="position">1</property>
+                                                            </packing>
+                                                            </child>
+                                                            </widget>
+                                                            </child>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">True</property>
+                                                            <property name="fill">True</property>
+                                                            <property name="position">2</property>
+                                                            </packing>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
@@ -26362,6 +26409,9 @@ Concentric</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
@@ -32770,6 +32820,18 @@ 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>
@@ -32806,18 +32868,6 @@ 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>
@@ -42122,6 +42172,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/runEncoder.cs b/src/gui/app1/runEncoder.cs
index 6d2610e7e..35bc5ef9c 100644
--- a/src/gui/app1/runEncoder.cs
+++ b/src/gui/app1/runEncoder.cs
@@ -62,6 +62,8 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.DrawingArea drawingarea_race_analyzer_capture_speed_time;
        [Widget] Gtk.DrawingArea drawingarea_race_analyzer_capture_accel_time;
        [Widget] Gtk.VBox vbox_race_analyzer_capture_graphs;
+       [Widget] Gtk.HScale hscale_race_analyzer_capture_smooth_graphs;
+       [Widget] Gtk.Label label_race_analyzer_capture_smooth_graphs;
 
        [Widget] Gtk.Frame frame_run_encoder_exercise;
        [Widget] Gtk.Entry entry_run_encoder_exercise_name;
@@ -166,6 +168,7 @@ public partial class ChronoJumpWindow
                followSignals = true;
 
                manageRunEncoderCaptureViews();
+               label_race_analyzer_capture_smooth_graphs.Text = Catalog.GetString ("No smooth");
 
                createRunEncoderExerciseCombo();
                createRunEncoderAnalyzeCombos();
@@ -2260,7 +2263,8 @@ public partial class ChronoJumpWindow
 
                cairoGraphRaceAnalyzer_dt.DoSendingList (preferences.fontType.ToString(),
                                cairoGraphRaceAnalyzerPoints_dt_l, triggerListRunEncoder,
-                               forceRedraw, CairoXY.PlotTypes.LINES);
+                               forceRedraw, CairoXY.PlotTypes.LINES,
+                               getSmoothFrom_hscale_race_analyzer_capture_smooth_graphs ());
        }
        private void updateRaceAnalyzerCaptureSpeedTime(bool forceRedraw)
        {
@@ -2282,7 +2286,8 @@ public partial class ChronoJumpWindow
 
                cairoGraphRaceAnalyzer_st.DoSendingList (preferences.fontType.ToString(),
                                cairoGraphRaceAnalyzerPoints_st_l, triggerListRunEncoder,
-                               forceRedraw, CairoXY.PlotTypes.LINES);
+                               forceRedraw, CairoXY.PlotTypes.LINES,
+                               getSmoothFrom_hscale_race_analyzer_capture_smooth_graphs ());
        }
        private void updateRaceAnalyzerCaptureAccelTime(bool forceRedraw)
        {
@@ -2307,7 +2312,29 @@ public partial class ChronoJumpWindow
 
                cairoGraphRaceAnalyzer_at.DoSendingList (preferences.fontType.ToString(),
                                cairoGraphRaceAnalyzerPoints_at_l, triggerListRunEncoder,
-                               forceRedraw, CairoXY.PlotTypes.LINES);
+                               forceRedraw, CairoXY.PlotTypes.LINES,
+                               getSmoothFrom_hscale_race_analyzer_capture_smooth_graphs ());
+       }
+
+       private int getSmoothFrom_hscale_race_analyzer_capture_smooth_graphs ()
+       {
+               if(hscale_race_analyzer_capture_smooth_graphs.Value == 0)
+                       return 0;
+
+               //if 1,2,3,4,5,6,7  return 3,5,7,9,11,13,15
+               return Convert.ToInt32(hscale_race_analyzer_capture_smooth_graphs.Value)*2 +1;
+       }
+       private void on_hscale_race_analyzer_capture_smooth_graphs_value_changed (object o, EventArgs args)
+       {
+               int smooth = getSmoothFrom_hscale_race_analyzer_capture_smooth_graphs ();
+               if(smooth == 0)
+                       label_race_analyzer_capture_smooth_graphs.Text = Catalog.GetString ("No smooth");
+               else
+                       label_race_analyzer_capture_smooth_graphs.Text = smooth.ToString();
+
+               updateRaceAnalyzerCapturePositionTime(true);
+               updateRaceAnalyzerCaptureSpeedTime(true);
+               updateRaceAnalyzerCaptureAccelTime(true);
        }
 
        private void on_button_race_analyzer_capture_save_image_clicked (object o, EventArgs args)
diff --git a/src/gui/cairo/raceAnalyzer.cs b/src/gui/cairo/raceAnalyzer.cs
index 0003b8bff..31ee5526a 100644
--- a/src/gui/cairo/raceAnalyzer.cs
+++ b/src/gui/cairo/raceAnalyzer.cs
@@ -74,14 +74,14 @@ public class CairoGraphRaceAnalyzer : CairoXY
        }
 
        //separated in two methods to ensure endGraphDisposing on any return of the other method
-       public override void DoSendingList (string font, List<PointF> points_list, TriggerList triggerList, 
bool forceRedraw, PlotTypes plotType)
+       public void DoSendingList (string font, List<PointF> points_list, TriggerList triggerList, bool 
forceRedraw, PlotTypes plotType, int smoothLineWindow)
        {
-               if(doSendingList (font, points_list, triggerList, forceRedraw, plotType))
+               if(doSendingList (font, points_list, triggerList, forceRedraw, plotType, smoothLineWindow))
                        endGraphDisposing(g, surface, area.GdkWindow);
        }
 
        //return true if graph is inited (to dispose it)
-       private bool doSendingList (string font, List<PointF> points_list, TriggerList triggerList, bool 
forceRedraw, PlotTypes plotType)
+       private bool doSendingList (string font, List<PointF> points_list, TriggerList triggerList, bool 
forceRedraw, PlotTypes plotType, int smoothLineWindow)
        {
                bool maxValuesChanged = false;
                if(points_list != null)
@@ -172,6 +172,16 @@ public class CairoGraphRaceAnalyzer : CairoXY
                        plotRealPoints(plotType, points_list, points_list_painted, false); //not fast. TODO: 
maybe use fast if is really faster
                        points_list_painted = points_list.Count;
 
+                       if(smoothLineWindow > 0 && points_list.Count > 5)
+                       {
+                               MovingAverage mAverageSmoothLine = new MovingAverage (points_list, 
smoothLineWindow);
+                               mAverageSmoothLine.Calculate ();
+                               g.SetSourceColor (bluePlots);
+                               plotRealPoints(plotType, mAverageSmoothLine.MovingAverage_l, 0, false); //not 
fast. TODO: maybe use fast if is really faster
+                               g.SetSourceRGB (0,0,0);
+                       }
+
+
                        if(plotMaxMark && points_list.Count > 1)
                        {
                                if(isSprint) //on sprint plot an arrow from top speed (with moving average) 
to the right
diff --git a/src/gui/cairo/xy.cs b/src/gui/cairo/xy.cs
index 7de43f1e2..fe154a185 100644
--- a/src/gui/cairo/xy.cs
+++ b/src/gui/cairo/xy.cs
@@ -119,9 +119,9 @@ public abstract class CairoXY : CairoGeneric
        }
 
        //raceAnalyzer XY graphs (triggers)
-       public virtual void DoSendingList(string font, List<PointF> points_list, TriggerList triggerList, 
bool forceRedraw, PlotTypes plotType)
-       {
-       }
+//     public virtual void DoSendingList(string font, List<PointF> points_list, TriggerList triggerList, 
bool forceRedraw, PlotTypes plotType)
+//     {
+//     }
 
        protected void initGraph(string font, double widthPercent1)
        {
diff --git a/src/utilMath.cs b/src/utilMath.cs
index 64eb79a8a..a98c49b0c 100644
--- a/src/utilMath.cs
+++ b/src/utilMath.cs
@@ -523,6 +523,11 @@ public class MovingAverage
 
                //tested with LibreOffice Calc, works as expected
        }
+
+       //the smoothed list
+       public List<PointF> MovingAverage_l {
+               get { return movingAverage_l; }
+       }
 }
 
 public static class MathCJ


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