[chronojump] 701534 - 1RM gets saved (90%)



commit 9ba98e01f4d589757c0572130fac8b745660b7a8
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Jun 12 17:00:54 2013 +0200

    701534 - 1RM gets saved (90%)

 encoder/graph.R           |   64 ++++++++++++++++++++++++--------------------
 glade/chronojump.glade    |    4 +--
 src/constants.cs          |    2 +
 src/encoder.cs            |    4 ++-
 src/gui/chronojump.cs     |    2 +-
 src/gui/encoder.cs        |   63 +++++++++++++++++++++++++++++++-------------
 src/gui/preferences.cs    |   43 +++++++++++++++++++++++++++++-
 src/sqlite/encoder.cs     |    4 +-
 src/sqlite/main.cs        |   15 ++++++++++-
 src/sqlite/preferences.cs |    1 +
 src/util.cs               |   11 +++++++-
 11 files changed, 155 insertions(+), 58 deletions(-)
---
diff --git a/encoder/graph.R b/encoder/graph.R
index ac6922b..f8ed85b 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=18)
+       options=readLines(optionsCon,n=19)
        close(optionsCon)
        return (options)
 }
@@ -55,8 +55,10 @@ options=getOptionsFromFile(optionsFile);
 
 print(options)
 
-OutputData2=options[4] #currently used to display processing feedback
-OperatingSystem=options[18]
+OutputData2 = options[4] #currently used to display processing feedback
+SpecialData = options[5]
+OperatingSystem=options[19]
+
 
 write("(1/5) Starting R", OutputData2)
 
