[chronojump] 701534 - 1RM prediction on all tests (75%)



commit 0f705af726d624b13c9e5136e892cb59e3ac769d
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Jun 11 22:04:05 2013 +0200

    701534 - 1RM prediction on all tests (75%)

 encoder/graph.R        |  157 ++++++++++++++++++++++++------------------------
 glade/chronojump.glade |    3 +-
 src/constants.cs       |    1 +
 src/encoder.cs         |   22 +++++++
 src/gui/encoder.cs     |  111 ++++++++++++++++++++++++----------
 src/gui/session.cs     |    1 -
 src/sqlite/encoder.cs  |   89 +++++++++++++++++++++++++++
 src/sqlite/main.cs     |   15 ++++-
 8 files changed, 286 insertions(+), 113 deletions(-)
---
diff --git a/encoder/graph.R b/encoder/graph.R
index 836911d..ac6922b 100644
--- a/encoder/graph.R
+++ b/encoder/graph.R
@@ -919,7 +919,7 @@ addUnits <- function (var) {
 }
 
 #option: mean or max
-paintCrossVariables <- function (paf, varX, varY, option, isAlone, title, singleFile, Eccon, seriesName) {
+paintCrossVariables <- function (paf, varX, varY, option, isAlone, title, singleFile, Eccon, seriesName, 
do1RM, do1RMMethod) {
        x = (paf[,findPosInPaf(varX, option)])
        y = (paf[,findPosInPaf(varY, option)])
 
@@ -966,75 +966,62 @@ paintCrossVariables <- function (paf, varX, varY, option, isAlone, title, single
                }
                
                plot(x,y, xlab=varX, ylab="", pch=21,col=colBalls,bg=bgBalls,cex=cexBalls,axes=F)
-               
-               speed1RM = 0.185
-               #lineal stuff
-               #without weights
-
-               fit = lm(y ~ x)
-               #abline(fit,col="red")
-               c.intercept = coef(fit)[[1]]
-               c.x = coef(fit)[[2]]
-               load1RM = ( speed1RM - c.intercept ) / c.x
-
-               #plot(x,y, xlim=c(min(x),load1RM), ylim=c(speed1RM, max(y)), xlab=varX, ylab="", 
pch=21,col=colBalls,bg=bgBalls,cex=cexBalls,axes=F)
-               plot(x,y, xlim=c(min(x),load1RM), ylim=c(0, max(y)), xlab=varX, ylab="", 
pch=21,col=colBalls,bg=bgBalls,cex=cexBalls,axes=F)
-               abline(fit,col="red")
-               abline(h=speed1RM,col="gray",lty=2)
-               abline(v=load1RM,col="gray",lty=2)
-               mtext("1RM", at=load1RM, side=1, line=2,col="red")
-               mtext(round(load1RM,2), at=load1RM, side=1, line=3,col="red")
-               mtext("1RM", at=speed1RM, side=2, line=2,col="red")
-               mtext(speed1RM, at=speed1RM, side=2, line=3,col="red")
-               points(load1RM,speed1RM,cex=2,col="red")
-               
-               #weights x^2
-               fit = lm(y ~ x, weights=x/max(x)) 
-               print(x/max(x))
-               c.intercept = coef(fit)[[1]]
-               c.x = coef(fit)[[2]]
-               load1RM = ( speed1RM - c.intercept ) / c.x
-
-               abline(fit,col="green")
-               abline(h=speed1RM,col="gray",lty=2)
-               abline(v=load1RM,col="gray",lty=2)
-               mtext("1RM", at=load1RM, side=3, line=2,col="green")
-               mtext(round(load1RM,2), at=load1RM, side=3, line=3,col="green")
-               mtext("1RM", at=speed1RM, side=2, line=2,col="green")
-               mtext(speed1RM, at=speed1RM, side=2, line=3,col="green")
-               points(load1RM,speed1RM,cex=2,col="green")
-
-               #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))
-               c.intercept = coef(fit)[[1]]
-               c.x = coef(fit)[[2]]
-               load1RM = ( speed1RM - c.intercept ) / c.x
-
-               abline(fit,col="blue")
-               abline(h=speed1RM,col="gray",lty=2)
-               abline(v=load1RM,col="gray",lty=2)
-               mtext("1RM", at=load1RM, side=3, line=2,col="blue")
-               mtext(round(load1RM,2), at=load1RM, side=3, line=3,col="blue")
-               mtext("1RM", at=speed1RM, side=2, line=2,col="blue")
-               mtext(speed1RM, at=speed1RM, side=2, line=3,col="blue")
-               points(load1RM,speed1RM,cex=2,col="blue")
-
-
-               #quadratic stuff
-               #fit2 = lm(y ~ I(x^2) + x)
-               #fit2line = predict(fit2, data.frame(x = 10:100))
-               #lines(10:100 ,fit2line, col="red") #puts line on plot
-               
-               
        
-               #x vector should contain at least 4 different values
-               if(length(unique(x)) >= 4)
-                       lines(smooth.spline(x,y,df=4),col=colBalls,lwd=2)
+               if(do1RM != FALSE & do1RM != "0") {     
+                       speed1RM = as.numeric(do1RM)
+
+                       print("speed1RM")
+                       print(speed1RM)
+                       
+                       #lineal stuff
+               
+                       if(do1RMMethod == "nonweighted")  {
+                               #without weights
+                               fit = lm(y ~ x)
+                       } else if(do1RMMethod == "weighted")  {
+                               #weights x
+                               fit = lm(y ~ x, weights=x/max(x)) 
+                               print(x/max(x))
+                       } 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")  {
+                               #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))
+                       }
+
+                       c.intercept = coef(fit)[[1]]
+                       c.x = coef(fit)[[2]]
+                       load1RM = ( speed1RM - c.intercept ) / c.x
+
+                       #plot(x,y, xlim=c(min(x),load1RM), ylim=c(speed1RM, max(y)), xlab=varX, ylab="", 
pch=21,col=colBalls,bg=bgBalls,cex=cexBalls,axes=F)
+                       plot(x,y, xlim=c(min(x),load1RM), ylim=c(0, max(y)), xlab=varX, ylab="", 
pch=21,col=colBalls,bg=bgBalls,cex=cexBalls,axes=F)
+                       abline(fit,col="red")
+                       abline(h=speed1RM,col="gray",lty=2)
+                       abline(v=load1RM,col="gray",lty=2)
+                       mtext("1RM", at=load1RM, side=1, line=2,col="red")
+                       mtext(round(load1RM,2), at=load1RM, side=1, line=3,col="red")
+                       mtext("1RM", at=speed1RM, side=2, line=2,col="red")
+                       mtext(speed1RM, at=speed1RM, side=2, line=3,col="red")
+                       points(load1RM,speed1RM,cex=2,col="red")
+
+
+
+                       #quadratic stuff
+                       #fit2 = lm(y ~ I(x^2) + x)
+                       #fit2line = predict(fit2, data.frame(x = 10:100))
+                       #lines(10:100 ,fit2line, col="red") #puts line on plot
+               }
+               else {
+                       #x vector should contain at least 4 different values
+                       if(length(unique(x)) >= 4)
+                               lines(smooth.spline(x,y,df=4),col=colBalls,lwd=2)
+               }
                
                title(title, cex.main=1, font.main=2)
                text(x,y,nums,adj=c(adjHor,.5),cex=cexNums)
