[chronojump] capture.R reads options
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] capture.R reads options
- Date: Mon, 19 Jan 2015 20:28:57 +0000 (UTC)
commit cd8fd952ccfd8dda14e435b03a5406ed7f058983
Author: Xavier de Blas <xaviblas gmail com>
Date: Mon Jan 19 21:28:21 2015 +0100
capture.R reads options
encoder/capture.R | 59 ++++++++++++++++++----------------
encoder/util.R | 3 +-
src/gui/encoder.cs | 89 ++++++++++++++++++++++++++++++++++++----------------
src/utilEncoder.cs | 8 +++--
4 files changed, 100 insertions(+), 59 deletions(-)
---
diff --git a/encoder/capture.R b/encoder/capture.R
index 852f6f3..863f12e 100644
--- a/encoder/capture.R
+++ b/encoder/capture.R
@@ -1,8 +1,9 @@
#http://stackoverflow.com/questions/26053302/is-there-a-way-to-use-standard-input-output-stream-to-communicate-c-sharp-and-r/26058010#26058010
#Caution: Do not 'print, cat' stuff because it's readed from gui/encoder as results
+#it can be printed safely to stderr. See end of this file
-#cat("Arrived at capture.R\n")
+write("Arriving at capture.R", stderr())
f <- file("stdin")
open(f)
@@ -19,11 +20,12 @@ getOptionsFromFile <- function(optionsFile, lines) {
return (options)
}
-options <- getOptionsFromFile(optionsFile, 1)
+#options <- getOptionsFromFile(optionsFile, 1)
+options <- getOptionsFromFile(optionsFile, 32)
-scriptUtilR = options[1]
-
+#scriptUtilR = options[1]
+scriptUtilR = options[28]
source(scriptUtilR)
#print("Loaded libraries")
@@ -32,6 +34,11 @@ input <- readLines(f, n = 1L)
while(input[1] != "Q") {
#Sys.sleep(4) #just to test how Chronojump reacts if process takes too long
#cat(paste("input is:", input, "\n"))
+
+ op <- assignOptions(options)
+
+ #print ("----op----")
+ #print (op)
displacement = as.numeric(unlist(strsplit(input, " ")))
#if data file ends with comma. Last character will be an NA. remove it
@@ -40,10 +47,10 @@ while(input[1] != "Q") {
position = cumsum(displacement)
- reduceTemp = reduceCurveBySpeed("c", 1,
+ reduceTemp = reduceCurveBySpeed(op$Eccon, 1,
1, 0, #startT, startH
displacement, #displacement
- .7 #SmoothingOneC
+ op$SmoothingOneC #SmoothingOneC
)
start = reduceTemp[1]
end = reduceTemp[2]
@@ -57,33 +64,30 @@ while(input[1] != "Q") {
#print("reduced")
- myMassBody = 50
- myMassExtra = 100
- myExPercentBodyWeight = 0
- myEncoderConfigurationName = "LINEAR"
- myDiameter = 0
- myDiameterExt = 0
- myAnglePush = 90
- myAngleWeight = 90
- myInertiaMomentum = 0
- myGearedDown = 0
- SmoothingsEC = 0.7
- SmoothingOneC = 0.7
g = 9.81
- myEcconKn = "c" #in ec can be "e" or "c"
- isPropulsive = TRUE
-
+
+ #read AnalysisOptions
+ #if is propulsive and rotatory inertial is: "p;ri"
+ #if nothing: "-;-"
+ analysisOptionsTemp = unlist(strsplit(op$AnalysisOptions, "\\;"))
+ isPropulsive = (analysisOptionsTemp[1] == "p")
+
+
+ #simplify on capture and have the SmoothingEC == SmoothingC
+ SmoothingsEC = op$SmoothingOneC
+
#print("pre kinematicsResult")
+
kinematicsResult <- kinematicsF(displacement,
- myMassBody, myMassExtra, myExPercentBodyWeight,
-
myEncoderConfigurationName,myDiameter,myDiameterExt,myAnglePush,myAngleWeight,myInertiaMomentum,myGearedDown,
- SmoothingsEC,SmoothingOneC,
- g, myEcconKn, isPropulsive)
+ op$MassBody, op$MassExtra, op$ExercisePercentBodyWeight,
+ op$EncoderConfigurationName, op$diameter, op$diameterExt, op$anglePush, op$angleWeight,
op$inertiaMomentum, op$gearedDown,
+ SmoothingsEC, op$SmoothingOneC,
+ g, op$Eccon, isPropulsive)
#print("kinematicsResult")
#print(kinematicsResult)
- paf = pafGenerate("c", kinematicsResult, myMassBody, myMassExtra)
+ paf = pafGenerate("c", kinematicsResult, op$MassBody, op$MassExtra)
#print("paf")
#print(paf)
@@ -94,5 +98,6 @@ while(input[1] != "Q") {
input <- readLines(f, n = 1L)
}
-#cat("Ending capture.R\n")
+
+write("Ending capture.R", stderr())
quit()
diff --git a/encoder/util.R b/encoder/util.R
index 8c92a4b..6359070 100644
--- a/encoder/util.R
+++ b/encoder/util.R
@@ -2,11 +2,10 @@
#It's included here to save time, because 'library("EMD")' is quite time consuming
#Caution: do not 'print, cat' stuff because (on captureR) it's readed from gui/encoder as results
+#it can be printed safely to stderr. See end capture.R
#used in graph.R and capture.R
assignOptions <- function(options) {
- print(options[25])
- print(options[26])
return(list(
File = options[1],
OutputGraph = options[2],
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 52d2f5b..0a3b432 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -386,7 +386,7 @@ public partial class ChronoJumpWindow
/*
* DEPRECATED
- string analysisOptions = getEncoderAnalysisOptions(true);
+ string analysisOptions = getEncoderAnalysisOptions();
double heightHigherCondition = -1;
if(repetitiveConditionsWin.EncoderHeightHigher)
@@ -684,7 +684,7 @@ public partial class ChronoJumpWindow
}
- private string getEncoderAnalysisOptions(bool captureOrAnalyze) {
+ private string getEncoderAnalysisOptions() {
string analysisOptions = "-";
if(preferences.encoderPropulsive)
analysisOptions = "p";
@@ -700,7 +700,7 @@ public partial class ChronoJumpWindow
{
string analysis = "curves";
- string analysisOptions = getEncoderAnalysisOptions(true);
+ string analysisOptions = getEncoderAnalysisOptions();
//see explanation on the top of this file
lastEncoderSQLSignal = new EncoderSQL(
@@ -1406,7 +1406,7 @@ public partial class ChronoJumpWindow
void on_button_encoder_export_all_curves_file_selected (string selectedFileName)
{
- string analysisOptions = getEncoderAnalysisOptions(true);
+ string analysisOptions = getEncoderAnalysisOptions();
string displacedMass = Util.ConvertToPoint( lastEncoderSQLSignal.extraWeight + (
getExercisePercentBodyWeightFromName(lastEncoderSQLSignal.exerciseName) *
@@ -1957,7 +1957,6 @@ public partial class ChronoJumpWindow
REngine rengine;
- static Process processCaptureNoRDotNet;
int encoderSelectedMinimumHeight;
private bool runEncoderCaptureCsharp(string title, int time, string outputData1, string port)
@@ -2177,9 +2176,7 @@ public partial class ChronoJumpWindow
heightCurve >=
encoderSelectedMinimumHeight &&
( ( eccon == "c" &&
previousWasUp ) || eccon != "c" )
) {
-
UtilEncoder.RunEncoderCaptureNoRDotNetSendCurve(
-
processCaptureNoRDotNet,
- curve);
+
UtilEncoder.RunEncoderCaptureNoRDotNetSendCurve(pCaptureNoRDotNet, curve);
ecca.curvesDone ++;
ecca.curvesAccepted ++;
ecca.ecc.Add(ecc);
@@ -2236,7 +2233,7 @@ public partial class ChronoJumpWindow
EncoderParams ep = new EncoderParams();
string dataFileName = "";
- string analysisOptions = getEncoderAnalysisOptions(false);
+ string analysisOptions = getEncoderAnalysisOptions();
//use this send because we change it to send it to R
//but we don't want to change encoderAnalysis because we want to know again if == "cross"
@@ -4434,7 +4431,7 @@ public partial class ChronoJumpWindow
}
*/
} else
- processCaptureNoRDotNet =
runEncoderCaptureNoRDotNetInitialize();
+ runEncoderCaptureNoRDotNetInitialize();
}
@@ -4596,8 +4593,39 @@ public partial class ChronoJumpWindow
- Process pCaptureNoRDotNet;
- private Process runEncoderCaptureNoRDotNetInitialize()
+ private void runEncoderCaptureNoRDotNetInitialize()
+ {
+ EncoderParams ep = new EncoderParams(
+ (int) encoderCaptureOptionsWin.spin_encoder_capture_min_height.Value,
+ getExercisePercentBodyWeightFromCombo (),
+ Util.ConvertToPoint(findMass(Constants.MassType.BODY)),
+ Util.ConvertToPoint(findMass(Constants.MassType.EXTRA)),
+ findEccon(true), //force ecS (ecc-conc
separated)
+ "-", //analysis
+ "none", //analysisVariables (not needed in create curves). Cannot be
blank
+ getEncoderAnalysisOptions(), //used on capture for pass the 'p' of
propulsive
+ encoderConfigurationCurrent,
+ Util.ConvertToPoint(preferences.encoderSmoothCon), //R decimal: '.'
+ 0, //curve is not used here
+ image_encoder_width, image_encoder_height,
+ preferences.CSVExportDecimalSeparator
+ );
+
+ EncoderStruct es = new EncoderStruct(
+ "none", //UtilEncoder.GetEncoderDataTempFileName(),
+ "none", //UtilEncoder.GetEncoderGraphTempFileName(),
+ "none", //UtilEncoder.GetEncoderCurvesTempFileName(),
+ "none", //UtilEncoder.GetEncoderStatusTempBaseFileName(),
+ "none", //SpecialData
+ ep);
+
+ runEncoderCaptureNoRDotNetStart(es);
+ }
+
+ private Process pCaptureNoRDotNet;
+
+ //this has to here (and not in UtilEncode.cs) in order to be able to call: readingCurveFromR
+ private void runEncoderCaptureNoRDotNetStart(EncoderStruct es)
{
LogB.Debug("A");
ProcessStartInfo pinfo;
@@ -4615,9 +4643,13 @@ LogB.Debug("A");
}
LogB.Debug("B");
- string scriptOptions = UtilEncoder.GetEncoderScriptUtilR();
- if (UtilAll.IsWindows())
- scriptOptions = scriptOptions.Replace("\\","/");
+
+ string scriptOptions = UtilEncoder.PrepareEncoderGraphOptions(
+ "none", //title
+ es,
+ false, //neuromuscularProfile
+ false //translate (graphs)
+ ).ToString();
string optionsFile = Path.GetTempPath() + "Roptions.txt";
@@ -4648,17 +4680,19 @@ LogB.Debug("B");
LogB.Debug("C");
- Process pCaptureNoRDotNet = new Process();
+ pCaptureNoRDotNet = new Process();
pCaptureNoRDotNet.StartInfo = pinfo;
// output will go here
pCaptureNoRDotNet.OutputDataReceived += new DataReceivedEventHandler(readingCurveFromR);
- //pCaptureNoRDotNet.ErrorDataReceived += new DataReceivedEventHandler(readingCurveFromRerror);
+ pCaptureNoRDotNet.ErrorDataReceived += new DataReceivedEventHandler(readingCurveFromRerror);
pCaptureNoRDotNet.Start();
// Start asynchronous read of the output.
+ // Caution: This has to be called after Start
pCaptureNoRDotNet.BeginOutputReadLine();
+ pCaptureNoRDotNet.BeginErrorReadLine();
LogB.Debug("D");
// LogB.Information(p.StandardOutput.ReadToEnd());
@@ -4667,9 +4701,9 @@ LogB.Debug("D");
// p.WaitForExit();
// while ( ! ( File.Exists(outputFileCheck) || CancelRScript ) );
-
- return pCaptureNoRDotNet;
}
+
+
/*
* unused, done while capturing
@@ -4708,7 +4742,7 @@ LogB.Debug("D");
LogB.Information("Sending... ");
UtilEncoder.RunEncoderCaptureNoRDotNetSendCurve(
- processCaptureNoRDotNet,
+ pCaptureNoRDotNet,
curve);
ecca.curvesAccepted ++;
@@ -4725,12 +4759,12 @@ LogB.Debug("D");
if (!String.IsNullOrEmpty(curveFromR.Data))
{
- LogB.Warning("Without trim");
- LogB.Warning(curveFromR.Data);
+ LogB.Information("Without trim");
+ LogB.Information(curveFromR.Data);
string trimmed = curveFromR.Data.Trim();
- LogB.Warning("With trim");
- LogB.Warning(trimmed);
+ LogB.Information("With trim");
+ LogB.Information(trimmed);
/*
encoderCaptureStringR +=
string.Format("\n{0},2,a,3,4,{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},7",
@@ -4760,7 +4794,8 @@ LogB.Debug("D");
{
if (!String.IsNullOrEmpty(curveFromR.Data))
{
- LogB.Error(curveFromR.Data);
+ //use Warning because it's used also to print flow messages
+ LogB.Warning(curveFromR.Data);
}
}
@@ -4771,8 +4806,8 @@ LogB.Debug("D");
finishPulsebar(encoderActions.CURVES);
if(! useRDotNet) {
- UtilEncoder.RunEncoderCaptureNoRDotNetSendEnd(processCaptureNoRDotNet);
- processCaptureNoRDotNet.WaitForExit();
+ UtilEncoder.RunEncoderCaptureNoRDotNetSendEnd(pCaptureNoRDotNet);
+ pCaptureNoRDotNet.WaitForExit();
}
LogB.ThreadEnded();
diff --git a/src/utilEncoder.cs b/src/utilEncoder.cs
index 8c5c23c..e29987e 100644
--- a/src/utilEncoder.cs
+++ b/src/utilEncoder.cs
@@ -352,7 +352,7 @@ public class UtilEncoder
}
- private static EncoderGraphROptions prepareEncoderGraphOptions(string title, EncoderStruct es, bool
neuromuscularProfileDo, bool translate)
+ public static EncoderGraphROptions PrepareEncoderGraphOptions(string title, EncoderStruct es, bool
neuromuscularProfileDo, bool translate)
{
string scriptUtilR = GetEncoderScriptUtilR();
@@ -440,7 +440,7 @@ public class UtilEncoder
Log.WriteLine(meanPower.ToString());
rengine.Evaluate("print(findPosInPaf(\"Power\", \"max\"))");
- EncoderGraphROptions roptions = prepareEncoderGraphOptions(title, es, neuromuscularProfileDo);
+ EncoderGraphROptions roptions = PrepareEncoderGraphOptions(title, es, neuromuscularProfileDo);
Log.WriteLine(roptions.ToString());
//--------------------------------------------
@@ -472,6 +472,8 @@ public class UtilEncoder
}
*/
+
+
public static void RunEncoderCaptureNoRDotNetSendCurve(Process p, double [] d)
{
LogB.Debug("writing line 1");
@@ -512,7 +514,7 @@ public class UtilEncoder
}
- string scriptOptions = prepareEncoderGraphOptions(title, es, neuromuscularProfileDo,
translate).ToString();
+ string scriptOptions = PrepareEncoderGraphOptions(title, es, neuromuscularProfileDo,
translate).ToString();
string optionsFile = Path.GetTempPath() + "Roptions.txt";
TextWriter writer = File.CreateText(optionsFile);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]