[chronojump] Support for laterality on encoder analyze



commit f6a4a51c15f909ed7391e609cbac69c9989b2974
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Feb 27 18:35:35 2015 +0100

    Support for laterality on encoder analyze

 encoder/graph.R             |   91 ++++++++++++++++++++++++++++++++-----------
 encoder/util.R              |    4 +-
 src/constants.cs            |    6 ++-
 src/encoder.cs              |    5 ++-
 src/gui/encoder.cs          |    5 +-
 src/gui/encoderTreeviews.cs |   36 ++++++++++++-----
 6 files changed, 106 insertions(+), 41 deletions(-)
---
diff --git a/encoder/graph.R b/encoder/graph.R
index 53aed7c..5f2310a 100644
--- a/encoder/graph.R
+++ b/encoder/graph.R
@@ -84,6 +84,15 @@ translate <- function(englishWord) {
                return(Translated[which(English == englishWord)])
 }
 
+translateVector <- function(englishVector) {
+       translatedVector <- englishVector
+       for(i in 1:length(englishVector)) {
+               translatedVector[i] <- translate(englishVector[i])
+       }
+
+       return(translatedVector)
+}
+
 
 # This function converts top curve into bottom curve
 #
@@ -967,6 +976,7 @@ paintPowerPeakPowerBars <- function(singleFile, title, paf, Eccon, height, n, sh
        myNums = rownames(paf)
        height = abs(height/10)
        load = paf[,findPosInPaf("Load","")]
+       laterality = translateVector(as.vector(paf[,findPosInPaf("Laterality","")]))
        
        if(Eccon=="ecS" || Eccon=="ceS") {
                if(singleFile) {
@@ -1008,12 +1018,13 @@ paintPowerPeakPowerBars <- function(singleFile, title, paf, Eccon, height, n, sh
 
        par(mar=c(2.5, 4, 5, marginRight))
        bp <- barplot(powerData,beside=T,col=pafColors[1:2],width=c(1.4,.6),
-                       names.arg=paste(myNums,"\n",load,sep=""),xlim=c(1,n*3+.5),cex.name=0.9,
+                       names.arg=paste(myNums," ",laterality,"\n",load,sep=""),xlim=c(1,n*3+.5),cex.name=0.8,
                        xlab="",ylab=paste(translate("Power"),"(W)"), 
                        ylim=c(lowerY,max(powerData)), xpd=FALSE) #ylim, xpd = F,  makes barplot starts high 
(compare between them)
        title(main=title,line=-2,outer=T)
        box()
        mtext(paste(translate("Repetition")," \n",translate("Mass")," 
",sep=""),side=1,at=1,adj=1,line=1,cex=.9)
+       #mtext(translate("Laterality"),side=1,adj=1,line=0,cex=.9)
 
        axisLineRight=0
 
@@ -1113,6 +1124,8 @@ findPosInPaf <- function(var, option) {
                pos = 12
        else if(var == "MassExtra")
                pos = 13
+       else if(var == "Laterality")
+               pos = 14
        
        if( ( var == "Speed" || var == "Power" || var == "Force") & option == "max")
                pos=pos+1
@@ -1209,7 +1222,7 @@ round.scientific <- function(x) {
 #http://stackoverflow.com/a/6234664
 #see if two labels overlap
 stroverlap <- function(x1,y1,s1, x2,y2,s2) {
-       print(c(x1,y1,s1, x2,y2,s2))
+       #print(c(x1,y1,s1, x2,y2,s2))
        sh1 <- strheight(s1)
        sw1 <- strwidth(s1)
        sh2 <- strheight(s2)
@@ -1284,9 +1297,18 @@ paintCrossVariables <- function (paf, varX, varY, option, isAlone, title, single
                        bgBalls="pink"
                }
        
-               pchVector = createPchVector(ecconVector)        
+               pchVector = createPchVector(ecconVector)
+
+               laterality = translateVector(as.vector(paf[,findPosInPaf("Laterality","")]))
+               #bgBallsVector = rep(bgBalls, length(x))        
+               #bgBallsVector[laterality=="L"] <- "red"
+               #bgBallsVector[laterality=="R"] <- "blue"
+               #plot(x,y, xlab=varXut, ylab="", pch=pchVector, 
col=colBalls,bg=bgBallsVector,cex=cexBalls,axes=F)
+               
                plot(x,y, xlab=varXut, ylab="", pch=pchVector, col=colBalls,bg=bgBalls,cex=cexBalls,axes=F)
-       
+               points(x[laterality=="L"], y[laterality=="L"], type="p", cex=1, col=colBalls, pch=3) # 
font=5, pch=220) #172, 220 don't looks good
+               points(x[laterality=="R"], y[laterality=="R"], type="p", cex=1, col=colBalls, pch=4) # 
font=5, pch=222) #174, 222 don't looks good
+
                for(i in 1:length(x)) {
                        name = i
                        if( ( Eccon=="ecS" || Eccon=="ceS" ) && singleFile) {
@@ -1427,21 +1449,31 @@ paintCrossVariables <- function (paf, varX, varY, option, isAlone, title, single
                        }
                }
                
-               title(title, cex.main=1, font.main=2, line=3)
-
                text(as.numeric(nums.print$x), as.numeric(nums.print$y), paste("  ", nums.print$curveNum), 
adj=c(adjHor,.5), cex=cexNums)
 
-               #show legend
-               legendText = 
c(translate("eccentric"),translate("concentric"),paste(translate("eccentric"),translate("concentric"),sep="-"))
-               rng=par("usr")
-               lg = legend(rng[1],rng[4], 
-                           legend=legendText, pch=c(25,24,21), col=colBalls, pt.bg=bgBalls,
-                           cex=1, ncol=length(legendText), bty="n",
-                           plot=F)
-               legend(rng[1],rng[4]+1.25*lg$rect$h, 
-                      legend=legendText, pch=c(25,24,21),  col=colBalls,  pt.bg=bgBalls,
-                      cex=1, bg=bgBalls, ncol=length(legendText), bty="n",
-                      plot=T, xpd=NA)
+               #don't write title two times on 'speed,power / load'
+               if(isAlone == "ALONE" || isAlone =="RIGHT")
+                       title(title, cex.main=1, font.main=2, line=3)
+
+               #don't write legend on 'speed,power / load' because it doesn't fits with the formulas and 
regressions
+               if(isAlone == "ALONE") {
+                       #show legend
+                       legendText = c(translate("concentric"),
+                                      translate("eccentric"),
+                                      paste(translate("eccentric"),translate("concentric"),sep="-"),
+                                      translate("L"),
+                                      translate("R")
+                                      )
+                       rng=par("usr")
+                       lg = legend(rng[1],rng[4], 
+                                   legend=legendText, pch=c(24,25,21,3,4), col="black", pt.bg="white",
+                                   cex=1, ncol=2, bty="n",
+                                   plot=F)
+                       legend(rng[1],rng[4]+1*lg$rect$h, 
+                              legend=legendText, pch=c(24,25,21,3,4),  col="black",  pt.bg="white",
+                              cex=1, bg=bgBalls, ncol=2, bty="n",
+                              plot=T, xpd=NA)
+               }
 
        } else { #more than one series
                #colBalls = "black"
@@ -1767,6 +1799,7 @@ doProcess <- function(options)
                #encoderConfiguration
                econfName = NULL; econfd = NULL; econfD = NULL; econfAnglePush = NULL; econfAngleWeight = 
NULL; 
                econfInertia = NULL; econfGearedDown = NULL;
+               laterality = NULL;
 
                newLines=0;
                countLines=1; #useful to know the correct ids of active curves
@@ -1871,6 +1904,7 @@ doProcess <- function(options)
                                }
                                
                                seriesName[(i+newLines)] = as.vector(inputMultiData$seriesName[i])
+                               laterality[(i+newLines)] = as.vector(inputMultiData$laterality[i])
 
                                count = count + length(dataTempPhase)
                        }
@@ -1889,11 +1923,13 @@ doProcess <- function(options)
                        curves = data.frame(start,end,startH,exerciseName,massBody,massExtra,
                                            dateTime,myEccon,seriesName,percentBodyWeight,
                                            
econfName,econfd,econfD,econfAnglePush,econfAngleWeight,econfInertia,econfGearedDown,
+                                           laterality,
                                            stringsAsFactors=F,row.names=id)
                } else {
                        curves = data.frame(id,start,end,startH,exerciseName,massBody,massExtra,
                                            dateTime,myEccon,seriesName,percentBodyWeight,
                                            
econfName,econfd,econfD,econfAnglePush,econfAngleWeight,econfInertia,econfGearedDown,
+                                           laterality,
                                            stringsAsFactors=F,row.names=1)
                }
 
@@ -2046,6 +2082,7 @@ doProcess <- function(options)
                        myAngleWeight = op$angleWeight
                        myInertiaMomentum = op$inertiaMomentum
                        myGearedDown = op$gearedDown
+                       myLaterality = ""
                        if(! singleFile) {
                                myMassBody = curves[op$Jump,5]
                                myMassExtra = curves[op$Jump,6]
@@ -2060,8 +2097,9 @@ doProcess <- function(options)
                                myAngleWeight = curves[op$Jump,15]
                                myInertiaMomentum = curves[op$Jump,16]
                                myGearedDown = curves[op$Jump,17]
+                               myLaterality = curves[op$Jump,18]
                        }
-                       myCurveStr = paste("curve=", op$Jump, ", ", myMassExtra, "Kg", sep="")
+                       myCurveStr = paste(translate("Repetition"),"=", op$Jump, " ", myLaterality, " ", 
myMassExtra, "Kg", sep="")
                
                        #don't do this, because on inertial machines string will be rolled to machine and not 
connected to the body
                        #if(inertialType == "li") {
@@ -2073,7 +2111,7 @@ doProcess <- function(options)
                        paint(displacement, myEccon, myStart, myEnd,"undefined","undefined",FALSE,FALSE,
                              1,curves[op$Jump,3],SmoothingsEC[1],op$SmoothingOneC,myMassBody,myMassExtra,
                              
myEncoderConfigurationName,myDiameter,myDiameterExt,myAnglePush,myAngleWeight,myInertiaMomentum,myGearedDown,
-                             paste(op$Title, " ", op$Analysis, " ", myEccon, " ", myCurveStr, sep=""),
+                             paste(op$Title, " ", op$Analysis, " ", myEccon, ". ", myCurveStr, sep=""),
                              "", #subtitle
                              TRUE,     #draw
                              TRUE,     #showLabels
@@ -2116,6 +2154,7 @@ doProcess <- function(options)
                        myAngleWeight = op$angleWeight
                        myInertiaMomentum = op$inertiaMomentum
                        myGearedDown = op$gearedDown
+                       myLaterality = ""
                        if(! singleFile) {
                                myMassBody = curves[i,5]
                                myMassExtra = curves[i,6]
@@ -2130,13 +2169,14 @@ doProcess <- function(options)
                                myAngleWeight = curves[i,15]
                                myInertiaMomentum = curves[i,16]
                                myGearedDown = curves[i,17]
+                               myLaterality = curves[i,18]
                        }
 
                        myTitle = ""
                        if(i == 1)
                                myTitle = paste(op$Title)
                        
-                       mySubtitle = paste("curve=", rownames(curves)[i], ", ", myMassExtra, "Kg", sep="")
+                       mySubtitle = paste("curve=", rownames(curves)[i], ", ", myLaterality, " ", 
myMassExtra, "Kg", sep="")
 
                        paint(displacement, myEccon, curves[i,1],curves[i,2],yrange,knRanges,FALSE,FALSE,
                              1,curves[i,3],SmoothingsEC[i],op$SmoothingOneC,myMassBody,myMassExtra,
@@ -2222,6 +2262,7 @@ doProcess <- function(options)
                        myAngleWeight = op$angleWeight
                        myInertiaMomentum = op$inertiaMomentum
                        myGearedDown = op$gearedDown
+                       myLaterality = ""
                        if(! singleFile) {
                                myMassBody = curves[i,5]
                                myMassExtra = curves[i,6]
@@ -2236,6 +2277,7 @@ doProcess <- function(options)
                                myAngleWeight = curves[i,15]
                                myInertiaMomentum = curves[i,16]
                                myGearedDown = curves[i,17]
+                               myLaterality = curves[i,18]
 
                                #only use concentric data       
                                if( (op$Analysis == "1RMBadillo2010" || op$Analysis == "1RMAnyExercise") & 
myEccon == "e") {
@@ -2276,10 +2318,11 @@ doProcess <- function(options)
                                                     myEccon,
                                                     kinematicsF(displacement[curves[i,1]:curves[i,2]], 
                                                                 myMassBody, myMassExtra, 
myExPercentBodyWeight,
-                                                                
myEncoderConfigurationName,myDiameter,myDiameterExt,myAnglePush,myAngleWeight,myInertiaMomentum,myGearedDown,
+                                                                
myEncoderConfigurationName,myDiameter,myDiameterExt,myAnglePush,myAngleWeight,
+                                                                myInertiaMomentum,myGearedDown,
                                                                 SmoothingsEC[i],op$SmoothingOneC, 
                                                                 g, myEcconKn, isPropulsive),
-                                                    myMassBody, myMassExtra
+                                                    myMassBody, myMassExtra, myLaterality
                                                     )))
                }
 
@@ -2452,7 +2495,9 @@ doProcess <- function(options)
                                        "meanSpeed","maxSpeed","maxSpeedT",
                                        "meanPower","peakPower","peakPowerT",
                                        "pp_ppt",
-                                       "meanForce", "maxForce", "maxForceT")
+                                       "meanForce", "maxForce", "maxForceT",
+                                       "mass", "massBody", "massExtra", #unneded
+                                       "laterality")
                        write.csv(paf, op$OutputData1, quote=FALSE)
                        print("curves written")
                }
diff --git a/encoder/util.R b/encoder/util.R
index d4ec45d..910f01f 100644
--- a/encoder/util.R
+++ b/encoder/util.R
@@ -538,7 +538,7 @@ findPropulsiveEnd <- function(accel, concentric, maxSpeedTInConcentric,
 return (propulsiveEnd)
 }
 
-pafGenerate <- function(eccon, kinematics, massBody, massExtra) {
+pafGenerate <- function(eccon, kinematics, massBody, massExtra, laterality) {
        #print("speed$y")
        #print(kinematics$speedy)
 
@@ -573,7 +573,7 @@ pafGenerate <- function(eccon, kinematics, massBody, massExtra) {
                          meanSpeed, maxSpeed, maxSpeedT,
                          meanPower, peakPower, peakPowerT, pp_ppt,
                          meanForce, maxForce, maxForceT,
-                         kinematics$mass, massBody, massExtra)) #kinematics$mass is Load
+                         kinematics$mass, massBody, massExtra, laterality)) #kinematics$mass is Load
 }
 
 isInertial <- function(encoderConfigurationName) {
diff --git a/src/constants.cs b/src/constants.cs
index 29d199f..6556397 100644
--- a/src/constants.cs
+++ b/src/constants.cs
@@ -841,7 +841,8 @@ public class Constants
                "Adapted from",
                "Mean speed in concentric propulsive phase",
                "Sorry, no repetitions matched your criteria.",
-               "Need at least three jumps"
+               "Need at least three jumps",
+               "Laterality", "RL", "R", "L"
        };
        /*
         * written here in order to be translated
@@ -881,6 +882,7 @@ public class Constants
                Catalog.GetString("Adapted from"),
                Catalog.GetString("Mean speed in concentric propulsive phase"),
                Catalog.GetString("Sorry, no repetitions matched your criteria."),
-               Catalog.GetString("Need at least three jumps")
+               Catalog.GetString("Need at least three jumps"),
+               Catalog.GetString("Laterality"), Catalog.GetString("RL"), Catalog.GetString("R"), 
Catalog.GetString("L")
        };
 }
diff --git a/src/encoder.cs b/src/encoder.cs
index 601c016..b5565a2 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -199,6 +199,7 @@ public class EncoderCurve
        public string N;
        public string Series;
        public string Exercise;
+       public string Laterality;       //only on analyze
        public double ExtraWeight;
        public double DisplacedWeight;
        public string Start;
@@ -246,6 +247,7 @@ public class EncoderCurve
 
        //used on TreeView analyze
        public EncoderCurve (string n, string series, string exercise, 
+                       string laterality,
                        double extraWeight, double displacedWeight,
                        string start, string duration, string height,
                        string meanSpeed, string maxSpeed, string maxSpeedT,
@@ -255,6 +257,7 @@ public class EncoderCurve
                this.N = n;
                this.Series = series;
                this.Exercise = exercise;
+               this.Laterality = laterality;
                this.ExtraWeight = extraWeight;
                this.DisplacedWeight = displacedWeight;
                this.Start = start;
@@ -275,7 +278,7 @@ public class EncoderCurve
 
                string sep = ":::";
                string str = 
-                       N + sep + Series + sep + Exercise + sep + 
+                       N + sep + Series + sep + Exercise + sep + Laterality + sep +
                        ExtraWeight + sep + DisplacedWeight + sep + 
                        Start + sep + Duration + sep + Height + sep + 
                        MeanSpeed + sep + MaxSpeed + sep + MaxSpeedT + sep + 
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 629e63b..c2f2f61 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -2589,7 +2589,7 @@ public partial class ChronoJumpWindow
                        //create dataFileName
                        TextWriter writer = File.CreateText(dataFileName);
                        
writer.WriteLine("status,seriesName,exerciseName,massBody,massExtra,dateTime,fullURL,eccon,percentBodyWeight,"
 + 
-                                       "econfName, econfd, econfD, econfAnglePush, econfAngleWeight, 
econfInertia, econfGearedDown");
+                                       "econfName, econfd, econfD, econfAnglePush, econfAngleWeight, 
econfInertia, econfGearedDown, laterality");
                
                        ArrayList eeArray = SqliteEncoder.SelectEncoderExercises(false, -1, false);
                        EncoderExercise ex = new EncoderExercise();
@@ -2664,7 +2664,8 @@ public partial class ChronoJumpWindow
                                                fullURL + "," + 
                                                eSQL.eccon + "," +      //this is the eccon of every curve
                                                ex.percentBodyWeight.ToString() + "," +
-                                               eSQL.encoderConfiguration.ToString(",",true)
+                                               eSQL.encoderConfiguration.ToString(",",true) + "," +
+                                               eSQL.LateralityToEnglish()
                                                );
                                countSeries ++;
                        }
diff --git a/src/gui/encoderTreeviews.cs b/src/gui/encoderTreeviews.cs
index ba26bdd..571af01 100644
--- a/src/gui/encoderTreeviews.cs
+++ b/src/gui/encoderTreeviews.cs
@@ -443,6 +443,7 @@ public partial class ChronoJumpWindow
                Catalog.GetString("Repetition") + "\n",
                Catalog.GetString("Series") + "\n",
                Catalog.GetString("Exercise") + "\n",
+               Catalog.GetString("Laterality") + "\n",
                Catalog.GetString("Extra weight") + "\n (Kg)",
                Catalog.GetString("Total weight") + "\n (Kg)",
                Catalog.GetString("Start") + "\n (s)",
@@ -514,6 +515,7 @@ public partial class ChronoJumpWindow
                                                        cells[0], 
                                                        cells[1],       //seriesName 
                                                        exerciseName,
+                                                       cells[21],      //laterality
                                                        Convert.ToDouble(cells[4]),
                                                        totalMass,
                                                        cells[5], cells[6], cells[7], 
@@ -557,39 +559,42 @@ public partial class ChronoJumpWindow
                                        aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc 
(RenderExercise));
                                        break;
                                case 3:
-                                       aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc 
(RenderExtraWeight));
+                                       aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc 
(RenderLaterality));
                                        break;
                                case 4:
-                                       aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc 
(RenderDisplacedWeight));
+                                       aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc 
(RenderExtraWeight));
                                        break;
                                case 5:
-                                       aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc 
(RenderStart));
+                                       aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc 
(RenderDisplacedWeight));
                                        break;
                                case 6:
-                                       aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc 
(RenderDuration));
+                                       aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc 
(RenderStart));
                                        break;
                                case 7:
-                                       aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc 
(RenderHeight));
+                                       aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc 
(RenderDuration));
                                        break;
                                case 8:
-                                       aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc 
(RenderMeanSpeed));
+                                       aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc 
(RenderHeight));
                                        break;
                                case 9:
-                                       aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc 
(RenderMaxSpeed));
+                                       aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc 
(RenderMeanSpeed));
                                        break;
                                case 10:
-                                       aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc 
(RenderMaxSpeedT));
+                                       aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc 
(RenderMaxSpeed));
                                        break;
                                case 11:
-                                       aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc 
(RenderMeanPower));
+                                       aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc 
(RenderMaxSpeedT));
                                        break;
                                case 12:
-                                       aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc 
(RenderPeakPower));
+                                       aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc 
(RenderMeanPower));
                                        break;
                                case 13:
-                                       aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc 
(RenderPeakPowerT));
+                                       aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc 
(RenderPeakPower));
                                        break;
                                case 14:
+                                       aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc 
(RenderPeakPowerT));
+                                       break;
+                               case 15:
                                        aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc 
(RenderPP_PPT));
                                        break;
                        }
@@ -830,6 +835,12 @@ public partial class ChronoJumpWindow
                (cell as Gtk.CellRendererText).Text = curve.Exercise;
        }
 
+       private void RenderLaterality (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, 
Gtk.TreeIter iter)
+       {
+               EncoderCurve curve = (EncoderCurve) model.GetValue (iter, 0);
+               (cell as Gtk.CellRendererText).Text = curve.Laterality;
+       }
+
        private void RenderExtraWeight (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel 
model, Gtk.TreeIter iter)
        {
                EncoderCurve curve = (EncoderCurve) model.GetValue (iter, 0);
@@ -1128,6 +1139,9 @@ public partial class ChronoJumpWindow
                        for(int i=15; i <= 17; i++)
                                cells[i] = 
Util.TrimDecimals(Convert.ToDouble(Util.ChangeDecimalSeparator(cells[i])),3);
 
+               //18, 19, 20 ara mass, massBody, massExtra. They are unneded because this parameters are also 
in cells [3],[4]
+               //21: laterality
+
                return cells;
        }
        


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