-
                
 
        } else { #more than one series
@@ -1201,7 +1188,7 @@ doProcess <- function(options) {
        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"
+       Analysis=options[9]     #in cross comes as "cross;Force;Speed;mean"
        AnalysisOptions=options[10]     #p: propulsive
        SmoothingOneEC=options[11]
        SmoothingOneC=options[12]
@@ -1518,14 +1505,15 @@ doProcess <- function(options) {
        writeCurves = TRUE
 
        #Analysis in cross variables comes as:
-       #"cross.Speed.Force.mean"       #2nd is Y, 3d is X. "mean" can also be "max"
+       #"cross;Speed;Force;mean"       #2nd is Y, 3d is X. "mean" can also be "max"
        #there's a double XY plot:
-       #"cross.Speed,Power.Load.mean"  #Speed,power are Y (left and right), 3d: Load is X.
-       analysisCross = unlist(strsplit(Analysis, "\\."))
+       #"cross;Speed,Power;Load;mean"  #Speed,power are Y (left and right), 3d: Load is X.
+       #in 1RMAnyExercise: "1RMAnyExercise;0.185;method" speed1RM = 0.185m/s
+       analysisCross = unlist(strsplit(Analysis, "\\;"))
        if(
           Analysis == "powerBars" || analysisCross[1] == "cross" || 
-          Analysis == "1RMBadillo2010" || Analysis == "curves" ||
-          writeCurves) 
+          Analysis == "1RMBadillo2010" || analysisCross[1] == "1RMAnyExercise" || 
+          Analysis == "curves" || writeCurves) 
        {
                paf = data.frame()
                discardedCurves = NULL
@@ -1540,13 +1528,13 @@ doProcess <- function(options) {
                                myEccon = curves[i,7]
 
                                #only use concentric data       
-                               if(Analysis == "1RMBadillo2010" & myEccon == "e") {
+                               if( (Analysis == "1RMBadillo2010" || analysisCross[1] == "1RMAnyExercise") & 
myEccon == "e") {
                                        discardedCurves = c(i,discardedCurves)
                                        discardingCurves = TRUE
                                        next;
                                }
                        } else {
-                               if(Analysis == "1RMBadillo2010" & Eccon == "ecS" & i%%2 == 1) {
+                               if( (Analysis == "1RMBadillo2010" || analysisCross[1] == "1RMAnyExercise") & 
Eccon == "ecS" & i%%2 == 1) {
                                        discardedCurves = c(i,discardedCurves)
                                        discardingCurves = TRUE
                                        next;
@@ -1601,19 +1589,32 @@ doProcess <- function(options) {
                                analysisCrossVertVars = unlist(strsplit(analysisCross[2], "\\,"))
                                paintCrossVariables(paf, analysisCross[3], analysisCrossVertVars[1], 
                                                    analysisCross[4], "LEFT", Title,
-                                                   singleFile,Eccon,mySeries)
+                                                   singleFile,Eccon,mySeries, 
+                                                   FALSE, FALSE) 
                                par(new=T)
                                paintCrossVariables(paf, analysisCross[3], analysisCrossVertVars[2], 
                                                    analysisCross[4], "RIGHT", "",
-                                                   singleFile,Eccon,mySeries)
+                                                   singleFile,Eccon,mySeries, 
+                                                   FALSE, FALSE) 
                        } else
                                paintCrossVariables(paf, analysisCross[3], analysisCross[2], 
                                                    analysisCross[4], "ALONE", Title,
-                                                   singleFile,Eccon,mySeries)
+                                                   singleFile,Eccon,mySeries, 
+                                                   FALSE, FALSE) 
+               }
+               else if(analysisCross[1] == "1RMAnyExercise") {
+                       mySeries = "1"
+                       if(! singleFile)
+                               mySeries = curves[,8]
+
+                       paintCrossVariables(paf, "Load", "Speed", 
+                                           "mean", "ALONE", Title,
+                                           singleFile,Eccon,mySeries, 
+                                           analysisCross[2], analysisCross[3]) #speed1RM, method
                }
                else if(Analysis == "1RMBadillo2010") {
                        paint1RMBadillo2010(paf, Title)
-               }
+               } 
                
                if(Analysis == "curves" || writeCurves) {
                        if(singleFile)
diff --git a/glade/chronojump.glade b/glade/chronojump.glade
index 2e8f834..4b85972 100644
--- a/glade/chronojump.glade
+++ b/glade/chronojump.glade
@@ -12237,7 +12237,7 @@ on current Chronojump version.</property>
                                                             <property 
name="secondary_icon_activatable">False</property>
                                                             <property 
name="primary_icon_sensitive">True</property>
                                                             <property 
name="secondary_icon_sensitive">True</property>
-                                                            <property name="adjustment">10 0 300 1 10 
0</property>
+                                                            <property name="adjustment">0 0 300 1 10 
0</property>
                                                             <property name="climb_rate">1</property>
                                                             <property name="snap_to_ticks">True</property>
                                                             <property name="numeric">True</property>
@@ -12291,6 +12291,7 @@ on current Chronojump version.</property>
                                                             <property name="snap_to_ticks">True</property>
                                                             <property name="numeric">True</property>
                                                             <property 
name="update_policy">if-valid</property>
+                                                            <signal name="value_changed" 
handler="on_spin_encoder_extra_weight_value_changed" swapped="no"/>
                                                             </widget>
                                                             <packing>
                                                             <property name="top_attach">1</property>
diff --git a/src/constants.cs b/src/constants.cs
index bf50327..8dd73c6 100644
--- a/src/constants.cs
+++ b/src/constants.cs
@@ -102,6 +102,7 @@ public class Constants
        public const string TempMultiChronopicTable = "tempMultiChronopic"; //TODO
        public const string EncoderTable = "encoder";
        public const string EncoderExerciseTable = "encoderExercise";
+       public const string Encoder1RMTable = "encoder1RM";
 
        //tests types
        public const string JumpTypeTable = "jumpType";
diff --git a/src/encoder.cs b/src/encoder.cs
index 139556b..df42b9e 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -467,3 +467,25 @@ public class EncoderExercise
        ~EncoderExercise() {}
 }
 
+public class Encoder1RM
+{
+       public int uniqueID;
+       public int personID;
+       public int sessionID;
+       public int exerciseID;
+       public double load1RM;
+       
+       public Encoder1RM() {
+       }
+
+       public Encoder1RM(int uniqueID, int personID, int sessionID, int exerciseID, double load1RM)
+       {
+               this.uniqueID = uniqueID;
+               this.personID = personID;
+               this.sessionID = sessionID;
+               this.exerciseID = exerciseID;
+               this.load1RM = load1RM;
+       }
+
+       ~Encoder1RM() {}
+}
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 01088e4..523257d 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -32,6 +32,8 @@ using Mono.Unix;
 public partial class ChronoJumpWindow 
 {
        [Widget] Gtk.SpinButton spin_encoder_extra_weight;
+       [Widget] Gtk.SpinButton spin_encoder_displaced_weight;
+       [Widget] Gtk.SpinButton spin_encoder_1RM_percent;
        
        [Widget] Gtk.Button button_encoder_capture;
        [Widget] Gtk.RadioButton radiobutton_encoder_capture_safe;
@@ -239,7 +241,7 @@ public partial class ChronoJumpWindow
                                Convert.ToInt32(
                                        Util.FindOnArray(':', 2, 3, exerciseNameShown, 
                                        encoderExercisesTranslationAndBodyPWeight) ),   
//ex.percentBodyWeight 
-                               findMass(true),
+                               Util.ConvertToPoint(findMass(true)),
                                Util.ConvertToPoint(encoderSmoothEccCon),               //R decimal: '.'
                                Util.ConvertToPoint(encoderSmoothCon),                  //R decimal: '.'
                                findEccon(true),                                        //force ecS (ecc-conc 
separated)
@@ -270,7 +272,8 @@ public partial class ChronoJumpWindow
                        //title to sen to python software has to be without spaces
                        Util.RunEncoderCapturePython( 
                                        Util.ChangeSpaceAndMinusForUnderscore(currentPerson.Name) + "----" + 
-                                       Util.ChangeSpaceAndMinusForUnderscore(exerciseNameShown) + "----(" + 
findMass(true) + "Kg)",
+                                       Util.ChangeSpaceAndMinusForUnderscore(exerciseNameShown) + "----(" + 
+                                       Util.ConvertToPoint(findMass(true)) + "Kg)",
                                        es, chronopicWin.GetEncoderPort());
                        
                        entry_encoder_signal_comment.Text = "";
@@ -291,6 +294,31 @@ public partial class ChronoJumpWindow
                        Log.WriteLine("ZZZZZZZZZZZZZZZ");
                }
        }
