[chronojump] Cairo JumpsEvolution and FVProfile show linear regression



commit 4b12f0205863c4b78ea7c8b52c2eeb5ab255c436
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Jan 10 18:43:59 2020 +0100

    Cairo JumpsEvolution and FVProfile show linear regression

 src/gui/app1/jumpsEvolution.cs        |  6 ++----
 src/gui/app1/jumpsWeightFVProfile.cs  |  3 ++-
 src/gui/cairo/jumpsDjOptimalFall.cs   |  2 +-
 src/gui/cairo/jumpsEvolution.cs       | 34 ++++++--------------------------
 src/gui/cairo/jumpsWeightFVProfile.cs | 37 +++++------------------------------
 src/gui/cairo/xy.cs                   | 32 ++++++++++++++++++++++++------
 src/jumpsEvolution.cs                 | 37 ++++++++---------------------------
 src/jumpsWeightFVProfile.cs           | 37 ++++++++---------------------------
 8 files changed, 58 insertions(+), 130 deletions(-)
---
diff --git a/src/gui/app1/jumpsEvolution.cs b/src/gui/app1/jumpsEvolution.cs
index 5731fbee..c3f100a0 100644
--- a/src/gui/app1/jumpsEvolution.cs
+++ b/src/gui/app1/jumpsEvolution.cs
@@ -91,10 +91,8 @@ public partial class ChronoJumpWindow
                        //regular constructor
                        JumpsEvolutionGraph jeg = new JumpsEvolutionGraph(
                                        jumpsEvolution.Point_l,
-                                       jumpsEvolution.Coefs,
-                                       jumpsEvolution.ParaboleType, //model
-                                       jumpsEvolution.XatMaxY, //model
-                                       jumpsEvolution.GetMaxValue(),
+                                       jumpsEvolution.Slope,
+                                       jumpsEvolution.Intercept,
                                        drawingarea_jumps_evolution,
                                        currentPerson.Name, jumpType, currentSession.DateShort);
                        jeg.Do();
diff --git a/src/gui/app1/jumpsWeightFVProfile.cs b/src/gui/app1/jumpsWeightFVProfile.cs
index 9be0b2a0..53bdfbf7 100644
--- a/src/gui/app1/jumpsWeightFVProfile.cs
+++ b/src/gui/app1/jumpsWeightFVProfile.cs
@@ -111,7 +111,8 @@ public partial class ChronoJumpWindow
                        //regular constructor
                        JumpsWeightFVProfileGraph jwfv = new JumpsWeightFVProfileGraph(
                                        jumpsWeightFVProfile.Point_l,
-                                       jumpsWeightFVProfile.Coefs,
+                                       jumpsWeightFVProfile.Slope,
+                                       jumpsWeightFVProfile.Intercept,
                                        drawingarea_jumps_weight_fv_profile,
                                        currentPerson.Name, //jumpType,
                                        currentSession.DateShort);
diff --git a/src/gui/cairo/jumpsDjOptimalFall.cs b/src/gui/cairo/jumpsDjOptimalFall.cs
index 73b44e22..b03f6447 100644
--- a/src/gui/cairo/jumpsDjOptimalFall.cs
+++ b/src/gui/cairo/jumpsDjOptimalFall.cs
@@ -76,7 +76,7 @@ public class JumpsDjOptimalFallGraph : CairoXY
 
                LogB.Information(string.Format("coef length:{0}", coefs.Length));
                if(coefs.Length == 3)
-                       plotPredictedLine();
+                       plotPredictedLine(predictedLineTypes.PARABOLE);
 
                plotRealPoints();
 
