[chronojump] Speed optimization



commit b2e3504680fb0af89838ada62e1f2944f34f8a59
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Jan 16 13:12:37 2013 +0100

    Speed optimization

 encoder/graph.R       |  833 +++++++++++++++++++++++++------------------------
 src/gui/encoder.cs    |   15 +-
 src/sqlite/encoder.cs |    2 +-
 3 files changed, 431 insertions(+), 419 deletions(-)
---
diff --git a/encoder/graph.R b/encoder/graph.R
index e2a1c31..dd6c564 100644
--- a/encoder/graph.R
+++ b/encoder/graph.R
@@ -18,6 +18,56 @@
 #   Copyright (C) 2004-2012   Xavier de Blas <xaviblas gmail com> 
 # 
 
+#TODO: capitalize first letter on all global variables names
+
+
+#concentric, eccentric-concentric, repetitions of eccentric-concentric
+#currently only used "c" and "ec". no need of ec-rep because c and ec are repetitive
+#"ecS" is like ec but eccentric and concentric phases are separated, used in findCurves, this is good for treeview to know power... on the 2 phases
+eccons=c("c","ec","ec-rep","ecS") 
+
+g = 9.81
+smoothingAll= 0.1
+#file="data_falla.txt"; isJump=FALSE #TODO em sembla que falla perque no hi ha cap curve, pq totes son mes petites que minHeight
+
+colSpeed="springgreen3"; colForce="blue2"; colPower="tomato2"	#colors
+#colSpeed="black"; colForce="black"; colPower="black"		#black & white
+cols=c(colSpeed,colForce,colPower); lty=rep(1,3)	
+
+#--- user commands ---
+
+#way A. passing options to a file
+#args <- commandArgs(TRUE)
+#optionsCon <- file(args[1], 'r')
+#options=readLines(optionsCon,n=15)
+
+#way B. put options as arguments
+options <- commandArgs(TRUE)
+
+print(options)
+if(length(options) < 3) {
+#	print("USAGE:\nRscript graph.R c superpose graph.png\neccons:curves, single, side, superpose, powerBars \nsingle and superpose needs a param at end (the jump):\nRscript graph.R c single graph.png 2\n")
+	quit()
+}
+
+file=options[1]
+outputGraph=options[2]
+outputData1=options[3]
+outputData2=options[4] #currently used to display status
+minHeight=as.numeric(options[5])*10 #from cm to mm
+exercisePercentBodyWeight=as.numeric(options[6])	#was isJump=as.logical(options[6])
+Mass=as.numeric(options[7])
+eccon=options[8]
+analysis=options[9]	#in cross comes as "cross.Force.Speed.mean"
+analysisOptions=options[10]	#p: propulsive
+smoothingOne=options[11]
+jump=options[12]
+width=as.numeric(options[13])
+height=as.numeric(options[14])
+Title=options[15]
+
+write("(1/4) Starting R", outputData2)
+
 
 #this will replace below methods: findPics1ByMinindex, findPics2BySpeed
 findCurves <- function(rawdata, eccon, min_height, draw, title) {
@@ -630,462 +680,415 @@ quitIfNoData <- function(n, curves, outputData1) {
 	}
 }
 
-#TODO: capitalize first letter on all global variables names
-
-
-#concentric, eccentric-concentric, repetitions of eccentric-concentric
-#currently only used "c" and "ec". no need of ec-rep because c and ec are repetitive
-#"ecS" is like ec but eccentric and concentric phases are separated, used in findCurves, this is good for treeview to know power... on the 2 phases
-eccons=c("c","ec","ec-rep","ecS") 
-
-g = 9.81
-smoothingAll= 0.1
-#file="data_falla.txt"; isJump=FALSE #TODO em sembla que falla perque no hi ha cap curve, pq totes son mes petites que minHeight
+write("(1/4) Calling EMD", outputData2)
 
-colSpeed="springgreen3"; colForce="blue2"; colPower="tomato2"	#colors
-#colSpeed="black"; colForce="black"; colPower="black"		#black & white
-cols=c(colSpeed,colForce,colPower); lty=rep(1,3)	
+library("EMD")
+#library("sfsmisc")
 
-#--- user commands ---
+write("(2/4) Starting process", outputData2)
 
-#way A. passing options to a file
-#args <- commandArgs(TRUE)
-#optionsCon <- file(args[1], 'r')
-#options=readLines(optionsCon,n=15)
+if(analysis != "exportCSV") {
+	png(outputGraph, width=width, height=height)
+	Title=gsub('_',' ',Title)
+	Title=gsub('-','    ',Title)
+}
 
-#way B. put options as arguments
-options <- commandArgs(TRUE)
+titleType = "n"
+#if(isJump)
+#	titleType="jump"
 