+       
+       void on_combo_encoder_exercise_changed (object o, EventArgs args) {
+               if(UtilGtk.ComboGetActive(combo_encoder_exercise) != "") //needed because 
encoder_exercise_edit updates this combo and can be without values in the changing process
+                       encoder_change_displaced_weight_and_1RM ();
+       }
+       void on_spin_encoder_extra_weight_value_changed (object o, EventArgs args) {
+               encoder_change_displaced_weight_and_1RM ();
+       }
+
+       void encoder_change_displaced_weight_and_1RM () {
+               //displaced weight
+               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); 
+               double load1RM = 0;
+               if(array1RM.Count > 0)
+                       load1RM = ((Encoder1RM) array1RM[0]).load1RM; //take only the first in array (will be 
the last uniqueID)
+
+               spin_encoder_1RM_percent.Value = load1RM;
+       }
+
 
        void calculeCurves() {
                encoderTimeStamp = UtilDate.ToFile(DateTime.Now);
@@ -385,7 +413,7 @@ public partial class ChronoJumpWindow
                                Convert.ToInt32(
                                        Util.FindOnArray(':', 2, 3, 
UtilGtk.ComboGetActive(combo_encoder_exercise), 
                                        encoderExercisesTranslationAndBodyPWeight) ),   
//ex.percentBodyWeight 
-                               findMass(true),
+                               Util.ConvertToPoint(findMass(true)),
                                findEccon(true),                                        //force ecS (ecc-conc 
separated)
                                "curves",
                                analysisOptions,
