[chronojump] call to graph.R FFFast. Fixed neuromuscular call
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] call to graph.R FFFast. Fixed neuromuscular call
- Date: Mon, 5 May 2014 15:30:28 +0000 (UTC)
commit 0beab2f52d679e825d68879012e98aef7160832b
Author: Xavier de Blas <xaviblas gmail com>
Date: Mon May 5 17:28:52 2014 +0200
call to graph.R FFFast. Fixed neuromuscular call
encoder/Makefile.am | 1 +
encoder/call_graph.R | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++
encoder/graph.R | 49 +++-----------------------------
encoder/util.R | 4 ++-
src/constants.cs | 1 +
src/gui/encoder.cs | 9 +++++-
src/utilEncoder.cs | 25 +++++++++++++---
7 files changed, 112 insertions(+), 51 deletions(-)
---
diff --git a/encoder/Makefile.am b/encoder/Makefile.am
index cc1d691..639404d 100644
--- a/encoder/Makefile.am
+++ b/encoder/Makefile.am
@@ -1,6 +1,7 @@
encoderdatadir = @datadir@/@PACKAGE@/encoder
dist_encoderdata_DATA = pyserial_pyper.py \
+ call_graph.R \
graph.R \
inertia-momentum.R \
neuromuscularProfile.R \
diff --git a/encoder/call_graph.R b/encoder/call_graph.R
new file mode 100644
index 0000000..502e9e2
--- /dev/null
+++ b/encoder/call_graph.R
@@ -0,0 +1,74 @@
+#
+# 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) 2014- Xavier de Blas <xaviblas gmail com>
+#
+
+#Is A LOT faster to call this file from C#, and this file will do a source(scriptGraphR)
+#than calling that file directly
+#
+#This call_graph.R is not written for this purpose,
+#it's written to be called if RDotNet is not working. Then this fill will call graph.R
+#
+#if RDotNet works, then graph.R will be in memory and there's no need to write Roptions.txt,
+#and there's no nead reading it from here because it will be done using RDotNet
+
+
+
+args <- commandArgs(TRUE)
+optionsFile <- args[1]
+print(optionsFile)
+
+#--- user commands ---
+getOptionsFromFile <- function(optionsFile, lines) {
+ optionsCon <- file(optionsFile, 'r')
+ options=readLines(optionsCon, n=lines)
+ close(optionsCon)
+ return (options)
+}
+
+#way A. passing options to a file
+options <- getOptionsFromFile(optionsFile, 32)
+
+#way B. put options as arguments
+#unused because maybe command line gets too long
+#options <- commandArgs(TRUE)
+
+#print(options)
+
+OutputData2 <- options[4] #currently used to display processing feedback
+SpecialData <- options[5]
+OperatingSystem <- options[27]
+EncoderConfigurationName <- ""
+
+English = unlist(strsplit(options[30], "\\;"))
+Translated = unlist(strsplit(options[31], "\\;"))
+
+scriptGraphR = options[32]
+
+#write(paste("(1/5)",translate("Starting R")), OutputData2)
+write(paste("(1/5)","Starting R"), OutputData2)
+
+source(scriptGraphR)
+
+write(paste("(2/5)",translate("Loading libraries")), OutputData2)
+
+loadLibraries(OperatingSystem)
+
+write(paste("(3/5)",translate("Starting process")), OutputData2)
+
+doProcess(options)
diff --git a/encoder/graph.R b/encoder/graph.R
index dde17c7..40cdc55 100644
--- a/encoder/graph.R
+++ b/encoder/graph.R
@@ -71,45 +71,11 @@ eccons=c("c","ec","ecS","ce","ceS")
g = 9.81
-smoothingAll= 0.1
-
colSpeed="springgreen3"; colForce="blue2"; colPower="tomato2" #colors
#colSpeed="black"; colForce="black"; colPower="black" #black & white
cols=c(colSpeed,colForce,colPower); lty=rep(1,3)
-#--- user commands ---
-#way A. passing options to a file
-getOptionsFromFile <- function(optionsFile) {
- optionsCon <- file(optionsFile, 'r')
- options=readLines(optionsCon,n=31)
- close(optionsCon)
- return (options)
-}
-
-#way B. put options as arguments
-#unused because maybe command line gets too long
-#options <- commandArgs(TRUE)
-
-
-args <- commandArgs(TRUE)
-optionsFile =args[1]
-
-print(optionsFile)
-
-options=getOptionsFromFile(optionsFile)
-
-#print(options)
-
-OutputData2 = options[4] #currently used to display processing feedback
-SpecialData = options[5]
-OperatingSystem=options[27]
-EncoderConfigurationName = ""
-
-English = unlist(strsplit(options[30], "\\;"))
-Translated = unlist(strsplit(options[31], "\\;"))
-
-
#translate
translate <- function(englishWord) {
if(length(Translated[which(English == englishWord)]) == 0)
@@ -118,8 +84,6 @@ translate <- function(englishWord) {
return(Translated[which(English == englishWord)])
}
-write(paste("(1/5)",translate("Starting R")), OutputData2)
-
# This function converts top curve into bottom curve
#
@@ -2008,6 +1972,8 @@ doProcess <- function(options) {
#print(options[30])
#print(options[31])
+ #options 32 is this graph.R file and it's used in call_graph.R to call this as source (in RDotNet)
+
print(File)
print(OutputGraph)
@@ -2318,6 +2284,8 @@ doProcess <- function(options) {
#plot speed
par(new=T)
+
+ smoothingAll= 0.1
speed <- getSpeed(displacement, smoothingAll)
plot((1:length(displacement))/1000, speed$y, col="green2",
type="l",
@@ -2674,7 +2642,7 @@ doProcess <- function(options) {
}
npj <- neuromuscularProfileGetData(displacement, curves, (MassBody + MassExtra),
SmoothingOneC)
- if(npj == -1) {
+ if(is.double(npj) && npj == -1) {
plot(0,0,type="n",axes=F,xlab="",ylab="")
text(x=0,y=0,paste(translate("Not enough data."), "\n",
translate("Need at least three jumps executed on the odd
concentric phases"),
@@ -2858,11 +2826,4 @@ doProcess <- function(options) {
warnings()
}
-write(paste("(2/5)",translate("Loading libraries")), OutputData2)
-
-loadLibraries(OperatingSystem)
-
-write(paste("(3/5)",translate("Starting process")), OutputData2)
-
-doProcess(options)
diff --git a/encoder/util.R b/encoder/util.R
index 2fa0c1e..d396fe9 100644
--- a/encoder/util.R
+++ b/encoder/util.R
@@ -71,4 +71,6 @@ extrema <- function(y, ndata = length(y), ndatam1 = ndata - 1) {
}
list(minindex=minindex, maxindex=maxindex, nextreme=nextreme, cross=cross, ncross=ncross)
-}
+}
+
+
diff --git a/src/constants.cs b/src/constants.cs
index 80464a0..1f503f0 100644
--- a/src/constants.cs
+++ b/src/constants.cs
@@ -643,6 +643,7 @@ public class Constants
public static string EncoderScriptCaptureLinux = "pyserial_pyper.py";
public static string EncoderScriptCaptureWindows = "pyserial_pyper_windows.exe";
+ public static string EncoderScriptCallGraph = "call_graph.R";
public static string EncoderScriptGraph = "graph.R";
public static string EncoderScriptInertiaMomentum = "inertia-momentum.R";
public static string EncoderScriptUtilR = "util.R";
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index f1760cc..4d8da99 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -1866,15 +1866,22 @@ public partial class ChronoJumpWindow
//load extrema method copied from EMD package
string utilRPath = UtilEncoder.GetEncoderScriptUtilR();
+ string graphRPath = UtilEncoder.GetEncoderScriptGraph();
//On win32 R understands backlash as an escape character and
//a file path uses Unix-like path separator '/'
- if(UtilAll.IsWindows())
+ if(UtilAll.IsWindows()) {
utilRPath = utilRPath.Replace("\\","/");
+ graphRPath = graphRPath.Replace("\\","/");
+ }
Log.WriteLine(utilRPath);
+ Log.WriteLine(graphRPath);
try {
+ //load extrema
rengine.Evaluate("source('" + utilRPath + "')");
+ //load more stuff and call later using RDotNet
+ rengine.Evaluate("source('" + graphRPath + "')");
} catch {
RInitialized = Constants.Status.ERROR;
return;
diff --git a/src/utilEncoder.cs b/src/utilEncoder.cs
index aa46e2c..df0c5f9 100644
--- a/src/utilEncoder.cs
+++ b/src/utilEncoder.cs
@@ -156,7 +156,18 @@ public class UtilEncoder
Util.GetDataDir(), "encoder", Constants.EncoderScriptCaptureLinux);
}
- private static string getEncoderScriptGraph() {
+
+ /*
+ * in RDotNet, graph.R is in memory, and call_graph.R is not called
+ * if RDotNet is not working, then call_graph.R is called and this calls graph.R
+ */
+
+ private static string getEncoderScriptCallGraph() {
+ return System.IO.Path.Combine(
+ Util.GetDataDir(), "encoder", Constants.EncoderScriptCallGraph);
+ }
+
+ public static string GetEncoderScriptGraph() {
return System.IO.Path.Combine(
Util.GetDataDir(), "encoder", Constants.EncoderScriptGraph);
}
@@ -260,6 +271,8 @@ public class UtilEncoder
string scriptNeuromuscularProfile = "none"; //cannot be blank
if(neuromuscularProfileDo)
scriptNeuromuscularProfile = GetEncoderScriptNeuromuscularProfile();
+
+ string scriptGraphR = GetEncoderScriptGraph();
pBin="Rscript";
//pBin="R";
@@ -280,6 +293,7 @@ public class UtilEncoder
es.SpecialData = es.SpecialData.Replace("\\","/");
scriptUtilR = scriptUtilR.Replace("\\","/");
scriptNeuromuscularProfile = scriptNeuromuscularProfile.Replace("\\","/");
+ scriptGraphR = scriptGraphR.Replace("\\","/");
operatingSystem = "Windows";
}
@@ -301,7 +315,8 @@ public class UtilEncoder
es.Ep.ToString2("\n") + "\n" + title + "\n" + operatingSystem + "\n" +
scriptUtilR + "\n" + scriptNeuromuscularProfile + "\n" +
Util.StringArrayToString(Constants.EncoderEnglishWords,";") + "\n" +
- Util.StringArrayToString(encoderTranslatedWordsOK,";") + "\n";
+ Util.StringArrayToString(encoderTranslatedWordsOK,";") + "\n" +
+ scriptGraphR + "\n";
string optionsFile = Path.GetTempPath() + "Roptions.txt";
@@ -317,13 +332,13 @@ public class UtilEncoder
}
//on Windows we need the \"str\" to call without problems in path with spaces
- pinfo.Arguments = "\"" + getEncoderScriptGraph() + "\" " + optionsFile;
+ pinfo.Arguments = "\"" + getEncoderScriptCallGraph() + "\" " + optionsFile;
Log.WriteLine("Arguments:" + pinfo.Arguments);
/*
pinfo.Arguments = "CMD BATCH --no-save '--args optionsFile=\"" + optionsFile + "\"' \"" +
- getEncoderScriptGraph() + "\" \"" +
+ getEncoderScriptCallGraph() + "\" \"" +
Path.GetTempPath() + "error.txt\"";
*/
@@ -333,7 +348,7 @@ public class UtilEncoder
es.OutputGraph + " " + es.OutputData1 + " " + es.OutputData2 + " " +
es.Ep.ToString2(" ") + " " + title;
- pinfo.Arguments = getEncoderScriptGraph() + " " + argumentOptions;
+ pinfo.Arguments = getEncoderScriptCallGraph() + " " + argumentOptions;
*/
Log.WriteLine("------------- 1 ---");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]