[chronojump] ForceSensor RFD automatic graph with exercise and date



commit c5d780b0a7daeb8f297e0d840580e8d86de53eb6
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Jan 31 18:28:00 2020 +0100

    ForceSensor RFD automatic graph with exercise and date

 r-scripts/maximumIsometricForce.R | 38 ++++++++++++++++++++++++++++++++++----
 src/forceSensor.cs                | 14 +++++++++++++-
 src/gui/app1/forceSensor.cs       | 14 +++++++++-----
 3 files changed, 56 insertions(+), 10 deletions(-)
---
diff --git a/r-scripts/maximumIsometricForce.R b/r-scripts/maximumIsometricForce.R
index e3efe5c7..c5482e2a 100644
--- a/r-scripts/maximumIsometricForce.R
+++ b/r-scripts/maximumIsometricForce.R
@@ -48,10 +48,32 @@ assignOptions <- function(options)
                testLength              = as.numeric(options[17]),
                captureOptions          = options[18],
                title                   = options[19],
-                scriptsPath            = options[20]
+               exercise                = options[20],
+               datetime                = options[21],
+                scriptsPath            = options[22]
         ))
 }
 
+fixTitleAndOtherStrings <- function(str)
+{
+       print(c("1 fixTitle=", str))
+       #unicoded titles arrive here like this "\\", convert to "\", as this is difficult, do like this:
+       #http://stackoverflow.com/a/17787736
+       str=parse(text = paste0("'", str, "'"))
+       print(c("2 fixTitle=", str))
+
+       #convert str to spaces
+       str=gsub('_',' ', str)
+       str=gsub('-','    ', str)
+
+       return (str)
+}
+fixDatetime <- function(str)
+{
+       str=gsub('_',' ', str)
+       str=gsub('-',':', str)
+}
+
 #-------------- get params -------------
 args <- commandArgs(TRUE)
 
@@ -67,6 +89,12 @@ options <- scan(optionsFile, comment.char="#", what=character(), sep="\n")
 op <- assignOptions(options)
 print(op)
 
+op$title = fixTitleAndOtherStrings(op$title)
+op$exercise = fixTitleAndOtherStrings(op$exercise)
+titleFull = paste(op$title, op$exercise, sep=" - ")
+
+op$datetime = fixDatetime(op$datetime)
+
 source(paste(op$scriptsPath, "/scripts-util.R", sep=""))
 
 
@@ -226,7 +254,7 @@ drawDynamicsFromLoadCell <- function(
                 yHeight = max(dynamics$fmax.raw, dynamics$fmax.fitted) * 1.1
         }
                 
-       par(mar=c(4,4,1,1))
+       par(mar=c(4,4,3,1))
         #Plotting raw data from startTime to endTime (Only the analysed data)
         if (!is.na(xlimits[1])){
                 xWidth = xlimits[2] - xlimits[1]
@@ -234,8 +262,9 @@ drawDynamicsFromLoadCell <- function(
                      type="l", xlab="Time[s]", ylab="Force[N]",
                      xlim = xlimits, ylim=c(0, yHeight),
                      #main = dynamics$nameOfFile,
-                    main = paste(parse(text = paste0("'", op$title, "'"))), #process unicode, needed paste 
because its an expression. See graph.R
+                    main = paste(parse(text = paste0("'", titleFull, "'"))), #process unicode, needed paste 
because its an expression. See graph.R
                     yaxs= "i", xaxs = "i")
+               mtext(op$datetime, line = 0)
                 xmin = xlimits[1]
                 xmax = xlimits[2]
                 #points(dynamics$time[dynamics$startSample:dynamics$endSample] , 
dynamics$f.raw[dynamics$startSample:dynamics$endSample])
@@ -248,8 +277,9 @@ drawDynamicsFromLoadCell <- function(
                      xlim = c(xmin, xmax),
                      ylim=c(0, yHeight),
                      #main = dynamics$nameOfFile,
-                    main = paste(parse(text = paste0("'", op$title, "'"))), #process unicode, needed paste 
because its an expression. See graph.R
+                    main = paste(parse(text = paste0("'", titleFull, "'"))), #process unicode, needed paste 
because its an expression. See graph.R
                     yaxs= "i", xaxs = "i")