@@ -406,7 +434,7 @@ public partial class ChronoJumpWindow
                Util.RunEncoderGraph(
                                Util.ChangeSpaceAndMinusForUnderscore(currentPerson.Name) + "-" + 
                                
Util.ChangeSpaceAndMinusForUnderscore(UtilGtk.ComboGetActive(combo_encoder_exercise)) + 
-                               "-(" + findMass(true) + "Kg)",
+                               "-(" + Util.ConvertToPoint(findMass(true)) + "Kg)",
                                es);
 
                //store this to show 1,2,3,4,... or 1e,1c,2e,2c,... in RenderN
@@ -941,7 +969,7 @@ public partial class ChronoJumpWindow
                                Convert.ToInt32(
                                        Util.FindOnArray(':', 2, 3, 
UtilGtk.ComboGetActive(combo_encoder_exercise), 
                                                encoderExercisesTranslationAndBodyPWeight) ),
-                               findMass(true),
+                               Util.ConvertToPoint(findMass(true)),
                                findEccon(false),               //do not force ecS (ecc-conc separated)
                                "exportCSV",
                                analysisOptions,
@@ -965,7 +993,7 @@ public partial class ChronoJumpWindow
                Util.RunEncoderGraph(
                                Util.ChangeSpaceAndMinusForUnderscore(currentPerson.Name) + "-" + 
                                
Util.ChangeSpaceAndMinusForUnderscore(UtilGtk.ComboGetActive(combo_encoder_exercise)) + 
-                                       "-(" + findMass(true) + "Kg)",
+                                       "-(" + Util.ConvertToPoint(findMass(true)) + "Kg)",
                                encoderStruct);
 
                //encoder_pulsebar_capture.Text = string.Format(Catalog.GetString(
