[chronojump] ForceSensor: fixed bugs/crashes analyze instant repetitions since last commits
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] ForceSensor: fixed bugs/crashes analyze instant repetitions since last commits
- Date: Fri, 14 Feb 2020 16:00:50 +0000 (UTC)
commit d03a654e2afecbbaf56cf71dbd2c2a83a99a4b1b
Author: Xavier de Blas <xaviblas gmail com>
Date: Fri Feb 14 16:59:07 2020 +0100
ForceSensor: fixed bugs/crashes analyze instant repetitions since last commits
src/forceSensor.cs | 12 ++++++++--
src/forceSensorDynamics.cs | 48 +++++++++++++++++++++++---------------
src/gui/app1/forceSensorAnalyze.cs | 24 ++++++++++++-------
3 files changed, 55 insertions(+), 29 deletions(-)
---
diff --git a/src/forceSensor.cs b/src/forceSensor.cs
index d8fbdb1d..73132384 100644
--- a/src/forceSensor.cs
+++ b/src/forceSensor.cs
@@ -1386,6 +1386,7 @@ public class ForceSensorAnalyzeInstant
double personWeight, ForceSensor.CaptureOptions fsco, double stiffness,
double eccMinDisplacement, double conMinDisplacement)
{
+ LogB.Information("at readFile");
fscAIPoints = new ForceSensorCapturePoints(graphWidth, graphHeight, -1);
List<string> contents = Util.ReadFileAsStringList(file);
@@ -1455,9 +1456,16 @@ 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);
+ times = times.GetRange(forceSensorDynamics.RemoveNValues -1, times.Count
-2*forceSensorDynamics.RemoveNValues); // (index, count)
+
+ //LogB.Information("times Length at C:", times.Count.ToString());
+
int i = 0;
foreach(int time in times)
{
@@ -1502,7 +1510,7 @@ public class ForceSensorAnalyzeInstant
//public int GetXFromSampleCount(int currentPos, int totalPos)
public int GetXFromSampleCount(int currentPos)
{
- //LogB.Information(string.Format("currentPos: {0}, totalPos: {1}", currentPos, totalPos));
+ //LogB.Information(string.Format("currentPos: {0}", currentPos));
//this can be called on expose event before calculating needed parameters
if(graphWidth == 0)
return 0;
diff --git a/src/forceSensorDynamics.cs b/src/forceSensorDynamics.cs
index 9094697b..6477a98b 100644
--- a/src/forceSensorDynamics.cs
+++ b/src/forceSensorDynamics.cs
@@ -75,7 +75,6 @@ public abstract class ForceSensorDynamics
protected double calculeForceWithCaptureOptions(double force)
{
- LogB.Information("at calculeForceWithCaptureOptions, fsco: " + fsco.ToString());
if(fsco == ForceSensor.CaptureOptions.ABS)
return Math.Abs(force);
if(fsco == ForceSensor.CaptureOptions.INVERTED)
@@ -101,7 +100,6 @@ public abstract class ForceSensorDynamics
//for each phase, stores the sample number of the biggest current sample.
int possibleExtremeSample = 0;
- int possibleExtremeSampleSend = 0;
//Stores the sample of the last actual maximum of the phase
int lastExtremeSample = 0;
@@ -174,15 +172,7 @@ public abstract class ForceSensorDynamics
searchingFirstExtreme = false;
}
- //LogB.Information(string.Format("-----------minDisplacement detected at:
{0}", currentSample));
- //LogB.Information(string.Format("Extreme added at: {0}",
possibleExtremeSample));
-
- possibleExtremeSampleSend = possibleExtremeSample - (RemoveNValues -1);
- if(possibleExtremeSampleSend < 0)
- possibleExtremeSampleSend = 0;
-
- if(displacementOk(concentricFlag, yList[possibleExtremeSampleSend],
yList[lastExtremeSample]))
- addRepetition(yList, lastExtremeSample, possibleExtremeSampleSend);
//list, start, end
+ prepareCheckAndSendRepetition(concentricFlag, yList, lastExtremeSample,
possibleExtremeSample);
//Save the sample of the last extreme in order to compare new samples with it
lastExtremeSample = possibleExtremeSample;
@@ -198,18 +188,38 @@ public abstract class ForceSensorDynamics
currentSample += 1;
}
- possibleExtremeSampleSend = possibleExtremeSample - (RemoveNValues -1);
- if(possibleExtremeSampleSend < 0)
- possibleExtremeSampleSend = 0;
+ prepareCheckAndSendRepetition(concentricFlag, yList, lastExtremeSample,
possibleExtremeSample);
+ }
+
+ private void prepareCheckAndSendRepetition(int concentricFlag, List<double> yList, int sampleStart,
int sampleEnd)
+ {
+ // 1) remove values to avoid smoothing problems:
+ sampleStart = sampleStart -RemoveNValues -1;
+ if(sampleStart < 0)
+ sampleStart = 0;
+
+ sampleEnd = sampleEnd -RemoveNValues -1;
+ if(sampleEnd < 0)
+ return;
+
+ // 2) check that end does not outside the after forceSensor.cs cut:
+ // times = times.GetRange(forceSensorDynamics.RemoveNValues -1, times.Count
-2*forceSensorDynamics.RemoveNValues);
+
+ if(sampleEnd >= yList.Count - 2*RemoveNValues)
+ sampleEnd = yList.Count - 2*RemoveNValues -1;
+
+ if(sampleEnd < 0 || sampleStart >= sampleEnd)
+ return;
- if(displacementOk(concentricFlag, yList[possibleExtremeSampleSend], yList[lastExtremeSample]))
- addRepetition(yList, lastExtremeSample, possibleExtremeSampleSend); //list, start, end
+ // 3) check if displacement is ok, and add the repetition
+ if(displacementOk(concentricFlag, yList[sampleStart], yList[sampleEnd]))
+ addRepetition(yList, sampleStart, sampleEnd);
}
- private bool displacementOk (int concentricFlag, double val1, double val2)
+ private bool displacementOk (int concentricFlag, double sampleStart, double sampleEnd)
{
- if ( ( concentricFlag == 1 && Math.Abs(val1 - val2) >= conMinDisplacement) ||
- (concentricFlag == -1 && Math.Abs(val1 - val2) >= eccMinDisplacement) )
+ if ( ( concentricFlag == 1 && Math.Abs(sampleStart - sampleEnd) >= conMinDisplacement) ||
+ (concentricFlag == -1 && Math.Abs(sampleStart - sampleEnd) >= eccMinDisplacement) )
return true;
return false;
diff --git a/src/gui/app1/forceSensorAnalyze.cs b/src/gui/app1/forceSensorAnalyze.cs
index b02626ed..28f71379 100644
--- a/src/gui/app1/forceSensorAnalyze.cs
+++ b/src/gui/app1/forceSensorAnalyze.cs
@@ -607,6 +607,7 @@ public partial class ChronoJumpWindow
//invert hscales if needed
int firstValue = Convert.ToInt32(hscale_force_sensor_ai_a.Value);
int secondValue = Convert.ToInt32(hscale_force_sensor_ai_b.Value);
+ //LogB.Information(string.Format("firstValue: {0}, secondValue: {1}", firstValue,
secondValue));
if(firstValue > secondValue) {
int temp = firstValue;
@@ -639,6 +640,7 @@ public partial class ChronoJumpWindow
conMinDispl = preferences.forceSensorNotElasticConMinForce;
}
+ //LogB.Information(string.Format("creating fsAI with zoomA: {0}, zoomB: {1}", zoomA, zoomB));
fsAI = new ForceSensorAnalyzeInstant(
lastForceSensorFullPath,
force_sensor_ai_drawingarea.Allocation.Width,
@@ -647,6 +649,7 @@ public partial class ChronoJumpWindow
currentForceSensorExercise, currentPersonSession.Weight,
getForceSensorCaptureOptions(), currentForceSensor.Stiffness,
eccMinDispl, conMinDispl);
+ //LogB.Information("created fsAI");
/*
* position the hscales on the left to avoid loading a csv
@@ -907,38 +910,42 @@ public partial class ChronoJumpWindow
LogB.Information("Repetition: " + repetition.ToString());
if(repetition >= 0)
{
- double start = fsAIRepetitionMouseLimits.GetStartOfARep(repetition) -1;
+ double start = fsAIRepetitionMouseLimits.GetStartOfARep(repetition);
if(start < 0)
start = 0; //just a precaution
- double end = fsAIRepetitionMouseLimits.GetEndOfARep(repetition) + 1;
+ double end = fsAIRepetitionMouseLimits.GetEndOfARep(repetition);
if(end >= fsAI.GetLength() -1)
end -= 1; //just a precaution
- //LogB.Information(string.Format("start: {0}, end: {1}", start, end));
+ LogB.Information(string.Format("start px: {0}, end px: {1}", start, end));
//find the hscale value for this x
//TODO: move this to forceSensor.cs
bool startFound = false;
bool endFound = false;
- for(int i = 0; i < fsAI.GetLength() -1; i++)
+ for(int i = 0; i < fsAI.GetLength(); i++)
{
int xposHere = fsAI.GetXFromSampleCount(i);
+ //LogB.Information(string.Format("xposHere: {0} px, startFound: {1},
endFound: {2}", xposHere, startFound, endFound));
//with >= to solve problems of doubles
if(! startFound && xposHere >= start)
{
hscale_force_sensor_ai_a.Value = i;
- //LogB.Information(string.Format("start2: {0}", i));
+ //LogB.Information(string.Format("start2 sample: {0}", i));
startFound = true;
}
if(! endFound && xposHere >= end)
{
hscale_force_sensor_ai_b.Value = i;
- //LogB.Information(string.Format("end2: {0}", i));
+ //LogB.Information(string.Format("end2 sample: {0}", i));
endFound = true;
}
}
- button_force_sensor_ai_zoom.Click();
+ //LogB.Information("call zoom start -->");
+ if(startFound && endFound)
+ button_force_sensor_ai_zoom.Click();
+ //LogB.Information("<-- call zoom end");
}
}
}
@@ -1004,6 +1011,7 @@ public partial class ChronoJumpWindow
forceSensorSignalPlotFeedbackRectangle(fsAI.FscAIPoints, force_sensor_ai_drawingarea,
force_sensor_ai_pixmap, pen_yellow_light_force_ai);
// 1) create paintPoints
+ //LogB.Information(string.Format("forceSensorAnalyzeManualGraphDo():
fsAI.FscAIPoints.Points.Count: {0}", fsAI.FscAIPoints.Points.Count));
Gdk.Point [] paintPoints = new Gdk.Point[fsAI.FscAIPoints.Points.Count];
for(int i = 0; i < fsAI.FscAIPoints.Points.Count; i ++)
paintPoints[i] = fsAI.FscAIPoints.Points[i];
@@ -1131,7 +1139,7 @@ public partial class ChronoJumpWindow
}
//show 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) // write last repetition count
+ if(forceSensorZoomApplied && j >= 0 && j < reps_l.Count) // write last repetition count
{
layout_force_ai_text.SetMarkup((j+1).ToString());
textWidth = 1; textHeight = 1;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]