[chronojump] Doing capture method adding to a file (WIP)



commit 9b25da95929ef07f5f24a5873fa057248be3a968
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Mar 5 19:29:43 2015 +0100

    Doing capture method adding to a file (WIP)

 encoder/capture.R  |   50 +++++++++++++++++++++++++++++++++++---------------
 encoder/graph.R    |   13 +++++++++----
 src/gui/encoder.cs |   43 +++++++++++++++++++++++++++++++++++--------
 3 files changed, 79 insertions(+), 27 deletions(-)
---
diff --git a/encoder/capture.R b/encoder/capture.R
index f51d8bd..da362a1 100644
--- a/encoder/capture.R
+++ b/encoder/capture.R
@@ -27,11 +27,17 @@ scriptUtilR = options[28]
 source(scriptUtilR)
 
 g = 9.81
+
+debug = FALSE
                    
+filename = "/tmp/captured.txt"; #TODO HARDCODED!!!
+file.create(filename)
+
 
 calcule <- function(displacement, start, end, op) 
 {
-write("At calcule", stderr())
+       if(debug)
+               write("At calcule", stderr())
        #read AnalysisOptions
        #if is propulsive and rotatory inertial is: "p;ri" 
        #if nothing: "-;-"
@@ -54,7 +60,8 @@ write("At calcule", stderr())
        }
 
 
-write("At calcule calling kinematics", stderr())
+       if(debug)
+               write("At calcule calling kinematics", stderr())
        kinematicsResult <- kinematicsF(displacement, 
                    op$MassBody, op$MassExtra, op$ExercisePercentBodyWeight,
                    op$EncoderConfigurationName, op$diameter, op$diameterExt, op$anglePush, op$angleWeight, 
op$inertiaMomentum, op$gearedDown,
@@ -68,15 +75,22 @@ write("At calcule calling kinematics", stderr())
        position = cumsum(displacement)
 
        #do not use print because it shows the [1] first. Use cat:
-       cat(paste(#start, #start is not used because we have no data of the initial zeros
-                 #(end-start), (position[end]-position[start]), #this is not used because the start, end 
values are not ok now
+       #cat(paste(#start, #start is not used because we have no data of the initial zeros
+       #         #(end-start), (position[end]-position[start]), #this is not used because the start, end 
values are not ok now
+       #         0, 0, 
+       #         paf$meanSpeed, paf$maxSpeed, paf$maxSpeedT, 
+       #         paf$meanPower, paf$peakPower, paf$peakPowerT, paf$pp_ppt, 
+       #         paf$meanForce, paf$maxForce, paf$maxForceT,
+       #         sep=", "))
+       #cat("\n") #mandatory to read this from C#, but beware, there we will need a trim to remove the 
windows \r\n
+       write(paste(#start, #start is not used because we have no data of the initial zeros
                  0, 0, 
                  paf$meanSpeed, paf$maxSpeed, paf$maxSpeedT, 
                  paf$meanPower, paf$peakPower, paf$peakPowerT, paf$pp_ppt, 
                  paf$meanForce, paf$maxForce, paf$maxForceT,
-                 sep=", "))
-       cat("\n") #mandatory to read this from C#, but beware, there we will need a trim to remove the 
windows \r\n
-write("ended calcule", stderr())
+                 sep=", "), filename, append=TRUE)
+       if(debug)
+               write("ended calcule", stderr())
 }
                
 getPositionStart <- function(input) 
@@ -108,19 +122,20 @@ uncompress <- function(curveSent)
        return (as.numeric(ints))
 }
 
-
-
 doProcess <- function() 
 {
-       write("doProcess", stderr())
+       if(debug)
+               write("doProcess", stderr())
        op <- assignOptions(options)
 
+
        #print ("----op----")
        #print (op)
        
        input <- readLines(f, n = 1L)
        while(input[1] != "Q") {
-               write("doProcess main while", stderr())
+               if(debug)
+                       write("doProcess main while", stderr())
                
                #Sys.sleep(4) #just to test how Chronojump reacts if process takes too long
                #cat(paste("input is:", input, "\n"))
@@ -141,7 +156,8 @@ doProcess <- function()
                }
                #-- curve readed
                
-               write("doProcess input", stderr())
+               if(debug)
+                       write("doProcess input", stderr())
                #write(input, stderr())
 
                #when data is sent uncompressed
@@ -154,7 +170,8 @@ doProcess <- function()
                displacement  = displacement[!is.na(displacement)]
 
 
-               write("doProcess 2", stderr())
+               if(debug)
+                       write("doProcess 2", stderr())
                if(isInertial(op$EncoderConfigurationName)) 
                {
                        displacement = fixDisplacementInertial(displacement, op$EncoderConfigurationName, 
op$diameter, op$diameterExt)
@@ -182,7 +199,8 @@ doProcess <- function()
 
                        displacement = displacement[start:end]
                }
-               write("doProcess 3", stderr())
+               if(debug)
+                       write("doProcess 3", stderr())
 
                #if isInertial: getDisplacementInertialBody separate phases using initial height of full 
extended person
                #so now there will be two different curves to process
@@ -205,10 +223,12 @@ doProcess <- function()
                } else {
                        calcule(displacement, start, end, op) #TODO: check this start, end
                }