@@ -1289,7 +1317,7 @@ public partial class ChronoJumpWindow
                                        encoderExercisesTranslationAndBodyPWeight) ),   //exerciseID
                                findEccon(true),        //force ecS (ecc-conc separated)
                                UtilGtk.ComboGetActive(combo_encoder_laterality),
-                               findMass(false),        //when save on sql, do not include person weight
+                               Util.ConvertToPoint(findMass(false)),   //when save on sql, do not include 
person weight
                                signalOrCurve,
                                fileSaved,              //to know date do: select substr(name,-23,19) from 
encoder;
                                path,                   //url
@@ -1367,14 +1395,17 @@ public partial class ChronoJumpWindow
                                        (
                                         crossNameTemp == "Speed,Power / Load" || 
                                         crossNameTemp == Catalog.GetString("Speed,Power / Load") ||
-                                        crossNameTemp == "1RM Prediction" || 
-                                        crossNameTemp == Catalog.GetString("1RM Prediction")
+                                        crossNameTemp == "1RM Bench Press" || 
+                                        crossNameTemp == Catalog.GetString("1RM Bench Press") ||
+                                        crossNameTemp == "1RM Any exercise" || 
+                                        crossNameTemp == Catalog.GetString("1RM Any exercise")
                                        )) {
                                new DialogMessage(Constants.MessageTypes.WARNING, 
                                                Catalog.GetString("Sorry, this graph is not supported yet.") +
                                                "\n\nUser curves - compare - cross variables" +
                                                "\n- Speed,Power / Load" +
-                                               "\n- 1RM Prediction"
+                                               "\n- 1RM Bench Press" +
+                                               "\n- 1RM Any exercise"
                                                );
 
                                return;
@@ -1392,7 +1423,8 @@ public partial class ChronoJumpWindow
                string exerciseNameShown = UtilGtk.ComboGetActive(combo_encoder_exercise);
                bool capturedOk = runEncoderCaptureCsharp( 
                                Util.ChangeSpaceAndMinusForUnderscore(currentPerson.Name) + "----" + 
-                               Util.ChangeSpaceAndMinusForUnderscore(exerciseNameShown) + "----(" + 
findMass(true) + "Kg)",
+                               Util.ChangeSpaceAndMinusForUnderscore(exerciseNameShown) + "----(" + 
+                               Util.ConvertToPoint(findMass(true)) + "Kg)",
                                //es, 
                                (int) spin_encoder_capture_time.Value, 
                                Util.GetEncoderDataTempFileName(),
@@ -1528,17 +1560,26 @@ public partial class ChronoJumpWindow
                        string crossName = 
Util.FindOnArray(':',1,0,UtilGtk.ComboGetActive(combo_encoder_analyze_cross),
                                                encoderAnalyzeCrossTranslation);
 
-                       if(crossName == "1RM Prediction") {
+                       if(crossName == "1RM Bench Press") {
                                sendAnalysis = "1RMBadillo2010";
                                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];
+                               
+                               sendAnalysis = "1RMAnyExercise;" + Util.ConvertToPoint(ex.speed1RM) + 
";weighted2" ; 
+                               analysisOptions = "p";
                        } else {
                                //convert: "Force / Speed" in: "cross.Force.Speed.mean"
                                string [] crossNameFull = crossName.Split(new char[] {' '});
-                               sendAnalysis += "." + crossNameFull[0] + "." + crossNameFull[2]; //[1]=="/"
+                               sendAnalysis += ";" + crossNameFull[0] + ";" + crossNameFull[2]; //[1]=="/"
                                if(radiobutton_encoder_analyze_mean.Active)
-                                       sendAnalysis += ".mean";
+                                       sendAnalysis += ";mean";
                                else
-                                       sendAnalysis += ".max";
+                                       sendAnalysis += ";max";
                        }
                }
                        
@@ -1695,7 +1736,7 @@ Log.WriteLine(str);
                                                Util.FindOnArray(':', 2, 3, 
                                                        UtilGtk.ComboGetActive(combo_encoder_exercise), 
                                                        encoderExercisesTranslationAndBodyPWeight) ),
