[chronojump] ForceSensor export manages differently decimalChar of file than of export



commit c1eb89d98944d24ae1f7fb7f3a2809f898d683ab
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Feb 16 18:56:23 2021 +0100

    ForceSensor export manages differently decimalChar of file than of export

 r-scripts/maximumIsometricForce.R  | 25 +++++++++++--------
 src/forceSensor.cs                 | 49 ++++++++++++++++++++++----------------
 src/gui/app1/forceSensor.cs        |  3 ++-
 src/gui/app1/forceSensorAnalyze.cs |  3 ++-
 src/preferences.cs                 | 12 ++++++++++
 5 files changed, 60 insertions(+), 32 deletions(-)
---
diff --git a/r-scripts/maximumIsometricForce.R b/r-scripts/maximumIsometricForce.R
index 78b3dc41..b76502b3 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],   #unused on multiple
+        decimalCharAtFile      = options[2],   #unused on multiple
         graphWidth             = as.numeric(options[3]),
         graphHeight            = as.numeric(options[4]),
         averageLength          = as.numeric(options[5]),
@@ -51,12 +51,13 @@ assignOptions <- function(options)
         exercise               = options[20],
         datetime               = options[21],
         scriptsPath            = options[22],
-        triggersOnList  = as.numeric(unlist(strsplit(options[23], "\\;"))),
-        triggersOffList  = as.numeric(unlist(strsplit(options[24], "\\;"))),
-        startSample = as.numeric(options[25]),
-        endSample = as.numeric(options[26]),
-        startEndOptimized = options[27],       #bool
-       singleOrMultiple = options[28]          #bool (true is single)
+        triggersOnList         = as.numeric(unlist(strsplit(options[23], "\\;"))),
+        triggersOffList        = as.numeric(unlist(strsplit(options[24], "\\;"))),
+        startSample    = as.numeric(options[25]),
+        endSample      = as.numeric(options[26]),
+        startEndOptimized      = options[27],  #bool
+       singleOrMultiple        = options[28],          #bool (true is single)
+       decimalCharAtExport     = options[29]
     ))
 }
 
@@ -1104,8 +1105,9 @@ start <- function(op)
        if(op$singleOrMultiple == "TRUE")
        {
                dataFile <- paste(tempPath, "/cj_mif_Data.csv", sep="")
-                       pngFile <- paste(tempPath, "/cj_mif_Graph.png", sep="")
-                       doProcess(pngFile, dataFile, op$decimalChar, op$title, op$exercise, op$datetime, 
op$captureOptions, op$startSample, op$endSample)
+               pngFile <- paste(tempPath, "/cj_mif_Graph.png", sep="")
+               doProcess(pngFile, dataFile, op$decimalCharAtFile, op$title, op$exercise,
+                               op$datetime, op$captureOptions, op$startSample, op$endSample)
        } else {
                #export
                #1) define exportDF and the model vector if model does not succeed
@@ -1187,7 +1189,10 @@ start <- function(op)
                        write(0, file = paste(tempPath, "/cj_mif_export.csv", sep = ""))
                } else {
                        #print csv
-                       write.csv2(exportDF, file = paste(tempPath, "/cj_mif_export.csv", sep = ""), 
row.names = FALSE, col.names = TRUE, quote = FALSE)
+                       if(op$decimalCharAtExport == ".")
+                               write.csv(exportDF, file = paste(tempPath, "/cj_mif_export.csv", sep = ""), 
row.names = FALSE, col.names = TRUE, quote = FALSE)
+                       else if(op$decimalCharAtExport == ",")
+                               write.csv2(exportDF, file = paste(tempPath, "/cj_mif_export.csv", sep = ""), 
row.names = FALSE, col.names = TRUE, quote = FALSE)
                }
        }
 }
diff --git a/src/forceSensor.cs b/src/forceSensor.cs
index da9a0272..84d048d2 100644
--- a/src/forceSensor.cs
+++ b/src/forceSensor.cs
@@ -1587,13 +1587,17 @@ public class ForceSensorGraph
        private int startSample;
        private int endSample;
        private bool startEndOptimized;
