[chronojump] Encoder save table now detects convertDecimalSeparator preference



commit 28464f0ca0129f25d2c1f9c0582319f58e8ed5de
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Oct 6 17:17:48 2014 +0200

    Encoder save table now detects convertDecimalSeparator preference

 src/encoder.cs     |   38 ++++++++++++++++++++++++++++++++------
 src/gui/encoder.cs |   14 ++++++++++----
 src/util.cs        |    8 ++++++++
 3 files changed, 50 insertions(+), 10 deletions(-)
---
diff --git a/src/encoder.cs b/src/encoder.cs
index 102b502..e0e2878 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -261,15 +261,28 @@ public class EncoderCurve
                this.PP_PPT = PP_PPT;   //PeakPower / PeakPowerTime
        }
 
-       public string ToCSV() {
-               string sep = ";";
-               return 
+       public string ToCSV(string decimalSeparator) {
+               //latin:        2,3 ; 2,5
+               //non-latin:    2.3 , 2.5
+
+               string sep = ":::";
+               string str = 
                        N + sep + Series + sep + Exercise + sep + 
                        ExtraWeight + sep + DisplacedWeight + sep + 
                        Start + sep + Duration + sep + Height + sep + 
                        MeanSpeed + sep + MaxSpeed + sep + MaxSpeedT + sep + 
                        MeanPower + sep + PeakPower + sep + PeakPowerT + sep + 
                        PP_PPT;
+               
+               if(decimalSeparator == "COMMA")
+                       str = Util.ConvertToComma(str);
+               else
+                       str = Util.ConvertToPoint(str);
+                       
+               if(decimalSeparator == "COMMA")
+                       return Util.ChangeChars(str, ":::", ";");
+               else
+                       return Util.ChangeChars(str, ":::", ",");
        }
        
        ~EncoderCurve() {}
@@ -408,9 +421,12 @@ public class EncoderNeuromuscularData
                this.cl_p_max   = Convert.ToDouble(cells[16]);
        }
 
-       public string ToCSV() {
-               string sep = ";";
-               return 
+       public string ToCSV(string decimalSeparator) {
+               //latin:        2,3 ; 2,5
+               //non-latin:    2.3 , 2.5
+
+               string sep = ":::";
+               string str = 
                        n + sep + e1_range.ToString() + sep + 
                        e1_t.ToString() + sep + e1_fmax.ToString() + sep + 
                        e1_rfd_avg.ToString() + sep + e1_i.ToString() + sep + 
@@ -419,6 +435,16 @@ public class EncoderNeuromuscularData
                        cl_f_avg.ToString() + sep + cl_vf.ToString() + sep + cl_f_max.ToString() + sep + 
                        cl_s_avg.ToString() + sep + cl_s_max.ToString() + sep + 
                        cl_p_avg.ToString() + sep + cl_p_max.ToString();
+
+               if(decimalSeparator == "COMMA")
+                       str = Util.ConvertToComma(str);
+               else
+                       str = Util.ConvertToPoint(str);
+                       
+               if(decimalSeparator == "COMMA")
+                       return Util.ChangeChars(str, ":::", ";");
+               else
+                       return Util.ChangeChars(str, ":::", ",");
        }
 }
 
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 2f78494..2ce5c12 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -3026,22 +3026,28 @@ public partial class ChronoJumpWindow
                        //this overwrites if needed
                        TextWriter writer = File.CreateText(destination);
 
+                       string sep = " ";
+                       if (preferences.CSVExportDecimalSeparator == "COMMA")
+                               sep = ";";
+                       else
+                               sep = ",";
+
                        if(lastTreeviewEncoderAnalyzeIsNeuromuscular) {
                                //write header
                                writer.WriteLine(Util.RemoveNewLine(Util.StringArrayToString(
-                                                       treeviewEncoderAnalyzeNeuromuscularHeaders, ";"), 
false));
+                                                       treeviewEncoderAnalyzeNeuromuscularHeaders, sep), 
false));
                                //write curves rows
                                ArrayList array = getTreeViewNeuromuscular(encoderAnalyzeListStore);
                                foreach (EncoderNeuromuscularData nm in array)
-                                       writer.WriteLine(nm.ToCSV());
+                                       writer.WriteLine(nm.ToCSV(preferences.CSVExportDecimalSeparator));
                        } else {
                                //write header
                                writer.WriteLine(Util.RemoveNewLine(Util.StringArrayToString(
-                                                       treeviewEncoderAnalyzeHeaders, ";"), false));
+                                                       treeviewEncoderAnalyzeHeaders, sep), false));
                                //write curves rows
                                ArrayList array = getTreeViewCurves(encoderAnalyzeListStore);
                                foreach (EncoderCurve ec in array)
-                                       writer.WriteLine(ec.ToCSV());
+                                       writer.WriteLine(ec.ToCSV(preferences.CSVExportDecimalSeparator));
                        }
                        
                        writer.Flush();
diff --git a/src/util.cs b/src/util.cs
index 31eadcd..127c459 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -44,6 +44,14 @@ public class Util
                myStringBuilder.Replace(",", ".");
                return myStringBuilder.ToString();
        }
+       
+       public static string ConvertToComma (string myString)
+       {
+               StringBuilder myStringBuilder = new StringBuilder(myString);
+               myStringBuilder.Replace(".", ",");
+               return myStringBuilder.ToString();
+       }
+
 
        //when we do a query to the server, it returns avg as "0,54" because it's latin localized
        //if client is on english machine, need to convert this to "0.54"


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