-                                       findMass(true),
+                                       Util.ConvertToPoint(findMass(true)),
                                        findEccon(false),               //do not force ecS (ecc-conc 
separated)
                                        sendAnalysis,
                                        analysisOptions,
@@ -1718,7 +1759,7 @@ Log.WriteLine(str);
                                ep);
 
                //show mass in title except if it's curves because then can be different mass
-               //string massString = "-(" + findMass(true) + "Kg)";
+               //string massString = "-(" + Util.ConvertToPoint(findMass(true)) + "Kg)";
                //if(radiobutton_encoder_analyze_data_user_curves.Active)
                //      massString = "";
 
@@ -1800,7 +1841,7 @@ Log.WriteLine(str);
        
                label_encoder_analyze_side_max.Visible = false;
 
-               //restore 1RM Prediction sensitiveness
+               //restore 1RM Bench Press sensitiveness
                radiobutton_encoder_analyze_max.Sensitive = true;
                
                encoderButtonsSensitive(encoderSensEnumStored);
@@ -1818,7 +1859,7 @@ Log.WriteLine(str);
                check_encoder_analyze_eccon_together.Sensitive=false;
                check_encoder_analyze_eccon_together.Active = true;
                
-               //restore 1RM Prediction sensitiveness
+               //restore 1RM Bench Press sensitiveness
                radiobutton_encoder_analyze_max.Sensitive = true;
                
                on_combo_encoder_analyze_cross_changed (obj, args);
@@ -1835,7 +1876,7 @@ Log.WriteLine(str);
                check_encoder_analyze_eccon_together.Sensitive=false;
                check_encoder_analyze_eccon_together.Active = true;
 
-               //restore 1RM Prediction sensitiveness
+               //restore 1RM Bench Press sensitiveness
                radiobutton_encoder_analyze_max.Sensitive = true;
                
                encoderButtonsSensitive(encoderSensEnumStored);
@@ -1851,7 +1892,7 @@ Log.WriteLine(str);
 
                label_encoder_analyze_side_max.Visible = false;
 
-               //restore 1RM Prediction sensitiveness
+               //restore 1RM Bench Press sensitiveness
                radiobutton_encoder_analyze_max.Sensitive = true;
                
                encoderButtonsSensitive(encoderSensEnumStored);
@@ -1885,7 +1926,7 @@ Log.WriteLine(str);
                return false;
        }
 
-       private string findMass(bool includePerson) {
+       private double findMass(bool includePerson) {
                double mass = spin_encoder_extra_weight.Value;
                if(includePerson) {
                        //TODO: maybe better have a currentEncoderExercise global variable
@@ -1895,7 +1936,7 @@ Log.WriteLine(str);
                        mass += currentPersonSession.Weight * exPBodyWeight / 100.0;
                }
 
-               return Util.ConvertToPoint(mass); //R decimal: '.'
+               return mass;
        }
 
        //TODO: check all this  
@@ -1937,6 +1978,7 @@ Log.WriteLine(str);
                UtilGtk.ComboUpdate(combo_encoder_exercise, exerciseNamesToCombo, "");
                combo_encoder_exercise.Active = UtilGtk.ComboMakeActive(combo_encoder_exercise, 
                                Catalog.GetString(((EncoderExercise) encoderExercises[0]).name));
+               combo_encoder_exercise.Changed += new EventHandler (on_combo_encoder_exercise_changed);
                
                //create combo eccon
                string [] comboEcconOptions = { "Concentric", "Eccentric-concentric" };
@@ -1987,15 +2029,16 @@ Log.WriteLine(str);
                
                //create combo analyze cross (variables)
                string [] comboAnalyzeCrossOptions = { 
-                       "Speed / Load", "Force / Load", "Power / Load", "Speed,Power / Load", "Force / 
Speed", "Power / Speed", "1RM Prediction"};
+                       "Speed / Load", "Force / Load", "Power / Load", "Speed,Power / Load", "Force / 
Speed", "Power / Speed", 
+                       "1RM Bench Press", "1RM Any exercise"};
                string [] comboAnalyzeCrossOptionsTranslated = { 
                        Catalog.GetString("Speed / Load"), Catalog.GetString("Force / Load"), 
                        Catalog.GetString("Power / Load"), Catalog.GetString("Speed,Power / Load"), 
-                       Catalog.GetString("Force / Speed"), Catalog.GetString("Power / Speed") , 
-                       Catalog.GetString("1RM Prediction")
-               };
+                       Catalog.GetString("Force / Speed"), Catalog.GetString("Power / Speed"), 
+                       Catalog.GetString("1RM Bench Press"), Catalog.GetString("1RM Any exercise")
+               }; //if added more, change the int in the 'for' below
                encoderAnalyzeCrossTranslation = new String [comboAnalyzeCrossOptions.Length];
