[chronojump] ForceSensor MaxAvgForce in Window now shows that force as a green line



commit a05d7b84dad2871af4a3abc40abcebfced2f928c
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Feb 15 17:52:30 2021 +0100

    ForceSensor MaxAvgForce in Window now shows that force as a green line

 src/forceSensor.cs                 | 48 +++++++++++++++++++++++++++++++-------
 src/gui/app1/forceSensorAnalyze.cs | 12 ++++++++++
 src/gui/cairo/util.cs              | 13 +++++++++++
 3 files changed, 65 insertions(+), 8 deletions(-)
---
diff --git a/src/forceSensor.cs b/src/forceSensor.cs
index 67b5d666..6d8eefde 100644
--- a/src/forceSensor.cs
+++ b/src/forceSensor.cs
@@ -943,7 +943,8 @@ public class ForceSensorCapturePoints
        //stored, to not calculate again with same data
        CalculatedForceMaxAvgInWindow calculatedForceMaxAvgInWindow;
 
-       public void GetForceMaxAvgInWindow (int countA, int countB, double windowSeconds, out double avgMax, 
out string error)
+       public void GetForceMaxAvgInWindow (int countA, int countB, double windowSeconds,
+                       out double avgMax, out int avgMaxSampleStart, out int avgMaxSampleEnd, out string 
error)
        {
                // 1) check if ws calculated before
                if(calculatedForceMaxAvgInWindow != null &&
@@ -952,6 +953,8 @@ public class ForceSensorCapturePoints
                {
                        LogB.Information("Was calculated before");
                        avgMax = calculatedForceMaxAvgInWindow.Result;
+                       avgMaxSampleStart = calculatedForceMaxAvgInWindow.ResultSampleStart;
+                       avgMaxSampleEnd = calculatedForceMaxAvgInWindow.ResultSampleEnd;
                        error = ""; //there will be no error, because when is stored is without error
                        return;
                }
@@ -962,11 +965,15 @@ public class ForceSensorCapturePoints
                if(GetTimeAtCount(countB) - timeA <= 1000000 * windowSeconds)
                {
                        avgMax = 0;
+                       avgMaxSampleStart = countA; //there is an error, this will not be used
+                       avgMaxSampleEnd = countA; //there is an error, this will not be used
                        error = "Need more time";
                        return;
                }
 
                avgMax = 0;
+               avgMaxSampleStart = countA;     //sample where avgMax starts (to draw a line)
+               avgMaxSampleEnd = countA;       //sample where avgMax starts (to draw a line)
                error = "";
 
                double sum = 0;
@@ -979,8 +986,10 @@ public class ForceSensorCapturePoints
                {
                        sum += forces[i];
                        count ++;
-                       avgMax = sum / count;
                }
+               avgMax = sum / count;
+               avgMaxSampleEnd = countA + count;
+
                LogB.Information(string.Format("avgMax 1st for: {0}", avgMax));
                //note "count" has the window size in samples
 
@@ -992,14 +1001,19 @@ public class ForceSensorCapturePoints
 
                        double avg = sum / count;
                        if(avg > avgMax)
+                       {
                                avgMax = avg;
+                               avgMaxSampleStart = j - count;
+                               avgMaxSampleEnd = j;
+                       }
                }
 
-               LogB.Information(string.Format("Average max force in {0} seconds: {1}", windowSeconds, 
avgMax));
+               LogB.Information(string.Format("Average max force in {0} seconds: {1}, started at sample 
range: {2}:{3}",
+                                       windowSeconds, avgMax, avgMaxSampleStart, avgMaxSampleEnd));
 
                // 5) store data to not calculate it again if data is the same
                calculatedForceMaxAvgInWindow = new CalculatedForceMaxAvgInWindow (
-                               countA, countB, windowSeconds, avgMax);
+                               countA, countB, windowSeconds, avgMax, avgMaxSampleStart, avgMaxSampleEnd);
        }
 
        public double GetRFD(int countA, int countB)
@@ -1217,13 +1231,18 @@ public class CalculatedForceMaxAvgInWindow
        private int countB;
        private double windowSeconds;
        private double result; //avgMax
+       private int resultSampleStart; //avgMaxSampleStart
+       private int resultSampleEnd; //avgMaxSampleEnd
 
-       public CalculatedForceMaxAvgInWindow (int countA, int countB, double windowSeconds, double result)
+       public CalculatedForceMaxAvgInWindow (int countA, int countB, double windowSeconds,
+                       double result, int resultSampleStart, int resultSampleEnd)
        {
                this.countA = countA;
                this.countB = countB;
                this.windowSeconds = windowSeconds;
                this.result = result;
+               this.resultSampleStart = resultSampleStart;
+               this.resultSampleEnd = resultSampleEnd;
        }
        public CalculatedForceMaxAvgInWindow (int countA, int countB, double windowSeconds)
        {
@@ -1241,6 +1260,14 @@ public class CalculatedForceMaxAvgInWindow
        {
                get { return result; }
        }
+       public int ResultSampleStart
+       {
+               get { return resultSampleStart; }
+       }
+       public int ResultSampleEnd
+       {
+               get { return resultSampleEnd; }
+       }
 }
 
 public class ForceSensorRFD
