[chronojump] Encoder: export curves correct decimal



commit f7b8118c88d698874d9d43812e68430b73fafaa8
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Feb 27 01:41:55 2013 +0100

    Encoder: export curves correct decimal

 encoder/graph.R    |   49 +++++++++++++++++++++++++++----------------------
 src/encoder.cs     |   10 +++++++---
 src/gui/encoder.cs |   16 ++++++++++++----
 src/util.cs        |   12 ++++++++++++
 4 files changed, 58 insertions(+), 29 deletions(-)
---
diff --git a/encoder/graph.R b/encoder/graph.R
index 1adcb71..702e5e6 100644
--- a/encoder/graph.R
+++ b/encoder/graph.R
@@ -36,7 +36,7 @@ cols=c(colSpeed,colForce,colPower); lty=rep(1,3)
 #way A. passing options to a file
 getOptionsFromFile <- function(optionsFile) {
        optionsCon <- file(optionsFile, 'r')
-       options=readLines(optionsCon,n=16)
+       options=readLines(optionsCon,n=17)
        close(optionsCon)
        return (options)
 }
@@ -56,7 +56,7 @@ options=getOptionsFromFile(optionsFile);
 print(options)
 
 OutputData2=options[4] #currently used to display status
-OperatingSystem=options[16]
+OperatingSystem=options[17]
 
 write("(1/5) Starting R", OutputData2)
 
@@ -786,8 +786,9 @@ doProcess <- function(options) {
        Jump=options[12]
        Width=as.numeric(options[13])
        Height=as.numeric(options[14])
-       Title=options[15]
-       OperatingSystem=options[16]
+       DecimalSeparator=options[15]
+       Title=options[16]
+       OperatingSystem=options[17]
 
        print(File)
        print(OutputGraph)
@@ -1148,10 +1149,12 @@ doProcess <- function(options) {
                }
 
                curveCols = 6   #change this value if there are more colums
-               names=c("Dist.", "Dist. +", "Speed", "Accel.", "Force", "Power")
+               names=c("DIST.", "DIST. +", "SPEED", "ACCEL.", "FORCE", "POWER")
                nums=1:curvesNum
                nums=rep(nums,each=curveCols)           
                namesNums=paste(names, nums)
+               units=c("\n(mm)", "\n(mm)", "\n(m/s)", "\n(m/s^2)", "\n(N)", "\n(W)")
+               namesNums=paste(namesNums, units)
 
                for(i in 1:curvesNum) { 
                        kn = kinematicsF (rawdata[curves[i,1]:curves[i,2]], Mass, SmoothingOne, g)
@@ -1162,45 +1165,41 @@ doProcess <- function(options) {
 
                        #add mean, max, and time to max
                        col1=append(col1,
-                                   c(NA,NA,NA,NA,namesNums[((i-1)*curveCols)+1]),
+                                   c(NA,NA,NA,NA),
                                    after=0)
                        col2=append(col2,
-                                   c(NA,"mean (ABS):","max:","time to max:",namesNums[((i-1)*curveCols)+2]),
+                                   c(NA,NA,NA,range(col2)[2]-range(col2)[1]),
                                    after=0)
                        kn$speedy=append(kn$speedy,
                                         c(
-                                          namesNums[((i-1)*curveCols)+3],
                                           mean(abs(kn$speedy)),
                                           max(kn$speedy),
                                           (min(which(kn$speedy == max(kn$speedy)))/1000),
-                                          namesNums[((i-1)*curveCols)+3]),
+                                          NA),
                                         after=0)
                        kn$accely=append(kn$accely,
                                         c(
-                                          namesNums[((i-1)*curveCols)+4],
                                           mean(abs(kn$accely)),
                                           max(kn$accely),
                                           NA,
-                                          namesNums[((i-1)*curveCols)+4]),
+                                          NA),
                                         after=0)
                        kn$force=append(kn$force,
                                        c(
-                                         namesNums[((i-1)*curveCols)+5],
                                          mean(abs(kn$force)),
                                          max(kn$force),
                                          NA,
-                                         namesNums[((i-1)*curveCols)+5]),
+                                         NA),
                                        after=0)
                        kn$power=append(kn$power,
                                        c(
-                                         namesNums[((i-1)*curveCols)+6],
                                          mean(abs(kn$power)),
                                          max(kn$power),
                                          (min(which(kn$power == max(kn$power)))/1000),
-                                         namesNums[((i-1)*curveCols)+6]),
+                                         NA),
                                        after=0)
 
-                       extraRows=5
+                       extraRows=4
                        length(col1)=maxLength+extraRows
                        length(col2)=maxLength+extraRows
                        length(kn$speedy)=maxLength+extraRows
@@ -1216,16 +1215,22 @@ doProcess <- function(options) {
                                                    kn$speedy, kn$accely, kn$force, kn$power))
                }
 
+               rownames(df) = c("MEAN (ABS)", "MAX", "TIME TO MAX", "RANGE", 1:maxLength)
+               colnames(df) = namesNums
+
                #TODO: time
                #TODO: tenir en compte el startH
 