-               write("doProcess 4", stderr())
+               if(debug)
+                       write("doProcess 4", stderr())
 
                input <- readLines(f, n = 1L)
        }
+
 }
                
 
diff --git a/encoder/graph.R b/encoder/graph.R
index 70b1d55..0aec293 100644
--- a/encoder/graph.R
+++ b/encoder/graph.R
@@ -64,6 +64,8 @@
 #
 #
 
+debug = FALSE
+
 #concentric, eccentric-concentric, repetitions of eccentric-concentric
 #currently only used "c" and "ec". no need of ec-rep because c and ec are repetitive
 #"ecS" is like ec but eccentric and concentric phases are separated, used in findCurves, this is good for 
treeview to know power... on the 2 phases
@@ -2335,10 +2337,13 @@ doProcess <- function(options)
                        curves = curves[-discardedCurves,]
 
                rownames(paf)=rownames(curves)
-               print("--------CURVES (propulsive is not calculated yet) --------------")
-               print(curves)
-               print("----------PAF---------------")
-               print(paf)
+               
+               if(debug) {
+                       print("--------CURVES (propulsive is not calculated yet) --------------")
+                       print(curves)
+                       print("----------PAF---------------")
+                       print(paf)
+               }
 
                if(op$Analysis == "powerBars") {
                        if(! singleFile) 
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index da10061..1edb644 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -4696,6 +4696,11 @@ public partial class ChronoJumpWindow
                                                "meanPower,peakPower,peakPowerT,pp_ppt," +
                                                "meanForce, maxForce, maxForceT");
 
+                                       string filename = "/tmp/captured.txt"; //HARDCODED
+                                       if(File.Exists(filename))
+                                               File.Delete(filename);
+
+                                       encoderCaptureReadedLines = 0;
                                        capturingCsharp = encoderCaptureProcess.CAPTURING;
 
                                        massDisplacedEncoder = UtilEncoder.GetMassByEncoderConfiguration( 
encoderConfigurationCurrent, 
@@ -4941,7 +4946,7 @@ LogB.Debug("B");
                pinfo.UseShellExecute = false;
                pinfo.RedirectStandardInput = true;
                pinfo.RedirectStandardError = true;
-               pinfo.RedirectStandardOutput = true; 
+               //pinfo.RedirectStandardOutput = true; 
 
                
 
@@ -4951,14 +4956,14 @@ try {
                pCaptureNoRDotNet.StartInfo = pinfo;
                
                // output will go here
-               pCaptureNoRDotNet.OutputDataReceived += new DataReceivedEventHandler(readingCurveFromR);
+               //pCaptureNoRDotNet.OutputDataReceived += new DataReceivedEventHandler(readingCurveFromR);
                pCaptureNoRDotNet.ErrorDataReceived += new DataReceivedEventHandler(readingCurveFromRerror);
 
                pCaptureNoRDotNet.Start();
 
                // Start asynchronous read of the output.
                // Caution: This has to be called after Start
-               pCaptureNoRDotNet.BeginOutputReadLine();
+               //pCaptureNoRDotNet.BeginOutputReadLine();
                pCaptureNoRDotNet.BeginErrorReadLine();
 
 LogB.Debug("D");
@@ -5024,14 +5029,36 @@ LogB.Debug("D");
 
 
        static bool needToRefreshTreeviewCapture;
-       private void readingCurveFromR (object sendingProcess, DataReceivedEventArgs curveFromR)
+       static int encoderCaptureReadedLines;
+       //private void readingCurveFromR (object sendingProcess, DataReceivedEventArgs curveFromR)
+       private void readingCurveFromR ()
        {
-               if (!String.IsNullOrEmpty(curveFromR.Data))
+               string filename = "/tmp/captured.txt"; //HARDCODED
+               if(! File.Exists(filename))
+                       return;
+               
+               //StreamReader reader = File.OpenText(filename);
+               //string line = reader.ReadLine();
+               
+               string line = "";
+               
+               //http://stackoverflow.com/a/119572
+               var lineCount = File.ReadLines(filename).Count();
+               if(lineCount > encoderCaptureReadedLines) {
+                       //http://stackoverflow.com/a/1262985
+                       line = File.ReadLines(filename).Skip(encoderCaptureReadedLines ++).Take(1).First();
+               }
+
+
+               //if (!String.IsNullOrEmpty(curveFromR.Data))
+               if (!String.IsNullOrEmpty(line))
                {
                        LogB.Information("Without trim");
-                       LogB.Information(curveFromR.Data);
+                       //LogB.Information(curveFromR.Data);
+                       LogB.Information(line);
 
-                       string trimmed = curveFromR.Data.Trim();
+                       //string trimmed = curveFromR.Data.Trim();
+                       string trimmed = line.Trim();
                        LogB.Information("With trim");
                        LogB.Information(trimmed);
 
@@ -5125,7 +5152,7 @@ LogB.Debug("D");
                                        updateEncoderCaptureGraph(true, true, true); //graphSignal, 
calcCurves, plotCurvesBars
                        } else {
                                //capturingSendCurveToR(); //unused, done while capturing
-                               //readingCurveFromR();
+                               readingCurveFromR();
                                
                                updateEncoderCaptureGraph(true, false, false); //graphSignal, no calcCurves, 
no plotCurvesBars
        


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