-       private bool decimalIsPoint; //but on export this will be related to each set
+       private bool decimalIsPointAtReadFile; //but on export this will be related to each set
+       private char exportDecimalSeparator;
 
        //private method to help on assigning params
        private void assignGenericParams(
                        List<ForceSensorRFD> rfdList,
                        ForceSensorImpulse impulse, double testLength, int percentChange,
-                       bool startEndOptimized, bool decimalIsPoint)
+                       bool startEndOptimized,
+                       bool decimalIsPointAtReadFile,  //at read
+                       char exportDecimalSeparator     //at write
+                       )
        {
                //generic of any data
                this.rfdList = rfdList;
@@ -1601,7 +1605,8 @@ public class ForceSensorGraph
                this.testLength = testLength;
                this.percentChange = percentChange;
                this.startEndOptimized = startEndOptimized;
-               this.decimalIsPoint = decimalIsPoint;
+               this.decimalIsPointAtReadFile = decimalIsPointAtReadFile;
+               this.exportDecimalSeparator = exportDecimalSeparator;
 
                averageLength = 0.1;
                vlineT0 = false;
@@ -1616,12 +1621,13 @@ public class ForceSensorGraph
                        List<ForceSensorRFD> rfdList,
                        ForceSensorImpulse impulse, double testLength, int percentChange,
                        bool startEndOptimized,
-                       bool decimalIsPoint,
+                       bool decimalIsPointAtReadFile,
+                       char exportDecimalSeparator,
                        ForceSensorGraphAB fsgAB
                        )
        {
-               assignGenericParams(rfdList, impulse, testLength, percentChange,
-                       startEndOptimized, decimalIsPoint);
+               assignGenericParams(rfdList, impulse, testLength, percentChange, startEndOptimized,
+                               decimalIsPointAtReadFile, exportDecimalSeparator);
 
                //this A-B data
                this.fsco = fsgAB.fsco;
@@ -1638,12 +1644,13 @@ public class ForceSensorGraph
                        List<ForceSensorRFD> rfdList,
                        ForceSensorImpulse impulse, double testLength, int percentChange,
                        bool startEndOptimized,
-                       bool decimalIsPoint, //this param is not used here. it is in fsgAB_l
+                       bool decimalIsPointAtReadFile, //this param is used here to print results. but to 
read data what id is used is in fsgAB_l
+                       char exportDecimalSeparator,
                        List<ForceSensorGraphAB> fsgAB_l
                        )
        {
-               assignGenericParams(rfdList, impulse, testLength, percentChange,
-                               startEndOptimized, decimalIsPoint);
+               assignGenericParams(rfdList, impulse, testLength, percentChange, startEndOptimized,
+                               decimalIsPointAtReadFile, exportDecimalSeparator);
 
                writeMultipleFilesCSV(fsgAB_l);
        }
@@ -1668,13 +1675,13 @@ public class ForceSensorGraph
 
                LogB.Information("writeOptionsFile 1");
                //since 2.0.3 decimalChar is . (before it was locale specific)
-               string decimalChar = ".";
-               if(! decimalIsPoint)
-                       decimalChar = localeInfo.NumberDecimalSeparator;
+               string decimalCharAtFile = ".";
+               if(! decimalIsPointAtReadFile)
+                       decimalCharAtFile = localeInfo.NumberDecimalSeparator;
 
                string scriptOptions =
                        "#os\n" +                       UtilEncoder.OperatingSystemForRGraphs() + "\n" +
-                       "#decimalChar\n" +              decimalChar + "\n" +
+                       "#decimalCharAtFile\n" +        decimalCharAtFile + "\n" +
                        "#graphWidth\n" +               graphWidth.ToString() + "\n" +
                        "#graphHeight\n" +              graphHeight.ToString() + "\n" +
                        "#averageLength\n" +            Util.ConvertToPoint(averageLength) + "\n" +
@@ -1728,7 +1735,8 @@ public class ForceSensorGraph
                        "#startSample\n" +              startSample.ToString() + "\n" + //unused on multiple
                        "#endSample\n" +                endSample.ToString() + "\n" +   //unused on multiple
                        "#startEndOptimized\n" +        Util.BoolToRBool(startEndOptimized) + "\n" +
