[chronojump/michrolab] JumpsRjFatigue cairo graph div by time instead of n jumps (TODO: need to count % of jump on each lim



commit 1710355eeac241508e90811cab57be6f71af4a56
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Sep 2 17:21:30 2022 +0200

    JumpsRjFatigue cairo graph div by time instead of n jumps (TODO: need to count % of jump on each limit)

 src/gui/app1/jumpsRjFatigue.cs  |  5 +--
 src/gui/cairo/jumpsRjFatigue.cs | 67 +++++++++++++++++++++++++++++++++++++----
 src/jump.cs                     | 37 ++++++++++++++++++++++-
 src/jumpsRjFatigue.cs           | 15 +++++++--
 4 files changed, 113 insertions(+), 11 deletions(-)
---
diff --git a/src/gui/app1/jumpsRjFatigue.cs b/src/gui/app1/jumpsRjFatigue.cs
index 9cfb472bd..b4e6b15f2 100644
--- a/src/gui/app1/jumpsRjFatigue.cs
+++ b/src/gui/app1/jumpsRjFatigue.cs
@@ -16,7 +16,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) 2020   Xavier de Blas <xaviblas gmail com> 
+ * Copyright (C) 2022   Xavier de Blas <xaviblas gmail com>
  */
 
 
@@ -194,7 +194,8 @@ public partial class ChronoJumpWindow
                                divideIn = Convert.ToInt32(divideInStr);
 
                        //regular constructor
