[chronojump] ForceSensor AI zoom cut after calcule and get dynamics



commit 59b2b07b13d56e5303c7170a54c3d01442bf4440
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Mar 16 18:28:13 2020 +0100

    ForceSensor AI zoom cut after calcule and get dynamics

 src/forceSensor.cs                 | 72 ++++++++++++++++++++++++++------------
 src/forceSensorDynamics.cs         | 56 +++++++++++++++++++++++++----
 src/gui/app1/forceSensor.cs        |  2 +-
 src/gui/app1/forceSensorAnalyze.cs |  2 +-
 4 files changed, 101 insertions(+), 31 deletions(-)
---
diff --git a/src/forceSensor.cs b/src/forceSensor.cs
index 158973fd..1768cb06 100644
--- a/src/forceSensor.cs
+++ b/src/forceSensor.cs
@@ -1498,14 +1498,8 @@ public class ForceSensorAnalyzeInstant
 
                if(fse.ComputeAsElastic)
                {
-                       /*
-                       LogB.Information(string.Format("Should zoom displ?: {0}, {1}, {2}, {3}, {4}", 
-                                               fscAIPointsDispl.RealWidthG != fscAIPoints.RealWidthG,
-                                               forceSensorValuesDispl.TimeLast, forceSensorValuesDispl.Max, 
forceSensorValuesDispl.Min,
-                                               fscAIPointsDispl.OutsideGraphChangeValues(
-                                                       forceSensorValuesDispl.TimeLast, 
forceSensorValuesDispl.Max, forceSensorValuesDispl.Min, true)
-                                               ));
-                                               */
+                       //LogB.Information(string.Format("fscAiPointsDispl.GetLastTime: {0}, 
forceSensorValuesDispl.TimeLast: {1}, forceSensorValuesDispl.Max: {2}, forceSensorValuesDispl.Min: {3}", 
+                       //                      fscAIPointsDispl.GetLastTime(), 
forceSensorValuesDispl.TimeLast, forceSensorValuesDispl.Max, forceSensorValuesDispl.Min));
 
                        if(fscAIPointsDispl.RealWidthG != fscAIPoints.RealWidthG) {
                                fscAIPointsDispl.RealWidthG = fscAIPoints.RealWidthG;
@@ -1513,16 +1507,16 @@ public class ForceSensorAnalyzeInstant
                                        fscAIPointsDispl.Redo();
                        }
 
-                       if(fscAIPointsDispl.OutsideGraphChangeValues(forceSensorValuesDispl.TimeLast, 
forceSensorValuesDispl.Max, forceSensorValuesDispl.Min, true))
+                       if(fscAIPointsDispl.OutsideGraphChangeValues(forceSensorValuesDispl.TimeLast, 
forceSensorValuesDispl.Max, forceSensorValuesDispl.Min, false))
                                fscAIPointsDispl.Redo();
                }
        }
 
