[chronojump] RaceAnalyzer capture graphs use new class RunEncoderSegmentCalcs instead of TwoListsOfDoubles Segmen



commit dab1368f6e477ccf777f7df7279c2350f525f1ac
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon May 9 11:56:53 2022 +0200

    RaceAnalyzer capture graphs use new class RunEncoderSegmentCalcs instead of TwoListsOfDoubles 
SegmentDistTime_2l
    this will allow a,F,P

 src/gui/app1/runEncoder.cs    | 24 +++++++++----------
 src/gui/cairo/raceAnalyzer.cs | 33 +++++++++++++++----------
 src/runEncoder.cs             | 56 +++++++++++++++++++++++++++++++++++--------
 3 files changed, 78 insertions(+), 35 deletions(-)
---
diff --git a/src/gui/app1/runEncoder.cs b/src/gui/app1/runEncoder.cs
index 0648bea03..adc4ee1e6 100644
--- a/src/gui/app1/runEncoder.cs
+++ b/src/gui/app1/runEncoder.cs
@@ -2278,17 +2278,17 @@ public partial class ChronoJumpWindow
                if(currentRunEncoderExercise != null && currentRunEncoderExercise.IsSprint)
                        isSprint = true;
 
-               TwoListsOfDoubles verticalLinesUs_2l = new TwoListsOfDoubles();
+               RunEncoderSegmentCalcs segmentCalcs = new RunEncoderSegmentCalcs ();
                if(currentRunEncoderExercise != null && //currentRunEncoderExercise.SegmentCm > 0 &&
-                               reCGSD != null && reCGSD.SegmentDistTime_2l != null)
-                       verticalLinesUs_2l = reCGSD.SegmentDistTime_2l;
+                               reCGSD != null && reCGSD.SegmentCalcs != null)
+                       segmentCalcs = reCGSD.SegmentCalcs;
 
                if(cairoGraphRaceAnalyzer_dt == null)
                        cairoGraphRaceAnalyzer_dt = new CairoGraphRaceAnalyzer(
                                        drawingarea_race_analyzer_capture_position_time, "title",
                                        Catalog.GetString("Distance"), "m",
                                        isSprint, false,
-                                       verticalLinesUs_2l, true);
+                                       segmentCalcs, true);
 
                cairoGraphRaceAnalyzer_dt.DoSendingList (preferences.fontType.ToString(),
                                cairoGraphRaceAnalyzerPoints_dt_l, triggerListRunEncoder,
@@ -2301,17 +2301,17 @@ public partial class ChronoJumpWindow
                if(currentRunEncoderExercise != null && currentRunEncoderExercise.IsSprint)
                        isSprint = true;
 
-               TwoListsOfDoubles verticalLinesUs_2l = new TwoListsOfDoubles();
+               RunEncoderSegmentCalcs segmentCalcs = new RunEncoderSegmentCalcs ();
                if(currentRunEncoderExercise != null && //currentRunEncoderExercise.SegmentCm > 0 &&
-                               reCGSD != null && reCGSD.SegmentDistTime_2l != null)
-                       verticalLinesUs_2l = reCGSD.SegmentDistTime_2l;
+                               reCGSD != null && reCGSD.SegmentCalcs != null)
+                       segmentCalcs = reCGSD.SegmentCalcs;
 
                if(cairoGraphRaceAnalyzer_st == null)
                        cairoGraphRaceAnalyzer_st = new CairoGraphRaceAnalyzer(
                                        drawingarea_race_analyzer_capture_speed_time, "title",
                                        Catalog.GetString("Speed"), "m/s",
                                        isSprint, true,
-                                       verticalLinesUs_2l, false);
+                                       segmentCalcs, false);
 
                cairoGraphRaceAnalyzer_st.DoSendingList (preferences.fontType.ToString(),
                                cairoGraphRaceAnalyzerPoints_st_l, triggerListRunEncoder,
@@ -2327,17 +2327,17 @@ public partial class ChronoJumpWindow
                if(currentRunEncoderExercise != null && currentRunEncoderExercise.IsSprint)
                        isSprint = true;
 
-               TwoListsOfDoubles verticalLinesUs_2l = new TwoListsOfDoubles();
+               RunEncoderSegmentCalcs segmentCalcs = new RunEncoderSegmentCalcs ();
                if(currentRunEncoderExercise != null && //currentRunEncoderExercise.SegmentCm > 0 &&
-                               reCGSD != null && reCGSD.SegmentDistTime_2l != null)
-                       verticalLinesUs_2l = reCGSD.SegmentDistTime_2l;
+                               reCGSD != null && reCGSD.SegmentCalcs != null)
+                       segmentCalcs = reCGSD.SegmentCalcs;
 
                if(cairoGraphRaceAnalyzer_at == null)
                        cairoGraphRaceAnalyzer_at = new CairoGraphRaceAnalyzer(
                                        drawingarea_race_analyzer_capture_accel_time, "title",
                                        Catalog.GetString("Accel"), "m/s^2",
                                        isSprint, false,
-                                       verticalLinesUs_2l, false);
+                                       segmentCalcs, false);
 
                cairoGraphRaceAnalyzer_at.DoSendingList (preferences.fontType.ToString(),
                                cairoGraphRaceAnalyzerPoints_at_l, triggerListRunEncoder,
diff --git a/src/gui/cairo/raceAnalyzer.cs b/src/gui/cairo/raceAnalyzer.cs
index 31ee5526a..01406ddb2 100644
--- a/src/gui/cairo/raceAnalyzer.cs
+++ b/src/gui/cairo/raceAnalyzer.cs
@@ -30,7 +30,7 @@ public class CairoGraphRaceAnalyzer : CairoXY
        int points_list_painted;
        private bool isSprint;
        private bool plotMaxMark;
-       private TwoListsOfDoubles verticalLinesUs_2l;
+       private RunEncoderSegmentCalcs segmentCalcs;
        private bool useListOfDoublesOnY;
 
        //to avoid to have new data on PassData while the for is working on plotRealPoints
@@ -40,7 +40,7 @@ public class CairoGraphRaceAnalyzer : CairoXY
                        DrawingArea area, string title,
                        string yVariable, string yUnits,
                        bool isSprint, bool plotMaxMark,
-                       TwoListsOfDoubles verticalLinesUs_2l,
+                       RunEncoderSegmentCalcs segmentCalcs,
                        bool useListOfDoublesOnY) //for pos/time graph
        {
                this.area = area;
@@ -53,7 +53,7 @@ public class CairoGraphRaceAnalyzer : CairoXY
                this.yUnits = yUnits;
                this.isSprint = isSprint;
                this.plotMaxMark = plotMaxMark;
-               this.verticalLinesUs_2l = verticalLinesUs_2l;
+               this.segmentCalcs = segmentCalcs;
                this.useListOfDoublesOnY = useListOfDoublesOnY;
                
 //             doing = false;
@@ -83,6 +83,8 @@ public class CairoGraphRaceAnalyzer : CairoXY
        //return true if graph is inited (to dispose it)
        private bool doSendingList (string font, List<PointF> points_list, TriggerList triggerList, bool 
forceRedraw, PlotTypes plotType, int smoothLineWindow)
        {
+               // 1) init graph
+
                bool maxValuesChanged = false;
                if(points_list != null)
                        maxValuesChanged = findPointMaximums(false, points_list);
@@ -106,23 +108,24 @@ public class CairoGraphRaceAnalyzer : CairoXY
                        return graphInited;
                }
 
+               // 2) paint grid and write vaules on grid lines
                if(maxValuesChanged || forceRedraw)
                {
-                       if(verticalLinesUs_2l.Count() == 0)
+                       if(segmentCalcs.Count == 0)
                        {
                                // do not show vertical grid lines if we do not pass any distance mark. Show 
only horizontal.
                                paintGrid(gridTypes.HORIZONTALLINES, true);
                        }
                        else {
                                //horizontal
-                               if(verticalLinesUs_2l.Count() > 0 && useListOfDoublesOnY)
+                               if(segmentCalcs.Count > 0 && useListOfDoublesOnY)
                                {
                                        g.LineWidth = 1;
                                        g.Save();
                                        g.SetDash(new double[]{1, 2}, 0);
-                                       for(int i = 0 ; i < verticalLinesUs_2l.Count() ; i ++)
+                                       for(int i = 0 ; i < segmentCalcs.Count ; i ++)
                                        {
-                                               double yValue = verticalLinesUs_2l.GetFromFirst(i);
+                                               double yValue = segmentCalcs.Dist_l[i];
                                                paintHorizontalGridLine(g, 
Convert.ToInt32(calculatePaintY(yValue)), yValue.ToString(), textHeight -3);
                                        }
                                        g.Stroke ();
@@ -131,17 +134,17 @@ public class CairoGraphRaceAnalyzer : CairoXY
                                        paintGrid(gridTypes.HORIZONTALLINES, true);
 
                                //vertical
-                               if(verticalLinesUs_2l.Count() > 0)
+                               if(segmentCalcs.Count > 0)
                                {
                                        g.Save();
                                        g.SetDash(new double[]{1, 2}, 0);
-                                       for(int i = 0 ; i < verticalLinesUs_2l.Count() ; i ++)
+                                       for(int i = 0 ; i < segmentCalcs.Count ; i ++)
                                        {
-                                               string xTextTop = 
verticalLinesUs_2l.GetFromFirst(i).ToString();
+                                               string xTextTop = segmentCalcs.Dist_l[i].ToString();
 
                                                //seconds
-                                               string xTextBottom = 
Util.TrimDecimals(verticalLinesUs_2l.GetFromSecond(i)/1000000.0, 1).ToString();
-                                               double xGraph = 
calculatePaintX(verticalLinesUs_2l.GetFromSecond(i)/1000000.0);
+                                               string xTextBottom = 
Util.TrimDecimals(segmentCalcs.Time_l[i]/1000000.0, 1).ToString();
+                                               double xGraph = 
calculatePaintX(segmentCalcs.Time_l[i]/1000000.0);
 
                                                if(useListOfDoublesOnY)
                                                        paintVerticalGridLine(g, Convert.ToInt32(xGraph), 
xTextBottom, textHeight-3);
@@ -165,13 +168,16 @@ public class CairoGraphRaceAnalyzer : CairoXY
                        paintAxis();
                }
 
+               // 3) paint points, paint smooth line, paint maximum mark
                pointsRadius = 1;
                if( points_list != null &&
                                (maxValuesChanged || forceRedraw || points_list.Count != points_list_painted) 
)
                {
+                       // 3.a) paint points
                        plotRealPoints(plotType, points_list, points_list_painted, false); //not fast. TODO: 
maybe use fast if is really faster
                        points_list_painted = points_list.Count;
 
+                       // 3.b) paint smooth line
                        if(smoothLineWindow > 0 && points_list.Count > 5)
                        {
                                MovingAverage mAverageSmoothLine = new MovingAverage (points_list, 
smoothLineWindow);
@@ -181,7 +187,7 @@ public class CairoGraphRaceAnalyzer : CairoXY
                                g.SetSourceRGB (0,0,0);
                        }
 
-
+                       // 3.c) paint maximum mark
                        if(plotMaxMark && points_list.Count > 1)
                        {
                                if(isSprint) //on sprint plot an arrow from top speed (with moving average) 
to the right
@@ -218,6 +224,7 @@ public class CairoGraphRaceAnalyzer : CairoXY
                        }
                }
 
+               // 4) paint triggers
                if(triggerList != null && triggerList.Count() > 0)
                        foreach(Trigger trigger in triggerList.GetList())
                                paintVerticalTriggerLine(g, trigger, textHeight -3);
diff --git a/src/runEncoder.cs b/src/runEncoder.cs
index 02aec94f3..1448b2530 100644
--- a/src/runEncoder.cs
+++ b/src/runEncoder.cs
@@ -282,7 +282,7 @@ public class RunEncoderCaptureGetSpeedAndDisplacement
        private int segmentCm;
        private List<int> segmentVariableCm; //if segmentCm == -1 then this is used
        private int segmentVariableCmDistAccumulated;
-       private TwoListsOfDoubles segmentDistTime_2l;
+       private RunEncoderSegmentCalcs segmentCalcs;
 
        private int encoderDisplacement;
        private int time;
@@ -301,7 +301,7 @@ public class RunEncoderCaptureGetSpeedAndDisplacement
                this.segmentVariableCm = segmentVariableCm;
                segmentVariableCmDistAccumulated = 0;
 
-               segmentDistTime_2l = new TwoListsOfDoubles();
+               segmentCalcs = new RunEncoderSegmentCalcs ();
                timePre = 0;
        }
 
@@ -354,21 +354,21 @@ public class RunEncoderCaptureGetSpeedAndDisplacement
        }
        private void updateSegmentDistTimeFixed () //m
        {
-               if(runEncoderCaptureDistance >= (segmentCm/100.0) * (segmentDistTime_2l.Count() +1))
-                       segmentDistTime_2l.Add((segmentCm/100.0) * (segmentDistTime_2l.Count() +1), time);
+               if(runEncoderCaptureDistance >= (segmentCm/100.0) * (segmentCalcs.Count +1))
+                       segmentCalcs.Add((segmentCm/100.0) * (segmentCalcs.Count +1), time);
                //note this is not very precise because time can be a bit later than the selected dist
        }
        private void updateSegmentDistTimeVariable () //cm
        {
                //care of overflow
-               if(segmentDistTime_2l.Count() >= segmentVariableCm.Count)
+               if(segmentCalcs.Count >= segmentVariableCm.Count)
                        return;
 
-               double distToBeat = (segmentVariableCm[segmentDistTime_2l.Count()] + 
segmentVariableCmDistAccumulated) / 100.0; //cm -> m
+               double distToBeat = (segmentVariableCm[segmentCalcs.Count] + 
segmentVariableCmDistAccumulated) / 100.0; //cm -> m
                if(runEncoderCaptureDistance >= distToBeat)
                {
-                       segmentVariableCmDistAccumulated += segmentVariableCm[segmentDistTime_2l.Count()];
-                       segmentDistTime_2l.Add(distToBeat, time);
+                       segmentVariableCmDistAccumulated += segmentVariableCm[segmentCalcs.Count];
+                       segmentCalcs.Add (distToBeat, time);
                }
        }
 
@@ -395,8 +395,44 @@ public class RunEncoderCaptureGetSpeedAndDisplacement
        public double RunEncoderCaptureDistance {
                get { return runEncoderCaptureDistance; }
        }
-       public TwoListsOfDoubles SegmentDistTime_2l {
-               get { return segmentDistTime_2l; }
+       public RunEncoderSegmentCalcs SegmentCalcs {
+               get { return segmentCalcs; }
+       }
+}
+
+/*
+   first we had TwoListsOfDoubles SegmentDistTime_2l
+   but as we want to implement (accel, F, P) avg on each track, we use this new class
+   */
+public class RunEncoderSegmentCalcs
+{
+       private List<double> dist_l;
+       private List<double> time_l;
+       //TODO: a, F, P
+
+       public RunEncoderSegmentCalcs ()
+       {
+               dist_l = new List<double> ();
+               time_l = new List<double> ();
+               //TODO: a, F, P
+       }
+
+       public void Add (double dist, double time)
+       {
+               dist_l.Add (dist);
+               time_l.Add (time);
+       }
+
+       public int Count
+       {
+               get { return dist_l.Count; }
+       }
+
+       public List<double> Dist_l {
+               get { return dist_l; }
+       }
+       public List<double> Time_l {
+               get { return time_l; }
        }
 }
 


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