-                       jumpsRjFatigueGraph = new JumpsRjFatigueGraph(
+                       jumpsRjFatigueGraph = new JumpsRjFatigueGraph (
+                                       jumpsRjFatigue.TimesAccu_l,
                                        jumpsRjFatigue.Point_l,
                                        jumpsRjFatigue.Slope,
                                        jumpsRjFatigue.Intercept,
diff --git a/src/gui/cairo/jumpsRjFatigue.cs b/src/gui/cairo/jumpsRjFatigue.cs
index 6d60345ed..15f3b70d5 100644
--- a/src/gui/cairo/jumpsRjFatigue.cs
+++ b/src/gui/cairo/jumpsRjFatigue.cs
@@ -27,6 +27,7 @@ using Cairo;
 
 public class JumpsRjFatigueGraph : CairoXY
 {
+       private List<double> timesAccu_l;
        private int divideIn;
 
        //constructor when there are no points
@@ -43,10 +44,12 @@ public class JumpsRjFatigueGraph : CairoXY
                endGraphDisposing(g, surface, area.GdkWindow);
        }
        public JumpsRjFatigueGraph (
+                       List<double> timesAccu_l,
                        List<PointF> point_l, double slope, double intercept,
                        DrawingArea area, string title, string jumpType, string date,
                        JumpsRjFatigue.Statistic statistic, int divideIn)
        {
+               this.timesAccu_l = timesAccu_l;
                this.point_l = point_l;
                this.slope = slope;
                this.intercept = intercept;
@@ -96,7 +99,7 @@ public class JumpsRjFatigueGraph : CairoXY
                        plotPredictedLine(predictedLineTypes.STRAIGHT, predictedLineCrossMargins.TOUCH);
                //g.SetSourceColor(black);
                g.SetSourceColor(gray99);
-               divideAndPlotAverage(divideIn);
+               divideAndPlotAverage (divideIn, true);
                g.SetSourceColor(black);
 
                plotRealPoints(PlotTypes.POINTSLINES);
@@ -129,12 +132,17 @@ public class JumpsRjFatigueGraph : CairoXY
                writeTextAtRight(ypos++, date, false);
        }
 
-       private void divideAndPlotAverage(int parts)
+       private void divideAndPlotAverage (int parts, bool byTime) //byTime or byJumps
        {
                if(point_l.Count < parts * 2)
                        return;
 
-               List<List<PointF>> l_l = SplitList(point_l, Convert.ToInt32(Math.Floor(point_l.Count / (1.0 * 
parts))));
+               List<List<PointF>> l_l = new List<List<PointF>> ();
+               if (byTime)
+                       l_l = divideAndPlotAverageByTime (parts);
+               else
+                       l_l = divideAndPlotAverageByJumps (parts);
+
                int done = 0;
                foreach(List<PointF> l in l_l)
                {
@@ -149,6 +157,16 @@ public class JumpsRjFatigueGraph : CairoXY
                }
        }
 
+       private List<List<PointF>> divideAndPlotAverageByTime (int parts)
+       {
+               return SplitListByTime (timesAccu_l, point_l, parts);
+       }
+
+       private List<List<PointF>> divideAndPlotAverageByJumps (int parts)
+       {
+               return SplitListByJumps (point_l, Convert.ToInt32(Math.Floor(point_l.Count / (1.0 * parts))));
+       }
+
        private void paintHorizSegment (double xa, double xb, double y)
        {
                double xap = calculatePaintX(xa);
@@ -172,13 +190,50 @@ public class JumpsRjFatigueGraph : CairoXY
                g.Stroke ();
        }
 
+       public static List<List<PointF>> SplitListByTime (List<double> timesAccu_l, List<PointF> p_l, int 
parts)
+       {
+               var l_l = new List<List<PointF>>();
+
+               if (p_l.Count <= 1)
+                       return l_l;
+
+               double partRange = timesAccu_l[timesAccu_l.Count -1] / (1.0 * parts);
+
+               for (int p = 0; p < parts; p ++)
+               {
+                       int start = -1;
+                       int count = 0;
+                       int j;
+                       for (j = 0; j < timesAccu_l.Count ; j ++)
+                       {
+                               LogB.Information (string.Format ("p: {0}, j: {1}, timesAccu_l[j]: {2}, 
partRange: {3}", p, j, timesAccu_l[j], partRange));
+                               if ( timesAccu_l[j] >= partRange * p && (
+                                                       timesAccu_l[j] < partRange * (p+1) ||
+                                                       p == parts -1) ) //to have also the last value
+                               {
+                                       if (start < 0)
+                                               start = j;
+                                       count ++;
+                               }
+                       }
+
+                       if (start >= 0 && count > 0)
+                       {
+                               LogB.Information (string.Format ("p: {0}, j: {1}, start: {2}, count: {3}", p, 
j, start, count));
+                               l_l.Add (p_l.GetRange (start, count));
+                       }
+               }
+
+               return l_l;
+       }
+
        //https://stackoverflow.com/a/11463800
-       public static List<List<PointF>> SplitList(List<PointF> listMain, int nSize)
+       public static List<List<PointF>> SplitListByJumps (List<PointF> p_l, int nSize)
        {
                var l_l = new List<List<PointF>>();
 
-               for (int i = 0; i < listMain.Count; i += nSize)
-                       l_l.Add(listMain.GetRange(i, Math.Min(nSize, listMain.Count - i)));
+               for (int i = 0; i < p_l.Count; i += nSize)
+                       l_l.Add (p_l.GetRange (i, Math.Min (nSize, p_l.Count - i)));
 
                return l_l;
        }
diff --git a/src/jump.cs b/src/jump.cs
index 368643765..07d626498 100644
--- a/src/jump.cs
+++ b/src/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;
@@ -508,6 +508,41 @@ public class JumpRj : Jump
                }
        }
 
+       /*
+       public List<double> TcPlusTvList
+       {
+               get {
+                       List<double> l = new List<double>();
+                       for (int i = 0; i < tcList.Count; i ++)
+                       {
+                               if (tcList[i] <= 0)
+                                       l.Add (tvList[i]); //discard -1 tc on first jump starting in
+                               else
+                                       l.Add (tcList[i] + tvList[i]);
+                       }
+                       return l;
+               }
+       }
+       */
+       //tc + tv, used on jumpsRjFatigue
+       public List<double> TcPlusTvAccumulatedList
+       {
+               get {
+                       List<double> l = new List<double>();
+                       double accumulatedSum = 0;
+                       for (int i = 0; i < tcList.Count; i ++)
+                       {
+                               if (tcList[i] <= 0)
+                                       accumulatedSum += tvList[i]; //discard -1 tc on first jump starting in
+                               else
+                                       accumulatedSum += tcList[i] + tvList[i];
+
+                               l.Add (accumulatedSum);
+                       }
+                       return l;
+               }
+       }
+
        public double tvLast
        {
                get {
diff --git a/src/jumpsRjFatigue.cs b/src/jumpsRjFatigue.cs
index a8c71916f..4736419f8 100644
--- a/src/jumpsRjFatigue.cs
+++ b/src/jumpsRjFatigue.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) 2020   Xavier de Blas <xaviblas gmail com>
+ *  Copyright (C) 2022   Xavier de Blas <xaviblas gmail com>
  */
 
 using System;
@@ -26,6 +26,8 @@ using System.Collections.Generic; //List
 public class JumpsRjFatigue
 {
        private List<PointF> point_l;
+       private List<double> timesAccu_l;
+       //private List<Point3F> point_3l;
        LeastSquaresLine ls;
        public enum Statistic { HEIGHTS, Q, RSI } //RSI is jump height (m)/ contact time (s)
 
@@ -46,10 +48,14 @@ public class JumpsRjFatigue
                else if(statistic == Statistic.RSI)
                        y_l = jumpRj.RSIList;
 
+               //List<double> z_l = jumpRj.SumTcTvList;
+               timesAccu_l = jumpRj.TcPlusTvAccumulatedList;
+
                point_l = new List<PointF>();
+               //point_3l = new List<Point3F>();
 
                for(int i = 0; i < y_l.Count ; i ++)
-                       point_l.Add(new PointF(i+1, y_l[i]));
+                       point_l.Add (new PointF (i+1, y_l[i]));
 
                //3 get LeastSquaresLine (straight line)
                ls = new LeastSquaresLine();
@@ -78,6 +84,11 @@ public class JumpsRjFatigue
                get { return point_l; }
        }
 
+       public List<double> TimesAccu_l
+       {
+               get { return timesAccu_l; }
+       }
+
        public double Slope
        {
                get { return ls.Slope; }


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