[chronojump] ForceSensor export: GraphAB draws max avg force in window



commit 1941307b27c635f08e51114296158674018b695e
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Feb 22 13:21:52 2021 +0100

    ForceSensor export: GraphAB draws max avg force in window

 r-scripts/maximumIsometricForce.R | 23 ++++++++++++++++++++---
 src/forceSensor.cs                | 28 +++++++++++++++++++++++++---
 2 files changed, 45 insertions(+), 6 deletions(-)
---
diff --git a/r-scripts/maximumIsometricForce.R b/r-scripts/maximumIsometricForce.R
index 48a32d12..8342cad8 100644
--- a/r-scripts/maximumIsometricForce.R
+++ b/r-scripts/maximumIsometricForce.R
@@ -1101,7 +1101,8 @@ doProcess <- function(pngFile, dataFile, decimalChar, title, exercise, datetime,
        return(exportedValues)
 }
 
-plotABGraph <- function(pngFile, dataFile, decimalChar, title, exercise, datetime, captureOptions, 
startSample, endSample)
+plotABGraph <- function(pngFile, dataFile, decimalChar, title, exercise, datetime, captureOptions, 
startSample, endSample,
+                       maxAvgForceInWindow, maxAvgForceInWindowSampleStart, maxAvgForceInWindowSampleEnd)
 {
        title = fixTitleAndOtherStrings(title)
        exercise = fixTitleAndOtherStrings(exercise)
@@ -1119,11 +1120,25 @@ plotABGraph <- function(pngFile, dataFile, decimalChar, title, exercise, datetim
        else if(captureOptions == "INVERTED")
                y = -1 * y
 
-       plot(y ~ x, type="l")
+       plot(y ~ x, type="l", xlab="Time (s)", ylab="Force (N)")
 
        #mark max point
        points(x[which(y == max(y))[1]], max(y), col="red", cex=2)
 
+       #draw a segment related to max avg force in window
+       segments(x[maxAvgForceInWindowSampleStart], maxAvgForceInWindow,
+                x[maxAvgForceInWindowSampleEnd], maxAvgForceInWindow, lwd=2, col="green4")
+       if(maxAvgForceInWindow > 0)
+       {
+               topTick = maxAvgForceInWindow/100
+               segments(x[maxAvgForceInWindowSampleStart], maxAvgForceInWindow - topTick,
+                        x[maxAvgForceInWindowSampleStart], maxAvgForceInWindow + topTick,
+                        lwd=2, col="green4")
+               segments(x[maxAvgForceInWindowSampleEnd], maxAvgForceInWindow - topTick,
+                        x[maxAvgForceInWindowSampleEnd], maxAvgForceInWindow + topTick,
+                        lwd=2, col="green4")
+       }
+
        endGraph()
 }
 
@@ -1203,7 +1218,9 @@ start <- function(op)
                        pngFile <- paste(tempGraphsABFolder, i, ".png", sep="")  #but remember to graph also 
when model fails
                        plotABGraph(pngFile, as.vector(dataFiles$fullURL[i]),
                                        dataFiles$decimalChar[i], dataFiles$title[i], dataFiles$exercise[i], 
paste(dataFiles$date[i], dataFiles$time[i], sep=" "),
-                                       dataFiles$captureOptions[i], dataFiles$startSample[i], 
dataFiles$endSample[i])
+                                       dataFiles$captureOptions[i], dataFiles$startSample[i], 
dataFiles$endSample[i],
+                                       dataFiles$maxAvgForceInWindow[i], 
dataFiles$maxAvgForceInWindowSampleStart[i], dataFiles$maxAvgForceInWindowSampleEnd[i]
+                       )
 
                        if(! modelOk)
                                exportModelVector = exportModelVectorOnFail #done here and not on the catch, 
because it didn't worked there
diff --git a/src/forceSensor.cs b/src/forceSensor.cs
index 2183fa94..8a226006 100644
--- a/src/forceSensor.cs
+++ b/src/forceSensor.cs
@@ -1575,6 +1575,8 @@ public class ForceSensorGraphABExport: ForceSensorGraphAB
        public double maxForceRaw;
        public double maxAvgForceInWindow;
        public double forceSensorAnalyzeMaxAVGInWindowSeconds;
+       public double maxAvgForceInWindowSampleStart;
+       public double maxAvgForceInWindowSampleEnd;
        public string laterality;
        public int setCount;
        public int repCount;
@@ -1583,6 +1585,7 @@ public class ForceSensorGraphABExport: ForceSensorGraphAB
        public ForceSensorGraphABExport (
                        string fullURL, bool decimalIsPoint, double maxForceRaw,
                        double maxAvgForceInWindow, double forceSensorAnalyzeMaxAVGInWindowSeconds,
+                       double maxAvgForceInWindowSampleStart, double maxAvgForceInWindowSampleEnd,
                        string laterality, int setCount, int repCount, string commentOfSet,
                        ForceSensor.CaptureOptions fsco, int startSample, int endSample,
                        string title, string exercise, string date, string time, TriggerList triggerList)