@@ -290,8 +292,8 @@ return (propulsiveEnd)
 #eccon="ec" one time each curve
 #eccon="ecS" means ecSeparated. two times each curve: one for "e", one for "c"
 kinematicsF <- function(a, mass, smoothingOneEC, smoothingOneC, g, eccon, analysisOptions) {
-       print("length unique x in spline")
-       print(length(unique(1:length(a))))
+       #print("length unique x in spline")
+       #print(length(unique(1:length(a))))
 
        smoothing = 0
        if(eccon == "c")
@@ -308,8 +310,8 @@ kinematicsF <- function(a, mass, smoothingOneEC, smoothingOneC, g, eccon, analys
        concentric = 0
        propulsiveEnd = 0
 
-print("at kinematicsF eccon==")
-print(eccon)
+#print("at kinematicsF eccon==")
+#print(eccon)
 
        #search propulsiveEnd
        if(analysisOptions == "p") {
@@ -335,8 +337,8 @@ print("WARNING ECS\n\n\n\n\n")
 
        power <- force*speed$y
 
-       print("propulsiveEnd")
-       print(propulsiveEnd)
+       #print("propulsiveEnd")
+       #print(propulsiveEnd)
 
        if( analysisOptions == "p" && ( eccon== "c" || eccon == "ec" ) )
                return(list(speedy=speed$y[1:propulsiveEnd], accely=accel$y[1:propulsiveEnd], 
@@ -974,19 +976,19 @@ paintCrossVariables <- function (paf, varX, varY, option, isAlone, title, single
                        print(speed1RM)
                        
                        #lineal stuff
-               
-                       if(do1RMMethod == "nonweighted")  {
+                       fit = lm(y ~ x) #declare
+                       if(do1RMMethod == "NONWEIGHTED")  {
                                #without weights
                                fit = lm(y ~ x)
-                       } else if(do1RMMethod == "weighted")  {
+                       } else if(do1RMMethod == "WEIGHTED")  {
                                #weights x
                                fit = lm(y ~ x, weights=x/max(x)) 
                                print(x/max(x))
-                       } else if(do1RMMethod == "weighted2")  {
+                       } else if(do1RMMethod == "WEIGHTED2")  {
                                #weights x^2
                                fit = lm(y ~ x, weights=x^2/max(x^2)) 
                                print(x^2/max(x^2))
-                       } else if(do1RMMethod == "weighted3")  {
+                       } else if(do1RMMethod == "WEIGHTED3")  {
                                #weights x^3 (as higher then more important are the right values) 
                                fit = lm(y ~ x, weights=x^3/max(x^3)) 
                                print(x^3/max(x^3))
@@ -1007,7 +1009,7 @@ paintCrossVariables <- function (paf, varX, varY, option, isAlone, title, single
                        mtext(speed1RM, at=speed1RM, side=2, line=3,col="red")
                        points(load1RM,speed1RM,cex=2,col="red")
 
-
+                       write(paste("1RM;",round(load1RM,2),sep=""), SpecialData)
 
                        #quadratic stuff
                        #fit2 = lm(y ~ I(x^2) + x)
@@ -1133,6 +1135,8 @@ paint1RMBadillo2010 <- function (paf, title) {
 
        segments(predicted1RM,0.185,predicted1RM,0,lty=1)
        mtext(side=1, at=predicted1RM, round(predicted1RM,2), cex=.8)
+                       
+       write(paste("1RM;",round(predicted1RM,2),sep=""), SpecialData)
 }
 
                        
@@ -1184,26 +1188,28 @@ doProcess <- function(options) {
        OutputGraph=options[2]
        OutputData1=options[3]
        OutputData2=options[4] #currently used to display processing feedback
-       MinHeight=as.numeric(options[5])*10 #from cm to mm
-       ExercisePercentBodyWeight=as.numeric(options[6])        #was isJump=as.logical(options[6])
-       Mass=as.numeric(options[7])
-       Eccon=options[8]
-       Analysis=options[9]     #in cross comes as "cross;Force;Speed;mean"
-       AnalysisOptions=options[10]     #p: propulsive
-       SmoothingOneEC=options[11]
-       SmoothingOneC=options[12]
-       Jump=options[13]
-       Width=as.numeric(options[14])
-       Height=as.numeric(options[15])
-       DecimalSeparator=options[16]
-       Title=options[17]
-       OperatingSystem=options[18]     #if this changes, change it also at start of this R file
+       SpecialData=options[5] #currently used to write 1RM. variable;result (eg. "1RM;82.78")
+       MinHeight=as.numeric(options[6])*10 #from cm to mm
+       ExercisePercentBodyWeight=as.numeric(options[7])        #was isJump=as.logical(options[6])
+       Mass=as.numeric(options[8])
+       Eccon=options[9]
+       Analysis=options[10]    #in cross comes as "cross;Force;Speed;mean"
+       AnalysisOptions=options[11]     #p: propulsive
+       SmoothingOneEC=options[12]
+       SmoothingOneC=options[13]
+       Jump=options[14]
+       Width=as.numeric(options[15])
+       Height=as.numeric(options[16])
+       DecimalSeparator=options[17]
+       Title=options[18]
+       OperatingSystem=options[19]     #if this changes, change it also at start of this R file
        #important, if this grows, change the readLines value on getOptionsFromFile
 
        print(File)
        print(OutputGraph)
        print(OutputData1)
        print(OutputData2)
+       print(SpecialData)
        
        if(Analysis != "exportCSV") {
                if(OperatingSystem=="Windows")
diff --git a/glade/chronojump.glade b/glade/chronojump.glade
index acd2e94..28bfa8f 100644
--- a/glade/chronojump.glade
+++ b/glade/chronojump.glade
@@ -14027,7 +14027,6 @@ on current Chronojump version.</property>
                                                             <property name="tooltip" translatable="yes">Save 
image</property>
                                                             <property 
name="use_action_appearance">False</property>
                                                             <signal name="clicked" 
handler="on_button_encoder_analyze_image_save_clicked" swapped="no"/>
-                                                            <accelerator key="z" signal="clicked"/>
                                                             <child>
                                                             <widget class="GtkImage" 
id="image_encoder_analyze_image_save">
                                                             <property name="visible">True</property>
@@ -14052,7 +14051,7 @@ on current Chronojump version.</property>
                                                             <property name="has_tooltip">True</property>
                                                             <property name="tooltip" translatable="yes">Save 
1RM value</property>
                                                             <property 
name="use_action_appearance">False</property>
-                                                            <accelerator key="z" signal="clicked"/>
+                                                            <signal name="clicked" 
handler="on_button_encoder_analyze_1RM_save_clicked" swapped="no"/>
                                                             <child>
                                                             <widget class="GtkVBox" id="vbox5">
                                                             <property name="visible">True</property>
@@ -14153,7 +14152,6 @@ on current Chronojump version.</property>
                                                             <property name="tooltip" translatable="yes">Save 
table</property>
                                                             <property 
name="use_action_appearance">False</property>
                                                             <signal name="clicked" 
handler="on_button_encoder_analyze_table_save_clicked" swapped="no"/>
-                                                            <accelerator key="z" signal="clicked"/>
                                                             <child>
                                                             <widget class="GtkImage" 
id="image_encoder_analyze_image_save1">
                                                             <property name="visible">True</property>
diff --git a/src/constants.cs b/src/constants.cs
index 8dd73c6..8067335 100644
--- a/src/constants.cs
+++ b/src/constants.cs
@@ -594,12 +594,14 @@ public class Constants
        public static string EncoderGraphTemp = "chronojump-last-encoder-graph.png";
        public static string EncoderStatusTemp = "chronojump-encoder-status.txt";
        public static string EncoderExportTemp = "chronojump-export.csv";
+       public static string EncoderSpecialDataTemp = "chronojump-special-data.txt"; //variable;result (eg. 
"1RM;82.78")
 
        //note next has 40 chars, and its used also in encoder/graph.R to detect how a file will be treated
        //if this name changes, change it in encoder/graph.R
        public static string EncoderGraphInputMulti = "chronojump-encoder-graph-input-multi.csv"; 
 
        public enum EncoderCheckFileOp { ANALYZE_EXPORT_ALL_CURVES, ANALYZE_SAVE_IMAGE, ANALYZE_SAVE_TABLE}
+       public enum Encoder1RMMethod { NONWEIGHTED, WEIGHTED, WEIGHTED2, WEIGHTED3 }
 
        public enum DoubleContact {
                FIRST, AVERAGE, LAST
diff --git a/src/encoder.cs b/src/encoder.cs
index df42b9e..9812f66 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -153,15 +153,17 @@ public class EncoderStruct
        public string OutputGraph;
        public string OutputData1;
        public string OutputData2;
+       public string SpecialData;
        public EncoderParams Ep;
 
        public EncoderStruct(string InputData, string OutputGraph, string OutputData1, string OutputData2,
-                      EncoderParams Ep)
+                       string SpecialData, EncoderParams Ep)
        {
                this.InputData = InputData;
                this.OutputGraph = OutputGraph;
                this.OutputData1 = OutputData1;
                this.OutputData2 = OutputData2;
+               this.SpecialData = SpecialData;
                this.Ep = Ep;
        }
 
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index 961e058..96c7d18 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -2616,7 +2616,7 @@ public partial class ChronoJumpWindow
                                //System.Threading.Thread.CurrentThread.CurrentUICulture.ToString(),
                                SqlitePreferences.Select("language"),
                                encoderPropulsive, encoderSmoothEccCon, encoderSmoothCon,
-                               videoDevices, videoDeviceNum 
+                               videoDevices, videoDeviceNum, SqlitePreferences.Select("encoder1RMMethod")
                                );
                myWin.Button_accept.Clicked += new EventHandler(on_preferences_accepted);
        }
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 523257d..c861344 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -87,6 +87,7 @@ public partial class ChronoJumpWindow
        
        [Widget] Gtk.Button button_encoder_analyze_image_save;
        [Widget] Gtk.Button button_encoder_analyze_table_save;
+       [Widget] Gtk.Button button_encoder_analyze_1RM_save;
 
        [Widget] Gtk.RadioButton radiobutton_encoder_analyze_powerbars;
        [Widget] Gtk.RadioButton radiobutton_encoder_analyze_cross;
@@ -258,7 +259,10 @@ public partial class ChronoJumpWindow
                EncoderStruct es = new EncoderStruct(
                                "",                                     //no data input
                                "",                                     //no graph ouptut
-                               Util.GetEncoderDataTempFileName(), "", ep);                             
+                               Util.GetEncoderDataTempFileName(),      //OutputData1
+                               "",                                     //OutputData2
+                               "",                                     //SpecialData
+                               ep);                            
                                
                lastRecalculateWasInverted = check_encoder_inverted.Active;
 
@@ -308,10 +312,7 @@ public partial class ChronoJumpWindow
                spin_encoder_displaced_weight.Value = findMass(true);
 
                //1RM
-               int exerciseID = Convert.ToInt32(
-                               Util.FindOnArray(':', 2, 0, UtilGtk.ComboGetActive(combo_encoder_exercise), 
-                               encoderExercisesTranslationAndBodyPWeight) );   //exerciseID
-               ArrayList array1RM = SqliteEncoder.Select1RM(false, currentPerson.UniqueID, 
currentSession.UniqueID, exerciseID); 
+               ArrayList array1RM = SqliteEncoder.Select1RM(false, currentPerson.UniqueID, 
currentSession.UniqueID, getExerciseID()); 
                double load1RM = 0;
                if(array1RM.Count > 0)
                        load1RM = ((Encoder1RM) array1RM[0]).load1RM; //take only the first in array (will be 
the last uniqueID)
@@ -429,6 +430,7 @@ public partial class ChronoJumpWindow
                                Util.GetEncoderGraphTempFileName(),
                                Util.GetEncoderCurvesTempFileName(), 
                                Util.GetEncoderStatusTempFileName(),
+                               "",     //SpecialData
                                ep);
                
                Util.RunEncoderGraph(
@@ -988,6 +990,7 @@ public partial class ChronoJumpWindow
                                Util.GetEncoderGraphTempFileName(),
                                selectedFileName, 
                                Util.GetEncoderStatusTempFileName(),
+                               "",             //SpecialData
                                ep);
 
                Util.RunEncoderGraph(
@@ -1311,10 +1314,8 @@ public partial class ChronoJumpWindow
 
                EncoderSQL eSQL = new EncoderSQL(
                                myID, 
-                               currentPerson.UniqueID, currentSession.UniqueID, 
-                               Convert.ToInt32(
-                                       Util.FindOnArray(':', 2, 0, 
UtilGtk.ComboGetActive(combo_encoder_exercise), 
-                                       encoderExercisesTranslationAndBodyPWeight) ),   //exerciseID
+                               currentPerson.UniqueID, currentSession.UniqueID,
+                               getExerciseID(),        
                                findEccon(true),        //force ecS (ecc-conc separated)
                                UtilGtk.ComboGetActive(combo_encoder_laterality),
                                Util.ConvertToPoint(findMass(false)),   //when save on sql, do not include 
person weight
@@ -1565,12 +1566,11 @@ public partial class ChronoJumpWindow
                                analysisOptions = "p";
                        } else if(crossName == "1RM Any exercise") {
                                //get speed1RM
-                               int exerciseID = Convert.ToInt32(
-                                               Util.FindOnArray(':', 2, 0, 
UtilGtk.ComboGetActive(combo_encoder_exercise), 
-                                                       encoderExercisesTranslationAndBodyPWeight) );   
//exerciseID
-                               EncoderExercise ex = (EncoderExercise) 
SqliteEncoder.SelectEncoderExercises(false,exerciseID,false)[0];
+                               EncoderExercise ex = (EncoderExercise) 
SqliteEncoder.SelectEncoderExercises(false,getExerciseID(),false)[0];
                                
-                               sendAnalysis = "1RMAnyExercise;" + Util.ConvertToPoint(ex.speed1RM) + 
";weighted2" ; 
+                               sendAnalysis = "1RMAnyExercise;" + Util.ConvertToPoint(ex.speed1RM) + ";" +
+                                       SqlitePreferences.Select("encoder1RMMethod");
+
                                analysisOptions = "p";
                        } else {
                                //convert: "Force / Speed" in: "cross.Force.Speed.mean"
@@ -1756,6 +1756,7 @@ Log.WriteLine(str);
                                Util.GetEncoderGraphTempFileName(),
                                Util.GetEncoderCurvesTempFileName(),    //since 1.3.6 all the analysis write 
curves table
                                Util.GetEncoderStatusTempFileName(),
+                               Util.GetEncoderSpecialDataTempFileName(),
                                ep);
 
                //show mass in title except if it's curves because then can be different mass
@@ -2186,7 +2187,20 @@ Log.WriteLine(str);
                        new DialogMessage(Constants.MessageTypes.WARNING, myString);
                }
        }
-       
+
+       void on_button_encoder_analyze_1RM_save_clicked (object o, EventArgs args)
+       {
+               string contents = Util.ReadFile(Util.GetEncoderSpecialDataTempFileName(), true);
+               string [] load1RMStr = contents.Split(new char[] {';'});
+               double load1RM = Convert.ToDouble(Util.ChangeDecimalSeparator(load1RMStr[1]));
+
+               SqliteEncoder.Insert1RM(false, currentPerson.UniqueID, currentSession.UniqueID, 
+                               getExerciseID(), load1RM);
+               
+               new DialogMessage(Constants.MessageTypes.INFO, Catalog.GetString("Saved"));
+       }
+
+
        ArrayList getTreeViewCurves(Gtk.ListStore ls) {
                TreeIter iter = new TreeIter();
                ls.GetIterFirst ( out iter ) ;
@@ -2199,13 +2213,15 @@ Log.WriteLine(str);
        }
 
 
+       int getExerciseID () {
+               return Convert.ToInt32(
+                               Util.FindOnArray(':', 2, 0, UtilGtk.ComboGetActive(combo_encoder_exercise), 
+                               encoderExercisesTranslationAndBodyPWeight) );
+       }
        
        void on_button_encoder_exercise_info_clicked (object o, EventArgs args) 
        {
-               int exerciseID = Convert.ToInt32(
-                               Util.FindOnArray(':', 2, 0, UtilGtk.ComboGetActive(combo_encoder_exercise), 
-                               encoderExercisesTranslationAndBodyPWeight) );   //exerciseID
-               EncoderExercise ex = (EncoderExercise) 
SqliteEncoder.SelectEncoderExercises(false,exerciseID,false)[0];
+               EncoderExercise ex = (EncoderExercise) 
SqliteEncoder.SelectEncoderExercises(false,getExerciseID(),false)[0];
 
                ArrayList bigArray = new ArrayList();
 
@@ -2958,6 +2974,7 @@ Log.WriteLine(str);
                treeview_encoder_analyze_curves.Sensitive = false;
                button_encoder_analyze_image_save.Sensitive = false;
                button_encoder_analyze_table_save.Sensitive = false;
+               button_encoder_analyze_1RM_save.Sensitive = false;
 
                //put some data just in case user doesn't click on compare button
                encoderCompareInitialize();
@@ -3268,6 +3285,7 @@ Log.WriteLine(str);
                        treeview_encoder_analyze_curves.Sensitive = false;
                        button_encoder_analyze_image_save.Sensitive = false;
                        button_encoder_analyze_table_save.Sensitive = false;
+                       button_encoder_analyze_1RM_save.Sensitive = false;
 
                        encoderThreadR.Start(); 
                }
@@ -3440,6 +3458,7 @@ Log.WriteLine(str);
                        treeview_encoder_analyze_curves.Sensitive = false;
                        button_encoder_analyze_image_save.Sensitive = false;
                        button_encoder_analyze_table_save.Sensitive = false;
+                       button_encoder_analyze_1RM_save.Sensitive = false;
 
                } else { //ANALYZE
                        if(encoderProcessCancel) {
@@ -3462,8 +3481,14 @@ Log.WriteLine(str);
                        encoderButtonsSensitive(encoderSensEnumStored);
                        image_encoder_analyze.Sensitive = true;
                        treeview_encoder_analyze_curves.Sensitive = true;
+                       
                        button_encoder_analyze_image_save.Sensitive = true;
                        button_encoder_analyze_table_save.Sensitive = true;
+                       
+                       string crossName = 
Util.FindOnArray(':',1,0,UtilGtk.ComboGetActive(combo_encoder_analyze_cross),
+                                               encoderAnalyzeCrossTranslation);
+                       button_encoder_analyze_1RM_save.Sensitive = 
+                               (crossName == "1RM Bench Press" || crossName == "1RM Any exercise");
                }
 
                treeview_encoder_capture_curves.Sensitive = true;
diff --git a/src/gui/preferences.cs b/src/gui/preferences.cs
index fb0e0ca..d4c950b 100644
--- a/src/gui/preferences.cs
+++ b/src/gui/preferences.cs
@@ -64,6 +64,11 @@ public class PreferencesWindow {
        [Widget] Gtk.SpinButton spin_encoder_smooth_con;
        [Widget] Gtk.Label label_encoder_ecc_con;
        [Widget] Gtk.Label label_encoder_con;
+                       
+       [Widget] Gtk.RadioButton radio_encoder_1RM_nonweighted;
+       [Widget] Gtk.RadioButton radio_encoder_1RM_weighted;
+       [Widget] Gtk.RadioButton radio_encoder_1RM_weighted2;
+       [Widget] Gtk.RadioButton radio_encoder_1RM_weighted3;
 
 //     [Widget] Gtk.Box hbox_language_row;
 //     [Widget] Gtk.Box hbox_combo_language;
@@ -102,7 +107,7 @@ public class PreferencesWindow {
                        bool showInitialSpeed, bool showAngle, bool showQIndex, bool showDjIndex,
                        bool askDeletion, bool weightStatsPercent, bool heightPreferred, bool 
metersSecondsPreferred, 
                        string language, bool encoderPropulsive, double encoderSmoothEccCon, double 
encoderSmoothCon,
-                       string [] videoDevices, int videoDeviceNum)
+                       string [] videoDevices, int videoDeviceNum, string encoder1RMMethod)
        {
                if (PreferencesWindowBox == null) {
                        PreferencesWindowBox = new PreferencesWindow ();
@@ -186,6 +191,31 @@ public class PreferencesWindow {
                PreferencesWindowBox.spin_encoder_smooth_ecc_con.Value = encoderSmoothEccCon;
                PreferencesWindowBox.spin_encoder_smooth_con.Value = encoderSmoothCon;
 
+               if(encoder1RMMethod == Constants.Encoder1RMMethod.NONWEIGHTED.ToString())
+                       PreferencesWindowBox.radio_encoder_1RM_nonweighted.Active = true;
+               else if(encoder1RMMethod == Constants.Encoder1RMMethod.WEIGHTED.ToString())
+                       PreferencesWindowBox.radio_encoder_1RM_weighted.Active = true;
+               else if(encoder1RMMethod == Constants.Encoder1RMMethod.WEIGHTED2.ToString())
+                       PreferencesWindowBox.radio_encoder_1RM_weighted2.Active = true;
+               else //(encoder1RMMethod == Constants.Encoder1RMMethod.WEIGHTED3.ToString())
+                       PreferencesWindowBox.radio_encoder_1RM_weighted3.Active = true;
+               /*
+               switch(encoder1RMMethod) {
+                       case Constants.Encoder1RMMethod.NONWEIGHTED.ToString():
+                               PreferencesWindowBox.radio_encoder_1RM_nonweighted.Active = true;
+                               break;
+                       case Constants.Encoder1RMMethod.WEIGHTED.ToString():
+                               PreferencesWindowBox.radio_encoder_1RM_weighted.Active = true;
+                               break;
+                       case Constants.Encoder1RMMethod.WEIGHTED2.ToString():
+                               PreferencesWindowBox.radio_encoder_1RM_weighted2.Active = true;
+                               break;
+                       case Constants.Encoder1RMMethod.WEIGHTED3.ToString():
+                               PreferencesWindowBox.radio_encoder_1RM_weighted3.Active = true;
+                               break;
+               }
+               */
+
                //done here and not in glade to be shown with the decimal point of user language        
                PreferencesWindowBox.label_encoder_ecc_con.Text = (0.6).ToString();
                PreferencesWindowBox.label_encoder_con.Text = (0.7).ToString();
@@ -400,6 +430,17 @@ public class PreferencesWindow {
                                (double) PreferencesWindowBox.spin_encoder_smooth_con.Value), true);
                SqlitePreferences.Update("videoDevice", UtilGtk.ComboGetActivePos(combo_camera).ToString(), 
true);
        
+               string encoder1RMMethod = "";   
+               if(PreferencesWindowBox.radio_encoder_1RM_nonweighted.Active)
+                       encoder1RMMethod = Constants.Encoder1RMMethod.NONWEIGHTED.ToString();
+               else if(PreferencesWindowBox.radio_encoder_1RM_weighted.Active)
+                       encoder1RMMethod = Constants.Encoder1RMMethod.WEIGHTED.ToString();
+               else if(PreferencesWindowBox.radio_encoder_1RM_weighted2.Active)
+                       encoder1RMMethod = Constants.Encoder1RMMethod.WEIGHTED2.ToString();
+               else // (PreferencesWindowBox.radio_encoder_1RM_weighted3.Active)
+                       encoder1RMMethod = Constants.Encoder1RMMethod.WEIGHTED3.ToString();
+               SqlitePreferences.Update("encoder1RMMethod", encoder1RMMethod, true);
+       
                Sqlite.Close();
                
                /*
diff --git a/src/sqlite/encoder.cs b/src/sqlite/encoder.cs
index d7e7591..6da82d5 100644
--- a/src/sqlite/encoder.cs
+++ b/src/sqlite/encoder.cs
@@ -431,7 +431,7 @@ class SqliteEncoder : Sqlite
                dbcmd.CommandText = "INSERT INTO " + Constants.Encoder1RMTable +  
                                " (uniqueID, personID, sessionID, exerciseID, load1RM, future1, future2, 
future3)" +
                                " VALUES (NULL, " + personID + ", " + sessionID + ", " + 
-                               exerciseID + ", " + load1RM + ", '','','')";
+                               exerciseID + ", " + Util.ConvertToPoint(load1RM) + ", '','','')";
                Log.WriteLine(dbcmd.CommandText.ToString());
                dbcmd.ExecuteNonQuery();
 
@@ -480,7 +480,7 @@ class SqliteEncoder : Sqlite
                                        Convert.ToInt32(reader[1].ToString()),  //personID      
                                        Convert.ToInt32(reader[2].ToString()),  //sessionID
                                        Convert.ToInt32(reader[3].ToString()),  //exerciseID
-                                       Convert.ToDouble(reader[4].ToString())  //load1RM
+                                       Convert.ToDouble(Util.ChangeDecimalSeparator(reader[4].ToString()))  
//load1RM
                                        );
                        array.Add (e1RM);
                }
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index c331bee..9bab50c 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -72,7 +72,7 @@ class Sqlite
         * Important, change this if there's any update to database
         * Important2: if database version get numbers higher than 1, check if the comparisons with 
currentVersion works ok
         */
-       static string lastChronojumpDatabaseVersion = "0.94";
+       static string lastChronojumpDatabaseVersion = "0.95";
 
        public Sqlite() {
        }
@@ -1274,6 +1274,18 @@ class Sqlite
 
                                currentVersion = "0.94";
                        }
+                       if(currentVersion == "0.94") {
+                               dbcon.Open();
+                               
+                               SqlitePreferences.Insert ("encoder1RMMethod", 
+                                               Constants.Encoder1RMMethod.WEIGHTED2.ToString());
+                               Log.WriteLine("Added encoder1RMMethod");
+                               
+                               SqlitePreferences.Update ("databaseVersion", "0.95", true); 
+                               dbcon.Close();
+
+                               currentVersion = "0.95";
+                       }
                }
 
                //if changes are made here, remember to change also in CreateTables()
@@ -1413,6 +1425,7 @@ class Sqlite
                SqliteCountry.initialize();
                
                //changes [from - to - desc]
+               //0.94 - 0.95 Converted DB to 0.95 Added encoder1RMMethod
                //0.93 - 0.94 Converted DB to 0.94 Added encoder1RM table
                //0.92 - 0.93 Converted DB to 0.93 Added speed1RM on encoder exercise
                //0.91 - 0.92 Converted DB to 0.92 Added videoDevice to preferences
diff --git a/src/sqlite/preferences.cs b/src/sqlite/preferences.cs
index 143383e..b6b40c5 100644
--- a/src/sqlite/preferences.cs
+++ b/src/sqlite/preferences.cs
@@ -75,6 +75,7 @@ class SqlitePreferences : Sqlite
                Insert ("encoderSmoothEccCon", "0.6");
                Insert ("encoderSmoothCon", "0.7");
                Insert ("videoDevice", "0"); //first
+               Insert ("encoder1RMMethod", Constants.Encoder1RMMethod.WEIGHTED2.ToString());
        }
 
        public static void Insert(string myName, string myValue)
diff --git a/src/util.cs b/src/util.cs
index aca0526..7e78cd1 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -907,6 +907,9 @@ public class Util
        public static string GetEncoderExportTempFileName() {
                return Path.Combine(Path.GetTempPath(), Constants.EncoderExportTemp);
        }
+       public static string GetEncoderSpecialDataTempFileName() {
+               return Path.Combine(Path.GetTempPath(), Constants.EncoderSpecialDataTemp);
+       }
 
 
 //     public static void MoveTempToEncoderData(int sessionID, int uniqueID) {
@@ -1167,12 +1170,14 @@ public class Util
                        es.OutputGraph = es.OutputGraph.Replace("\\","/");
                        es.OutputData1 = es.OutputData1.Replace("\\","/");
                        es.OutputData2 = es.OutputData2.Replace("\\","/");
+                       es.SpecialData = es.SpecialData.Replace("\\","/");
                        operatingSystem = "Windows";
                }
                
                //--- way A. passing options to a file
                string scriptOptions = es.InputData + "\n" + 
-               es.OutputGraph + "\n" + es.OutputData1 + "\n" + es.OutputData2 + "\n" + 
+               es.OutputGraph + "\n" + es.OutputData1 + "\n" + 
+               es.OutputData2 + "\n" + es.SpecialData + "\n" + 
                es.Ep.ToString2("\n") + "\n" + title + "\n" + operatingSystem + "\n";
 
                string optionsFile = Path.GetTempPath() + "Roptions.txt";
@@ -1248,6 +1253,10 @@ public class Util
                        if (File.Exists(outputFileCheck2))
                                File.Delete(outputFileCheck2);
                }
+                       
+               //delete 1RM data if exists
+               if (File.Exists(es.SpecialData))
+                       File.Delete(es.SpecialData);
        
                p = new Process();
                p.StartInfo = pinfo;


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