diff --git a/src/gui/cairo/jumpsEvolution.cs b/src/gui/cairo/jumpsEvolution.cs
index 0fb035cd..723761ab 100644
--- a/src/gui/cairo/jumpsEvolution.cs
+++ b/src/gui/cairo/jumpsEvolution.cs
@@ -43,18 +43,12 @@ public class JumpsEvolutionGraph : CairoXY
 
        //regular constructor
        public JumpsEvolutionGraph (
-                       List<Point> point_l, double[] coefs,
-                       LeastSquaresParabole.ParaboleTypes paraboleType,
-                       double xAtMMaxY, //x at Model MaxY
-                       double pointsMaxValue,
-                       DrawingArea area,
-                       string title, string jumpType, string date)
+                       List<Point> point_l, double slope, double intercept,
+                       DrawingArea area, string title, string jumpType, string date)
        {
                this.point_l = point_l;
-               this.coefs = coefs;
-               this.paraboleType = paraboleType;
-               this.xAtMMaxY = xAtMMaxY;
-               this.pointsMaxValue = pointsMaxValue;
+               this.slope = slope;
+               this.intercept = intercept;
                this.area = area;
                this.title = title;
                this.jumpType = jumpType;
@@ -70,29 +64,13 @@ public class JumpsEvolutionGraph : CairoXY
                initGraph();
 
                 findPointMaximums();
-                findAbsoluteMaximums();
+                //findAbsoluteMaximums();
                paintAxisAndGrid(gridTypes.HORIZONTALLINES);
                paintGridDatetime();
 
-               LogB.Information(string.Format("coef length:{0}", coefs.Length));
-               if(coefs.Length == 3)
-                       plotPredictedLine();
-
+               plotPredictedLine(predictedLineTypes.STRAIGHT);
                plotRealPoints();
 
-               if(coefs.Length == 3)
-               {
-                       if(paraboleType == LeastSquaresParabole.ParaboleTypes.CONVEX)
-                       {
-                               plotPredictedMaxPoint();
-                               writeTextPredictedPoint();
-                       }
-                       else
-                               writeTextConcaveParabole();
-               } else {
-                       //TODO: if two points draw a line, but no need to show error if there are 1 or 2 
points
-                       //writeTextNeed3PointsWithDifferentFall();
-               }
                writeTitle();
 
                endGraph();
diff --git a/src/gui/cairo/jumpsWeightFVProfile.cs b/src/gui/cairo/jumpsWeightFVProfile.cs
index 80374493..b6607288 100644
--- a/src/gui/cairo/jumpsWeightFVProfile.cs
+++ b/src/gui/cairo/jumpsWeightFVProfile.cs
@@ -53,21 +53,13 @@ public class JumpsWeightFVProfileGraph : CairoXY
 
        //regular constructor
        public JumpsWeightFVProfileGraph (
-                       List<Point> point_l, double[] coefs,
-                       //LeastSquaresParabole.ParaboleTypes paraboleType,
-                       //double xAtMMaxY, //x at Model MaxY
-                       //double pointsMaxValue,
-                       DrawingArea area,
-                       string title, //string jumpType,
+                       List<Point> point_l, double slope, double intercept,
+                       DrawingArea area, string title, //string jumpType,
                        string date)
        {
                this.point_l = point_l;
-               this.coefs = coefs;
-               /*
-               this.paraboleType = paraboleType;
-               this.xAtMMaxY = xAtMMaxY;
-               this.pointsMaxValue = pointsMaxValue;
-               */
+               this.slope = slope;
+               this.intercept = intercept;
                this.area = area;
                this.title = title;
                //this.jumpType = jumpType;
@@ -87,28 +79,9 @@ public class JumpsWeightFVProfileGraph : CairoXY
                //findAbsoluteMaximums();
                paintAxisAndGrid(gridTypes.BOTH);
 
-               /*
-               LogB.Information(string.Format("coef length:{0}", coefs.Length));
-               if(coefs.Length == 3)
-                       plotPredictedLine();
-                       */
-
+               plotPredictedLine(predictedLineTypes.STRAIGHT);
                plotRealPoints();
 
-               /*
-               if(coefs.Length == 3)
-               {
-                       if(paraboleType == LeastSquaresParabole.ParaboleTypes.CONVEX)
-                       {
-                               plotPredictedMaxPoint();
-                               writeTextPredictedPoint();
-                       }
-                       else
-                               writeTextConcaveParabole();
-               } else {
-                       writeTextNeed3PointsWithDifferentFall();
-               }
-               */
                writeTitle();
 
                endGraph();
diff --git a/src/gui/cairo/xy.cs b/src/gui/cairo/xy.cs
index e8e10cbf..7135bef1 100644
--- a/src/gui/cairo/xy.cs
+++ b/src/gui/cairo/xy.cs
@@ -28,10 +28,17 @@ public abstract class CairoXY
 {
        //used on construction
        protected List<Point> point_l;
+
+       //regression line straight
+       protected double slope;
+       protected double intercept;
+
+       //regression line parabole
        protected double[] coefs;
        protected LeastSquaresParabole.ParaboleTypes paraboleType;
        protected double xAtMMaxY;
        protected double pointsMaxValue;
+
        protected DrawingArea area;
        protected string title;
        protected string jumpType;
@@ -156,14 +163,21 @@ public abstract class CairoXY
                paintGrid (minX, absoluteMaxX, minY, absoluteMaxY, 5, gridType);
        }
 
-       protected void plotPredictedLine()
+       protected enum predictedLineTypes { STRAIGHT, PARABOLE }
+       protected void plotPredictedLine(predictedLineTypes plt)
        {
                bool firstValue = false;
-               double minMax50Percent = (minX + absoluteMaxX)/2;
+               double range = absoluteMaxX - minX;
                double xgraphOld = 0;
                bool wasOutOfMargins = false; //avoids to not draw a line between the end point of a line on 
a margin and the start point again of that line
 
-               for(double x = minX - minMax50Percent; x < absoluteMaxX + minMax50Percent; x += 
(absoluteMaxX-minX)/200)
+               double xStart = minX - range/2;
+               double xEnd = absoluteMaxX + range/2;
+               LogB.Information(string.Format("minX: {0}, absoluteMaxX: {1}, range: {2}, xStart: {3}; xEnd: 
{4}", minX, absoluteMaxX, range, xStart, xEnd));
+               //TODO: instead of doing this procedure for a straight line,
+               //just find the two points where the line gets out of the graph and draw a line between them
+
+               for(double x = xStart; x < xEnd; x += (xEnd - xStart)/1000)
                {
                        double xgraph = calculatePaintX(
                                        ( x ),
@@ -174,9 +188,15 @@ public abstract class CairoXY
                                continue;
                        xgraphOld = xgraph;
 
-                       double ygraph = calculatePaintY(
-                                       ( coefs[0] + coefs[1]*x + coefs[2]*Math.Pow(x,2) ),
-                                       graphHeight, absoluteMaxY, minY, totalMargins, totalMargins);
+                       double ygraph = 0;
+
+                       if(plt == predictedLineTypes.STRAIGHT)
+                               ygraph = calculatePaintY(slope * x + intercept,
+                                               graphHeight, absoluteMaxY, minY, totalMargins, totalMargins);
+                       else //(plt == predictedLineTypes.PARABOLE)
+                               ygraph = calculatePaintY(
+                                               ( coefs[0] + coefs[1]*x + coefs[2]*Math.Pow(x,2) ),
+                                               graphHeight, absoluteMaxY, minY, totalMargins, totalMargins);
 
                        //do not plot line outer the axis
                        if(
diff --git a/src/jumpsEvolution.cs b/src/jumpsEvolution.cs
index b855c67a..78f5c32e 100644
--- a/src/jumpsEvolution.cs
+++ b/src/jumpsEvolution.cs
@@ -26,7 +26,7 @@ using System.Collections.Generic; //List
 public class JumpsEvolution
 {
        private List<Point> point_l;
-       LeastSquaresParabole ls;
+       LeastSquaresLine ls;
 
        //constructor
        public JumpsEvolution()
@@ -52,17 +52,12 @@ public class JumpsEvolution
                                                ));
                }
 
-               //3 get LeastSquaresParabole
-               ls = new LeastSquaresParabole();
+               //3 get LeastSquaresLine (straight line)
+               ls = new LeastSquaresLine();
                ls.Calculate(point_l);
 
                //4 print data
-               if(ls.CalculatedCoef)
-                       LogB.Information(string.Format("coef = {0} {1} {2}",
-                                               ls.Coef[0], ls.Coef[1], ls.Coef[2]));
-
-               if(ls.CalculatedXatMaxY)
-                       LogB.Information(string.Format("XatMaxY = {0}", ls.XatMaxY));
+               LogB.Information(string.Format("slope = {0}; intercept = {1}", ls.Slope, ls.Intercept));
        }
 
        public double GetMaxValue()
@@ -84,29 +79,13 @@ public class JumpsEvolution
                get { return point_l; }
        }
 
-       public double[] Coefs
-       {
-               get {
-                       if(! ls.CalculatedCoef)
-                               return new double[0];
-
-                       LogB.Information(string.Format("coef0:{0}", ls.Coef[0]));
-                       return ls.Coef;
-               }
-       }
-
-       public LeastSquaresParabole.ParaboleTypes ParaboleType
+       public double Slope
        {
-               get { return ls.ParaboleType; }
+               get { return ls.Slope; }
        }
 
-       public double XatMaxY //model
+       public double Intercept
        {
-               get {
-                       if(! ls.CalculatedXatMaxY)
-                               return -1;
-
-                       return ls.XatMaxY;
-               }
+               get { return ls.Intercept; }
        }
 }
diff --git a/src/jumpsWeightFVProfile.cs b/src/jumpsWeightFVProfile.cs
index 0ce46518..b57b03d2 100644
--- a/src/jumpsWeightFVProfile.cs
+++ b/src/jumpsWeightFVProfile.cs
@@ -24,7 +24,7 @@ using System.Collections.Generic; //List
 public class JumpsWeightFVProfile
 {
        private List<Point> point_l;
-       LeastSquaresParabole ls;
+       LeastSquaresLine ls;
 
        //constructor
        public JumpsWeightFVProfile()
@@ -59,17 +59,12 @@ public class JumpsWeightFVProfile
                                                ));
                }
 
-               //3 get LeastSquaresParabole
-               ls = new LeastSquaresParabole();
+               //3 get LeastSquaresLine (straight line)
+               ls = new LeastSquaresLine();
                ls.Calculate(point_l);
 
                //4 print data
-               if(ls.CalculatedCoef)
-                       LogB.Information(string.Format("coef = {0} {1} {2}",
-                                               ls.Coef[0], ls.Coef[1], ls.Coef[2]));
-
-               if(ls.CalculatedXatMaxY)
-                       LogB.Information(string.Format("XatMaxY = {0}", ls.XatMaxY));
+               LogB.Information(string.Format("slope = {0}; intercept = {1}", ls.Slope, ls.Intercept));
        }
 
        public double GetMaxValue()
@@ -91,29 +86,13 @@ public class JumpsWeightFVProfile
                get { return point_l; }
        }
 
-       public double[] Coefs
-       {
-               get {
-                       if(! ls.CalculatedCoef)
-                               return new double[0];
-
-                       LogB.Information(string.Format("coef0:{0}", ls.Coef[0]));
-                       return ls.Coef;
-               }
-       }
-
-       public LeastSquaresParabole.ParaboleTypes ParaboleType
+       public double Slope
        {
-               get { return ls.ParaboleType; }
+               get { return ls.Slope; }
        }
 
-       public double XatMaxY //model
+       public double Intercept
        {
-               get {
-                       if(! ls.CalculatedXatMaxY)
-                               return -1;
-
-                       return ls.XatMaxY;
-               }
+               get { return ls.Intercept; }
        }
 }


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