[chronojump] Cleaned R code and delete lots of slow prints



commit c7a3c1344bdb1c4eede8e596478a867f9b31a1ea
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Mar 3 15:37:07 2016 +0100

    Cleaned R code and delete lots of slow prints

 encoder/graph.R            |   39 +++-------------------
 encoder/graphSmoothingEC.R |   50 +++--------------------------
 encoder/util.R             |   74 +------------------------------------------
 3 files changed, 14 insertions(+), 149 deletions(-)
---
diff --git a/encoder/graph.R b/encoder/graph.R
index 78b7b23..742861e 100644
--- a/encoder/graph.R
+++ b/encoder/graph.R
@@ -1170,8 +1170,8 @@ paintPowerPeakPowerBars <- function(singleFile, title, paf, Eccon, height, n, sh
                peakPowerName = translateToPrint("Peak Power")
        }
 
-       print("powerData")
-       print(powerData)
+       #print("powerData")
+       #print(powerData)
 
        #put lowerY on power, but definetively, leave it at 0
        #lowerY=min(powerData)-100
@@ -1252,8 +1252,6 @@ paintPowerPeakPowerBars <- function(singleFile, title, paf, Eccon, height, n, sh
                                mean(height[which(load == i)]),
                                myLabel, "darkgreen", "white", ypad=1)
                        