-                       "#singleOrMultiple\n" +         Util.BoolToRBool(singleOrMultiple) + "\n";
+                       "#singleOrMultiple\n" +         Util.BoolToRBool(singleOrMultiple) + "\n" +
+                       "#decimalCharAtExport\n" +      exportDecimalSeparator + "\n";
 
                /*
                #startEndOptimized on gui can be:
@@ -2407,7 +2415,7 @@ public class ForceSensorExport
        private double forceSensorElasticConMinDispl;
        private int forceSensorNotElasticConMinForce;
        private bool forceSensorStartEndOptimized;
-       private string CSVExportDecimalSeparator;
+       private char CSVExportDecimalSeparatorChar;
 
        private static Thread thread;
        private static bool cancel;
@@ -2432,7 +2440,7 @@ public class ForceSensorExport
                        double forceSensorElasticConMinDispl,
                        int forceSensorNotElasticConMinForce,
                        bool forceSensorStartEndOptimized,
-                       string CSVExportDecimalSeparator)
+                       char CSVExportDecimalSeparatorChar)
 
        {
                this.notebook = notebook;
@@ -2449,7 +2457,7 @@ public class ForceSensorExport
                this.forceSensorElasticConMinDispl = forceSensorElasticConMinDispl;
                this.forceSensorNotElasticConMinForce = forceSensorNotElasticConMinForce;
                this.forceSensorStartEndOptimized = forceSensorStartEndOptimized;
-               this.CSVExportDecimalSeparator = CSVExportDecimalSeparator;
+               this.CSVExportDecimalSeparatorChar = CSVExportDecimalSeparatorChar;
        }
 
        ///public method
@@ -2503,8 +2511,8 @@ public class ForceSensorExport
                                new DialogMessage(Constants.MessageTypes.INFO, 
Catalog.GetString("Cancelled."));
                        else
                                new DialogMessage(Constants.MessageTypes.INFO,
-                                               string.Format("Exported to {0}", exportFilename) +
-                                               Constants.GetSpreadsheetString(CSVExportDecimalSeparator)
+                                               string.Format("Exported to {0}", exportFilename)// +
+                                               //Constants.GetSpreadsheetString(CSVExportDecimalSeparator)
                                                );
 
                        return false;
@@ -2689,7 +2697,8 @@ public class ForceSensorExport
                                        rfdList, impulse,
                                        duration, durationPercent,
                                        forceSensorStartEndOptimized,
-                                       true, //unused on export
+                                       true, //not used to read data, but used to print data
+                                       CSVExportDecimalSeparatorChar, // at write file
                                        fsgAB_l
                                        );
 
diff --git a/src/gui/app1/forceSensor.cs b/src/gui/app1/forceSensor.cs
index a8712fa3..d803289f 100644
--- a/src/gui/app1/forceSensor.cs
+++ b/src/gui/app1/forceSensor.cs
@@ -2178,7 +2178,8 @@ LogB.Information(" fs R ");
                                rfdList, impulse,
                                duration, Convert.ToInt32(spin_force_rfd_duration_percent.Value),
                                preferences.forceSensorStartEndOptimized,
-                               Util.CSVDecimalColumnIsPoint(UtilEncoder.GetmifCSVFileName(), 1),
+                               Util.CSVDecimalColumnIsPoint(UtilEncoder.GetmifCSVFileName(), 1),       
//decimalIsPointAtFile (read)
+                               preferences.CSVExportDecimalSeparatorChar,                              
//decimalIsPointAtExport (write)
                                new ForceSensorGraphAB(
                                        "",     //unused on single graph (no export)
                                        true,   //unused on single graph (no export)
diff --git a/src/gui/app1/forceSensorAnalyze.cs b/src/gui/app1/forceSensorAnalyze.cs
index 150e97d9..b9b986b7 100644
--- a/src/gui/app1/forceSensorAnalyze.cs
+++ b/src/gui/app1/forceSensorAnalyze.cs
@@ -753,7 +753,8 @@ public partial class ChronoJumpWindow
                                preferences.forceSensorElasticConMinDispl,
                                preferences.forceSensorNotElasticConMinForce,
                                preferences.forceSensorStartEndOptimized,
-                               preferences.CSVExportDecimalSeparator);
+                               preferences.CSVExportDecimalSeparatorChar       //decimalIsPointAtExport 
(write)
+                               );
 
                if(personID == -1)
                        checkFile(Constants.CheckFileOp.FORCESENSOR_EXPORT_GROUPAL_CURRENT_SESSION);
diff --git a/src/preferences.cs b/src/preferences.cs
index 62d18c4b..243bd9b0 100644
--- a/src/preferences.cs
+++ b/src/preferences.cs
@@ -445,6 +445,18 @@ public class Preferences
                }
        }
 
+       //get the decimalChar for R . or ,
+       public char CSVExportDecimalSeparatorChar
+       {
+               get {
+                       char c = '.';
+                       if(CSVExportDecimalSeparator == "COMMA")
+                               c = ',';
+
+                       return c;
+               }
+       }
+
        public bool IsVideoConfigured()
        {
                return (videoDevice != "" &&


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