[chronojump] Call to maximumIsometricForce.R 50% done



commit e883b43ff5d750c84a5714ba9b7db39fa0fd1001
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Apr 6 18:50:07 2017 +0200

    Call to maximumIsometricForce.R 50% done

 chronojump.csproj                 |    1 +
 r-scripts/maximumIsometricForce.R |   18 +----
 src/Makefile.am                   |    1 +
 src/forceSensor.cs                |  130 +++++++++++++++++++++++++++++++++++++
 src/utilEncoder.cs                |    7 ++
 5 files changed, 143 insertions(+), 14 deletions(-)
---
diff --git a/chronojump.csproj b/chronojump.csproj
index c269f24..e54845b 100644
--- a/chronojump.csproj
+++ b/chronojump.csproj
@@ -1117,6 +1117,7 @@
     <Compile Include="src\gui\sprint.cs" />
     <Compile Include="src\sqlite\trigger.cs" />
     <Compile Include="src\trigger.cs" />
+    <Compile Include="src\forceSensor.cs" />
   </ItemGroup>
   <ItemGroup>
     <Folder Include="src\" />
diff --git a/r-scripts/maximumIsometricForce.R b/r-scripts/maximumIsometricForce.R
index 3e5f0b8..2ac1b67 100644
--- a/r-scripts/maximumIsometricForce.R
+++ b/r-scripts/maximumIsometricForce.R
@@ -37,10 +37,10 @@ endGraph <- function()
 assignOptions <- function(options) {
        return(list(
                    os          = options[1],
-                   averageLength = as.numeric(options[2]),
-                   percentChange = as.numeric(options[3]),
-                   graphWidth  = as.numeric(options[4]),
-                   graphHeight = as.numeric(options[5]),
+                   graphWidth  = as.numeric(options[2]),
+                   graphHeight = as.numeric(options[3]),
+                   averageLength = as.numeric(options[4]),
+                   percentChange = as.numeric(options[5]),
                    vlineT0     = as.numeric(options[6]),
                    vline50fmax.raw     = as.numeric(options[7]),
                    vline50fmax.fitted  = as.numeric(options[8]),
@@ -394,16 +394,6 @@ getMovingAverageForce <- function(test, averageLength = 0.1)
         return(movingAverageForce)
 }
 
-assignOptions <- function(options) {
-        return(list(
-                os             = options[1],
-                averageLength   = as.numeric(options[2]),
-                percentChange   = as.numeric(options[3]),
-                graphWidth     = as.numeric(options[4]),
-                graphHeight    = as.numeric(options[5])
-        ))
-}
-
 prepareGraph(op$os, pngFile, op$graphWidth, op$graphHeight)
 dynamics = getDynamicsFromLoadCellFile(dataFile, op$averageLength, op$percentChange)
 drawDynamicsFromLoadCell(dynamics, op$vlineT0, op$vline50fmax.raw, op$vline50fmax.fitted, 
op$hline50fmax.raw, op$hline50fmax.fitted,
diff --git a/src/Makefile.am b/src/Makefile.am
index ff30380..77933e0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -142,6 +142,7 @@ SOURCES = \
        event.cs\
        eventType.cs\
        FTD2XX_NET.cs\
+       forceSensor.cs\
        genericObjects.cs\
        json.cs\
        jump.cs\
diff --git a/src/forceSensor.cs b/src/forceSensor.cs
new file mode 100644
index 0000000..9b53f6a
--- /dev/null
+++ b/src/forceSensor.cs
@@ -0,0 +1,130 @@
+/*
+ * This file is part of ChronoJump
+ *
+ * ChronoJump is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or   
+ *    (at your option) any later version.
+ *    
+ * ChronoJump is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
+ *    GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ *  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> 
+ */
+
+using System;
+using System.IO;               //for detect OS
+using System.Collections.Generic; //List<T>
+
+public class ForceSensor
+{
+       double averageLength;
+       double percentChange;
+       bool vlineT0;
+       bool vline50fmax_raw;
+       bool vline50fmax_fitted;
+       bool hline50fmax_raw;
+       bool hline50fmax_fitted;
+       bool rfd0_fitted;
+       bool rfd100_raw;
+       bool rfd0_100_raw;
+       bool rfd0_100_fitted;
+       bool rfd200_raw;
+       bool rfd0_200_raw;
+       bool rfd0_200_fitted;
+       bool rfd50fmax_raw;
+       bool rfd50fmax_fitted;
+
+       public ForceSensor()
+       {
+               averageLength = 0.1; 
+               percentChange = 5;
+               vlineT0 = false;
+               vline50fmax_raw = false;
+               vline50fmax_fitted = false;
+               hline50fmax_raw = false;
+               hline50fmax_fitted = false;
+               rfd0_fitted = false;
+               rfd100_raw = false;
+               rfd0_100_raw = false;
+               rfd0_100_fitted = false;
+               rfd200_raw = false;
+               rfd0_200_raw = false;
+               rfd0_200_fitted = false;
+               rfd50fmax_raw = false;
+               rfd50fmax_fitted = false;
+       }
+
+       public bool CallR(int graphWidth, int graphHeight)
+       {
+               string executable = UtilEncoder.RProcessBinURL();
+               List<string> parameters = new List<string>();
+
+               //A) mifcript
+               string mifScript = UtilEncoder.GetmifScript();
+               if(UtilAll.IsWindows())
+                       mifScript = mifScript.Replace("\\","/");
+
+               parameters.Insert(0, "\"" + mifScript + "\"");
+
+               //B) tempPath
+               string tempPath = Path.GetTempPath();
+               if(UtilAll.IsWindows())
+                       tempPath = tempPath.Replace("\\","/");
+
+               parameters.Insert(1, "\"" + tempPath + "\"");
+
+               //C) writeOptions
+               writeOptionsFile(graphWidth, graphHeight);
+
+               LogB.Information("\nCalling mif R file ----->");
+
+               //D) call process
+               //ExecuteProcess.run (executable, parameters);
+               ExecuteProcess.Result execute_result = ExecuteProcess.run (executable, parameters);
+               //LogB.Information("Result = " + execute_result.stdout);
+
+               LogB.Information("\n<------ Done calling mif R file.");
+               return execute_result.success;
+       }
+
+       private void writeOptionsFile(int graphWidth, int graphHeight)
+       {
+               string scriptsPath = UtilEncoder.GetSprintPath();
+               if(UtilAll.IsWindows())
+                       scriptsPath = scriptsPath.Replace("\\","/");
+
+               string scriptOptions =
+                       "#os\n" +                       UtilEncoder.OperatingSystemForRGraphs() + "\n" +
+                       "#graphWidth\n" +               graphWidth.ToString() + "\n" +
+                       "#graphHeight\n" +              graphHeight.ToString() + "\n" +
+                       "#averageLength\n" +            Util.ConvertToPoint(averageLength) + "\n" +
+                       "#percentChange\n" +            Util.ConvertToPoint(percentChange) + "\n" +
+                       "#vlineT0\n" +                  Util.BoolToRBool(vlineT0) + "\n" +
+                       "#vline50fmax.raw\n" +          Util.BoolToRBool(vline50fmax_raw) + "\n" +
+                       "#vline50fmax.fitted\n" +       Util.BoolToRBool(vline50fmax_fitted) + "\n" +
+                       "#hline50fmax.raw\n" +          Util.BoolToRBool(hline50fmax_raw) + "\n" +
+                       "#hline50fmax.fitted\n" +       Util.BoolToRBool(hline50fmax_fitted) + "\n" +
+                       "#rfd0.fitted\n" +              Util.BoolToRBool(rfd0_fitted) + "\n" +
+                       "#rfd100.raw\n" +               Util.BoolToRBool(rfd100_raw) + "\n" +
+                       "#rfd0_100.raw\n" +             Util.BoolToRBool(rfd0_100_raw) + "\n" +
+                       "#rfd0_100.fitted\n" +          Util.BoolToRBool(rfd0_100_fitted) + "\n" +
+                       "#rfd200.raw\n" +               Util.BoolToRBool(rfd200_raw) + "\n" +
+                       "#rfd0_200.raw\n" +             Util.BoolToRBool(rfd0_200_raw) + "\n" +
+                       "#rfd0_200.fitted\n" +          Util.BoolToRBool(rfd0_200_fitted) + "\n" +
+                       "#rfd50fmax.raw\n" +            Util.BoolToRBool(rfd50fmax_raw) + "\n" +
+                       "#rfd50fmax.fitted\n" +         Util.BoolToRBool(rfd50fmax_fitted);
+
+               TextWriter writer = File.CreateText(Path.GetTempPath() + "Roptions.txt");
+               writer.Write(scriptOptions);
+               writer.Flush();
+               writer.Close();
+               ((IDisposable)writer).Dispose();
+       }
+}
diff --git a/src/utilEncoder.cs b/src/utilEncoder.cs
index 7a1d0fb..a29780f 100644
--- a/src/utilEncoder.cs
+++ b/src/utilEncoder.cs
@@ -247,6 +247,13 @@ public class UtilEncoder
                return System.IO.Path.Combine(Path.GetTempPath(), "sprintGraph.png");
        }
 
+       public static string GetmifPath() {
+               return System.IO.Path.Combine(Util.GetDataDir(), "r-scripts");
+       }
+       public static string GetmifScript() {
+               return System.IO.Path.Combine(GetSprintPath(), "maximumisometricForce.R");
+       }
+
        /********** end of r-scripts paths ************/
 
        private static string changeSpaceToSpaceMark(string myString) 


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