-                       #print(paste("mean",i,mean(height[which(load == i)])))
-                       
                        segments(
                                 bp[2,min(which(load == i))],mean(height[which(load == i)]),
                                 bp[2,max(which(load == i))],mean(height[which(load == i)]),
@@ -1407,7 +1405,6 @@ getModelPValue <- function(model) {
 #> round(-0.0002,4)
 #[1] -2e-04
 round.scientific <- function(x) {
-       print(c("at round.scientic",x))
        if(x == 0)
                return(0)
 
@@ -1435,7 +1432,6 @@ 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))
        sh1 <- strheight(s1)
        sw1 <- strwidth(s1)
        sh2 <- strheight(s2)
@@ -1458,7 +1454,6 @@ stroverlap <- function(x1,y1,s1, x2,y2,s2) {
 stroverlapArray <- function(newPoint, points) {
        overlap = FALSE
 
-       #print(c("at Array newPoint, points",newPoint, points))
        if(length(points$x) == 1)       #if there's only one row
                return (stroverlap(
                              as.numeric(newPoint[1]), as.numeric(newPoint[2]), newPoint[3],
@@ -1513,9 +1508,6 @@ paintCrossVariables <- function (paf, varX, varY, option, isAlone, title, single
        if(varX == "Inertia")
                x = x * 10000
 
-       #print("seriesName")
-       #print(seriesName)
-
        colBalls = NULL
        bgBalls = NULL
 
@@ -1526,7 +1518,6 @@ paintCrossVariables <- function (paf, varX, varY, option, isAlone, title, single
        varXut = addUnitsAndTranslate(varX)
        varYut = addUnitsAndTranslate(varY)
        
-       #nums.print.df = NULL
        nums.print = NULL
 
        #if only one series
@@ -1584,9 +1575,6 @@ paintCrossVariables <- function (paf, varX, varY, option, isAlone, title, single
                if(do1RM != FALSE & do1RM != "0") {     
                        speed1RM = as.numeric(do1RM)
 
-                       print("speed1RM")
-                       print(speed1RM)
-                       
                        #lineal stuff
                        fit = lm(y ~ x) #declare
                        if(do1RMMethod == "NONWEIGHTED")  {
@@ -1595,15 +1583,12 @@ paintCrossVariables <- function (paf, varX, varY, option, isAlone, title, single
                        } 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]]
@@ -2368,9 +2353,6 @@ doProcess <- function(options)
                        
                position=cumsum(displacement)
 
-               #print(c("position",position))
-               #print(c("displacement",displacement))
-               
                curves=findCurvesNew(displacement, op$Eccon, isInertial(op$EncoderConfigurationName), 
                                     op$MinHeight, curvesPlot, op$Title)
                
@@ -2380,8 +2362,8 @@ doProcess <- function(options)
                n=length(curves[,1])
                quitIfNoData(n, curves, op$OutputData1)
                
-               print("curves before reduceCurveBySpeed")
-               print(curves)
+               #print("curves before reduceCurveBySpeed")
+               #print(curves)
        
                #reduceCurveBySpeed, don't do in inertial because it doesn't do a good right adjust on 
changing phase
                #what reduceCurveBySpeed is doing in inertial is adding a value at right, and this value is a 
descending value
@@ -2399,8 +2381,8 @@ doProcess <- function(options)
                        }
                }
                
-               print("curves after reduceCurveBySpeed")
-               print(curves)
+               #print("curves after reduceCurveBySpeed")
+               #print(curves)
                
                #find SmoothingsEC
                SmoothingsEC = findSmoothingsEC(
@@ -2471,7 +2453,6 @@ doProcess <- function(options)
        #write(paste("(4/5)",translateToPrint("Repetitions processed")), op$FeedbackFileBase)
        print("Creating (op$FeedbackFileBase)4.txt with touch method...")
        file.create(paste(op$FeedbackFileBase,"4.txt",sep=""))
-       print("Created")
        #print(curves)
 
        if(op$Analysis=="single") {
@@ -2701,8 +2682,6 @@ doProcess <- function(options)
                               else
                                       repOpSeparated$eccon = "e"
                        }
-                       print("start integer before kinematicsF __________")
-                       print(c(curves[i,1], displacement[curves[i,1]]))
 
                        paf = rbind(paf,(pafGenerate(
                                                     repOp$eccon,
@@ -2749,11 +2728,6 @@ doProcess <- function(options)
 
                        ecconVector = createEcconVector(singleFile, op$Eccon, length(curves[,1]), curves[,8])
 
-                       #print("AnalysisVariables:")
-                       #print(op$AnalysisVariables[1])
-                       #print(op$AnalysisVariables[2])
-                       #print(op$AnalysisVariables[3])
-
                        if(op$AnalysisVariables[1] == "Speed,Power") {
                                par(mar=c(5,4,5,5))
                                analysisVertVars = unlist(strsplit(op$AnalysisVariables[1], "\\,"))
@@ -3090,7 +3064,6 @@ doProcess <- function(options)
        #write(paste("(5/5)",translateToPrint("R tasks done")), op$FeedbackFileBase)
        print("Creating (op$FeedbackFileBase)5.txt with touch method...")
        file.create(paste(op$FeedbackFileBase,"5.txt",sep=""))
-       print("Created")
        write("created ...5.txt", stderr())
 
        warnings()
diff --git a/encoder/graphSmoothingEC.R b/encoder/graphSmoothingEC.R
index b2919ad..e0b48af 100644
--- a/encoder/graphSmoothingEC.R
+++ b/encoder/graphSmoothingEC.R
@@ -83,32 +83,10 @@ findSmoothingsECYPoints <- function(eccentric.concentric, conStart, conEnd, x, m
 findSmoothingsEC <- function(singleFile, displacement, curves, eccon, smoothingOneC,
                             singleFileEncoderConfigurationName, singleFileDiameter, 
singleFileInertiaMomentum, singleFileGearedDown)
 {
-print("singleFile")
-print(singleFile)
-print("displacement")
-print(displacement)
-print("curves")
-print(curves)
-print("eccon")
-print(eccon)
-print("smoothingOneC")
-print(smoothingOneC)
-print("singleFileEncoderConfigurationName")
-print(singleFileEncoderConfigurationName)
-print("singleFileDiameter")
-print(singleFileDiameter)
-print("singleFileInertiaMomentum")
-print(singleFileInertiaMomentum)
-print("singleFileGearedDown")
-print(singleFileGearedDown)
-
-
        ptm <- as.vector(proc.time()[3])
        write("time start", stderr())
        write(ptm, stderr())
 
-       #print(c("findSmoothingsEC: eccon smoothingOneC", eccon, smoothingOneC))
-
        smoothings = NULL
        n=length(curves[,1])
 
@@ -147,24 +125,8 @@ print(singleFileGearedDown)
                                        conEnd = mean(which(position == max(position)))
                                }
 
-print("position")
-print(position)
-print("which(position == min(position))")
-print(which(position == min(position)))
-print("i conStart, conEnd, curves[i,1] curves[i,2] 1st part, 2nd part")
-print(i)
-print(conStart)
-print(conEnd)
-print(curves[i,1])
-print(curves[i,2])
-print((curves[i,1]+conStart))
-print((curves[i,1]+conStart))
-print((curves[i,1]+conEnd))
-print("displacement[(curves[i,1]+conStart):(curves[i,1]+conEnd)]")
-print(displacement[(curves[i,1]+conStart):(curves[i,1]+conEnd)])
-                               concentric=displacement[(curves[i,1]+conStart):(curves[i,1]+conEnd)]
                                
-#1 get max power concentric at concentric phase with current smoothing
+                               #1 get max power concentric at concentric phase with current smoothing
 
                                speed <- getSpeed(concentric, smoothingOneC)
 
@@ -189,7 +151,7 @@ print(displacement[(curves[i,1]+conStart):(curves[i,1]+conEnd)])
                                
                                maxPowerConAtCon <- max(powerTemp)
 
-#2 get max power concentric (y) at eccentric-concentric phase with current smoothing of an interval of 
possible smoothings (x)
+                               #2 get max power concentric (y) at eccentric-concentric phase with current 
smoothing of an interval of possible smoothings (x)
                                
                                x <- seq(from = as.numeric(smoothingOneC), 
                                                    to = as.numeric(smoothingOneC)/2, 
@@ -216,7 +178,7 @@ print(displacement[(curves[i,1]+conStart):(curves[i,1]+conEnd)])
                                #find the max power in concentric phase of this ecc-con movement
                                maxPowerConAtFullrep <- max(powerTemp[conStart:conEnd])
 
-#3 check if first aproximation is OK
+                               #3 check if first aproximation is OK
 
                                #write(paste("MID i, smoothingOneEC, maxPowerConAtFullrep, maxPowerConAtCon, 
diff", 
                                #           i, smoothingOneEC,
@@ -225,7 +187,7 @@ print(displacement[(curves[i,1]+conStart):(curves[i,1]+conEnd)])
                                #           round( (maxPowerConAtFullrep - maxPowerConAtCon),2 ))
                                #, stderr())
 
-#4 create new x values closer
+                               #4 create new x values closer
 
                                #eg 
                                #x:   .7,     .6125,     .525,     .4375,     .35
@@ -254,7 +216,7 @@ print(displacement[(curves[i,1]+conStart):(curves[i,1]+conEnd)])
                                }
 
 
-#5 get max power concentric (y) at eccentric-concentric phase with current smoothing of an interval of 
possible smoothings (x)
+                               #5 get max power concentric (y) at eccentric-concentric phase with current 
smoothing of an interval of possible smoothings (x)
                                
                                x <- seq(
                                         from = xUpperValue, 
@@ -267,7 +229,7 @@ print(displacement[(curves[i,1]+conStart):(curves[i,1]+conEnd)])
                                smodel <- smooth.spline(y,x)
                                smoothingOneEC <- predict(smodel, maxPowerConAtCon)$y
                                        
-#6 check if aproximation is OK
+                               #6 check if aproximation is OK
                                
                                if(! isInertial(myEncoderConfigurationName) )
                                        powerTemp <- findSmoothingsECGetPowerNI(speed)
diff --git a/encoder/util.R b/encoder/util.R
index 8b69f54..d86d4ca 100644
--- a/encoder/util.R
+++ b/encoder/util.R
@@ -229,15 +229,10 @@ findTakeOff <- function(forceConcentric, maxSpeedTInConcentric)
        #2 create df2 with only the rows where force is below or equal zero
        df2 = subset(df,subset=df$belowZero)
 
-       #print("df2")
-       #print(df2)
-
        #3 find takeoff as the df2 row with less distance to maxSpeedT
        df2row = min(which(df2$dist == min(df2$dist)))
        takeoff = as.integer(rownames(df2)[df2row])
 
-       #print(c("takeoff",takeoff))
-
        return(takeoff)
 }
        
@@ -404,16 +399,10 @@ reduceCurveBySpeed <- function(eccon, row, startT, startH, displacement, smoothi
                                x.end = i
        }
 
-       #print(speed.ext$cross[,2])
-       #print(ext.cross.len)
-       #print(c("time1,time2",time1,time2))
-       #print(c("x.ini x.end",x.ini,x.end))
-
        #to know the new startH
        #calculate displacement from original start to the new: x.ini
        startH.old = startH
        startH = startH + sum(displacement[1:x.ini])
-       #print(c("old startH:", startH.old, "; new startH:", startH))
 
        return(c(startT + x.ini, startT + x.end, startH))
 }
@@ -493,11 +482,6 @@ kinematicsF <- function(displacement, repOp, smoothingOneEC, smoothingOneC, g, i
        
        accel <- getAccelerationSafe(speed)
        
-       #print(c(" ms",round(mean(speed$y),5)," ma",round(mean(accel$y),5)))
-       #print(c(" Ms",round(max(speed$y),5)," Ma",round(max(accel$y),5)))
-       #print(c(" |ms|",round(mean(abs(speed$y)),5)," |ma|:",round(mean(abs(accel$y)),5)))
-       #print(c(" |Ms|",round(max(abs(speed$y)),5)," |Ma|",round(max(abs(accel$y)),5)))
-
        #speed comes in mm/ms when derivate to accel its mm/ms^2 to convert it to m/s^2 need to *1000 because 
it's quadratic
        accel$y <- accel$y * 1000 
 
@@ -505,8 +489,6 @@ kinematicsF <- function(displacement, repOp, smoothingOneEC, smoothingOneC, g, i
        concentric = 0
        propulsiveEnd = 0
 
-       #print(c("at kinematicsF eccon: ", repOp$eccon, " length(displacement): ",length(displacement)))
-
        #search propulsiveEnd
        if(isPropulsive) {
                if(repOp$eccon=="c") {
@@ -535,7 +517,6 @@ kinematicsF <- function(displacement, repOp, smoothingOneEC, smoothingOneC, g, i
                                                findPropulsiveEnd(accel$y, concentric, maxSpeedTInConcentric, 
                                                                  repOp$econfName, repOp$anglePush, 
repOp$angleWeight, 
                                                                  repOp$massBody, repOp$massExtra, 
repOp$exPercentBodyWeight)
-                               #print(c("lengths: ", length(eccentric), length(isometric), 
findPropulsiveEnd(accel$y,concentric), propulsiveEnd))
                        }
                } else if(repOp$eccon=="e") {
                        #not repOp$eccon="e" because not propulsive calculations on eccentric
@@ -580,7 +561,6 @@ kinematicsF <- function(displacement, repOp, smoothingOneEC, smoothingOneC, g, i
                end <- propulsiveEnd
 
        #as acceleration can oscillate, start at the eccentric part where there are not negative values
-       #print(c(inertiaMomentum, repOp$eccon, length(eccentric), min(accel$y[eccentric])))
        if(repOp$inertiaM > 0 && (repOp$eccon == "e" || repOp$eccon == "ec")) 
        {
                if(repOp$eccon=="e") {
@@ -590,16 +570,6 @@ kinematicsF <- function(displacement, repOp, smoothingOneEC, smoothingOneC, g, i
                #if there is eccentric data and there are negative values
                if(length(eccentric) > 0 && min(accel$y[eccentric]) < 0)
                { 
-                       #print(c("length(eccentric)",length(eccentric)))
-                       #print("min accel y eccentric ++++++++++++")
-                       #print(c("min(accel$y[eccentric])",min(accel$y[eccentric])))
-       
-                       #print(c("accel$y[eccentric]", accel$y[eccentric]))
-                       #print("displacement eccentric")
-                       #print(displacement[eccentric])
-
-
-
                        #deactivated:
                        #start = max(which(accel$y[eccentric] < 0)) +1
                        #print("------------ start -----------")
@@ -608,7 +578,6 @@ kinematicsF <- function(displacement, repOp, smoothingOneEC, smoothingOneC, g, i
        }
 
        #print(c("kinematicsF start end",start,end))
-                       
        #write("kinematicsF speed length and mean,", stderr())
        #write(length(speed$y[start:end]), stderr())
        #write(mean(speed$y[start:end]), stderr())
@@ -624,28 +593,17 @@ kinematicsF <- function(displacement, repOp, smoothingOneEC, smoothingOneC, g, i
 
 findECPhases <- function(displacement,speed) {
        speed.ext=extrema(speed)
-       #print(speed.ext)
-       #print(speed)
        
        #In all the extrema minindex values, search which range (row) has the min values,
        #and in this range search last value
-       #print("searchMinSpeedEnd")
        searchMinSpeedEnd = max(which(speed == min(speed)))
-       #print(searchMinSpeedEnd)
        
        #In all the extrema maxindex values, search which range (row) has the max values,
        #and in this range search first value
-       #print("searchMaxSpeedIni")
        searchMaxSpeedIni = min(which(speed == max(speed)))
-       #print(searchMaxSpeedIni)
        
        #find the cross between both
-       #print("speed.ext-Cross")
-       #print(speed.ext$cross[,1])
-       #print("search min cross: crossMinRow")
-
        crossMinRow=which(speed.ext$cross[,1] > searchMinSpeedEnd & speed.ext$cross[,1] < searchMaxSpeedIni)
-       #print(crossMinRow)
                        
        
        eccentric = 0
@@ -662,8 +620,6 @@ findECPhases <- function(displacement,speed) {
 
        isometricUse = TRUE
 
-       #print("at findECPhases")
-
        if(isometricUse) {
                eccentric=1:min(speed.ext$cross[crossMinRow,1])
                isometric=min(speed.ext$cross[crossMinRow,1]+1):max(speed.ext$cross[crossMinRow,2])
@@ -719,10 +675,8 @@ findPropulsiveEnd <- function(accel, concentric, maxSpeedTInConcentric,
 return (propulsiveEnd)
 }
 
-pafGenerate <- function(eccon, kinematics, massBody, massExtra, laterality, inertiaMomentum) {
-       #print("speed$y")
-       #print(kinematics$speedy)
-
+pafGenerate <- function(eccon, kinematics, massBody, massExtra, laterality, inertiaMomentum) 
+{
        meanSpeed <- mean(kinematics$speedy)
 
        #max speed and max speed time can be at eccentric or concentric
@@ -736,15 +690,9 @@ pafGenerate <- function(eccon, kinematics, massBody, massExtra, laterality, iner
                meanPower <- mean(abs(kinematics$power))
        }
 
-       #print(c("eccon meanPowerSigned meanPowerABS",eccon, mean(kinematics$power), 
mean(abs(kinematics$power))))
-       #print("kinematics$power")
-       #print(abs(kinematics$power))
-
        peakPower <- max(abs(kinematics$power))
        peakPowerT <- min(which(abs(kinematics$power) == peakPower))
        
-       #print(which(abs(kinematics$power) == peakPower))
-
        pp_ppt <- peakPower / (peakPowerT/1000) # ms->s
        meanForce <- mean(kinematics$force)
        maxForce <- max(abs(kinematics$force))
@@ -996,26 +944,12 @@ getDisplacementInertial <- function(displacement, encoderConfigurationName, diam
 {
        write("at getDisplacementInertial", stderr())
        
-       print("encoderConfigurationName")
-       print(encoderConfigurationName)
-       
-       print("diameter")
-       print(diameter)
-       print("diameterExt")
-       print(diameterExt)
-       print("gearedDown")
-       print(gearedDown)
-
-       print("displacement at beginning of getDisplacementInertial")
-       print(displacement)
-
        #scanned displacement is ticks of rotary axis encoder
        #now convert it to mm of body displacement
        if(encoderConfigurationName == "ROTARYAXISINERTIAL" ||
             encoderConfigurationName == "ROTARYAXISINERTIALLATERAL" ||
             encoderConfigurationName == "ROTARYAXISINERTIALMOVPULLEY") {
                ticksRotaryEncoder = 200 #our rotary axis encoder send 200 ticks per revolution
-#              diameterMeters = diameter / 100 #cm -> m
                
                #Number of revolutions that the flywheel rotates every millisecond
                revolutionsPerMs = displacement / ticksRotaryEncoder # One revolution every 
ticksRotaryEncoder ticks
@@ -1041,9 +975,6 @@ getDisplacementInertial <- function(displacement, encoderConfigurationName, diam
          
        }
        
-       print("displacement at end of getDisplacementInertial")
-       print(displacement)
-       
        return (displacement)
 }
 
@@ -1065,7 +996,6 @@ getDisplacementInertialBody <- function(positionStart, displacement, draw, title
        position.ext=extrema(position)
 
        #print("at findCurvesInertial")
-       #print(position.ext)
 
        #do if extrema(position)$nextreme == 0... then do not use extrema
        #TODO: check if started backwards on realtime capture (extrema is null)


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