-               for(int j=0; j < 7 ; j++)
+               for(int j=0; j < 8 ; j++)
                        encoderAnalyzeCrossTranslation[j] = 
                                comboAnalyzeCrossOptions[j] + ":" + comboAnalyzeCrossOptionsTranslated[j];
                combo_encoder_analyze_cross = ComboBox.NewText ();
@@ -2074,7 +2117,9 @@ Log.WriteLine(str);
        void on_combo_encoder_analyze_cross_changed (object o, EventArgs args)
        {
                if(Util.FindOnArray(':',1,0,UtilGtk.ComboGetActive(combo_encoder_analyze_cross),
-                                       encoderAnalyzeCrossTranslation) == "1RM Prediction") {
+                                       encoderAnalyzeCrossTranslation) == "1RM Bench Press" ||
+                               Util.FindOnArray(':',1,0,UtilGtk.ComboGetActive(combo_encoder_analyze_cross),
+                                       encoderAnalyzeCrossTranslation) == "1RM Any exercise" ) {
                        radiobutton_encoder_analyze_mean.Active = true;
                        radiobutton_encoder_analyze_max.Sensitive = false;
                        check_encoder_analyze_eccon_together.Active = false;
@@ -2439,7 +2484,7 @@ Log.WriteLine(str);
                //write exercise and extra weight data
                ArrayList curvesData = new ArrayList();
                string exerciseName = "";
-               string mass = ""; 
+               double mass = 0; 
                if(radiobutton_encoder_analyze_data_user_curves.Active) {
                        curvesData = SqliteEncoder.Select(
                                        false, -1, currentPerson.UniqueID, currentSession.UniqueID, "curve", 
true);
@@ -2472,14 +2517,14 @@ Log.WriteLine(str);
                                        mass = eSQL.extraWeight;
                                        */
                                        exerciseName = cells[2];
-                                       mass = cells[3];
+                                       mass = Convert.ToDouble(cells[3]);
                                }
 
                                encoderAnalyzeCurves.Add (new EncoderCurve (
                                                        cells[0], 
                                                        cells[1],       //seriesName 
                                                        exerciseName, 
-                                                       Convert.ToDouble(mass),
+                                                       mass,
                                                        cells[4], cells[5], cells[6], 
                                                        cells[7], cells[8], cells[9], 
                                                        cells[10], cells[11], cells[12],
@@ -2916,6 +2961,8 @@ Log.WriteLine(str);
 
                //put some data just in case user doesn't click on compare button
                encoderCompareInitialize();
+               
+               encoder_change_displaced_weight_and_1RM ();
        }
 
        private void encoderButtonsSensitive(encoderSensEnum option) {
diff --git a/src/gui/session.cs b/src/gui/session.cs
index 365ebe5..fa9dc87 100644
--- a/src/gui/session.cs
+++ b/src/gui/session.cs
@@ -854,7 +854,6 @@ public class SessionLoadWindow {
                        selected = (string)model.GetValue (iter, 0);
                        button_accept.Sensitive = true;
                }
-               Log.WriteLine (selected);
        }
        
        void on_row_double_clicked (object o, Gtk.RowActivatedArgs args)
diff --git a/src/sqlite/encoder.cs b/src/sqlite/encoder.cs
index 1360b94..d7e7591 100644
--- a/src/sqlite/encoder.cs
+++ b/src/sqlite/encoder.cs
@@ -402,5 +402,94 @@ class SqliteEncoder : Sqlite
 
                return array;
        }
+       
+       
+       /*
+        * 1RM stuff
+        */
+
+       protected internal static void createTable1RM()
+       {
+               dbcmd.CommandText = 
+                       "CREATE TABLE " + Constants.Encoder1RMTable + " ( " +
+                       "uniqueID INTEGER PRIMARY KEY, " +
+                       "personID INT, " +
+                       "sessionID INT, " +
+                       "exerciseID INT, " +
+                       "load1RM FLOAT, " +
+                       "future1 TEXT, " +      
+                       "future2 TEXT, " +
+                       "future3 TEXT )";
+               dbcmd.ExecuteNonQuery();
+       }
+       
+       public static void Insert1RM(bool dbconOpened, int personID, int sessionID, int exerciseID, double 
load1RM)     
+       {
+               if(! dbconOpened)
+                       dbcon.Open();
+
+               dbcmd.CommandText = "INSERT INTO " + Constants.Encoder1RMTable +  
+                               " (uniqueID, personID, sessionID, exerciseID, load1RM, future1, future2, 
future3)" +
+                               " VALUES (NULL, " + personID + ", " + sessionID + ", " + 
+                               exerciseID + ", " + load1RM + ", '','','')";
+               Log.WriteLine(dbcmd.CommandText.ToString());
+               dbcmd.ExecuteNonQuery();
+
+               if(! dbconOpened)
+                       dbcon.Close();
+       }
+       
+       public static ArrayList Select1RM (bool dbconOpened, int personID, int sessionID, int exerciseID)
+       {
+               if(! dbconOpened)
+                       dbcon.Open();
+
+               string whereStr = "";
+               if(personID != -1 || sessionID != -1 || exerciseID != -1) {
+                       whereStr = " WHERE ";
+                       string andStr = "";
+
+                       if(personID != -1) {
+                               whereStr += " personID = " + personID;
+                               andStr = " AND ";
+                       }
+
+                       if(sessionID != -1) {
+                               whereStr += andStr + " sessionID = " + sessionID;
+                               andStr = " AND ";
+                       }
+
+                       if(exerciseID != -1)
+                               whereStr += andStr + " exerciseID = " + exerciseID;
+               }
+
+               dbcmd.CommandText = "SELECT * FROM " + Constants.Encoder1RMTable + whereStr +
+                       " ORDER BY uniqueID DESC"; //this allows to select the last uniqueID because will be 
the first in the returned array 
+
+               Log.WriteLine(dbcmd.CommandText.ToString());
+               
+               SqliteDataReader reader;
+               reader = dbcmd.ExecuteReader();
+
+               ArrayList array = new ArrayList(1);
+
+               Encoder1RM e1RM = new Encoder1RM();
+               while(reader.Read()) {
+                       e1RM = new Encoder1RM (
+                                       Convert.ToInt32(reader[0].ToString()),  //uniqueID
+                                       Convert.ToInt32(reader[1].ToString()),  //personID      
+                                       Convert.ToInt32(reader[2].ToString()),  //sessionID
+                                       Convert.ToInt32(reader[3].ToString()),  //exerciseID
+                                       Convert.ToDouble(reader[4].ToString())  //load1RM
+                                       );
+                       array.Add (e1RM);
+               }
+               reader.Close();
+               if(! dbconOpened)
+                       dbcon.Close();
+
+               return array;
+       }
+       
 
 }
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index d86d2a0..c331bee 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.93";
+       static string lastChronojumpDatabaseVersion = "0.94";
 
        public Sqlite() {
        }
@@ -1263,6 +1263,17 @@ class Sqlite
 
                                currentVersion = "0.93";
                        }
+                       if(currentVersion == "0.93") {
+                               dbcon.Open();
+                               
+                               SqliteEncoder.createTable1RM();
+                               Log.WriteLine("Added encoder1RM table");
+                               
+                               SqlitePreferences.Update ("databaseVersion", "0.94", true); 
+                               dbcon.Close();
+
+                               currentVersion = "0.94";
+                       }
                }
 
                //if changes are made here, remember to change also in CreateTables()
@@ -1379,6 +1390,7 @@ class Sqlite
                SqliteEncoder.createTableEncoder();
                SqliteEncoder.createTableEncoderExercise();
                SqliteEncoder.initializeTableEncoderExercise();
+               SqliteEncoder.createTable1RM();
 
                //sports
                creationRate ++;
@@ -1401,6 +1413,7 @@ class Sqlite
                SqliteCountry.initialize();
                
                //changes [from - to - desc]
+               //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
                //0.90 - 0.91 Converted DB to 0.91 Encoder Squat 75% -> 100%


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