[chronojump] Several improvements on forceSensor analyze to match zoom in/out
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Several improvements on forceSensor analyze to match zoom in/out
- Date: Tue, 21 Apr 2020 16:47:22 +0000 (UTC)
commit f67afdcbca3ca17d2f5df131179b4c939fe52219
Author: Xavier de Blas <xaviblas gmail com>
Date: Tue Apr 21 18:46:23 2020 +0200
Several improvements on forceSensor analyze to match zoom in/out
src/forceSensor.cs | 80 ++++++++++++++++++++------------------
src/forceSensorDynamics.cs | 27 ++++++++-----
src/gui/app1/forceSensorAnalyze.cs | 37 +++++++++++-------
3 files changed, 83 insertions(+), 61 deletions(-)
---
diff --git a/src/forceSensor.cs b/src/forceSensor.cs
index d8c944a6..5df4c1fc 100644
--- a/src/forceSensor.cs
+++ b/src/forceSensor.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) 2017 Xavier de Blas <xaviblas gmail com>
+ * Copyright (C) 2017-2020 Xavier de Blas <xaviblas gmail com>
*/
using System;
@@ -921,7 +921,7 @@ public class ForceSensorCapturePoints
{
double calc = (forces[countB] - forces[countA]) / (times[countB]/1000000.0 -
times[countA]/1000000.0); //microsec to sec
//LogB.Information(string.Format("GetRFD {0}, {1}, {2}, {3}, {4}, {5}, RFD: {6}",
- // countA, countB, forces[countA], forces[countB], times[countA], times[countB], calc));
+ // countA, countB, forces[countA], forces[countB], times[countA],
times[countB], calc));
return calc;
}
public double GetImpulse(int countA, int countB)
@@ -1465,7 +1465,7 @@ public class ForceSensorAnalyzeInstant
private ForceSensorExercise fse;
public ForceSensorAnalyzeInstant(
- string file, int graphWidth, int graphHeight, double start, double end,
+ string file, int graphWidth, int graphHeight, int startSample, int endSample,
ForceSensorExercise fse, double personWeight, ForceSensor.CaptureOptions fsco, double
stiffness,
double eccMinDisplacement, double conMinDisplacement)
{
@@ -1473,10 +1473,10 @@ public class ForceSensorAnalyzeInstant
this.graphHeight = graphHeight;
this.fse = fse;
- readFile(file, start, end, personWeight, fsco, stiffness, eccMinDisplacement,
conMinDisplacement);
+ readFile(file, startSample, endSample, personWeight, fsco, stiffness, eccMinDisplacement,
conMinDisplacement);
//on zoom adjust width
- if(start >= 0 || end >= 0)
+ if(startSample >= 0 || endSample >= 0)
{
fscAIPoints.Zoom(forceSensorValues.TimeLast);
LogB.Information("Redo normal at constructor");
@@ -1512,11 +1512,14 @@ public class ForceSensorAnalyzeInstant
}
}
- private void readFile(string file, double startMs, double endMs,
+ private void readFile(string file, int startSample, int endSample,
double personWeight, ForceSensor.CaptureOptions fsco, double stiffness,
double eccMinDisplacement, double conMinDisplacement)
{
- LogB.Information(string.Format("at readFile, startMs: {0}, endMs: {1}", startMs, endMs));
+ LogB.Information(string.Format("at readFile, startSample: {0}, endSample: {1}", startSample,
endSample));
+
+ // 0 initialize
+
fscAIPoints = new ForceSensorCapturePoints(ForceSensorCapturePoints.GraphTypes.FORCEAIFORCE,
graphWidth, graphHeight, -1);
if(fse.ComputeAsElastic)
fscAIPointsDispl = new
ForceSensorCapturePoints(ForceSensorCapturePoints.GraphTypes.FORCEAIDISPL, graphWidth, graphHeight, -1);
@@ -1524,7 +1527,6 @@ public class ForceSensorAnalyzeInstant
List<string> contents = Util.ReadFileAsStringList(file);
bool headersRow = true;
- //initialize
forceSensorValues = new ForceSensorValues();
if(fse.ComputeAsElastic)
forceSensorValuesDispl = new ForceSensorValues();
@@ -1535,6 +1537,8 @@ public class ForceSensorAnalyzeInstant
List<int> times = new List<int>();
List<double> forces = new List<double>();
+ // 1 read all file
+
foreach(string str in contents)
{
if(headersRow)
@@ -1574,45 +1578,48 @@ public class ForceSensorAnalyzeInstant
}
}
+ // 2 calcule dynamics for all file
+
ForceSensorDynamics forceSensorDynamics;
if(fse.ComputeAsElastic)
forceSensorDynamics = new ForceSensorDynamicsElastic(
times, forces, fsco, fse, personWeight, stiffness,
eccMinDisplacement, conMinDisplacement,
- (startMs >= 0 && endMs >= 0) //zoomed
+ (startSample >= 0 && endSample >= 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;
+ // 3 remove times at start/end of the file to avoid first value from sensor,
+ // and values at start/end (RemoveNValues) needed for the shifted average
- j ++;
- }
- if(endAtSample < 0)
- endAtSample = j -1;
+ //LogB.Information("not zoomed, second time is: " + times[1].ToString());
+ times.RemoveAt(0); //always (not-elastic and elastic) 1st has to be removed, because time is
not ok there.
+
+ if(forceSensorDynamics.CalculedElasticPSAP)
+ times = times.GetRange(forceSensorDynamics.RemoveNValues +1,
+ times.Count -2*forceSensorDynamics.RemoveNValues); // (index, count)
- 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;
+ // 4 at zoom, cut time and force samples
+
+ if(startSample >= 0 && endSample >= 0) //zoom in
+ {
+ forceSensorDynamics.CutSamplesForZoom(startSample, endSample); //this takes in
account the RemoveNValues
+ times = times.GetRange(startSample, endSample - startSample + 1);
}
+
+ // 5 shift times to the left (make first one zero)
+
+ int startMsInt = times[0];
+ for(int j = 0; j < times.Count; j ++)
+ times[j] -= startMsInt;
+
forces = forceSensorDynamics.GetForces();
+ // 6 get caculated data
+
CalculedElasticPSAP = false;
if(forceSensorDynamics.CalculedElasticPSAP)
{
@@ -1624,14 +1631,11 @@ public class ForceSensorAnalyzeInstant
}
ForceSensorRepetition_l = forceSensorDynamics.GetRepetitions();
- if(startMs == -1)
- {
- times.RemoveAt(0); //always (not-elastic and elastic) 1st has to be removed, because
time is not ok there.
-
- if(CalculedElasticPSAP)
- times = times.GetRange(forceSensorDynamics.RemoveNValues +1, times.Count
-2*forceSensorDynamics.RemoveNValues); // (index, count)
- }
+ // 7 fill values for the GUI
+ LogB.Information(string.Format(
+ "readFile, printing forces, times.Count: {0}, forces.Count: {1}",
+ times.Count, forces.Count));
int i = 0;
foreach(int time in times)
{
diff --git a/src/forceSensorDynamics.cs b/src/forceSensorDynamics.cs
index 59ed5e5b..d97f63ae 100644
--- a/src/forceSensorDynamics.cs
+++ b/src/forceSensorDynamics.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 Xavier de Blas <xaviblas gmail com>
+ * Copyright (C) 2019-2020 Xavier de Blas <xaviblas gmail com>
*/
using System;
@@ -74,6 +74,7 @@ public abstract class ForceSensorDynamics
//so is better to remove it
protected virtual void removeFirstValue()
{
+ LogB.Information(string.Format("size of force_l: {0}", force_l.Count));
force_l.RemoveAt(0);
}
@@ -398,9 +399,11 @@ public class ForceSensorDynamicsNotElastic : ForceSensorDynamics
protected override void cutSamplesForZoomDo(int startAtSample, int endAtSample)
{
- LogB.Information(string.Format("force_l.Count: {0}, startAtSample: {1}, endAtSample: {2},
endAtSample - startAtSample: {3}",
+ LogB.Information(string.Format("cutSamplesForZoomDo, 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);
+
+ //+1 because we want both,the start and the end
+ force_l = force_l.GetRange(startAtSample, endAtSample - startAtSample + 1);
}
}
@@ -584,18 +587,22 @@ public class ForceSensorDynamicsElastic : ForceSensorDynamics
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);
+ //to cut, shift both values at right in order to be the same sample in/out zoom
+ startAtSample += RemoveNValues +1;
+ endAtSample += RemoveNValues +1;
+
+ //+1 because we want both,the start and the end
+ force_l = force_l.GetRange(startAtSample, endAtSample - startAtSample + 1);
+ position_l = position_l.GetRange(startAtSample, endAtSample - startAtSample + 1);
+ speed_l = speed_l.GetRange(startAtSample, endAtSample - startAtSample + 1);
+ accel_l = accel_l.GetRange(startAtSample, endAtSample - startAtSample + 1);
+ power_l = power_l.GetRange(startAtSample, endAtSample - startAtSample + 1);
}
private List<double> stripStartEnd(List<double> l)
{
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
+ //values have been shifted at cutSamplesForZoomDo
return l;
} else {
LogB.Information(string.Format("removeN: {0}, l.Count: {1}", RemoveNValues, l.Count));
diff --git a/src/gui/app1/forceSensorAnalyze.cs b/src/gui/app1/forceSensorAnalyze.cs
index 5c9d7aa6..882c443f 100644
--- a/src/gui/app1/forceSensorAnalyze.cs
+++ b/src/gui/app1/forceSensorAnalyze.cs
@@ -598,8 +598,9 @@ public partial class ChronoJumpWindow
if(lastForceSensorFullPath == null || lastForceSensorFullPath == "")
return;
- double zoomA = -1;
- double zoomB = -1;
+ int zoomFrameA = -1; //means no zoom
+ int zoomFrameB = -1; //means no zoom
+
if(forceSensorZoomApplied &&
Util.IsNumber(label_force_sensor_ai_time_a.Text, true) &&
Util.IsNumber(label_force_sensor_ai_time_b.Text, true))
@@ -616,15 +617,14 @@ public partial class ChronoJumpWindow
}
//-1 and +1 to have the points at the edges to calcule the RFDs
- zoomA = fsAI.GetTimeMS(firstValue -1) * 1000;
- zoomB = fsAI.GetTimeMS(secondValue +1) * 1000;
+ zoomFrameA = firstValue -1;
+ zoomFrameB = secondValue +1;
//do not zoom if both are the same, or the diff is just on pixel
- //if(zoomA == zoomB)
- if(Math.Abs(zoomA - zoomB) <= 1)
+ if(Math.Abs(zoomFrameA - zoomFrameB) <= 1)
{
- zoomA = -1;
- zoomB = -1;
+ zoomFrameA = -1;
+ zoomFrameB = -1;
}
}
@@ -637,17 +637,18 @@ public partial class ChronoJumpWindow
preferences.forceSensorNotElasticConMinForce);
LogB.Information(string.Format("eccMinDispl: {0}, conMinDispl: {1}", eccMinDispl,
conMinDispl));
- //LogB.Information(string.Format("creating fsAI with zoomA: {0}, zoomB: {1}", zoomA, zoomB));
+ //LogB.Information(string.Format("creating fsAI with zoomFrameA: {0}, zoomFrameB: {1}",
zoomFrameA, zoomFrameB));
fsAI = new ForceSensorAnalyzeInstant(
lastForceSensorFullPath,
force_sensor_ai_drawingarea.Allocation.Width,
force_sensor_ai_drawingarea.Allocation.Height,
- zoomA, zoomB,
+ zoomFrameA, zoomFrameB,
currentForceSensorExercise, currentPersonSession.Weight,
getForceSensorCaptureOptions(), currentForceSensor.Stiffness,
eccMinDispl, conMinDispl
);
//LogB.Information("created fsAI");
+ LogB.Information(string.Format("fsAI.GetLength: {0}", fsAI.GetLength()));
/*
* position the hscales on the left to avoid loading a csv
@@ -664,11 +665,12 @@ public partial class ChronoJumpWindow
//ranges should have max value the number of the lines of csv file minus the header
hscale_force_sensor_ai_a.SetRange(1, fsAI.GetLength() -2);
hscale_force_sensor_ai_b.SetRange(1, fsAI.GetLength() -2);
+
hscale_force_sensor_ai_ab.SetRange(1, fsAI.GetLength() -2);
LogB.Information(string.Format("hscale_force_sensor_ai_time_a,b,ab ranges: 1, {0}",
fsAI.GetLength() -2));
//on zoom put hscale B at the right
- if(zoomB >= 0)
+ if(zoomFrameB >= 0)
hscale_force_sensor_ai_b.Value = fsAI.GetLength() -2;
//to update values
@@ -1010,6 +1012,9 @@ public partial class ChronoJumpWindow
//store hscale a to help return to position on unzoom
hscale_force_sensor_ai_a_BeforeZoom = Convert.ToInt32(hscale_force_sensor_ai_a.Value);
hscale_force_sensor_ai_b_BeforeZoom = Convert.ToInt32(hscale_force_sensor_ai_b.Value);
+ //LogB.Information(string.Format("before zoom set to: {0}, {1}",
+ // hscale_force_sensor_ai_a_BeforeZoom,
+ // hscale_force_sensor_ai_b_BeforeZoom));
forceSensorRepetition_lZoomApplied = fsAI.ForceSensorRepetition_l;
@@ -1024,11 +1029,17 @@ public partial class ChronoJumpWindow
hscale_force_sensor_ai_a_AtZoom = Convert.ToInt32(hscale_force_sensor_ai_a.Value);
hscale_force_sensor_ai_b_AtZoom = Convert.ToInt32(hscale_force_sensor_ai_b.Value);
+ //LogB.Information(string.Format("at zoom, AtZoom values set to: {0}, {1}",
+ // hscale_force_sensor_ai_a_AtZoom,
+ // hscale_force_sensor_ai_b_AtZoom));
forceSensorDoGraphAI();
hscale_force_sensor_ai_a.Value = hscale_force_sensor_ai_a_BeforeZoom +
(hscale_force_sensor_ai_a_AtZoom -1);
hscale_force_sensor_ai_b.Value = hscale_force_sensor_ai_a_BeforeZoom +
(hscale_force_sensor_ai_b_AtZoom -1);
+ //LogB.Information(string.Format("at zoom A,B values set to: {0}, {1}",
+ // hscale_force_sensor_ai_a.Value,
+ // hscale_force_sensor_ai_b.Value));
button_force_sensor_ai_zoom.Visible = true;
button_force_sensor_ai_zoom_out.Visible = false;
@@ -1182,8 +1193,8 @@ public partial class ChronoJumpWindow
int sampleEnd = reps_l[j].sampleEnd;
if(forceSensorZoomApplied)
{
- sampleStart -= hscale_force_sensor_ai_a_BeforeZoom;
- sampleEnd -= hscale_force_sensor_ai_a_BeforeZoom;
+ sampleStart -= hscale_force_sensor_ai_a_BeforeZoom -1;
+ sampleEnd -= hscale_force_sensor_ai_a_BeforeZoom -1;
//LogB.Information(string.Format("reps_l[j].sampleEnd: {0},
hscale_force_sensor_ai_b_BeforeZoom: {1}",
// reps_l[j].sampleEnd,
hscale_force_sensor_ai_b_BeforeZoom));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]