@@ -1594,6 +1597,8 @@ public class ForceSensorGraphABExport: ForceSensorGraphAB
                this.maxForceRaw = maxForceRaw;
                this.maxAvgForceInWindow = maxAvgForceInWindow;
                this.forceSensorAnalyzeMaxAVGInWindowSeconds = forceSensorAnalyzeMaxAVGInWindowSeconds;
+               this.maxAvgForceInWindowSampleStart = maxAvgForceInWindowSampleStart;
+               this.maxAvgForceInWindowSampleEnd = maxAvgForceInWindowSampleEnd;
                this.laterality = laterality;
                this.setCount = setCount;
                this.repCount = repCount;
@@ -1615,6 +1620,8 @@ public class ForceSensorGraphABExport: ForceSensorGraphAB
                        decimalChar + ";" +
                        Util.ConvertToPoint(maxForceRaw) + ";" +
                        Util.ConvertToPoint(maxAvgForceInWindow) + ";" +
+                       maxAvgForceInWindowSampleStart + ";" +
+                       maxAvgForceInWindowSampleEnd + ";" +
                        fsco.ToString() + ";" +
                        title + ";" +
                        exercise + ";" +
@@ -1631,7 +1638,8 @@ public class ForceSensorGraphABExport: ForceSensorGraphAB
 
        public static string PrintCSVHeaderOnExport()
        {
-               return "fullURL;decimalChar;maxForceRaw;maxAvgForceInWindow;" +
+               return "fullURL;decimalChar;maxForceRaw;" +
+                       "maxAvgForceInWindow;maxAvgForceInWindowSampleStart;maxAvgForceInWindowSampleEnd;" +
                        "captureOptions;title;exercise;date;time;laterality;set;rep;" +
                        "triggersON;triggersOFF;" + //unused on export
                        "startSample;endSample;comments";
@@ -2848,10 +2856,15 @@ public class ForceSensorExport
                                else if(rep.type == ForceSensorRepetition.Types.ECC && 
repConcentricSampleStart != -1)
                                {
                                        double maxAvgForceInWindow = 0;
+                                       double maxAvgForceInWindowSampleStart = 0;
+                                       double maxAvgForceInWindowSampleEnd = 0;
                                        bool success = fsAI.CalculateRangeParams(repConcentricSampleStart, 
rep.sampleEnd,
                                                        forceSensorAnalyzeMaxAVGInWindowSeconds);
-                                       if(success)
+                                       if(success) {
                                                maxAvgForceInWindow = fsAI.ForceMaxAvgInWindow;
+                                               maxAvgForceInWindowSampleStart = 
fsAI.ForceMaxAvgInWindowSampleStart;
+                                               maxAvgForceInWindowSampleEnd = 
fsAI.ForceMaxAvgInWindowSampleEnd;
+                                       }
 
                                        if(! addedSet) {
                                                fsesm.AddSet(p.UniqueID, fsEx.UniqueID, fs.Laterality);
@@ -2863,6 +2876,8 @@ public class ForceSensorExport
                                                                fsAI.ForceMAX,                  //raw
                                                                maxAvgForceInWindow,            //raw
                                                                forceSensorAnalyzeMaxAVGInWindowSeconds, //raw
+                                                               maxAvgForceInWindowSampleStart, //the start 
sample of the result
+                                                               maxAvgForceInWindowSampleEnd,   //the end 
sample of the result
                                                                fs.Laterality,
                                                                fsesm.GetCount(p.UniqueID, fsEx.UniqueID, 
fs.Laterality),
                                                                repCount ++,
@@ -2899,10 +2914,15 @@ public class ForceSensorExport
                                }
 
                                double maxAvgForceInWindow = 0;
+                               double maxAvgForceInWindowSampleStart = 0;
+                               double maxAvgForceInWindowSampleEnd = 0;
                                bool success = fsAI.CalculateRangeParams(sampleA, sampleB,
                                                forceSensorAnalyzeMaxAVGInWindowSeconds);
-                               if(success)
+                               if(success) {
                                        maxAvgForceInWindow = fsAI.ForceMaxAvgInWindow;
+                                       maxAvgForceInWindowSampleStart = fsAI.ForceMaxAvgInWindowSampleStart;
+                                       maxAvgForceInWindowSampleEnd = fsAI.ForceMaxAvgInWindowSampleEnd;
+                               }
 
                                if(! addedSet) {
                                        fsesm.AddSet(p.UniqueID, fsEx.UniqueID, fs.Laterality);
@@ -2914,6 +2934,8 @@ public class ForceSensorExport
                                                        fsAI.ForceMAX,                  //raw
                                                        maxAvgForceInWindow,            //raw
                                                        forceSensorAnalyzeMaxAVGInWindowSeconds, //raw
+                                                       maxAvgForceInWindowSampleStart, //the start sample of 
the result
+                                                       maxAvgForceInWindowSampleEnd,   //the end sample of 
the result
                                                        fs.Laterality,
                                                        fsesm.GetCount(p.UniqueID, fsEx.UniqueID, 
fs.Laterality),
                                                        repCount ++,


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