@@ -1767,8 +1794,11 @@ public class ForceSensorAnalyzeInstant
        public double AccelMAX;
        public double PowerAVG;
        public double PowerMAX;
-       public double ForceMaxAvgInWindow;
-       public string ForceMaxAvgInWindowError; //if there is any error
+
+       public double ForceMaxAvgInWindow;              //the result
+       public int ForceMaxAvgInWindowSampleStart;      //the start sample of the result
+       public int ForceMaxAvgInWindowSampleEnd;        //the end sample of the result
+       public string ForceMaxAvgInWindowError;         //if there is any error
 
        //for elastic
        public bool CalculedElasticPSAP;
@@ -2070,7 +2100,9 @@ public class ForceSensorAnalyzeInstant
                }
 
                fscAIPoints.GetAverageAndMaxForce(countA, countB, out ForceAVG, out ForceMAX);
-               fscAIPoints.GetForceMaxAvgInWindow (countA, countB, 1, out ForceMaxAvgInWindow, out 
ForceMaxAvgInWindowError);
+               fscAIPoints.GetForceMaxAvgInWindow (countA, countB, 1,
+                               out ForceMaxAvgInWindow, out ForceMaxAvgInWindowSampleStart, out 
ForceMaxAvgInWindowSampleEnd,
+                               out ForceMaxAvgInWindowError);
 
                if(CalculedElasticPSAP)
                {
diff --git a/src/gui/app1/forceSensorAnalyze.cs b/src/gui/app1/forceSensorAnalyze.cs
index f75f2b78..e47e6d47 100644
--- a/src/gui/app1/forceSensorAnalyze.cs
+++ b/src/gui/app1/forceSensorAnalyze.cs
@@ -1101,12 +1101,23 @@ public partial class ChronoJumpWindow
                }
 
                if(fsAI != null)
+               {
                        CairoUtil.PaintVerticalLinesAndRectangle (
                                        force_sensor_ai_drawingarea,
                                        
fsAI.GetXFromSampleCount(Convert.ToInt32(hscale_force_sensor_ai_a.Value)),
                                        
fsAI.GetXFromSampleCount(Convert.ToInt32(hscale_force_sensor_ai_b.Value)),
                                        true, //paint the second line and rectangle (if a != b)
                                        15, 0); // top/bottom of the rectangle (top is greater than at 
encoder to acomodate the repetition green text), bottom 0 is ok.
+               
+                       if(fsAI.ForceMaxAvgInWindowError == "")
+                       {
+                               int yPx = fsAI.FscAIPoints.GetForceInPx(fsAI.ForceMaxAvgInWindow);
+                               CairoUtil.PaintSegment(force_sensor_ai_drawingarea,
+                                               new Cairo.Color(0/256.0, 256/256.0, 0/256.0),
+                                               
fsAI.GetXFromSampleCount(fsAI.ForceMaxAvgInWindowSampleStart), yPx,
+                                               fsAI.GetXFromSampleCount(fsAI.ForceMaxAvgInWindowSampleEnd), 
yPx);
+                       }
+               }
 
                force_sensor_ai_allocationXOld = allocation.Width;
 
@@ -1447,6 +1458,7 @@ public partial class ChronoJumpWindow
                                }
                        }
                }
+
                //show the start vertical line and the number of last repetition (when obviously no new rep 
will make writting it)
                //but only if zoomed and that repetition exists (has an end)
                if(forceSensorZoomApplied && j >= 0 && j < reps_l.Count)
diff --git a/src/gui/cairo/util.cs b/src/gui/cairo/util.cs
index f23e2530..e3db85a0 100644
--- a/src/gui/cairo/util.cs
+++ b/src/gui/cairo/util.cs
@@ -32,6 +32,19 @@ public static class CairoUtil
         * public methods
         */
 
+       public static void PaintSegment (Gtk.DrawingArea darea, Cairo.Color color, int x1, int y1, int x2, 
int y2)
+       {
+               using (Cairo.Context g = Gdk.CairoHelper.Create (darea.GdkWindow))
+               {
+                       g.Color = color;
+                       g.MoveTo(x1, y1);
+                       g.LineTo(x2, y2);
+                       g.Stroke();
+
+                       g.GetTarget ().Dispose ();
+               }
+       }
+
        public static void PaintVerticalLinesAndRectangle (
                        Gtk.DrawingArea darea, int xposA, int xposB, bool posBuse, int topRect, int 
bottomRect)
        {


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