[chronojump] jumpsEvolution refactorized to allow runsEvolution



commit c6d745f423bea659982d8e2aa0e036d7b203aae4
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Apr 21 07:47:54 2021 +0200

    jumpsEvolution refactorized to allow runsEvolution

 src/Makefile.am           |   2 +-
 src/jumpsRunsEvolution.cs | 116 +++++++++++++++++++++++++++++++---------------
 2 files changed, 80 insertions(+), 38 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index ebc5da9b..48edf509 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -215,7 +215,7 @@ SOURCES = \
        jump.cs\
        jumpsProfile.cs\
        jumpsDjOptimalFall.cs\
-       jumpsEvolution.cs\
+       jumpsRunsEvolution.cs\
        jumpsRjFatigue.cs\
        jumpsWeightFVProfile.cs\
        jumpType.cs\
diff --git a/src/jumpsRunsEvolution.cs b/src/jumpsRunsEvolution.cs
index ada12cdd..3e29a104 100644
--- a/src/jumpsRunsEvolution.cs
+++ b/src/jumpsRunsEvolution.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) 2019-2020   Xavier de Blas <xaviblas gmail com>
+ *  Copyright (C) 2019-2021   Xavier de Blas <xaviblas gmail com>
  */
 
 using System;
@@ -23,17 +23,59 @@ using System.Collections.Generic; //List
 
 //TODO: very similar to JumpsDjOptimalFall, refactorize if needed
 
-public class JumpsEvolution
+public abstract class JumpsRunsEvolution
 {
-       private List<PointF> point_l;
-       LeastSquaresLine ls;
+       protected List<PointF> point_l;
+       protected LeastSquaresLine ls;
 
+       public abstract void Calculate(int personID, string type, bool onlyBestInSession);
+
+       protected void getLeastSquaresLine () //straight line
+       {
+               ls = new LeastSquaresLine();
+               ls.Calculate(point_l);
+
+               LogB.Information(string.Format("slope = {0}; intercept = {1}", ls.Slope, ls.Intercept));
+       }
+
+       public double GetMaxValue()
+       {
+               double maxValue = 0;
+                foreach(PointF p in point_l)
+               {
+                       if(p.X > maxValue)
+                               maxValue = p.X;
+                       if(p.Y > maxValue)
+                               maxValue = p.Y;
+               }
+
+               return maxValue;
+       }
+
+       public List<PointF> Point_l
+       {
+               get { return point_l; }
+       }
+
+       public double Slope
+       {
+               get { return ls.Slope; }
+       }
+
+       public double Intercept
+       {
+               get { return ls.Intercept; }
+       }
+}
+
+public class JumpsEvolution : JumpsRunsEvolution
+{
        //constructor
        public JumpsEvolution()
        {
        }
-       
-       public void Calculate (int personID, string jumpType, bool onlyBestInSession)
+
+       public override void Calculate (int personID, string jumpType, bool onlyBestInSession)
        {
                //1 get data
                 List<Jump> jump_l = SqliteJump.SelectJumps (-1, personID, jumpType, 
Sqlite.Orders_by.DEFAULT, -1, false, onlyBestInSession);
@@ -55,46 +97,46 @@ public class JumpsEvolution
                        DateTime dt = UtilDate.FromFile(j.Datetime);
                        double dtDouble = UtilDate.DateTimeYearDayAsDouble(dt);
 
-                       point_l.Add(new PointF(
-                                               dtDouble,
-                                               Util.GetHeightInCentimeters(j.Tv)
-                                               ));
+                       point_l.Add(new PointF(dtDouble, Util.GetHeightInCentimeters(j.Tv)));
                }
 
-               //3 get LeastSquaresLine (straight line)
-               ls = new LeastSquaresLine();
-               ls.Calculate(point_l);
-
-               //4 print data
-               LogB.Information(string.Format("slope = {0}; intercept = {1}", ls.Slope, ls.Intercept));
+               getLeastSquaresLine ();
        }
+}
 
-       public double GetMaxValue()
+public class RunsEvolution : JumpsRunsEvolution
+{
+       //constructor
+       public RunsEvolution()
        {
-               double maxValue = 0;
-                foreach(PointF p in point_l)
-               {
-                       if(p.X > maxValue)
-                               maxValue = p.X;
-                       if(p.Y > maxValue)
-                               maxValue = p.Y;
-               }
-
-               return maxValue;
        }
 
-       public List<PointF> Point_l
+       public override void Calculate (int personID, string runType, bool onlyBestInSession)
        {
-               get { return point_l; }
-       }
+               //1 get data
+                List<Run> run_l = SqliteRun.SelectRuns (false, -1, personID, runType,
+                               Sqlite.Orders_by.DEFAULT, -1, false, onlyBestInSession);
 
-       public double Slope
-       {
-               get { return ls.Slope; }
-       }
+               //2 convert to list of PointF
+               point_l = new List<PointF>();
+               int currentSession = -1;
+                foreach(Run r in run_l)
+               {
+                       if(onlyBestInSession)
+                       {
+                               //at onlyBestInSession they return ordered by sessionID, 
run.distance/run.time DESC
+                               if(r.SessionID == currentSession)
+                                       continue;
+                               else
+                                       currentSession = r.SessionID;
+                       }
 
-       public double Intercept
-       {
-               get { return ls.Intercept; }
+                       DateTime dt = UtilDate.FromFile(r.Datetime);
+                       double dtDouble = UtilDate.DateTimeYearDayAsDouble(dt);
+
+                       point_l.Add(new PointF(dtDouble, r.Speed));
+               }
+
+               getLeastSquaresLine ();
        }
 }


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