-       private void readFile(string file, double start, double end,
+       private void readFile(string file, double startMs, double endMs,
                        double personWeight, ForceSensor.CaptureOptions fsco, double stiffness,
                        double eccMinDisplacement, double conMinDisplacement)
        {
-               LogB.Information(string.Format("at readFile, start: {0}, end: {1}", start, end));
+               LogB.Information(string.Format("at readFile, startMs: {0}, endMs: {1}", startMs, endMs));
                fscAIPoints = new ForceSensorCapturePoints(ForceSensorCapturePoints.GraphTypes.FORCEAIFORCE, 
graphWidth, graphHeight, -1);
                if(fse.ComputeAsElastic)
                        fscAIPointsDispl = new 
ForceSensorCapturePoints(ForceSensorCapturePoints.GraphTypes.FORCEAIDISPL, graphWidth, graphHeight, -1);
@@ -1559,15 +1553,20 @@ public class ForceSensorAnalyzeInstant
                                {
                                        double timeD = Convert.ToDouble(strFull[0]);
 
+                                       /*
+                                        * do not use this code, because  start/end cut will be after 
calculing forceSensorDynamics
+                                        * to have same data on that samples on zoom than on full signal
+                                        *
                                        //start can be -1 meaning that no zoom has to be applied
-                                       if(start != -1)
+                                       if(startMs != -1)
                                        {
-                                               if(timeD < start || timeD > end)
+                                               if(timeD < startMS || timeD > endMs)
                                                        continue;
 
                                                //put time at 0
-                                               timeD -= start;
+                                               timeD -= startMs;
                                        }
+                                       */
 
                                        times.Add(Convert.ToInt32(timeD));
                                        forces.Add(Convert.ToDouble(strFull[1]));
@@ -1578,11 +1577,40 @@ public class ForceSensorAnalyzeInstant
                ForceSensorDynamics forceSensorDynamics;
                if(fse.ComputeAsElastic)
                        forceSensorDynamics = new ForceSensorDynamicsElastic(
-                                       times, forces, fsco, fse, personWeight, stiffness, 
eccMinDisplacement, conMinDisplacement);
+                                       times, forces, fsco, fse, personWeight, stiffness, 
eccMinDisplacement, conMinDisplacement,
+                                       (startMs >= 0 && endMs >= 0) //zoomed
+                                       );
                else
                        forceSensorDynamics = new ForceSensorDynamicsNotElastic(
                                        times, forces, fsco, fse, personWeight, stiffness, 
eccMinDisplacement, conMinDisplacement);
 
+               if(startMs != -1)
+               {
+                       int startAtSample = -1;
+                       int endAtSample = -1;
+                       int j = 0;
+                       foreach(int time_micros in times)
+                       {
+                               if(startAtSample < 0 && time_micros >= startMs)
+                                       startAtSample = j;
+                               if(endAtSample < 0 && time_micros > endMs)
+                                       endAtSample = j -1;
+
+                               j ++;
+                       }
+                       if(endAtSample < 0)
+                               endAtSample = j -1;
+
+                       forceSensorDynamics.CutSamplesForZoom(startAtSample, endAtSample);
+
+                       //cut times
+                       times = times.GetRange(startAtSample, endAtSample - startAtSample);
+                       //shift times to the left (make firsts one zero)
+                       int startMsInt = times[0];
+                       for(j = 0;  j < times.Count; j ++)
+                               times[j] -= startMsInt;
+               }
+
                forces = forceSensorDynamics.GetForces();
 
                CalculedElasticPSAP = false;
@@ -1596,15 +1624,13 @@ public class ForceSensorAnalyzeInstant
                }
                ForceSensorRepetition_l = forceSensorDynamics.GetRepetitions();
 
-               //LogB.Information("times Length at A:", times.Count.ToString());
-
-               times.RemoveAt(0); //always (not-elastic and elastic) 1st has to be removed, because time is 
not ok there.
-
-               //LogB.Information("times Length at B:", times.Count.ToString());
-               if(CalculedElasticPSAP)
-                       times = times.GetRange(forceSensorDynamics.RemoveNValues +1, times.Count 
-2*forceSensorDynamics.RemoveNValues); // (index, count)
+               if(startMs == -1)
+               {
+                       times.RemoveAt(0); //always (not-elastic and elastic) 1st has to be removed, because 
time is not ok there.
 
-               //LogB.Information("times Length at C:", times.Count.ToString());
+                       if(CalculedElasticPSAP)
+                               times = times.GetRange(forceSensorDynamics.RemoveNValues +1, times.Count 
-2*forceSensorDynamics.RemoveNValues); // (index, count)
+               }
 
                int i = 0;
                foreach(int time in times)
diff --git a/src/forceSensorDynamics.cs b/src/forceSensorDynamics.cs
index 288fd9a8..59ed5e5b 100644
--- a/src/forceSensorDynamics.cs
+++ b/src/forceSensorDynamics.cs
@@ -47,12 +47,14 @@ public abstract class ForceSensorDynamics
 
        protected List<double> time_l;
 
-       protected void initialize(bool isElastic, List<double> force_l,
+       protected void initialize(bool isElastic,
+                       List<int> time_micros_l, List<double> force_l,
                        ForceSensor.CaptureOptions fsco, ForceSensorExercise fse,
                        double personMass, double stiffness,
                        double eccMinDisplacement, double conMinDisplacement)
        {
                this.isElastic = isElastic;
+               this.time_micros_l = time_micros_l;
                this.force_l = force_l;
                this.fsco = fsco;
                this.fse = fse;
@@ -297,6 +299,22 @@ public abstract class ForceSensorDynamics
 
        protected abstract void addRepetition(List <double> yList, int sampleStart, int sampleEnd);
 
+       public void CutSamplesForZoom(int startAtSample, int endAtSample)
+       {
+               //1 cut force_l on not elastic and all the lists on elastic
+               cutSamplesForZoomDo(startAtSample, endAtSample);
+               LogB.Information(" csfz 2b ");
+
+               //2 cut repetitions
+               List<ForceSensorRepetition> zoomed_forceSensorRepetition_l = new List 
<ForceSensorRepetition>();
+               foreach(ForceSensorRepetition fsr in forceSensorRepetition_l)
+                       if(fsr.sampleStart >= startAtSample && fsr.sampleEnd <= endAtSample)
+                               zoomed_forceSensorRepetition_l.Add(fsr);
+
+               forceSensorRepetition_l = zoomed_forceSensorRepetition_l;
+       }
+       protected abstract void cutSamplesForZoomDo(int startAtSample, int endAtSample);
+
        public virtual List<double> GetForces()
        {
                return force_l;
@@ -340,7 +358,7 @@ public class ForceSensorDynamicsNotElastic : ForceSensorDynamics
                        double personMass, double stiffness,
                        double eccMinDisplacement, double conMinDisplacement)
        {
-               initialize(false, force_l, fsco, fse, personMass, stiffness, eccMinDisplacement, 
conMinDisplacement);
+               initialize(false, time_micros_l, force_l, fsco, fse, personMass, stiffness, 
eccMinDisplacement, conMinDisplacement);
                removeFirstValue();
 
                if(! fse.ForceResultant)
@@ -377,6 +395,13 @@ public class ForceSensorDynamicsNotElastic : ForceSensorDynamics
 
                forceSensorRepetition_l.Add(new ForceSensorRepetition(sampleStart, sampleEnd));
        }
+
+       protected override void cutSamplesForZoomDo(int startAtSample, int endAtSample)
+       {
+               LogB.Information(string.Format("force_l.Count: {0}, startAtSample: {1}, endAtSample: {2}, 
endAtSample - startAtSample: {3}",
+                       force_l.Count, startAtSample, endAtSample, endAtSample - startAtSample));
+               force_l = force_l.GetRange(startAtSample, endAtSample - startAtSample);
+       }
 }
 
 public class ForceSensorDynamicsElastic : ForceSensorDynamics
@@ -388,16 +413,20 @@ public class ForceSensorDynamicsElastic : ForceSensorDynamics
        List<double> speed_l;
        List<double> accel_l;
        List<double> power_l;
+       private bool zoomed;
+
 
        public ForceSensorDynamicsElastic (List<int> time_micros_l, List<double> force_l, 
                        ForceSensor.CaptureOptions fsco, ForceSensorExercise fse,
                        double personMass, double stiffness,
-                       double eccMinDisplacement, double conMinDisplacement)
+                       double eccMinDisplacement, double conMinDisplacement,
+                       bool zoomed)
        {
                RemoveNValues = 10;
-               initialize(true, force_l, fsco, fse, personMass, stiffness, eccMinDisplacement, 
conMinDisplacement);
+               initialize(true, time_micros_l, force_l, fsco, fse, personMass, stiffness, 
eccMinDisplacement, conMinDisplacement);
                convertTimeToSeconds(time_micros_l);
                removeFirstValue();
+               this.zoomed = zoomed;
 
                if(! fse.ForceResultant)
                {
@@ -553,10 +582,25 @@ public class ForceSensorDynamicsElastic : ForceSensorDynamics
                forceSensorRepetition_l.Add(new ForceSensorRepetition(sampleStart, sampleEnd, lastMeanSpeed, 
lastRFD));
        }
 
+       protected override void cutSamplesForZoomDo(int startAtSample, int endAtSample)
+       {
+               force_l = force_l.GetRange(startAtSample, endAtSample - startAtSample);
+               position_l = position_l.GetRange(startAtSample, endAtSample - startAtSample);
+               speed_l = speed_l.GetRange(startAtSample, endAtSample - startAtSample);
+               accel_l = accel_l.GetRange(startAtSample, endAtSample - startAtSample);
+               power_l = power_l.GetRange(startAtSample, endAtSample - startAtSample);
+       }
+
        private List<double> stripStartEnd(List<double> l)
        {
-               LogB.Information(string.Format("removeN: {0}, l.Count: {1}", RemoveNValues, l.Count));
-               return l.GetRange(RemoveNValues +1, l.Count - 2*RemoveNValues);
+               if(zoomed) {
+                       //TODO: but if we are on the beginning or end of the signal we should RemoveNVales, 
but maybe this is impossible
+                       //            because ab lines will not move on that values
+                       return l;
+               } else {
+                       LogB.Information(string.Format("removeN: {0}, l.Count: {1}", RemoveNValues, l.Count));
+                       return l.GetRange(RemoveNValues +1, l.Count - 2*RemoveNValues);
+               }
        }
 
        public override List<double> GetForces()
diff --git a/src/gui/app1/forceSensor.cs b/src/gui/app1/forceSensor.cs
index fe064821..8607d2ab 100644
--- a/src/gui/app1/forceSensor.cs
+++ b/src/gui/app1/forceSensor.cs
@@ -1874,7 +1874,7 @@ LogB.Information(" fs R ");
                if(currentForceSensorExercise.ComputeAsElastic)
                        fsd = new ForceSensorDynamicsElastic(
                                        times, forces, fsco, currentForceSensorExercise, 
currentPersonSession.Weight, currentForceSensor.Stiffness,
-                                       preferences.forceSensorElasticEccMinDispl, 
preferences.forceSensorElasticConMinDispl);
+                                       preferences.forceSensorElasticEccMinDispl, 
preferences.forceSensorElasticConMinDispl, false);
                else
                        fsd = new ForceSensorDynamicsNotElastic(
                                        times, forces, fsco, currentForceSensorExercise, 
currentPersonSession.Weight, currentForceSensor.Stiffness,
diff --git a/src/gui/app1/forceSensorAnalyze.cs b/src/gui/app1/forceSensorAnalyze.cs
index e066d065..7254e3a2 100644
--- a/src/gui/app1/forceSensorAnalyze.cs
+++ b/src/gui/app1/forceSensorAnalyze.cs
@@ -1217,7 +1217,7 @@ public partial class ChronoJumpWindow
                                xposRepEnd = fsAI.GetXFromSampleCount(sampleEnd);
                                force_sensor_ai_pixmap.DrawLine(pen_green_force_ai,
                                                xposRepEnd, 0, xposRepEnd, allocation.Height -20);
-                               //LogB.Information(string.Format("repetition paint, i:{0}, xposRep:{1}", i, 
xposRep));
+                               //LogB.Information(string.Format("repetition paint, j: {0}, xposRepEnd: {1}", 
j, xposRepEnd));
                        }
 
                        if(sampleEnd >= 0)


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