[chronojump] Now export manages individually decimalIsPoint, also fix crash since recent commits



commit 978e0b8fb320c2f064224ef049a1e6e2f8f3f534
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Feb 9 12:32:56 2021 +0100

    Now export manages individually decimalIsPoint, also fix crash since recent commits

 r-scripts/maximumIsometricForce.R | 14 +++++++-------
 src/forceSensor.cs                | 26 +++++++++++++++++++++-----
 src/gui/app1/forceSensor.cs       |  1 +
 3 files changed, 29 insertions(+), 12 deletions(-)
---
diff --git a/r-scripts/maximumIsometricForce.R b/r-scripts/maximumIsometricForce.R
index d848d749..90eb469b 100644
--- a/r-scripts/maximumIsometricForce.R
+++ b/r-scripts/maximumIsometricForce.R
@@ -33,7 +33,7 @@ assignOptions <- function(options)
     
     return(list(
         os                     = options[1],
-        decimalChar            = options[2],
+        decimalChar            = options[2],   #unused on multiple
         graphWidth             = as.numeric(options[3]),
         graphHeight            = as.numeric(options[4]),
         averageLength          = as.numeric(options[5]),
@@ -111,11 +111,11 @@ getForceModel <- function(time, force, startTime, # startTime is the instant whe
     return(list(fmax = fmax, K = K, T0 = T0, error = 100*residuals(model)/mean(data$force)))
 }
 
-getDynamicsFromLoadCellFile <- function(captureOptions, inputFile, averageLength = 0.1, percentChange = 5, 
testLength = -1, startSample, endSample)
+getDynamicsFromLoadCellFile <- function(captureOptions, inputFile, decimalChar, averageLength = 0.1, 
percentChange = 5, testLength = -1, startSample, endSample)
 {
     print("Entered getDynamicsFromLoadCellFile")
     
-    originalTest = read.csv(inputFile, header = F, dec = op$decimalChar, sep = ";", skip = 2)
+    originalTest = read.csv(inputFile, header = F, dec = decimalChar, sep = ";", skip = 2)
     colnames(originalTest) <- c("time", "force")
     originalTest$time = as.numeric(originalTest$time / 1000000)  # Time is converted from microseconds to 
seconds
     
@@ -1075,7 +1075,7 @@ readImpulseOptions <- function(optionsStr)
     } 
 }
 
-doProcess <- function(dataFile, title, exercise, datetime, captureOptions, startSample, endSample)
+doProcess <- function(dataFile, decimalChar, title, exercise, datetime, captureOptions, startSample, 
endSample)
 {
        title = fixTitleAndOtherStrings(title)
        exercise = fixTitleAndOtherStrings(exercise)
@@ -1086,7 +1086,7 @@ doProcess <- function(dataFile, title, exercise, datetime, captureOptions, start
        prepareGraph(op$os, pngFile, op$graphWidth, op$graphHeight)
 
        print("Going to enter getDynamicsFromLoadCellFille")
-       dynamics = getDynamicsFromLoadCellFile(captureOptions, dataFile, op$averageLength, op$percentChange, 
testLength = op$testLength, startSample, endSample)
+       dynamics = getDynamicsFromLoadCellFile(captureOptions, dataFile, decimalChar, op$averageLength, 
op$percentChange, testLength = op$testLength, startSample, endSample)
 
        print("Going to draw")
        drawDynamicsFromLoadCell(titleFull, datetime, dynamics, captureOptions, op$vlineT0, 
op$vline50fmax.raw, op$vline50fmax.fitted, op$hline50fmax.raw, op$hline50fmax.fitted,
@@ -1098,7 +1098,7 @@ doProcess <- function(dataFile, title, exercise, datetime, captureOptions, start
 if(op$singleOrMultiple == "TRUE")
 {
        dataFile <- paste(tempPath, "/cj_mif_Data.csv", sep="")
-       doProcess(dataFile, op$title, op$exercise, op$datetime, op$captureOptions, op$startSample, 
op$endSample)
+       doProcess(dataFile, op$decimalChar, op$title, op$exercise, op$datetime, op$captureOptions, 
op$startSample, op$endSample)
 } else
 {
        #1) read the csv
@@ -1110,7 +1110,7 @@ if(op$singleOrMultiple == "TRUE")
                print(as.vector(dataFiles$fullURL[i]))
 
                executing  <- tryCatch({
-                               doProcess(as.vector(dataFiles$fullURL[i]), dataFiles$title[i], 
dataFiles$exercise[i], dataFiles$datetime[i],
+                               doProcess(as.vector(dataFiles$fullURL[i]), dataFiles$decimalChar[i], 
dataFiles$title[i], dataFiles$exercise[i], dataFiles$datetime[i],
                                                dataFiles$captureOptions[i], dataFiles$startSample[i], 
dataFiles$endSample[i])
                }, error = function(e) {
                        print("error on doProcess:")
diff --git a/src/forceSensor.cs b/src/forceSensor.cs
index 39e0083e..9bb00a33 100644
--- a/src/forceSensor.cs
+++ b/src/forceSensor.cs
@@ -1387,6 +1387,7 @@ public class ForceSensorImpulse : ForceSensorRFD
 public class ForceSensorGraphAB
 {
        public string fullURL;
+       public bool decimalIsPoint;
        public ForceSensor.CaptureOptions fsco;
        public int startSample;
        public int endSample;
@@ -1396,10 +1397,12 @@ public class ForceSensorGraphAB
        public TriggerList triggerList;
 
        public ForceSensorGraphAB (string fullURL,
+                       bool decimalIsPoint,
                        ForceSensor.CaptureOptions fsco, int startSample, int endSample,
                        string title, string exercise, string datetime, TriggerList triggerList)
        {
                this.fullURL = fullURL;
+               this.decimalIsPoint = decimalIsPoint;
                this.fsco = fsco;
                this.startSample = startSample;
                this.endSample = endSample;
@@ -1411,7 +1414,17 @@ public class ForceSensorGraphAB
 
        public string ToCSVRow()
        {
+               //since 2.0.3 decimalChar is . (before it was locale specific)
+               string decimalChar = ".";
+               if(! decimalIsPoint)
+               {
+                       System.Globalization.NumberFormatInfo localeInfo = new 
System.Globalization.NumberFormatInfo();
+                       localeInfo = System.Globalization.NumberFormatInfo.CurrentInfo;
+                       decimalChar = localeInfo.NumberDecimalSeparator;
+               }
+
                return fullURL + ";" +
+                       decimalChar + ";" +
                        fsco.ToString() + ";" +
                        title + ";" +
                        exercise + ";" +
@@ -1423,7 +1436,7 @@ public class ForceSensorGraphAB
 
        public static string PrintCSVHeader()
        {
-               return "fullURL;captureOptions;title;exercise;datetime;" +
+               return "fullURL;decimalChar;captureOptions;title;exercise;datetime;" +
                        "triggersON;triggersOFF;" + //unused on export
                        "startSample;endSample";
        }
@@ -1450,7 +1463,7 @@ public class ForceSensorGraph
        private int startSample;
        private int endSample;
        private bool startEndOptimized;
-       private bool decimalIsPoint;
+       private bool decimalIsPoint; //but on export this will be related to each set
 
        //private method to help on assigning params
        private void assignGenericParams(
@@ -1478,7 +1491,8 @@ public class ForceSensorGraph
        public ForceSensorGraph(
                        List<ForceSensorRFD> rfdList,
                        ForceSensorImpulse impulse, int testLength, int percentChange,
-                       bool startEndOptimized, bool decimalIsPoint,
+                       bool startEndOptimized,
+                       bool decimalIsPoint,
                        ForceSensorGraphAB fsgAB
                        )
        {
@@ -1499,7 +1513,8 @@ public class ForceSensorGraph
        public ForceSensorGraph(
                        List<ForceSensorRFD> rfdList,
                        ForceSensorImpulse impulse, int testLength, int percentChange,
-                       bool startEndOptimized, bool decimalIsPoint,
+                       bool startEndOptimized,
+                       bool decimalIsPoint, //this param is not used here. it is in fsgAB_l
                        List<ForceSensorGraphAB> fsgAB_l
                        )
        {
@@ -2472,6 +2487,7 @@ public class ForceSensorExport
                        {
                                fsgAB_l.Add(new ForceSensorGraphAB (
                                                        fs.FullURL,
+                                                       Util.CSVDecimalColumnIsPoint(fs.FullURL, 1),
                                                        fs.CaptureOption, rep.sampleStart, rep.sampleEnd,
                                                        title, exercise, fs.DateTimePublic, new TriggerList()
                                                        ));
@@ -2514,7 +2530,7 @@ public class ForceSensorExport
                                        rfdList, impulse,
                                        duration, durationPercent,
                                        forceSensorStartEndOptimized,
-                                       Util.CSVDecimalColumnIsPoint(UtilEncoder.GetmifCSVFileName(), 1),
+                                       true, //unused on export
                                        fsgAB_l
                                        );
 
diff --git a/src/gui/app1/forceSensor.cs b/src/gui/app1/forceSensor.cs
index a77ed57f..b9352736 100644
--- a/src/gui/app1/forceSensor.cs
+++ b/src/gui/app1/forceSensor.cs
@@ -2174,6 +2174,7 @@ LogB.Information(" fs R ");
                                Util.CSVDecimalColumnIsPoint(UtilEncoder.GetmifCSVFileName(), 1),
                                new ForceSensorGraphAB(
                                        "",     //unused on single graph (no export)
+                                       true,   //unused on single graph (no export)
                                        getForceSensorCaptureOptions(),
                                        sampleA, sampleB,
                                        title, exercise, currentForceSensor.DateTimePublic, 
triggerListForceSensor)


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