[chronojump] code clean and fixed 1RMBadillo low data



commit af7b223f7847e80f98540f95891463b189ea9759
Author: Xavier de Blas <xaviblas gmail com>
Date:   Sat Nov 16 11:59:10 2013 +0100

    code clean and fixed 1RMBadillo low data

 encoder/graph.R    |  108 ++++++++++++++++++++++++++++-----------------------
 src/encoder.cs     |    6 ++-
 src/gui/encoder.cs |   47 ++++++++++++++---------
 3 files changed, 92 insertions(+), 69 deletions(-)
---
diff --git a/encoder/graph.R b/encoder/graph.R
index 0bdd346..0e945a9 100644
--- a/encoder/graph.R
+++ b/encoder/graph.R
@@ -101,7 +101,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)
 }
@@ -122,7 +122,7 @@ print(options)
 
 OutputData2 = options[4] #currently used to display processing feedback
 SpecialData = options[5]
-OperatingSystem=options[18]
+OperatingSystem=options[19]
 
 
 write("(1/5) Starting R", OutputData2)
@@ -1485,7 +1485,13 @@ paint1RMBadillo2010 <- function (paf, title, outputData1) {
        maxy=max(c(msp,curvesSpeed))
        miny=min(c(msp,curvesSpeed))
 
+
        loadPercentCalc=8.4326*curvesSpeed^2 - 73.501*curvesSpeed + 112.33
+       #sometimes there's a negative value, fix it
+       for(i in 1:length(loadPercentCalc))
+              if(loadPercentCalc[i] < 0)
+                      loadPercentCalc[i] = NA
+
        loadCalc= 100 * curvesLoad / loadPercentCalc
 
        #for calculations take only the curves slower or == than 1.33
@@ -1583,18 +1589,28 @@ doProcess <- function(options) {
        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"
-                               #in single comes as "single;Speed;Accel;Force;Power", or eg: 
"single;NoSpeed;NoAccel;Force;Power"
-                               #in side same as in single
-       AnalysisOptions=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
-       #important, if this grows, change the readLines value on getOptionsFromFile
+       
+       #in Analysis "cross", AnalysisVariables can be "Force;Speed;mean". 1st is Y, 2nd is X. "mean" can 
also be "max"
+       #Analysis "cross" can have a double XY plot, AnalysisVariables = "Speed,Power;Load;mean"
+       #       1st: Speed,power are Y (left and right), 2n: Load is X.
+       #
+       #in Analysis "single" or "side", AnalysisVariables can be:
+       #       "Speed;Accel;Force;Power", or eg: "NoSpeed;NoAccel;Force;Power"
+       #
+       #in Analysis = "1RMAnyExercise"
+       #AnalysisVariables = "0.185;method". speed1RM = 0.185m/s
+       Analysis=options[10]    
+       AnalysisVariables=unlist(strsplit(options[11], "\\;"))
+       
+       AnalysisOptions=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)
@@ -1602,11 +1618,6 @@ doProcess <- function(options) {
        print(OutputData2)
        print(SpecialData)
 
-       #TODO: write this clearer
-       analysisSingleOrSideSAFE = unlist(strsplit(Analysis, "\\;"))
-       if(analysisSingleOrSideSAFE[1] == "single" || analysisSingleOrSideSAFE[1] == "side")
-               Analysis = analysisSingleOrSideSAFE[1]
-
        #read AnalysisOptions
        #if is propulsive and rotatory inertial is: "p;ri;0.010" (last is momentum)
        #if nothing: "-;-;-"
@@ -1909,10 +1920,10 @@ doProcess <- function(options) {
                              TRUE,     #showAxes
                              TRUE,     #legend
                              Analysis, isPropulsive, inertialType, myExPercentBodyWeight,
-                             (analysisSingleOrSideSAFE[2] == "Speed"), #show speed
-                             (analysisSingleOrSideSAFE[3] == "Accel"), #show accel
-                             (analysisSingleOrSideSAFE[4] == "Force"), #show force
-                             (analysisSingleOrSideSAFE[5] == "Power") #show power
+                             (AnalysisVariables[1] == "Speed"), #show speed
+                             (AnalysisVariables[2] == "Accel"), #show accel
+                             (AnalysisVariables[3] == "Force"), #show force
+                             (AnalysisVariables[4] == "Power")  #show power
                              ) 
                }
        }