+               mtext(op$datetime, line = 0)
         }
         
 
diff --git a/src/forceSensor.cs b/src/forceSensor.cs
index 021c91fe..48e1d4d6 100644
--- a/src/forceSensor.cs
+++ b/src/forceSensor.cs
@@ -276,6 +276,12 @@ public class ForceSensor
                        return Util.GetVideoFileName(sessionID, Constants.TestTypes.FORCESENSOR, uniqueID);
                }
        }
+
+       public string DateTimePublic
+       {
+               get { return dateTime; }
+       }
+
        public string Filename
        {
                get { return filename; }
@@ -1236,15 +1242,19 @@ public class ForceSensorGraph
        bool hline50fmax_fitted;
        int testLength;
        string title;
+       string exercise;
+       string datetime;
 
        public ForceSensorGraph(ForceSensor.CaptureOptions fsco, List<ForceSensorRFD> rfdList,
-                       ForceSensorImpulse impulse, int testLength, string title)
+                       ForceSensorImpulse impulse, int testLength, string title, string exercise, string 
datetime)
        {
                this.fsco = fsco;
                this.rfdList = rfdList;
                this.impulse = impulse;
                this.testLength = testLength;
                this.title = title;
+               this.exercise = exercise;
+               this.datetime = datetime;
 
                averageLength = 0.1;
                percentChange = 5;
@@ -1300,6 +1310,8 @@ public class ForceSensorGraph
                        "\n#testLength\n" +             testLength.ToString() + "\n" +
                        "#captureOptions\n" +           fsco.ToString() + "\n" +
                        "#title\n" +                    title + "\n" +
+                       "#exercise\n" +                 exercise + "\n" +
+                       "#datetime\n" +                 datetime + "\n" +
                        "#scriptsPath\n" +              UtilEncoder.GetScriptsPath() + "\n";
 
                TextWriter writer = File.CreateText(Path.GetTempPath() + "Roptions.txt");
diff --git a/src/gui/app1/forceSensor.cs b/src/gui/app1/forceSensor.cs
index bf3045d5..d8327285 100644
--- a/src/gui/app1/forceSensor.cs
+++ b/src/gui/app1/forceSensor.cs
@@ -1754,16 +1754,20 @@ LogB.Information(" fs R ");
                if(radio_force_duration_seconds.Active)
                        duration = Convert.ToInt32(spin_force_duration_seconds.Value);
 
-               string title = lastForceSensorFile;
-               if (UtilAll.IsWindows())
+               //string title = lastForceSensorFile;
+               string title = currentPerson.Name;
+               string exercise = currentForceSensorExercise.Name;
+               if (UtilAll.IsWindows()) {
                        title = Util.ConvertToUnicode(title);
+                       exercise = Util.ConvertToUnicode(exercise);
+               }
 
                if (title == null || title == "")
                        title = "unnamed";
-               else
-                       title = Util.RemoveChar(title, '_');
+               //else
+               //      title = Util.RemoveChar(title, '_');
 
-               ForceSensorGraph fsg = new ForceSensorGraph(getForceSensorCaptureOptions(), rfdList, impulse, 
duration, title);
+               ForceSensorGraph fsg = new ForceSensorGraph(getForceSensorCaptureOptions(), rfdList, impulse, 
duration, title, exercise, currentForceSensor.DateTimePublic);
 
                int imageWidth = UtilGtk.WidgetWidth(viewport_force_sensor_graph);
                int imageHeight = UtilGtk.WidgetHeight(viewport_force_sensor_graph);


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