-print(options)
-if(length(options) < 3) {
-#	print("USAGE:\nRscript graph.R c superpose graph.png\neccons:curves, single, side, superpose, powerBars \nsingle and superpose needs a param at end (the jump):\nRscript graph.R c single graph.png 2\n")
-} else {
-	file=options[1]
-	outputGraph=options[2]
-	outputData1=options[3]
-	outputData2=options[4] #currently used to display status
-	minHeight=as.numeric(options[5])*10 #from cm to mm
-	exercisePercentBodyWeight=as.numeric(options[6])	#was isJump=as.logical(options[6])
-	Mass=as.numeric(options[7])
-	eccon=options[8]
-	analysis=options[9]	#in cross comes as "cross.Force.Speed.mean"
-	analysisOptions=options[10]	#p: propulsive
-	smoothingOne=options[11]
-	jump=options[12]
-	width=as.numeric(options[13])
-	height=as.numeric(options[14])
-	Title=options[15]
-
-	write("(1/4) Starting R", outputData2)
-
-	library("EMD")
-	#library("sfsmisc")
-
-	write("(2/4) Starting process", outputData2)
-
-	if(analysis != "exportCSV") {
-		png(outputGraph, width=width, height=height)
-		Title=gsub('_',' ',Title)
-		Title=gsub('-','    ',Title)
-	}
+curvesPlot = FALSE
+if(analysis=="curves") {
+	curvesPlot = TRUE
+	par(mar=c(2,2.5,2,1))
+}
 
-	titleType = "n"
-	#if(isJump)
-	#	titleType="jump"
-	
-	curvesPlot = FALSE
-	if(analysis=="curves") {
-		curvesPlot = TRUE
-		par(mar=c(2,2.5,2,1))
+singleFile = TRUE
+if(nchar(file) >= 40) {
+	#file="/tmp...../chronojump-encoder-graph-input-multi.csv"
+	#substr(file, nchar(file)-39, nchar(file))
+	#[1] "chronojump-encoder-graph-input-multi.csv"
+	if(substr(file, nchar(file)-39, nchar(file)) == "chronojump-encoder-graph-input-multi.csv") {
+		singleFile = FALSE
 	}
+}
 
-	singleFile = TRUE
-	if(nchar(file) >= 40) {
-		#file="/tmp...../chronojump-encoder-graph-input-multi.csv"
-		#substr(file, nchar(file)-39, nchar(file))
-		#[1] "chronojump-encoder-graph-input-multi.csv"
-		if(substr(file, nchar(file)-39, nchar(file)) == "chronojump-encoder-graph-input-multi.csv") {
-			singleFile = FALSE
+if(! singleFile) {
+	#this produces a rawdata, but note that a cumsum(rawdata) cannot be done because:
+	#this are separated movements
+	#maybe all are concentric (there's no returning to 0 phase)
+
+	#this version of curves has added specific data cols:
+	#status, exerciseName, mass, smoothingOne, dateTime, myEccon
+
+	inputMultiData=read.csv(file=file,sep=",",stringsAsFactors=F)
+
+	rawdata = NULL
+	count = 1
+	start = NULL; end = NULL; startH = NULL
+	status = NULL; id = NULL; exerciseName = NULL; mass = NULL; smooth = NULL; dateTime = NULL; myEccon = NULL
+	curvesHeight = NULL
+	newLines=0;
+	countLines=1; #useful to know the correct ids of active curves
+	for(i in 1:length(inputMultiData[,1])) { 
+		#plot only active curves
+		status = as.vector(inputMultiData$status[i])
+		if(status != "active") {
+			newLines=newLines-1; 
+			countLines=countLines+1;
+			next;
 		}
-	}
-	
-	if(! singleFile) {
-		#this produces a rawdata, but note that a cumsum(rawdata) cannot be done because:
-		#this are separated movements
-		#maybe all are concentric (there's no returning to 0 phase)
-
-		#this version of curves has added specific data cols:
-		#status, exerciseName, mass, smoothingOne, dateTime, myEccon
-
-		inputMultiData=read.csv(file=file,sep=",",stringsAsFactors=F)
-
-		rawdata = NULL
-		count = 1
-		start = NULL; end = NULL; startH = NULL
-		status = NULL; id = NULL; exerciseName = NULL; mass = NULL; smooth = NULL; dateTime = NULL; myEccon = NULL
-		curvesHeight = NULL
-		newLines=0;
-		countLines=1; #useful to know the correct ids of active curves
-		for(i in 1:length(inputMultiData[,1])) { 
-			#plot only active curves
-			status = as.vector(inputMultiData$status[i])
-			if(status != "active") {
-				newLines=newLines-1; 
-				countLines=countLines+1;
-				next;
-			}
 
-			dataTempFile=scan(file=as.vector(inputMultiData$fullURL[i]),sep=",")
-			dataTempPhase=dataTempFile
-			processTimes = 1
-			changePos = 0
-			#if this curve is ecc-con and we want separated, divide the curve in two
-			if(as.vector(inputMultiData$eccon[i]) != "c" & eccon =="ecS") {
-				changePos = mean(which(cumsum(dataTempFile) == min(cumsum(dataTempFile))))
-				processTimes = 2
-			}
-			for(j in 1:processTimes) {
-				if(processTimes == 2) {
-					if(j == 1) {
-						dataTempPhase=dataTempFile[1:changePos]
-					} else {
-						#IMP: 
-						#note that following line without the parentheses on changePos+1
-						#gives different data.
-						#never forget parentheses to operate inside the brackets
-						dataTempPhase=dataTempFile[(changePos+1):length(dataTempFile)]
-						newLines=newLines+1
-					}
+		dataTempFile=scan(file=as.vector(inputMultiData$fullURL[i]),sep=",")
+		dataTempPhase=dataTempFile
+		processTimes = 1
+		changePos = 0
+		#if this curve is ecc-con and we want separated, divide the curve in two
+		if(as.vector(inputMultiData$eccon[i]) != "c" & eccon =="ecS") {
+			changePos = mean(which(cumsum(dataTempFile) == min(cumsum(dataTempFile))))
+			processTimes = 2
+		}
+		for(j in 1:processTimes) {
+			if(processTimes == 2) {
+				if(j == 1) {
+					dataTempPhase=dataTempFile[1:changePos]
+				} else {
+					#IMP: 
+					#note that following line without the parentheses on changePos+1
+					#gives different data.
+					#never forget parentheses to operate inside the brackets
+					dataTempPhase=dataTempFile[(changePos+1):length(dataTempFile)]
+					newLines=newLines+1
 				}
-				rawdata = c(rawdata, dataTempPhase)
-				id[(i+newLines)] = countLines
-				start[(i+newLines)] = count
-				end[(i+newLines)] = length(dataTempPhase) + count -1
-				startH[(i+newLines)] = 0
-				exerciseName[(i+newLines)] = as.vector(inputMultiData$exerciseName[i])
-				mass[(i+newLines)] = inputMultiData$mass[i]
-				smooth[(i+newLines)] = inputMultiData$smoothingOne[i]
-				dateTime[(i+newLines)] = as.vector(inputMultiData$dateTime[i])
-
-				curvesHeight[(i+newLines)] = sum(dataTempPhase)
-
-				if(processTimes == 2) {
-					if(j == 1) {
-						myEccon[(i+newLines)] = "e"
-						id[(i+newLines)] = paste(countLines, myEccon[(i+newLines)], sep="")
-					} else {
-						myEccon[(i+newLines)] = "c"
-						id[(i+newLines)] = paste(countLines, myEccon[(i+newLines)], sep="")
-						countLines = countLines + 1
-					}
+			}
+			rawdata = c(rawdata, dataTempPhase)
+			id[(i+newLines)] = countLines
+			start[(i+newLines)] = count
+			end[(i+newLines)] = length(dataTempPhase) + count -1
+			startH[(i+newLines)] = 0
+			exerciseName[(i+newLines)] = as.vector(inputMultiData$exerciseName[i])
+			mass[(i+newLines)] = inputMultiData$mass[i]
+			smooth[(i+newLines)] = inputMultiData$smoothingOne[i]
+			dateTime[(i+newLines)] = as.vector(inputMultiData$dateTime[i])
+
+			curvesHeight[(i+newLines)] = sum(dataTempPhase)
+
+			if(processTimes == 2) {
+				if(j == 1) {
+					myEccon[(i+newLines)] = "e"
+					id[(i+newLines)] = paste(countLines, myEccon[(i+newLines)], sep="")
 				} else {
-					if(inputMultiData$eccon[i] == "c")
-						myEccon[(i+newLines)] = "c"
-					else
-						myEccon[(i+newLines)] = "ec"
+					myEccon[(i+newLines)] = "c"
+					id[(i+newLines)] = paste(countLines, myEccon[(i+newLines)], sep="")
 					countLines = countLines + 1
 				}
-
-				count = count + length(dataTempPhase)
+			} else {
+				if(inputMultiData$eccon[i] == "c")
+					myEccon[(i+newLines)] = "c"
+				else
+					myEccon[(i+newLines)] = "ec"
+				countLines = countLines + 1
 			}
-		}		
-		
-		#rawdata.cumsum=cumsum(rawdata)
-
-		#curves = data.frame(id,start,end,startH,exerciseName,mass,smooth,dateTime,myEccon,stringsAsFactors=F,row.names=1)
-		#this is a problem when there's only one row as seen by the R code of data.frame. ?data.frame:
-		#"If row names are supplied of length one and the data frame has a
-     		#single row, the ârow.namesâ is taken to specify the row names and
-     		#not a column (by name or number)."
-		#then a column id is created when there's only on row, but it is not created there's more than one.
-		#solution:
-		if(length(id)==1) {
-			curves = data.frame(start,end,startH,exerciseName,mass,smooth,dateTime,myEccon,stringsAsFactors=F,row.names=id)
-		} else {
-			curves = data.frame(id,start,end,startH,exerciseName,mass,smooth,dateTime,myEccon,stringsAsFactors=F,row.names=1)
-		}
 
-		n=length(curves[,1])
-		quitIfNoData(n, curves, outputData1)
-	} else {
-		rawdata=scan(file=file,sep=",")
-
-		if(length(rawdata)==0) {
-			plot(0,0,type="n",axes=F,xlab="",ylab="")
-			text(x=0,y=0,"Encoder is not connected.",cex=1.5)
-			dev.off()
-			write("", outputData1)
-			quit()
+			count = count + length(dataTempPhase)
 		}
+	}		
+
+	#rawdata.cumsum=cumsum(rawdata)
+
+	#curves = data.frame(id,start,end,startH,exerciseName,mass,smooth,dateTime,myEccon,stringsAsFactors=F,row.names=1)
+	#this is a problem when there's only one row as seen by the R code of data.frame. ?data.frame:
+	#"If row names are supplied of length one and the data frame has a
+	#single row, the ârow.namesâ is taken to specify the row names and
+	#not a column (by name or number)."
+	#then a column id is created when there's only on row, but it is not created there's more than one.
+	#solution:
+	if(length(id)==1) {
+		curves = data.frame(start,end,startH,exerciseName,mass,smooth,dateTime,myEccon,stringsAsFactors=F,row.names=id)
+	} else {
+		curves = data.frame(id,start,end,startH,exerciseName,mass,smooth,dateTime,myEccon,stringsAsFactors=F,row.names=1)
+	}
 
-		rawdata.cumsum=cumsum(rawdata)
-	
-		curves=findCurves(rawdata, eccon, minHeight, curvesPlot, Title)
-		print(curves)
-		n=length(curves[,1])
-		quitIfNoData(n, curves, outputData1)
-		
-		for(i in 1:n) { 
-			curves[i,1]=reduceCurveBySpeed(eccon, i, curves[i,1],rawdata[curves[i,1]:curves[i,2]], smoothingOne)
-		}
-		if(curvesPlot) {
-			#/10 mm -> cm
-			for(i in 1:length(curves[,1])) { 
-				myLabel = i
-				myY = min(rawdata.cumsum)/10
-				adjVert = 0
-				if(eccon=="ecS") {
-					myEc=c("c","e")
-					myLabel = paste(trunc((i+1)/2),myEc[((i%%2)+1)],sep="")
-					myY = rawdata.cumsum[curves[i,1]]/10
-					if(i%%2 == 1) {
-						adjVert = 1
-					}
+	n=length(curves[,1])
+	quitIfNoData(n, curves, outputData1)
+} else {
+	rawdata=scan(file=file,sep=",")
+
+	if(length(rawdata)==0) {
+		plot(0,0,type="n",axes=F,xlab="",ylab="")
+		text(x=0,y=0,"Encoder is not connected.",cex=1.5)
+		dev.off()
+		write("", outputData1)
+		quit()
+	}
+
+	rawdata.cumsum=cumsum(rawdata)
+
+	curves=findCurves(rawdata, eccon, minHeight, curvesPlot, Title)
+	print(curves)
+	n=length(curves[,1])
+	quitIfNoData(n, curves, outputData1)
+
+	for(i in 1:n) { 
+		curves[i,1]=reduceCurveBySpeed(eccon, i, curves[i,1],rawdata[curves[i,1]:curves[i,2]], smoothingOne)
+	}
+	if(curvesPlot) {
+		#/10 mm -> cm
+		for(i in 1:length(curves[,1])) { 
+			myLabel = i
+			myY = min(rawdata.cumsum)/10
+			adjVert = 0
+			if(eccon=="ecS") {
+				myEc=c("c","e")
+				myLabel = paste(trunc((i+1)/2),myEc[((i%%2)+1)],sep="")
+				myY = rawdata.cumsum[curves[i,1]]/10
+				if(i%%2 == 1) {
+					adjVert = 1
 				}
-				text(x=(curves[i,1]+curves[i,2])/2,y=myY,labels=myLabel, adj=c(0.5,adjVert),cex=1,col="blue")
-				arrows(x0=curves[i,1],y0=myY,x1=curves[i,2],y1=myY,
-						col="blue",code=3,length=0.1)
 			}
+			text(x=(curves[i,1]+curves[i,2])/2,y=myY,labels=myLabel, adj=c(0.5,adjVert),cex=1,col="blue")
+			arrows(x0=curves[i,1],y0=myY,x1=curves[i,2],y1=myY,
+			       col="blue",code=3,length=0.1)
 		}
 	}
-	
-	write("(3/4) Curves processed", outputData2)
-		
-	if(analysis=="single") {
-		if(jump>0) {
-			myMass = Mass
-			mySmoothingOne = smoothingOne
-			myEccon = eccon
-			myStart = curves[jump,1]
-			myEnd = curves[jump,2]
-			if(! singleFile) {
-				myMass = curves[jump,5]
-				mySmoothingOne = curves[jump,6]
-				myEccon = curves[jump,8]
-			}
-			paint(rawdata, myEccon, myStart, myEnd,"undefined","undefined",FALSE,FALSE,
-					1,curves[jump,3],mySmoothingOne,myMass,
-					paste(Title, " ", analysis, " ", myEccon, " ", titleType, " ", jump,
-					      " (smoothing: ",mySmoothingOne,")",sep=""),
-					TRUE,	#draw
-					TRUE,	#showLabels
-					FALSE,	#marShrink
-					TRUE,	#showAxes
-					TRUE	#legend
-					)	
+}
+
+write("(3/4) Curves processed", outputData2)
+
+if(analysis=="single") {
+	if(jump>0) {
+		myMass = Mass
+		mySmoothingOne = smoothingOne
+		myEccon = eccon
+		myStart = curves[jump,1]
+		myEnd = curves[jump,2]
+		if(! singleFile) {
+			myMass = curves[jump,5]
+			mySmoothingOne = curves[jump,6]
+			myEccon = curves[jump,8]
 		}
+		paint(rawdata, myEccon, myStart, myEnd,"undefined","undefined",FALSE,FALSE,
+		      1,curves[jump,3],mySmoothingOne,myMass,
+		      paste(Title, " ", analysis, " ", myEccon, " ", titleType, " ", jump,
+			    " (smoothing: ",mySmoothingOne,")",sep=""),
+		      TRUE,	#draw
+		      TRUE,	#showLabels
+		      FALSE,	#marShrink
+		      TRUE,	#showAxes
+		      TRUE	#legend
+		      )	
 	}
+}
 
-	if(analysis=="side") {
-		#comparar 6 salts, falta que xlim i ylim sigui el mateix
-		par(mfrow=find.mfrow(n))
+if(analysis=="side") {
+	#comparar 6 salts, falta que xlim i ylim sigui el mateix
+	par(mfrow=find.mfrow(n))
 
-		#a=cumsum(rawdata)
-		#yrange=c(min(a),max(a))
-		yrange=find.yrange(singleFile, rawdata, curves)
+	#a=cumsum(rawdata)
+	#yrange=c(min(a),max(a))
+	yrange=find.yrange(singleFile, rawdata, curves)
 
-		knRanges=kinematicRanges(singleFile,rawdata,curves,Mass,smoothingOne,g)
+	knRanges=kinematicRanges(singleFile,rawdata,curves,Mass,smoothingOne,g)
 
-		for(i in 1:n) {
-			myMass = Mass
-			mySmoothingOne = smoothingOne
-			myEccon = eccon
-			if(! singleFile) {
-				myMass = curves[i,5]
-				mySmoothingOne = curves[i,6]
-				myEccon = curves[i,8]
-			}
-			paint(rawdata, myEccon, curves[i,1],curves[i,2],yrange,knRanges,FALSE,FALSE,
-				1,curves[i,3],mySmoothingOne,myMass,paste(Title, " ", titleType,rownames(curves)[i]),
-				TRUE,	#draw
-				FALSE,	#showLabels
-				TRUE,	#marShrink
-				FALSE,	#showAxes
-				FALSE	#legend
-				)
+	for(i in 1:n) {
+		myMass = Mass
+		mySmoothingOne = smoothingOne
+		myEccon = eccon
+		if(! singleFile) {
+			myMass = curves[i,5]
+			mySmoothingOne = curves[i,6]
+			myEccon = curves[i,8]
 		}
-		par(mfrow=c(1,1))
+		paint(rawdata, myEccon, curves[i,1],curves[i,2],yrange,knRanges,FALSE,FALSE,
+		      1,curves[i,3],mySmoothingOne,myMass,paste(Title, " ", titleType,rownames(curves)[i]),
+		      TRUE,	#draw
+		      FALSE,	#showLabels
+		      TRUE,	#marShrink
+		      FALSE,	#showAxes
+		      FALSE	#legend
+		      )
 	}
-	if(analysis=="superpose") {	#TODO: fix on ec startH
-		#falta fer un graf amb les 6 curves sobreposades i les curves de potencia (per exemple) sobrepossades
-		#fer que acabin al mateix punt encara que no iniciin en el mateix
-		#arreglar que els eixos de l'esq han de seguir un ylim,pero els de la dreta un altre, basat en el que es vol observar
-		#fer que es pugui enviar colors que es vol per cada curva, o linetypes
-		wide=max(curves$end-curves$start)
-		
-		#a=cumsum(rawdata)
-		#yrange=c(min(a),max(a))
-		yrange=find.yrange(singleFile, rawdata,curves)
-
-		knRanges=kinematicRanges(singleFile,rawdata,curves,Mass,smoothingOne,g)
-		for(i in 1:n) {
-			#in superpose all jumps end at max height
-			#start can change, some are longer than other
-			#xmin and xmax should be the same for all in terms of X concordance
-			#but line maybe don't start on the absolute left
-			#this is controled by startX
-			startX = curves[i,1]-(curves[i,2]-wide)+1;
-			myTitle = "";
-			if(i==1)
-				myTitle = paste(titleType,jump);
-
-			paint(rawdata, eccon, curves[i,2]-wide,curves[i,2],yrange,knRanges,TRUE,(i==jump),
-				startX,curves[i,3],smoothingOne,Mass,myTitle,
-				TRUE,	#draw
-				TRUE,	#showLabels
-				FALSE,	#marShrink
-				(i==1),	#showAxes
-				TRUE	#legend
-				)
-			par(new=T)
-		}
-		par(new=F)
-		#print(knRanges)
+	par(mfrow=c(1,1))
+}
+if(analysis=="superpose") {	#TODO: fix on ec startH
+	#falta fer un graf amb les 6 curves sobreposades i les curves de potencia (per exemple) sobrepossades
+	#fer que acabin al mateix punt encara que no iniciin en el mateix
+	#arreglar que els eixos de l'esq han de seguir un ylim,pero els de la dreta un altre, basat en el que es vol observar
+	#fer que es pugui enviar colors que es vol per cada curva, o linetypes
+	wide=max(curves$end-curves$start)
+
+	#a=cumsum(rawdata)
+	#yrange=c(min(a),max(a))
+	yrange=find.yrange(singleFile, rawdata,curves)
+
+	knRanges=kinematicRanges(singleFile,rawdata,curves,Mass,smoothingOne,g)
+	for(i in 1:n) {
+		#in superpose all jumps end at max height
+		#start can change, some are longer than other
+		#xmin and xmax should be the same for all in terms of X concordance
+		#but line maybe don't start on the absolute left
+		#this is controled by startX
+		startX = curves[i,1]-(curves[i,2]-wide)+1;
+		myTitle = "";
+		if(i==1)
+			myTitle = paste(titleType,jump);
+
+		paint(rawdata, eccon, curves[i,2]-wide,curves[i,2],yrange,knRanges,TRUE,(i==jump),
+		      startX,curves[i,3],smoothingOne,Mass,myTitle,
+		      TRUE,	#draw
+		      TRUE,	#showLabels
+		      FALSE,	#marShrink
+		      (i==1),	#showAxes
+		      TRUE	#legend
+		      )
+		par(new=T)
 	}
+	par(new=F)
+	#print(knRanges)
+}
 
-	#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.
-	analysisCross = unlist(strsplit(analysis, "\\."))
-	if(
-			analysis == "powerBars" || analysisCross[1] == "cross" || analysis == "curves") 
-	{
-		paf = data.frame()
-		for(i in 1:n) { 
-			myMass = Mass
-			mySmoothingOne = smoothingOne
-			myEccon = eccon
-			if(! singleFile) {
-				myMass = curves[i,5]
-				mySmoothingOne = curves[i,6]
-				myEccon = curves[i,8]
-			}
-			paf=rbind(paf,(powerBars(kinematicsF(rawdata[curves[i,1]:curves[i,2]], myMass, mySmoothingOne, g))))
+#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.
+analysisCross = unlist(strsplit(analysis, "\\."))
+if(
+   analysis == "powerBars" || analysisCross[1] == "cross" || analysis == "curves") 
+{
+	paf = data.frame()
+	for(i in 1:n) { 
+		myMass = Mass
+		mySmoothingOne = smoothingOne
+		myEccon = eccon
+		if(! singleFile) {
+			myMass = curves[i,5]
+			mySmoothingOne = curves[i,6]
+			myEccon = curves[i,8]
 		}
-		#print(paf)
-		rownames(paf)=rownames(curves) #put correct rownames when there are inactive curves
-print("----------------------------")
-		print(paf)
-
-		if(analysis == "powerBars") {
-			if(! singleFile) 
-				paintPowerPeakPowerBars(Title, paf, curves[,8], 		#myEccon
+		paf=rbind(paf,(powerBars(kinematicsF(rawdata[curves[i,1]:curves[i,2]], myMass, mySmoothingOne, g))))
+	}
+	#print(paf)
+	rownames(paf)=rownames(curves) #put correct rownames when there are inactive curves
+	print("----------------------------")
+	print(paf)
+
+	if(analysis == "powerBars") {
+		if(! singleFile) 
+			paintPowerPeakPowerBars(Title, paf, curves[,8], 		#myEccon
 						curvesHeight)				#height
-			else 
-				paintPowerPeakPowerBars(Title, paf, curves[,8], 		#myEccon
+		else 
+			paintPowerPeakPowerBars(Title, paf, curves[,8], 		#myEccon
 						rawdata.cumsum[curves[,2]]-curves[,3])	#height
-		}
-		else if(analysisCross[1] == "cross") {
-			if(analysisCross[2] == "Speed,Power") {
-				par(mar=c(5,4,4,5))
-				analysisCrossVertVars = unlist(strsplit(analysisCross[2], "\\,"))
-				paintCrossVariables(paf, analysisCross[3], analysisCrossVertVars[1], 
-						    analysisCross[4], "LEFT", Title)
-				par(new=T)
-				paintCrossVariables(paf, analysisCross[3], analysisCrossVertVars[2], 
-						    analysisCross[4], "RIGHT", "")
-			} else
-				paintCrossVariables(paf, analysisCross[3], analysisCross[2], 
-						    analysisCross[4], "ALONE", Title)
-		}
-		else if(analysis == "curves") {
-			paf=cbind(curves[,1],curves[,2]-curves[,1],rawdata.cumsum[curves[,2]]-curves[,3],paf)
-			colnames(paf)=c("start","width","height","meanSpeed","maxSpeed",
+	}
+	else if(analysisCross[1] == "cross") {
+		if(analysisCross[2] == "Speed,Power") {
+			par(mar=c(5,4,4,5))
+			analysisCrossVertVars = unlist(strsplit(analysisCross[2], "\\,"))
+			paintCrossVariables(paf, analysisCross[3], analysisCrossVertVars[1], 
+					    analysisCross[4], "LEFT", Title)
+			par(new=T)
+			paintCrossVariables(paf, analysisCross[3], analysisCrossVertVars[2], 
+					    analysisCross[4], "RIGHT", "")
+		} else
+			paintCrossVariables(paf, analysisCross[3], analysisCross[2], 
+					    analysisCross[4], "ALONE", Title)
+	}
+	else if(analysis == "curves") {
+		paf=cbind(curves[,1],curves[,2]-curves[,1],rawdata.cumsum[curves[,2]]-curves[,3],paf)
+		colnames(paf)=c("start","width","height","meanSpeed","maxSpeed",
 				"meanPower","peakPower","peakPowerT","pp_ppt")
-			write.csv(paf, outputData1, quote=FALSE)
-		}
+		write.csv(paf, outputData1, quote=FALSE)
+	}
+}
+if(analysis=="exportCSV") {
+	print("Starting export...")
+	file=outputData1;
+	curvesNum = length(curves[,1])
+
+	maxLength = 0
+	for(i in 1:curvesNum) { 
+		myLength = curves[i,2]-curves[i,1]
+		if(myLength > maxLength)
+			maxLength=myLength
 	}
-	if(analysis=="exportCSV") {
-		print("Starting export...")
-		file=outputData1;
-		curvesNum = length(curves[,1])
-		
-		maxLength = 0
-		for(i in 1:curvesNum) { 
-			myLength = curves[i,2]-curves[i,1]
-			if(myLength > maxLength)
-				maxLength=myLength
-		}
 
-		curveCols = 6	#change this value if there are more colums
-		names=c("Dist.", "Dist. +", "Speed", "Accel.", "Force", "Power")
-		nums=1:curvesNum
-		nums=rep(nums,each=curveCols)		
-		namesNums=paste(names, nums)
-		
-		for(i in 1:curvesNum) { 
-			kn = kinematicsF (rawdata[curves[i,1]:curves[i,2]], Mass, smoothingOne, g)
-			
-			#fill with NAs in order to have the same length
-			col1 = rawdata[curves[i,1]:curves[i,2]]
-			col2 = rawdata.cumsum[curves[i,1]:curves[i,2]]
-			
-			#add mean and max
-			col1=append(col1,
-				    c(NA,NA,NA,namesNums[((i-1)*curveCols)+1]),
-				    after=0)
-			col2=append(col2,
-				    c(NA,"mean (ABS):","max:",namesNums[((i-1)*curveCols)+2]),
-				    after=0)
-			kn$speedy=append(kn$speedy,
-					 c(
-					   namesNums[((i-1)*curveCols)+3],
-					   mean(abs(kn$speedy)),max(kn$speedy),
-					   namesNums[((i-1)*curveCols)+3]),
-					 after=0)
-			kn$accely=append(kn$accely,
-					 c(
-					   namesNums[((i-1)*curveCols)+4],
-					   mean(abs(kn$accely)),max(kn$accely),
-					   namesNums[((i-1)*curveCols)+4]),
-					 after=0)
-			kn$force=append(kn$force,
-					c(
-					  namesNums[((i-1)*curveCols)+5],
-					  mean(abs(kn$force)),max(kn$force),
-					  namesNums[((i-1)*curveCols)+5]),
-					after=0)
-			kn$power=append(kn$power,
-					c(
-					  namesNums[((i-1)*curveCols)+6],
-					  mean(abs(kn$power)),max(kn$power),
-					  namesNums[((i-1)*curveCols)+6]),
-					after=0)
-			
-			extraRows=4
-			length(col1)=maxLength+extraRows
-			length(col2)=maxLength+extraRows
-			length(kn$speedy)=maxLength+extraRows
-			length(kn$accely)=maxLength+extraRows
-			length(kn$force)=maxLength+extraRows
-			length(kn$power)=maxLength+extraRows
-
-			if(i==1)
-				df=data.frame(cbind(col1, col2,
-						    kn$speedy, kn$accely, kn$force, kn$power))
-			else
-				df=data.frame(cbind(df, col1, col2,
-						    kn$speedy, kn$accely, kn$force, kn$power))
-		}
-	
-		#TODO: time
-		#TODO: tenir en compte el startH
-		
-		Title=gsub('_',' ',Title)
-		print(Title)
-		titleColumns=unlist(strsplit(Title,'-'))
-		colnames(df)=c(titleColumns[1]," ", titleColumns[2],titleColumns[3],rep(" ",(curvesNum*curveCols-4)))
-
-		write.csv2(df, file=file, row.names=F, na="")
-		#write.csv2(df, file=file, quotes=F)
-		print("Export done.")
+	curveCols = 6	#change this value if there are more colums
+	names=c("Dist.", "Dist. +", "Speed", "Accel.", "Force", "Power")
+	nums=1:curvesNum
+	nums=rep(nums,each=curveCols)		
+	namesNums=paste(names, nums)
+
+	for(i in 1:curvesNum) { 
+		kn = kinematicsF (rawdata[curves[i,1]:curves[i,2]], Mass, smoothingOne, g)
+
+		#fill with NAs in order to have the same length
+		col1 = rawdata[curves[i,1]:curves[i,2]]
+		col2 = rawdata.cumsum[curves[i,1]:curves[i,2]]
+
+		#add mean and max
+		col1=append(col1,
+			    c(NA,NA,NA,namesNums[((i-1)*curveCols)+1]),
+			    after=0)
+		col2=append(col2,
+			    c(NA,"mean (ABS):","max:",namesNums[((i-1)*curveCols)+2]),
+			    after=0)
+		kn$speedy=append(kn$speedy,
+				 c(
+				   namesNums[((i-1)*curveCols)+3],
+				   mean(abs(kn$speedy)),max(kn$speedy),
+				   namesNums[((i-1)*curveCols)+3]),
+				 after=0)
+		kn$accely=append(kn$accely,
+				 c(
+				   namesNums[((i-1)*curveCols)+4],
+				   mean(abs(kn$accely)),max(kn$accely),
+				   namesNums[((i-1)*curveCols)+4]),
+				 after=0)
+		kn$force=append(kn$force,
+				c(
+				  namesNums[((i-1)*curveCols)+5],
+				  mean(abs(kn$force)),max(kn$force),
+				  namesNums[((i-1)*curveCols)+5]),
+				after=0)
+		kn$power=append(kn$power,
+				c(
+				  namesNums[((i-1)*curveCols)+6],
+				  mean(abs(kn$power)),max(kn$power),
+				  namesNums[((i-1)*curveCols)+6]),
+				after=0)
+
+		extraRows=4
+		length(col1)=maxLength+extraRows
+		length(col2)=maxLength+extraRows
+		length(kn$speedy)=maxLength+extraRows
+		length(kn$accely)=maxLength+extraRows
+		length(kn$force)=maxLength+extraRows
+		length(kn$power)=maxLength+extraRows
+
+		if(i==1)
+			df=data.frame(cbind(col1, col2,
+					    kn$speedy, kn$accely, kn$force, kn$power))
+		else
+			df=data.frame(cbind(df, col1, col2,
+					    kn$speedy, kn$accely, kn$force, kn$power))
 	}
-	if(analysis != "exportCSV")
-		dev.off()
 
-	write("(4/4) R tasks done", outputData2)
+	#TODO: time
+	#TODO: tenir en compte el startH
+
+	Title=gsub('_',' ',Title)
+	print(Title)
+	titleColumns=unlist(strsplit(Title,'-'))
+	colnames(df)=c(titleColumns[1]," ", titleColumns[2],titleColumns[3],rep(" ",(curvesNum*curveCols-4)))
+
+	write.csv2(df, file=file, row.names=F, na="")
+	#write.csv2(df, file=file, quotes=F)
+	print("Export done.")
 }
+if(analysis != "exportCSV")
+	dev.off()
+
+write("(4/4) R tasks done", outputData2)
 
 warnings()
 
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index eeb0524..7e32145 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -812,10 +812,19 @@ public partial class ChronoJumpWindow
 			writer.WriteLine("status,exerciseName,mass,smoothingOne,dateTime,fullURL,eccon");
 		
 			Sqlite.Open();	
+			ArrayList eeArray = 
+					SqliteEncoder.SelectEncoderExercises(true, -1, false);
+			Sqlite.Close();	
+			EncoderExercise ex = new EncoderExercise();
+
 			foreach(EncoderSQL eSQL in data) {
+				foreach(EncoderExercise eeSearch in eeArray)
+					if(eSQL.exerciseID == eeSearch.uniqueID)
+						ex = eeSearch;
+
 				double mass = Convert.ToDouble(eSQL.extraWeight); //TODO: future problem if this has '%'
-				EncoderExercise ex = (EncoderExercise) 
-					SqliteEncoder.SelectEncoderExercises(true, eSQL.exerciseID, false)[0];
+				//EncoderExercise ex = (EncoderExercise) 
+				//	SqliteEncoder.SelectEncoderExercises(true, eSQL.exerciseID, false)[0];
 				mass += bodyMass * ex.percentBodyWeight / 100.0;
 
 				writer.WriteLine(eSQL.future1 + "," + ex.name + "," + 
@@ -827,7 +836,7 @@ public partial class ChronoJumpWindow
 			}
 			writer.Flush();
 			((IDisposable)writer).Dispose();
-			Sqlite.Close();	
+			//Sqlite.Close();	
 		} else {
 			ep = new EncoderParams(
 					(int) spin_encoder_capture_min_height.Value, 
diff --git a/src/sqlite/encoder.cs b/src/sqlite/encoder.cs
index d71d1e2..b7917f0 100644
--- a/src/sqlite/encoder.cs
+++ b/src/sqlite/encoder.cs
@@ -249,7 +249,7 @@ class SqliteEncoder : Sqlite
 		}
 	}
 
-	//if submited a -1, returns an especific EncoderExercise that can be read like this	
+	//if uniqueID != -1, returns an especific EncoderExercise that can be read like this	
 	//EncoderExercise ex = (EncoderExercise) SqliteEncoder.SelectEncoderExercises(eSQL.exerciseID)[0];
 	public static ArrayList SelectEncoderExercises(bool dbconOpened, int uniqueID, bool onlyNames) 
 	{



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