-               Title=gsub('_',' ',Title)
-               print(Title)
-               titleColumns=unlist(strsplit(Title,'-'))
-               colnames(df)=c(titleColumns[1]," ", titleColumns[2],titleColumns[3],rep(" 
",(curvesNum*curveCols-4)))
+               #Title=gsub('_',' ',Title)
+               #print(Title)
+               #titleColumns=unlist(strsplit(Title,'-'))
+               #colnames(df)=c(titleColumns[1]," ", titleColumns[2],titleColumns[3],rep(" 
",(curvesNum*curveCols-4)))
+
+               if(DecimalSeparator == "COMMA")
+                       write.csv2(df, file=File, row.names=T, na="")
+               else
+                       write.csv(df, file=File, row.names=T, na="")
 
-               write.csv2(df, file=File, row.names=F, na="")
-               #write.csv2(df, file=File, quotes=F)
                print("Export done.")
        }
        if(Analysis != "exportCSV")
diff --git a/src/encoder.cs b/src/encoder.cs
index c6e9fb2..2d58b6d 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -49,6 +49,7 @@ public class EncoderParams
        private int peakPowerHigherCondition;
        private int peakPowerLowerCondition;
        private string mainVariable;
+       private string decimalSeparator;        //used in export data from R to csv
 
        public EncoderParams()
        {
@@ -98,7 +99,8 @@ public class EncoderParams
        
        //to graph.R    
        public EncoderParams(int minHeight, int exercisePercentBodyWeight, string mass, string eccon, 
-                       string analysis, string analysisOptions, string smooth, int curve, int width, int 
height)
+                       string analysis, string analysisOptions, string smooth, int curve, int width, int 
height,
+                       string decimalSeparator)
        {
                this.minHeight = minHeight;
                this.exercisePercentBodyWeight = exercisePercentBodyWeight;
@@ -110,12 +112,14 @@ public class EncoderParams
                this.curve = curve;
                this.width = width;
                this.height = height;
+               this.decimalSeparator = decimalSeparator;
        }
        
        public string ToString2 (string sep) 
        {
-               return minHeight + sep + exercisePercentBodyWeight + sep + mass + sep + eccon + sep + 
-                       analysis + sep + analysisOptions + sep + smooth + sep + curve + sep + width + sep + 
height;
+               return minHeight + sep + exercisePercentBodyWeight + sep + mass + sep + eccon + 
+                       sep + analysis + sep + analysisOptions + sep + smooth + sep + curve + 
+                       sep + width + sep + height + sep + decimalSeparator;
        }
        
        public string Analysis {
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index a420542..3d89e32 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -356,7 +356,9 @@ public partial class ChronoJumpWindow
                                analysisOptions,
                                Util.ConvertToPoint((double) spin_encoder_smooth.Value), //R decimal: '.'
                                0,                      //curve is not used here
-                               image_encoder_width, image_encoder_height); 
+                               image_encoder_width, image_encoder_height,
+                               Util.GetDecimalSeparator()
+                               ); 
 
                EncoderStruct es = new EncoderStruct(
                                Util.GetEncoderDataTempFileName(), 
@@ -551,7 +553,9 @@ public partial class ChronoJumpWindow
                                Util.ConvertToPoint((double) spin_encoder_smooth.Value), //R decimal: '.'
                                
Convert.ToInt32(UtilGtk.ComboGetActive(combo_encoder_analyze_curve_num_combo)),
                                image_encoder_width,
-                               image_encoder_height); 
+                               image_encoder_height,
+                               Util.GetDecimalSeparator()
+                               );
 
                string dataFileName = Util.GetEncoderDataTempFileName();
 
@@ -1048,7 +1052,9 @@ public partial class ChronoJumpWindow
                                        "-1",
                                        myCurveNum,
                                        image_encoder_width, 
-                                       image_encoder_height); 
+                                       image_encoder_height,
+                                       Util.GetDecimalSeparator()
+                                       );
                        
                        dataFileName = Util.GetEncoderGraphInputMulti();
 
@@ -1100,7 +1106,9 @@ public partial class ChronoJumpWindow
                                        Util.ConvertToPoint((double) spin_encoder_smooth.Value), //R decimal: 
'.'
                                        
Convert.ToInt32(UtilGtk.ComboGetActive(combo_encoder_analyze_curve_num_combo)),
                                        image_encoder_width,
-                                       image_encoder_height); 
+                                       image_encoder_height,
+                                       Util.GetDecimalSeparator()
+                                       );
                        
                        dataFileName = Util.GetEncoderDataTempFileName();
                }
diff --git a/src/util.cs b/src/util.cs
index 28642b9..152c4a2 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -61,6 +61,18 @@ public class Util
                return myStringBuilder.ToString();
        }
        
+       //used to send to R and export csv there
+       public static string GetDecimalSeparator() {
+               System.Globalization.NumberFormatInfo localeInfo = new 
System.Globalization.NumberFormatInfo();
+               localeInfo = System.Globalization.NumberFormatInfo.CurrentInfo;
+
+               if(localeInfo.NumberDecimalSeparator == ".")
+                       return("POINT");
+               else if(localeInfo.NumberDecimalSeparator == ",")
+                       return("COMMA");
+               else 
+                       return("OTHER");
+       }
        
        //used for load from the database all numbers with correct decimal separator (locale defined)
        //used also for the tvString, tcString, and runIntervalTimesString


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