@@ -1954,10 +1965,10 @@ doProcess <- function(options) {
                              FALSE,    #showAxes
                              FALSE,    #legend
                              Analysis, isPropulsive, inertialType, myExPercentBodyWeight,
-                             (analysisSingleOrSideSAFE[2] == "Speed"), #show speed
-                             (analysisSingleOrSideSAFE[3] == "Accel"), #show accel
-                             (analysisSingleOrSideSAFE[4] == "Force"), #show force
-                             (analysisSingleOrSideSAFE[5] == "Power") #show power
+                             (AnalysisVariables[1] == "Speed"), #show speed
+                             (AnalysisVariables[2] == "Accel"), #show accel
+                             (AnalysisVariables[3] == "Force"), #show force
+                             (AnalysisVariables[4] == "Power")  #show power
                              )
                }
                par(mfrow=c(1,1))
@@ -2005,15 +2016,9 @@ doProcess <- function(options) {
        #when an analysis is done, curves file has to be written
        writeCurves = TRUE
 
-       #Analysis in cross variables comes as:
-       #"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.
-       #in 1RMAnyExercise: "1RMAnyExercise;0.185;method" speed1RM = 0.185m/s
-       analysisCross = unlist(strsplit(Analysis, "\\;"))
        if(
-          Analysis == "powerBars" || analysisCross[1] == "cross" || 
-          Analysis == "1RMBadillo2010" || analysisCross[1] == "1RMAnyExercise" || 
+          Analysis == "powerBars" || Analysis == "cross" || 
+          Analysis == "1RMBadillo2010" || Analysis == "1RMAnyExercise" || 
           Analysis == "curves" || writeCurves) 
        {
                paf = data.frame()
@@ -2029,18 +2034,18 @@ doProcess <- function(options) {
                                myEccon = curves[i,7]
 
                                #only use concentric data       
-                               if( (Analysis == "1RMBadillo2010" || analysisCross[1] == "1RMAnyExercise") & 
myEccon == "e") {
+                               if( (Analysis == "1RMBadillo2010" || Analysis == "1RMAnyExercise") & myEccon 
== "e") {
                                        discardedCurves = c(i,discardedCurves)
                                        discardingCurves = TRUE
                                        next;
                                }
                        } else {
-                               if( (Analysis == "1RMBadillo2010" || analysisCross[1] == "1RMAnyExercise") & 
Eccon == "ecS" & i%%2 == 1) {
+                               if( (Analysis == "1RMBadillo2010" || Analysis == "1RMAnyExercise") & Eccon == 
"ecS" & i%%2 == 1) {
                                        discardedCurves = c(i,discardedCurves)
                                        discardingCurves = TRUE
                                        next;
                                }
-                               else if( (Analysis == "1RMBadillo2010" || analysisCross[1] == 
"1RMAnyExercise") & Eccon == "ceS" & i%%2 == 0) {
+                               else if( (Analysis == "1RMBadillo2010" || Analysis == "1RMAnyExercise") & 
Eccon == "ceS" & i%%2 == 0) {
                                        discardedCurves = c(i,discardedCurves)
                                        discardingCurves = TRUE
                                        next;
@@ -2090,30 +2095,35 @@ doProcess <- function(options) {
                                                        curves[,7], Eccon,              #myEccon, Eccon
                                                        rawdata.cumsum[curves[,2]]-curves[,3], n) #height
                }
-               else if(analysisCross[1] == "cross") {
+               else if(Analysis == "cross") {
                        mySeries = "1"
                        if(! singleFile)
                                mySeries = curves[,8]
 
-                       if(analysisCross[2] == "Speed,Power") {
+                       print("AnalysisVariables:")
+                       print(AnalysisVariables[1])
+                       print(AnalysisVariables[2])
+                       print(AnalysisVariables[3])
+
+                       if(AnalysisVariables[1] == "Speed,Power") {
                                par(mar=c(5,4,4,5))
-                               analysisCrossVertVars = unlist(strsplit(analysisCross[2], "\\,"))
-                               paintCrossVariables(paf, analysisCross[3], analysisCrossVertVars[1], 
-                                                   analysisCross[4], "LEFT", Title,
+                               analysisVertVars = unlist(strsplit(AnalysisVariables[1], "\\,"))
+                               paintCrossVariables(paf, AnalysisVariables[2], analysisVertVars[1], 
+                                                   AnalysisVariables[3], "LEFT", Title,
                                                    singleFile,Eccon,mySeries, 
                                                    FALSE, FALSE, OutputData1) 
                                par(new=T)
-                               paintCrossVariables(paf, analysisCross[3], analysisCrossVertVars[2], 
-                                                   analysisCross[4], "RIGHT", "",
+                               paintCrossVariables(paf, AnalysisVariables[2], analysisVertVars[2], 
+                                                   AnalysisVariables[3], "RIGHT", "",
                                                    singleFile,Eccon,mySeries, 
                                                    FALSE, FALSE, OutputData1) 
                        } else
-                               paintCrossVariables(paf, analysisCross[3], analysisCross[2], 
-                                                   analysisCross[4], "ALONE", Title,
+                               paintCrossVariables(paf, AnalysisVariables[2], AnalysisVariables[1], 
+                                                   AnalysisVariables[3], "ALONE", Title,
                                                    singleFile,Eccon,mySeries, 
                                                    FALSE, FALSE, OutputData1) 
                }
-               else if(analysisCross[1] == "1RMAnyExercise") {
+               else if(Analysis == "1RMAnyExercise") {
                        mySeries = "1"
                        if(! singleFile)
                                mySeries = curves[,8]
@@ -2121,7 +2131,7 @@ doProcess <- function(options) {
                        paintCrossVariables(paf, "Load", "Speed", 
                                            "mean", "ALONE", Title,
                                            singleFile,Eccon,mySeries, 
-                                           analysisCross[2], analysisCross[3], #speed1RM, method
+                                           AnalysisVariables[1], AnalysisVariables[2], #speed1RM, method
                                            OutputData1) 
                }
                else if(Analysis == "1RMBadillo2010") {
diff --git a/src/encoder.cs b/src/encoder.cs
index 3176b6f..fc9c9ef 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -33,6 +33,7 @@ public class EncoderParams
        private int exercisePercentBodyWeight; //was private bool isJump; (if it's 0 is like "jump")
        private string eccon;
        private string analysis;
+       private string analysisVariables;
        private string analysisOptions;         //p: propulsive
        private string smoothCon; //to pass always as "." to R
        private int curve;
@@ -107,7 +108,7 @@ public class EncoderParams
        
        //to graph.R    
        public EncoderParams(int minHeight, int exercisePercentBodyWeight, string mass, string eccon, 
-                       string analysis, string analysisOptions, string smoothCon,
+                       string analysis, string analysisVariables, string analysisOptions, string smoothCon,
                        int curve, int width, int height, string decimalSeparator)
        {
                this.minHeight = minHeight;
@@ -115,6 +116,7 @@ public class EncoderParams
                this.mass = mass;
                this.eccon = eccon;
                this.analysis = analysis;
+               this.analysisVariables = analysisVariables;
                this.analysisOptions = analysisOptions;
                this.smoothCon = smoothCon;
                this.curve = curve;
@@ -126,7 +128,7 @@ public class EncoderParams
        public string ToString2 (string sep) 
        {
                return minHeight + sep + exercisePercentBodyWeight + sep + mass + sep + eccon + 
-                       sep + analysis + sep + analysisOptions + sep + smoothCon + 
+                       sep + analysis + sep + analysisVariables + sep + analysisOptions + sep + smoothCon + 
                        sep + curve + sep + width + sep + height + sep + decimalSeparator;
        }
        
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 3a1001f..11f088d 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -714,6 +714,7 @@ public partial class ChronoJumpWindow
                                Util.ConvertToPoint(findMassFromCombo(true)),
                                findEccon(true),                                        //force ecS (ecc-conc 
separated)
                                analysis,
+                               "none",                         //analysisVariables (not needed in create 
curves). Cannot be blank
                                analysisOptions,
                                Util.ConvertToPoint(encoderSmoothCon),                  //R decimal: '.'
                                0,                      //curve is not used here
@@ -1277,6 +1278,7 @@ public partial class ChronoJumpWindow
                                displacedMass,
                                findEccon(false), //do not force ecS (ecc-conc separated) //not taken from 
lastEncoderSQL because there is (true)
                                "exportCSV",
+                               "none",                                         //analysisVariables (not 
needed in create curves). Cannot be blank
                                analysisOptions,
                                Util.ConvertToPoint(encoderSmoothCon),                  //R decimal: '.'
                                -1,
@@ -1999,8 +2001,12 @@ public partial class ChronoJumpWindow
 
                //use this send because we change it to send it to R
                //but we don't want to change encoderAnalysis because we want to know again if == "cross" 
+               //encoderAnalysis can be "cross" and sendAnalysis be "1RMBadillo1010"
                string sendAnalysis = encoderAnalysis;
 
+               //see doProcess at encoder/graph.R
+               string analysisVariables = "none"; //cannot be blank
+
                string crossName = "";
                if(sendAnalysis == "cross") {
                        crossName = 
Util.FindOnArray(':',1,0,UtilGtk.ComboGetActive(combo_encoder_analyze_cross),
@@ -2013,23 +2019,23 @@ public partial class ChronoJumpWindow
                        } else {
                                //convert: "Force / Speed" in: "cross.Force.Speed.mean"
                                string [] crossNameFull = crossName.Split(new char[] {' '});
-                               sendAnalysis += ";" + crossNameFull[0] + ";" + crossNameFull[2]; //[1]=="/"
+                               analysisVariables = crossNameFull[0] + ";" + crossNameFull[2]; //[1]=="/"
                                if(radiobutton_encoder_analyze_mean.Active)
-                                       sendAnalysis += ";mean";
+                                       analysisVariables += ";mean";
                                else
-                                       sendAnalysis += ";max";
+                                       analysisVariables += ";max";
                        }
                }
                
                if(sendAnalysis == "single" || sendAnalysis == "side")
-                       sendAnalysis = getEncoderAnalysisSAFE(sendAnalysis);
+                       analysisVariables = getAnalysisVariablesSAFE(sendAnalysis);
 
                if(radiobutton_encoder_analyze_data_user_curves.Active) {
                        string myEccon = "ec";
                        if(! check_encoder_analyze_eccon_together.Active)
                                myEccon = "ecS";
                        int myCurveNum = -1;
-                       if(sendAnalysis.StartsWith("single"))
+                       if(sendAnalysis == "single")
                                myCurveNum = Convert.ToInt32(UtilGtk.ComboGetActive(
                                                        combo_encoder_analyze_curve_num_combo));
 
@@ -2103,7 +2109,8 @@ public partial class ChronoJumpWindow
                                        EncoderExercise exTemp = (EncoderExercise) 
SqliteEncoder.SelectEncoderExercises(
                                                false , exerciseOld, false)[0];
                                
-                                       sendAnalysis = "1RMAnyExercise;" + 
Util.ConvertToPoint(exTemp.speed1RM) + ";" +
+                                       sendAnalysis = "1RMAnyExercise";
+                                       analysisVariables = Util.ConvertToPoint(exTemp.speed1RM) + ";" +
                                                SqlitePreferences.Select("encoder1RMMethod");
                                        analysisOptions = "p";
                                }
@@ -2116,6 +2123,7 @@ public partial class ChronoJumpWindow
                                        "-1",           //mass
                                        myEccon,        //this decides if analysis will be together or 
separated
                                        sendAnalysis,
+                                       analysisVariables,
                                        analysisOptions,
                                        Util.ConvertToPoint(encoderSmoothCon),                  //R decimal: 
'.'
                                        myCurveNum,
@@ -2203,9 +2211,9 @@ Log.WriteLine(str);
                                EncoderExercise ex = (EncoderExercise) SqliteEncoder.SelectEncoderExercises(
                                                false, getExerciseIDFromCombo(), false)[0];
                                
-                               sendAnalysis = "1RMAnyExercise;" + Util.ConvertToPoint(ex.speed1RM) + ";" +
+                               sendAnalysis = "1RMAnyExercise";
+                               analysisVariables = Util.ConvertToPoint(ex.speed1RM) + ";" + 
                                        SqlitePreferences.Select("encoder1RMMethod");
-
                                analysisOptions = "p";
                        }
 
@@ -2215,6 +2223,7 @@ Log.WriteLine(str);
                                        Util.ConvertToPoint(findMassFromCombo(true)),
                                        findEccon(false),               //do not force ecS (ecc-conc 
separated)
                                        sendAnalysis,
+                                       analysisVariables, 
                                        analysisOptions,
                                        Util.ConvertToPoint(encoderSmoothCon),                  //R decimal: 
'.'
                                        
Convert.ToInt32(UtilGtk.ComboGetActive(combo_encoder_analyze_curve_num_combo)),
@@ -2304,28 +2313,30 @@ Log.WriteLine(str);
                radiobutton_encoder_analyze_side.Sensitive = true;
        }
 
-       private string getEncoderAnalysisSAFE(string encoderAnalysis) {
+       private string getAnalysisVariablesSAFE(string encoderAnalysis) {
+               string analysisVariables = "";
+
                if(check_encoder_analyze_show_speed.Active)
-                       encoderAnalysis += ";Speed";
+                       analysisVariables = "Speed";
                else
-                       encoderAnalysis += ";NoSpeed";
+                       analysisVariables = "NoSpeed";
 
                if(check_encoder_analyze_show_accel.Active)
-                       encoderAnalysis += ";Accel";
+                       analysisVariables += ";Accel";
                else
-                       encoderAnalysis += ";NoAccel";
+                       analysisVariables += ";NoAccel";
 
                if(check_encoder_analyze_show_force.Active)
-                       encoderAnalysis += ";Force";
+                       analysisVariables += ";Force";
                else
-                       encoderAnalysis += ";NoForce";
+                       analysisVariables += ";NoForce";
 
                if(check_encoder_analyze_show_power.Active)
-                       encoderAnalysis += ";Power";
+                       analysisVariables += ";Power";
                else
-                       encoderAnalysis += ";NoPower";
+                       analysisVariables += ";NoPower";
 
-               return encoderAnalysis;
+               return analysisVariables;
        }
 
        private void on_radiobutton_encoder_analyze_single_toggled (object obj, EventArgs args) {


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