[chronojump/michrolab] RaceAnalyzer can analyze/export non-sprints
- From: Xavier Padullés <xpadulles src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump/michrolab] RaceAnalyzer can analyze/export non-sprints
- Date: Fri, 5 Aug 2022 09:19:42 +0000 (UTC)
commit 91777d3dd1d908585951b02a54aa14277b0c6c6b
Author: Xavier de Blas <xaviblas gmail com>
Date: Thu Jul 28 17:14:57 2022 +0200
RaceAnalyzer can analyze/export non-sprints
r-scripts/sprintEncoder.R | 390 ++++++++++++++++++++++++++++---------------
r-scripts/sprintPhotocells.R | 5 +-
r-scripts/sprintUtil.R | 119 ++++++++++---
src/gui/app1/runEncoder.cs | 12 +-
src/runEncoder.cs | 21 ++-
5 files changed, 375 insertions(+), 172 deletions(-)
---
diff --git a/r-scripts/sprintEncoder.R b/r-scripts/sprintEncoder.R
index 2fee11933..e877b15f1 100644
--- a/r-scripts/sprintEncoder.R
+++ b/r-scripts/sprintEncoder.R
@@ -42,27 +42,29 @@ assignOptions <- function(options) {
personHeight = as.numeric(options[4]),
tempC = as.numeric(options[5]),
testLength = as.numeric(options[6]),
- os = options[7],
- graphWidth = as.numeric(options[8]),
- graphHeight = as.numeric(options[9]),
- device = options[10],
- splitLength = as.numeric(options[11]), #fixed, in meters
- splitVariableCm = as.numeric(unlist(strsplit(options[12], "\\;"))), #variable, in cm
- title = options[13],
- datetime = options[14],
- startAccel = as.numeric(options[15]),
- plotRawAccel = as.logical(options[16]),
- plotFittedAccel = as.logical(options[17]),
- plotRawForce = as.logical(options[18]),
- plotFittedForce = as.logical(options[19]),
- plotRawPower = as.logical(options[20]),
- plotFittedPower = as.logical(options[21]),
- triggersOnList = as.numeric(unlist(strsplit(options[22], "\\;"))),
- triggersOffList = as.numeric(unlist(strsplit(options[23], "\\;"))),
- singleOrMultiple = options[24],
- decimalCharAtExport = options[25],
- includeImagesOnExport = options[26],
- includeInstantaneousOnExport = options[27]
+ isSprint = as.logical(options[7]),
+ os = options[8],
+ graphWidth = as.numeric(options[9]),
+ graphHeight = as.numeric(options[10]),
+ device = options[11],
+ splitLength = as.numeric(options[12]), #fixed, in meters
+ splitVariableCm = as.numeric(unlist(strsplit(options[13], "\\;"))), #variable, in cm
+ title = options[14],
+ datetime = options[15],
+startAccel = as.numeric(options[16]),
+# startAccel = 40,
+ plotRawAccel = as.logical(options[17]),
+ plotFittedAccel = as.logical(options[18]),
+ plotRawForce = as.logical(options[19]),
+ plotFittedForce = as.logical(options[20]),
+ plotRawPower = as.logical(options[21]),
+ plotFittedPower = as.logical(options[22]),
+ triggersOnList = as.numeric(unlist(strsplit(options[23], "\\;"))),
+ triggersOffList = as.numeric(unlist(strsplit(options[24], "\\;"))),
+ singleOrMultiple = options[25],
+ decimalCharAtExport = options[26],
+ includeImagesOnExport = options[27],
+ includeInstantaneousOnExport = options[28]
))
}
@@ -72,9 +74,10 @@ op <- assignOptions(options)
op$title = fixTitleAndOtherStrings(op$title)
op$datetime = fixDatetime(op$datetime)
-getSprintFromEncoder <- function(filename, testLength, Mass, Temperature = 25, Height , Vw = 0, device =
"MANUAL", startAccel, splitLength, splitVariableCm)
+getSprintFromEncoder <- function(filename, testLength, isSprint, Mass, Temperature = 25, Height , Vw = 0,
device = "MANUAL", startAccel, splitLength, splitVariableCm)
{
print("#####Entering in getSprintFromEncoder###############")
+
# Constants for the air friction modeling
ro0 = 1.293
Pb = 760
@@ -171,13 +174,14 @@ getSprintFromEncoder <- function(filename, testLength, Mass, Temperature = 25, H
labels = "The capture does not reach the length of the test", cex = 2, pos = 3)
print("Capture too short")
longEnough = FALSE
- return(list(longEnough = longEnough))
+ return(list(longEnough = longEnough, problems = TRUE))
} else{
longEnough = TRUE
}
#Finding when the sprint starts
trimmingSamples = getTrimmingSamples(totalTime, position, speed, accel, testLength, startAccel)
+ print("trimmingSamples")
print(trimmingSamples)
#plot error if no enough acceleration
@@ -191,7 +195,7 @@ getSprintFromEncoder <- function(filename, testLength, Mass, Temperature = 25, H
text(x = length(position)/2, y = max(position) * .25,
labels = "or does not seem a sprint", cex = 2)
print("Capture has not enough accel")
- return(list(longEnough = longEnough, regressionDone = FALSE))
+ return(list(longEnough = longEnough, regressionDone = FALSE, problems = TRUE))
}
#Zeroing time to the initial acceleration sample
@@ -210,46 +214,71 @@ getSprintFromEncoder <- function(filename, testLength, Mass, Temperature = 25, H
data = data.frame(time = time[trimmingSamples$start:trimmingSamples$end], position =
position[trimmingSamples$start:trimmingSamples$end])
# print(data)
- print("Trying nls")
- regression = tryNLS(data)
-
- print("regression:")
- print(regression)
- print(paste("longEnough:", longEnough))
- print(paste("regressionDone:", regression$regressionDone))
-
- if (! regression$regressionDone)
- {
- print("NLS regression problem")
- if((length(totalTime) +1) == length(speed))
- {
- plot(totalTime[2:length(totalTime)], speed, type = "l",
- #ylim = c(min(speed), testLength)*1.05,
- xlab = "Time (s)", ylab = "Speed (m/s)")
- #abline(h = testLength, lty = 2)
- # text(x = (totalTime[length(totalTime)] + totalTime[1])/2,
- # y = testLength,
- # labels = (paste("Configured test length :", testLength, " m", sep = "")),
- # pos = 3)
- text(x = (totalTime[length(totalTime)] + totalTime[1])/2, max(speed) /2,
- labels = "The graph doesn't seem a sprint", cex = 2, pos = 3)
- }
- else
+ regression = NULL
+ if (isSprint)
+ {
+ print("Trying nls")
+ regression = tryNLS(data)
+
+ print("regression:")
+ print(regression)
+ print(paste("longEnough:", longEnough))
+ print(paste("regressionDone:", regression$regressionDone))
+
+ if (! regression$regressionDone)
{
- plot(0,0,type="n",axes=F,xlab="",ylab="")
- text(x=0, y=0, adj=0.5, cex=1.2, col="red", "This data does not seem a sprint.")
+ print("NLS regression problem")
+ if((length(totalTime) +1) == length(speed))
+ {
+ plot(totalTime[2:length(totalTime)], speed, type = "l",
+ #ylim = c(min(speed), testLength)*1.05,
+ xlab = "Time (s)", ylab = "Speed (m/s)")
+ #abline(h = testLength, lty = 2)
+ # text(x = (totalTime[length(totalTime)] + totalTime[1])/2,
+ # y = testLength,
+ # labels = (paste("Configured test length :", testLength, " m",
sep = "")),
+ # pos = 3)
+ text(x = (totalTime[length(totalTime)] + totalTime[1])/2, max(speed)
/2,
+ labels = "The graph doesn't seem a sprint", cex = 2, pos = 3)
+ }
+ else
+ {
+ #TODO: so show as not an sprint
+ plot(0,0,type="n",axes=F,xlab="",ylab="")
+ text(x=0, y=0, adj=0.5, cex=1.2, col="red", "This data does not seem
a sprint.")
+ }
+ return(list(longEnough = longEnough, regressionDone = regression$regressionDone,
problems = TRUE))
}
+ }
+# else
+# {
+# print("totalTime:")
+# print(totalTime)
+# print("time:")
+# print(raceAnalyzer$time)
+# print("speed:")
+# print(speed)
+# #plot(totalTime[2:length(totalTime)], speed, type = "l",
+# plot(totalTime, speed, type = "l",
+# ylim = c(min(speed), testLength)*1.05,
+# xlab = "Time (s)", ylab = "Speed (m/s)")
+# }
+
+
+ Vmax = NULL
+ K = NULL
+ T0 = 0
+ P0 = 0
+ if (isSprint)
+ {
+ #model = nls(speed ~ Vmax*(1-exp(-K*time)), data,
+ # start = list(Vmax = max(speed), K = 1), control=nls.control(warnOnly=TRUE))
+ Vmax =summary(regression$model)$coeff[2,1]
+ K = summary(regression$model)$coeff[1,1]
+ T0 = summary(regression$model)$coeff[3,1]
+ P0 = summary(regression$model)$coeff[4,1]
+ }
- return(list(longEnough = longEnough, regressionDone = regression$regressionDone))
- }
-
-
- #model = nls(speed ~ Vmax*(1-exp(-K*time)), data,
- # start = list(Vmax = max(speed), K = 1), control=nls.control(warnOnly=TRUE))
- Vmax =summary(regression$model)$coeff[2,1]
- K = summary(regression$model)$coeff[1,1]
- T0 = summary(regression$model)$coeff[3,1]
- P0 = summary(regression$model)$coeff[4,1]
print(paste("T0:", T0))
#time = time + T0
print(paste("P0:", P0))
@@ -272,6 +301,7 @@ getSprintFromEncoder <- function(filename, testLength, Mass, Temperature = 25, H
meanPower = splits$meanPower
return(list(Vmax = Vmax, K = K, T0 = T0, Ka=Ka, Vw=Vw, Mass=Mass,
+ height = Height, temperature = Temperature, #both used only at export row
time = time, rawPosition = position + P0, rawSpeed = speed, rawAccel = accel, rawForce =
totalForce, rawPower = power,
rawVmax = max(speed[trimmingSamples$start:trimmingSamples$end]),
rawAmax = max(accel[trimmingSamples$start:trimmingSamples$end]),
@@ -279,11 +309,16 @@ getSprintFromEncoder <- function(filename, testLength, Mass, Temperature = 25, H
rawPmax = max(power[trimmingSamples$start:trimmingSamples$end]),
startSample = trimmingSamples$start, startTime = totalTime[trimmingSamples$start] + T0,
endSample = trimmingSamples$end, testLength = testLength,
- longEnough = longEnough, regressionDone = regression$regressionDone, timeBefore = T0,
startAccel = startAccel,
- splitTime = splitTime, splitPosition = splitPosition, meanSpeed = meanSpeed, meanForde =
meanForce, meanPower = meanPower))
+ longEnough = longEnough,
+ #regression = regression,
+ regressionDone = regression$regressionDone, timeBefore = T0, startAccel = startAccel,
+ splitTime = splitTime, splitPosition = splitPosition, meanSpeed = meanSpeed, meanForde =
meanForce, meanPower = meanPower,
+ problems = FALSE#,
+ #comment = "" #to send comments of problems by previous returns
+ ))
}
-plotSprintFromEncoder <- function(sprintRawDynamics, sprintFittedDynamics,
+plotSprintFromEncoder <- function(sprintRawDynamics, sprintFittedDynamics, isSprint,
title = "Test graph",
subtitle = "",
triggersOn = "",
@@ -344,26 +379,36 @@ plotSprintFromEncoder <- function(sprintRawDynamics, sprintFittedDynamics,
legendColor = "black"
legendLty = ltyRaw
legendLwd = lwdRaw
-
- legendText = c(legendText, paste("V max (fitted) =", round(sprintFittedDynamics$Vmax.fitted, digits
= 2), "m/s"))
- legendColor = c(legendColor, "black")
- legendLty = c(legendLty, ltyFitted)
- legendLwd = c(legendLwd, lwdFitted)
-
- legendText = c(legendText, paste("K =", round(sprintFittedDynamics$K.fitted, digits = 2),
"s\u207B\u00B9"))
- legendColor = c(legendColor, "black")
- legendLty = c(legendLty, 0)
- legendLwd = c(legendLwd, 0)
- legendText = c(legendText, paste("\u03C4 =", round(1/sprintFittedDynamics$K.fitted, digits = 2),
"s"))
- legendColor = c(legendColor, "black")
- legendLty = c(legendLty, 0)
- legendLwd = c(legendLwd, 0)
+ if (isSprint)
+ {
+ legendText = c(legendText, paste("V max (fitted) =", round(sprintFittedDynamics$Vmax.fitted,
digits = 2), "m/s"))
+ legendColor = c(legendColor, "black")
+ legendLty = c(legendLty, ltyFitted)
+ legendLwd = c(legendLwd, lwdFitted)
+
+ legendText = c(legendText, paste("K =", round(sprintFittedDynamics$K.fitted, digits = 2),
"s\u207B\u00B9"))
+ legendColor = c(legendColor, "black")
+ legendLty = c(legendLty, 0)
+ legendLwd = c(legendLwd, 0)
+
+ legendText = c(legendText, paste("\u03C4 =", round(1/sprintFittedDynamics$K.fitted, digits =
2), "s"))
+ legendColor = c(legendColor, "black")
+ legendLty = c(legendLty, 0)
+ legendLwd = c(legendLwd, 0)
+ }
+
+ #T0 variable is lot used on this function, usually sprintFittedDynamics$T0, but this can be only used
on model (isSprint)
+ T0 <- 0
+ if (isSprint)
+ T0 <- sprintFittedDynamics$T0
#Plotting rawSpeed
ylimits = c(0, sprintRawDynamics$rawVmax*1.05)
- xlimits =c(-sprintFittedDynamics$T0, sprintRawDynamics$time[sprintRawDynamics$endSample])
+ xlimits =c(-T0, sprintRawDynamics$time[sprintRawDynamics$endSample])
+ #print ("xlimits: ")
+ #print (xlimits)
if(plotRawMeanSpeed)
{
@@ -375,7 +420,7 @@ plotSprintFromEncoder <- function(sprintRawDynamics, sprintFittedDynamics,
mtext(subtitle, line = 1)
lines(sprintRawDynamics$time[sprintRawDynamics$startSample:sprintRawDynamics$endSample],
sprintRawDynamics$rawSpeed[sprintRawDynamics$startSample:sprintRawDynamics$endSample])
-
lines(c(0,sprintRawDynamics$time[sprintRawDynamics$startSample]),c(0,sprintRawDynamics$rawSpeed[sprintRawDynamics$startSample]))
+
lines(c(0,sprintRawDynamics$time[sprintRawDynamics$startSample]),c(0,sprintRawDynamics$rawSpeed[sprintRawDynamics$startSample]))
# points(sprintRawDynamics$time[sprintRawDynamics$startSample:sprintRawDynamics$endSample],
#
sprintRawDynamics$rawSpeed[sprintRawDynamics$startSample:sprintRawDynamics$endSample])
# abline(v=sprintRawDynamics$time[sprintRawDynamics$startSample])
@@ -400,7 +445,7 @@ plotSprintFromEncoder <- function(sprintRawDynamics, sprintFittedDynamics,
abline(v = sprintRawDynamics$splitTime, lty = 3)
mtext(side = 3, at = sprintRawDynamics$splitTime, text = paste(sprintRawDynamics$splitPosition, "
m", sep=""))
mtext(side = 1, at = 0, text = paste(0, " s", sep=""))
- mtext(side = 1, at = -sprintFittedDynamics$T0, text = paste(round(-sprintFittedDynamics$T0, 3), "
s", sep=""))
+ mtext(side = 1, at = -T0, text = paste(round(-T0, 3), " s", sep=""))
mtext(side = 1, at = sprintRawDynamics$splitTime, text = paste(round(sprintRawDynamics$splitTime,
digits = 3), " s", sep=""))
if (plotFittedSpeed)
@@ -416,7 +461,10 @@ plotSprintFromEncoder <- function(sprintRawDynamics, sprintFittedDynamics,
if (plotRawAccel || plotFittedAccel)
{
if(plotRawAccel){
- ylimits =
c(min(sprintRawDynamics$rawAccel[sprintRawDynamics$startSample:sprintRawDynamics$endSample])*0.95,
max(c(sprintRawDynamics$rawAmax, sprintFittedDynamics$amax.fitted)*1.05))
+ if (isSprint)
+ ylimits =
c(min(sprintRawDynamics$rawAccel[sprintRawDynamics$startSample:sprintRawDynamics$endSample])*0.95,
max(c(sprintRawDynamics$rawAmax, sprintFittedDynamics$amax.fitted)*1.05))
+ else
+ ylimits =
c(min(sprintRawDynamics$rawAccel[sprintRawDynamics$startSample:sprintRawDynamics$endSample])*0.95,
max(sprintRawDynamics$rawAmax)*1.05)
} else {
ylimits = c(0,sprintFittedDynamics$amax.fitted)
}
@@ -463,7 +511,10 @@ plotSprintFromEncoder <- function(sprintRawDynamics, sprintFittedDynamics,
if(plotRawForce|| plotFittedForce)
{
if(plotRawForce){
- ylimits =
c(min(sprintRawDynamics$rawForce[sprintRawDynamics$startSample:sprintRawDynamics$endSample])*0.95,
max(c(sprintRawDynamics$rawFmax, sprintFittedDynamics$fmax.fitted)*1.05))
+ if (isSprint)
+ ylimits =
c(min(sprintRawDynamics$rawForce[sprintRawDynamics$startSample:sprintRawDynamics$endSample])*0.95,
max(c(sprintRawDynamics$rawFmax, sprintFittedDynamics$fmax.fitted)*1.05))
+ else
+ ylimits =
c(min(sprintRawDynamics$rawForce[sprintRawDynamics$startSample:sprintRawDynamics$endSample])*0.95,
max(sprintRawDynamics$rawFmax)*1.05)
} else {
ylimits = c(0,sprintFittedDynamics$fmax.fitted)
}
@@ -499,15 +550,23 @@ plotSprintFromEncoder <- function(sprintRawDynamics, sprintFittedDynamics,
legendLwd = c(legendLwd, lwdFitted)
}
axis(side = 4, col = "blue", line = 2)
- print("Mean force from the model")
- print(getMeanValue(sprintFittedDynamics$t.fitted, sprintRawDynamics$force.fitted, 0, 1.004))
+ if (isSprint)
+ {
+ print("Mean force from the model")
+ print(getMeanValue(sprintFittedDynamics$t.fitted, sprintRawDynamics$force.fitted, 0,
1.004))
+ }
}
if(plotMeanRawForce)
{
par(new = TRUE)
- ylimits =
c(min(sprintRawDynamics$rawForce[sprintRawDynamics$startSample:sprintRawDynamics$endSample])*0.95,
- max(c(sprintRawDynamics$rawFmax, sprintFittedDynamics$fmax.fitted)*1.05))
+ if (isSprint)
+ ylimits =
c(min(sprintRawDynamics$rawForce[sprintRawDynamics$startSample:sprintRawDynamics$endSample])*0.95,
+ max(c(sprintRawDynamics$rawFmax,
sprintFittedDynamics$fmax.fitted)*1.05))
+ else
+ ylimits =
c(min(sprintRawDynamics$rawForce[sprintRawDynamics$startSample:sprintRawDynamics$endSample])*0.95,
+ max(sprintRawDynamics$rawFmax)*1.05)
+
plot(NULL, NULL,
ylim = ylimits, xlim = xlimits,
xlab = "", ylab = "",
@@ -526,8 +585,12 @@ plotSprintFromEncoder <- function(sprintRawDynamics, sprintFittedDynamics,
#this 1.075 were 1.05, but sometimes the textg value in top of fitted power got out of
boundaries
if (plotRawPower)
{
- ylimits =
c(min(sprintRawDynamics$rawPower[sprintRawDynamics$startSample:sprintRawDynamics$endSample])*0.95,
- max(c(sprintRawDynamics$rawPmax,
sprintFittedDynamics$pmax.fitted)*1.075))
+ if(isSprint)
+ ylimits =
c(min(sprintRawDynamics$rawPower[sprintRawDynamics$startSample:sprintRawDynamics$endSample])*0.95,
+ max(c(sprintRawDynamics$rawPmax,
sprintFittedDynamics$pmax.fitted)*1.075))
+ else
+ ylimits =
c(min(sprintRawDynamics$rawPower[sprintRawDynamics$startSample:sprintRawDynamics$endSample])*0.95,
+ max(sprintRawDynamics$rawPmax)*1.075)
} else {
ylimits = c(0,sprintFittedDynamics$pmax.fitted*1.075)
}
@@ -548,7 +611,6 @@ plotSprintFromEncoder <- function(sprintRawDynamics, sprintFittedDynamics,
if (plotFittedPower)
{
-
sprintFittedDynamics$tpmax.fitted = sprintFittedDynamics$tpmax.fitted -
sprintFittedDynamics$T0
#Plotting fittedPower
par(new = TRUE)
@@ -579,8 +641,13 @@ plotSprintFromEncoder <- function(sprintRawDynamics, sprintFittedDynamics,
if(plotMeanRawPower)
{
par(new = TRUE)
- ylimits =
c(min(sprintRawDynamics$rawPower[sprintRawDynamics$startSample:sprintRawDynamics$endSample])*0.95,
- max(c(sprintRawDynamics$rawPmax, sprintFittedDynamics$pmax.fitted)*1.05))
+ if (isSprint)
+ ylimits =
c(min(sprintRawDynamics$rawPower[sprintRawDynamics$startSample:sprintRawDynamics$endSample])*0.95,
+ max(c(sprintRawDynamics$rawPmax,
sprintFittedDynamics$pmax.fitted)*1.05))
+ else
+ ylimits =
c(min(sprintRawDynamics$rawPower[sprintRawDynamics$startSample:sprintRawDynamics$endSample])*0.95,
+ max(sprintRawDynamics$rawPmax)*1.05)
+
plot(NULL, NULL,
ylim = ylimits, xlim = xlimits,
#xlim = c(sprintRawDynamics$time[sprintRawDynamics$startSample],
sprintRawDynamics$time[sprintRawDynamics$endSample]),
@@ -601,12 +668,14 @@ plotSprintFromEncoder <- function(sprintRawDynamics, sprintFittedDynamics,
print("triggersOn on plot:")
print(triggersOn)
#TODO: Find why the T0 have to be added twice
- triggersOn = triggersOn + 2*sprintFittedDynamics$T0.fitted
+ #triggersOn = triggersOn + 2*sprintFittedDynamics$T0.fitted
+ triggersOn = triggersOn + 2*T0
print(triggersOn)
abline(v=triggersOn, col="green")
print("triggersOff plot:")
print(triggersOff)
- triggersOff = triggersOff + 2*sprintFittedDynamics$T0.fitted
+ #triggersOff = triggersOff + 2*sprintFittedDynamics$T0.fitted
+ triggersOff = triggersOff + 2*T0
print(triggersOff)
abline(v=triggersOff, col="red")
@@ -692,8 +761,11 @@ getSplits <- function(time, rawPosition, rawForce, rawPower, startSample, endSam
else
splitPosition = min(testLength, splitVariableCm[1]/100)
print("Going to interpolate:")
+ print("time")
print(time[startSample:endSample])
+ print("rawPosition")
print(rawPosition[startSample:endSample])
+ print("splitPosition")
print(splitPosition)
splitTime = interpolateXAtY(time[startSample:endSample],
rawPosition[startSample:endSample],
@@ -805,10 +877,10 @@ tryNLS <- function(data){
)
}
-testEncoderCJ <- function(filename, filenameInstantaneous, testLength, splitLength, splitVariableCm,
splitPositionAll,
+testEncoderCJ <- function(filename, filenameInstantaneous, testLength, isSprint, splitLength,
splitVariableCm, splitPositionAll,
mass, personHeight, tempC, device, title, datetime, startAccel, triggersOn, triggersOff)
{
- sprintRawDynamics = getSprintFromEncoder(filename, testLength, mass, tempC, personHeight, Vw = 0,
+ sprintRawDynamics = getSprintFromEncoder(filename, testLength, isSprint, mass, tempC, personHeight,
Vw = 0,
device = device, startAccel, splitLength, splitVariableCm)
#print("sprintRawDynamics:")
#print(sprintRawDynamics)
@@ -819,21 +891,34 @@ testEncoderCJ <- function(filename, filenameInstantaneous, testLength, splitLeng
exportRow = NULL
- if (sprintRawDynamics$longEnough && sprintRawDynamics$regressionDone)
+ if (! sprintRawDynamics$longEnough)
+ {
+ print("Couldn't calculate the sprint model")
+ #TODO: here we have to be able to do:
+ #exportRow = exportSprintRawPrepareRow(sprintRawDynamics, splitPositionAll,
op$decimalCharAtExport == ",")
+ #so the first returns of getSprintFromEncoder should return Mass, hheight, temperature, Vw,
rawVmax, rawAmax, rasFmax, rawPmax
+
+ return(exportRow)
+ }
+
+ # print("triggersOn in testEncoderCJ:")
+ # print(triggersOn)
+ triggersOn = triggersOn/1000 - sprintRawDynamics$startTime
+ # print("triggersOn in testEncoderCJ:")
+ # print(triggersOn)
+ triggersOff = triggersOff/1000 - sprintRawDynamics$startTime
+ # print("triggersOff in testEncoderCJ:")
+ print(op$triggersOffList)
+
+ if (#! is.null(regression) &&
+ isSprint &&
+ sprintRawDynamics$regressionDone)
{
print(paste("Vmax:", sprintRawDynamics$Vmax))
print(paste("T0:", sprintRawDynamics$T0))
sprintFittedDynamics = getDynamicsFromSprint(K = sprintRawDynamics$K, Vmax =
sprintRawDynamics$Vmax, Mass = mass, T0 = sprintRawDynamics$T0, Temperature = tempC, Height = personHeight)
print(paste("K =",sprintFittedDynamics$K.fitted, "Vmax =", sprintFittedDynamics$Vmax.fitted))
- # print("triggersOn in testEncoderCJ:")
- # print(triggersOn)
- triggersOn = triggersOn/1000 - sprintRawDynamics$startTime
- # print("triggersOn in testEncoderCJ:")
- # print(triggersOn)
- triggersOff = triggersOff/1000 - sprintRawDynamics$startTime
- # print("triggersOff in testEncoderCJ:")
- print(op$triggersOffList)
- plotSprintFromEncoder(sprintRawDynamic = sprintRawDynamics, sprintFittedDynamics =
sprintFittedDynamics,
+ plotSprintFromEncoder(sprintRawDynamic = sprintRawDynamics, sprintFittedDynamics =
sprintFittedDynamics, isSprint,
title,
datetime, #subtitle
triggersOn = triggersOn,
@@ -851,22 +936,57 @@ testEncoderCJ <- function(filename, filenameInstantaneous, testLength, splitLeng
plotFittedPower = op$plotFittedPower,
startAccel = startAccel,
plotStartDetection = TRUE)
+ } else {
+ plotSprintFromEncoder(sprintRawDynamic = sprintRawDynamics, sprintFittedDynamics = NULL,
isSprint,
+ title,
+ datetime, #subtitle
+ triggersOn = triggersOn,
+ triggersOff = triggersOff,
+ plotRawMeanSpeed = TRUE,
+ plotRawSpeed = TRUE,
+ plotRawAccel = op$plotRawAccel,
+ plotRawForce = op$plotRawForce,
+ plotMeanRawForce = FALSE,
+ plotRawPower = op$plotRawPower,
+ plotMeanRawPower = FALSE,
+ plotFittedSpeed = FALSE,
+ plotFittedAccel = FALSE,
+ plotFittedForce = FALSE,
+ plotFittedPower = FALSE,
+ startAccel = startAccel,
+ plotStartDetection = TRUE)
+ }
+ if (#! is.null(regression) &&
+ isSprint &&
+ sprintRawDynamics$regressionDone)
+ {
#splitPositionAll is NULL on (op$singleOrMultiple == "TRUE")
- exportRow = exportSprintDynamicsPrepareRow(sprintFittedDynamics, sprintRawDynamics$splitTime,
sprintRawDynamics$splitPosition, splitPositionAll, op$decimalCharAtExport == ",")
+ exportRow = exportSprintDynamicsPrepareRow(sprintFittedDynamics, sprintRawDynamics,
sprintRawDynamics$splitTime, sprintRawDynamics$splitPosition, splitPositionAll, op$decimalCharAtExport == ",")
+ } else if (! sprintRawDynamics$problems) {
+ #TODO: note sprintRawDynamics can have only few information, make return of
getSprintFromEncoder return more variables in any of the returns, or check here what can be done i !
longEnough || ! enough accel
+ exportRow = exportSprintRawPrepareRow(sprintRawDynamics, splitPositionAll,
op$decimalCharAtExport == ",")
+ }
- if(filenameInstantaneous != "")
+ if(filenameInstantaneous != "")
+ {
+ srd = sprintRawDynamics #to shorten formulas
+ print("srd lengths:")
+ #print(length(srd$time))
+ #print(length(srd$rawPosition))
+ #print(length(srd$rawSpeed))
+ #print(length(srd$rawAccel))
+ #print(length(srd$rawForce))
+ #print(length(srd$rawPower))
+
+ s.fitted <- 0
+ a.fitted <- 0
+ f.fitted <- 0
+ p.fitted <- 0
+ if (#! is.null(regression) &&
+ isSprint &&
+ sprintRawDynamics$regressionDone)
{
- srd = sprintRawDynamics #to shorten formulas
-
- print("srd lengths:")
- #print(length(srd$time))
- #print(length(srd$rawPosition))
- #print(length(srd$rawSpeed))
- #print(length(srd$rawAccel))
- #print(length(srd$rawForce))
- #print(length(srd$rawPower))
-
s.fitted = srd$Vmax * (1-exp(-srd$K * srd$time))
a.fitted = srd$Vmax * srd$K * exp(-srd$K * srd$time)
f.fitted = srd$Mass * a.fitted + srd$Ka * (s.fitted - srd$Vw)^2
@@ -887,24 +1007,23 @@ testEncoderCJ <- function(filename, filenameInstantaneous, testLength, splitLeng
print(srd$Mass)
print(srd$Ka)
print(srd$Vw)
+ }
- exportInstantaneous <- cbind (srd$time, srd$rawPosition,
- srd$rawSpeed, srd$rawAccel, #0s are to have same length in all
variables
- srd$rawForce, srd$rawPower,
- s.fitted, a.fitted, f.fitted, p.fitted
- )
+ exportInstantaneous <- cbind (srd$time, srd$rawPosition,
+ srd$rawSpeed, srd$rawAccel, #0s are to have same length in all variables
+ srd$rawForce, srd$rawPower,
+ s.fitted, a.fitted, f.fitted, p.fitted
+ )
- colnames(exportInstantaneous) = c("Time", "Position",
- "Speed (raw)", "Accel (raw)", "Force (raw)", "Power (raw)",
- "Speed (fitted)", "Accel (fitted)", "Force (fitted)", "Power
(fitted)")
+ colnames(exportInstantaneous) = c("Time", "Position",
+ "Speed (raw)", "Accel (raw)", "Force (raw)", "Power (raw)",
+ "Speed (fitted)", "Accel (fitted)", "Force (fitted)", "Power (fitted)")
- if(op$decimalCharAtExport == ".")
- write.csv(exportInstantaneous, file = filenameInstantaneous, row.names =
FALSE, na="")
- else if(op$decimalCharAtExport == ",")
- write.csv2(exportInstantaneous, file = filenameInstantaneous, row.names =
FALSE, na="")
- }
- } else
- print("Couldn't calculate the sprint model")
+ if(op$decimalCharAtExport == ".")
+ write.csv(exportInstantaneous, file = filenameInstantaneous, row.names = FALSE, na="")
+ else if(op$decimalCharAtExport == ",")
+ write.csv2(exportInstantaneous, file = filenameInstantaneous, row.names = FALSE,
na="")
+ }
return(exportRow)
}
@@ -914,7 +1033,7 @@ start <- function(op)
if(op$singleOrMultiple == "TRUE")
{
prepareGraph(op$os, pngFile, op$graphWidth, op$graphHeight)
- exportRow = testEncoderCJ(op$filename, "", op$testLength, op$splitLength, op$splitVariableCm,
NULL,
+ exportRow = testEncoderCJ(op$filename, "", op$testLength, op$isSprint, op$splitLength,
op$splitVariableCm, NULL,
op$mass, op$personHeight, op$tempC,
op$device, op$title, op$datetime, op$startAccel,
op$triggersOnList, op$triggersOffList)
@@ -925,7 +1044,6 @@ start <- function(op)
# ------------------ op$singleOrMultiple == "FALSE" ------------------------->
-
#2) read the csv
dataFiles = read.csv(file = paste(tempPath, "/cj_race_analyzer_input_multi.csv", sep=""), sep=";",
stringsAsFactors=F)
@@ -973,7 +1091,7 @@ start <- function(op)
prepareGraph(op$os, pngFile, op$graphWidth, op$graphHeight)
exportRow = testEncoderCJ(
as.vector(dataFiles$fullURL[i]), paste(tempInstantFolder, i, ".csv", sep =
""),
- dataFiles$testLength[i], dataFiles$splitLength[i],
+ dataFiles$testLength[i], as.logical(dataFiles$isSprint)[i],
dataFiles$splitLength[i],
as.numeric(unlist(strsplit(as.character(dataFiles$splitVariableCm[i]),
"\\,"))), #as.character() because -1 (no triggers) is readed as a number and then the strsplit fails
splitPositionAll,
dataFiles$mass[i], dataFiles$personHeight[i], dataFiles$tempC[i],
diff --git a/r-scripts/sprintPhotocells.R b/r-scripts/sprintPhotocells.R
index 163b8fc5c..424f568d4 100644
--- a/r-scripts/sprintPhotocells.R
+++ b/r-scripts/sprintPhotocells.R
@@ -16,7 +16,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Copyright (C) 2017 Xavier Padullés <x padulles gmail com>
-# Copyright (C) 2017,2021 Xavier de Blas <xaviblas gmail com>
+# Copyright (C) 2017,2022 Xavier de Blas <xaviblas gmail com>
#This code uses splitTimes: accumulated time (not lap time)
@@ -287,7 +287,8 @@ drawSprintFromPhotocells <- function(sprintDynamics, splitTimes, positions, spli
paste("pmax =", round(sprintDynamics$pmax.rel.fitted, digits = 2), "W/kg")),
text.col = c("black", "black", "black", "magenta", "blue", "red"))
- return (exportSprintDynamicsPrepareRow(sprintDynamics, splitTimes, positions, splitPositionAll,
op$decimalCharAtExport == ","))
+ #TODO: check if we can pass raw values of v,a,F,P
+ return (exportSprintDynamicsPrepareRow(sprintDynamics, NULL, splitTimes, positions,
splitPositionAll, op$decimalCharAtExport == ","))
}
testPhotocellsCJ <- function(positions, splitTimes, splitPositionAll, mass, personHeight, tempC, personName)
diff --git a/r-scripts/sprintUtil.R b/r-scripts/sprintUtil.R
index 3698a4c03..b91777d7c 100644
--- a/r-scripts/sprintUtil.R
+++ b/r-scripts/sprintUtil.R
@@ -16,7 +16,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Copyright (C) 2017-2020 Xavier Padullés <x padulles gmail com>
-# Copyright (C) 2017-2020 Xavier de Blas <xaviblas gmail com>
+# Copyright (C) 2017-2022 Xavier de Blas <xaviblas gmail com>
#This code uses splitTimes: accumulated time (not lap time)
@@ -111,7 +111,7 @@ getDynamicsFromSprint <- function(K, Vmax, Mass, T0 = 0, Temperature = 25, Heigh
p.fitted = p.fitted ))
}
-exportSprintDynamicsPrepareRow <- function(sprintDynamics, splitTime, splitPosition, splitPositionAll,
decimalIsComma)
+getSplitsForPrepareRow <- function (splitTime, splitPosition, splitPositionAll, decimalIsComma)
{
splits = NULL
@@ -146,34 +146,99 @@ exportSprintDynamicsPrepareRow <- function(sprintDynamics, splitTime, splitPosit
names(splits) = paste(splitPositionAll, "m", sep="")
}
+ return (splits)
+}
+
+#data is an sprint and has been modelized
+exportSprintDynamicsPrepareRow <- function(sprintFittedDynamics, sprintRawDynamics, splitTime,
splitPosition, splitPositionAll, decimalIsComma)
+{
+ print ("at exportSprintDynamicsPrepareRow decimalIsComma:")
+ print (decimalIsComma)
+ splits <- getSplitsForPrepareRow (splitTime, splitPosition, splitPositionAll, decimalIsComma)
+
#print("exportSprintDynamicsPrepareRow names(splits):")
#print(names(splits))
- raw = c(list(Mass = sprintDynamics$Mass,
- Height = sprintDynamics$Height,
- Temperature = sprintDynamics$Temperature,
- V.wind = sprintDynamics$Vw,
- Ka = sprintDynamics$Ka,
- K.fitted = sprintDynamics$K.fitted,
- Vmax.fitted = sprintDynamics$Vmax,
- amax.fitted = sprintDynamics$amax.fitted,
- fmax.fitted = sprintDynamics$fmax.fitted,
- fmax.rel.fitted = sprintDynamics$fmax.rel.fitted,
- sfv.fitted = sprintDynamics$sfv.fitted,
- sfv.rel.fitted = sprintDynamics$sfv.rel.fitted,
- sfv.lm = sprintDynamics$sfv.lm,
- sfv.rel.lm = sprintDynamics$sfv.rel.lm,
- pmax.fitted = sprintDynamics$pmax.fitted,
- pmax.rel.fitted = sprintDynamics$pmax.rel.fitted,
- tpmax.fitted = sprintDynamics$tpmax.fitted,
- F0 = sprintDynamics$F0,
- F0.rel = sprintDynamics$F0.rel,
- V0 = sprintDynamics$V0,
- pmax.lm = sprintDynamics$pmax.lm,
- pmax.rel.lm = sprintDynamics$pmax.rel.lm), splits)
- print(raw)
-
- return(raw)
+ #on Race analyzer we send raw data, but on photocells we are not sending raw data here (right now).
+ rawVmax = 0
+ rawAmax = 0
+ rawFmax = 0
+ rawPmax = 0
+ if (! is.null(sprintRawDynamics))
+ {
+ rawVmax = sprintRawDynamics$rawVmax
+ rawAmax = sprintRawDynamics$rawAmax
+ rawFmax = sprintRawDynamics$rawFmax
+ rawPmax = sprintRawDynamics$rawPmax
+ }
+
+ row = c(list(Mass = sprintFittedDynamics$Mass,
+ Height = sprintFittedDynamics$Height,
+ Temperature = sprintFittedDynamics$Temperature,
+ V.wind = sprintFittedDynamics$Vw,
+ Ka = sprintFittedDynamics$Ka,
+ K.fitted = sprintFittedDynamics$K.fitted,
+ Vmax.fitted = sprintFittedDynamics$Vmax,
+ amax.fitted = sprintFittedDynamics$amax.fitted,
+ fmax.fitted = sprintFittedDynamics$fmax.fitted,
+ fmax.rel.fitted = sprintFittedDynamics$fmax.rel.fitted,
+ sfv.fitted = sprintFittedDynamics$sfv.fitted,
+ sfv.rel.fitted = sprintFittedDynamics$sfv.rel.fitted,
+ sfv.lm = sprintFittedDynamics$sfv.lm,
+ sfv.rel.lm = sprintFittedDynamics$sfv.rel.lm,
+ pmax.fitted = sprintFittedDynamics$pmax.fitted,
+ pmax.rel.fitted = sprintFittedDynamics$pmax.rel.fitted,
+ tpmax.fitted = sprintFittedDynamics$tpmax.fitted,
+ F0 = sprintFittedDynamics$F0,
+ F0.rel = sprintFittedDynamics$F0.rel,
+ V0 = sprintFittedDynamics$V0,
+ pmax.lm = sprintFittedDynamics$pmax.lm,
+ pmax.rel.lm = sprintFittedDynamics$pmax.rel.lm,
+ raw.Vmax = rawVmax,
+ raw.Amax = rawAmax,
+ raw.Fmax = rawFmax,
+ raw.Pmax = rawPmax
+ ), splits)
+ print(row)
+
+ return(row)
+}
+
+#data is not sprint or model has failed
+exportSprintRawPrepareRow <- function (sprintRawDynamics, splitPositionAll, decimalIsComma)
+{
+ splits <- getSplitsForPrepareRow (sprintRawDynamics$splitTime, sprintRawDynamics$splitPosition,
splitPositionAll, decimalIsComma)
+
+ row = c(list(Mass = sprintRawDynamics$Mass,
+ Height = sprintRawDynamics$height,
+ Temperature = sprintRawDynamics$temperature,
+ V.wind = sprintRawDynamics$Vw,
+ Ka = 0,
+ K.fitted = 0,
+ Vmax.fitted = 0,
+ amax.fitted = 0,
+ fmax.fitted = 0,
+ fmax.rel.fitted = 0,
+ sfv.fitted = 0,
+ sfv.rel.fitted = 0,
+ sfv.lm = 0,
+ sfv.rel.lm = 0,
+ pmax.fitted = 0,
+ pmax.rel.fitted = 0,
+ tpmax.fitted = 0,
+ F0 = 0,
+ F0.rel = 0,
+ V0 = 0,
+ pmax.lm = 0,
+ pmax.rel.lm = 0,
+ raw.Vmax = sprintRawDynamics$rawVmax,
+ raw.Amax = sprintRawDynamics$rawAmax,
+ raw.Fmax = sprintRawDynamics$rawFmax,
+ raw.Pmax = sprintRawDynamics$rawPmax
+ ), splits)
+ print(row)
+
+ return(row)
}
exportSprintDynamicsWriteRow <- function(exportRow)
diff --git a/src/gui/app1/runEncoder.cs b/src/gui/app1/runEncoder.cs
index cdba0330b..cd2b5488d 100644
--- a/src/gui/app1/runEncoder.cs
+++ b/src/gui/app1/runEncoder.cs
@@ -1523,7 +1523,8 @@ public partial class ChronoJumpWindow
typeof (string), typeof (string), typeof (string),
typeof (string), typeof (string), typeof (string),
typeof (string), typeof (string), typeof (string),
- typeof (string)
+ typeof (string),
+ typeof (string), typeof (string), typeof (string), typeof (string) //raw
(vmax, amax, fmax, pmax)
);
RunEncoderCSV recsv = readRunEncoderCSVContents (contents);
@@ -1544,7 +1545,8 @@ public partial class ChronoJumpWindow
"Sfv\nlm\n", "Sfv\nrel lm\n", "Pmax\nfitted\n(W)",
"Pmax\nrel fitted\n(W/Kg)", "Time to pmax\nfitted\n(s)", "F0\n\n(N)",
"F0\nrel\n(N/Kg)", "V0\n\n(m/s)", "Pmax\nlm\n(W)",
- "Pmax\nrel lm\n(W/Kg)"
+ "Pmax\nrel lm\n(W/Kg)",
+ "Vmax\nraw\n(m/s)", "Amax\nraw\n(m/s^2)", "Fmax\nraw\n(N)", "Pmax\nraw\n(W)"
};
return headers;
}
@@ -1566,7 +1568,7 @@ public partial class ChronoJumpWindow
string [] cells = line.Split(new char[] {';'});
- recsv = new RunEncoderCSV(
+ recsv = new RunEncoderCSV (
Convert.ToDouble(cells[0]), Convert.ToDouble(cells[1]),
Convert.ToInt32(cells[2]),
Convert.ToDouble(cells[3]), Convert.ToDouble(cells[4]),
Convert.ToDouble(cells[5]),
Convert.ToDouble(cells[6]), Convert.ToDouble(cells[7]),
Convert.ToDouble(cells[8]),
@@ -1574,7 +1576,9 @@ public partial class ChronoJumpWindow
Convert.ToDouble(cells[12]), Convert.ToDouble(cells[13]),
Convert.ToDouble(cells[14]),
Convert.ToDouble(cells[15]), Convert.ToDouble(cells[16]),
Convert.ToDouble(cells[17]),
Convert.ToDouble(cells[18]), Convert.ToDouble(cells[19]),
Convert.ToDouble(cells[20]),
- Convert.ToDouble(cells[21])
+ Convert.ToDouble(cells[21]),
+ Convert.ToDouble(cells[22]), Convert.ToDouble(cells[23]),
//vmax raw, amax raw
+ Convert.ToDouble(cells[24]), Convert.ToDouble(cells[25])
//fmax raw, pmax raw
);
} while(true);
}
diff --git a/src/runEncoder.cs b/src/runEncoder.cs
index 7536bcf0c..4f33d4673 100644
--- a/src/runEncoder.cs
+++ b/src/runEncoder.cs
@@ -838,12 +838,17 @@ public class RunEncoderCSV
public double V0;
public double Pmax_lm;
public double Pmax_rel_lm;
+ public double Vmax_raw;
+ public double Amax_raw;
+ public double Fmax_raw;
+ public double Pmax_raw;
public RunEncoderCSV ()
{
}
- public RunEncoderCSV (double mass, double height, int temperature, double vw, double ka, double
k_fitted, double vmax_fitted, double amax_fitted, double fmax_fitted, double fmax_rel_fitted, double
sfv_fitted, double sfv_rel_fitted, double sfv_lm, double sfv_rel_lm, double pmax_fitted, double
pmax_rel_fitted, double tpmax_fitted, double f0, double f0_rel, double v0, double pmax_lm, double pmax_rel_lm)
+ public RunEncoderCSV (double mass, double height, int temperature, double vw, double ka, double
k_fitted, double vmax_fitted, double amax_fitted, double fmax_fitted, double fmax_rel_fitted, double
sfv_fitted, double sfv_rel_fitted, double sfv_lm, double sfv_rel_lm, double pmax_fitted, double
pmax_rel_fitted, double tpmax_fitted, double f0, double f0_rel, double v0, double pmax_lm, double pmax_rel_lm,
+ double vmax_raw, double amax_raw, double fmax_raw, double pmax_raw)
{
this.Mass = mass;
this.Height = height;
@@ -867,6 +872,10 @@ public class RunEncoderCSV
this.V0 = v0;
this.Pmax_lm = pmax_lm;
this.Pmax_rel_lm = pmax_rel_lm;
+ this.Vmax_raw = vmax_raw;
+ this.Amax_raw = amax_raw;
+ this.Fmax_raw = fmax_raw;
+ this.Pmax_raw = pmax_raw;
}
public string [] ToTreeView()
@@ -893,7 +902,11 @@ public class RunEncoderCSV
Util.TrimDecimals(F0_rel, 3),
Util.TrimDecimals(V0, 3),
Util.TrimDecimals(Pmax_lm, 3),
- Util.TrimDecimals(Pmax_rel_lm, 3)
+ Util.TrimDecimals(Pmax_rel_lm, 3),
+ Util.TrimDecimals(Vmax_raw, 3),
+ Util.TrimDecimals(Amax_raw, 3),
+ Util.TrimDecimals(Fmax_raw, 3),
+ Util.TrimDecimals(Pmax_raw, 3),
};
}
@@ -979,6 +992,7 @@ public class RunEncoderGraphExport
device.ToString() + ";" +
Util.ConvertToPoint(tempC) + ";" +
testLength.ToString() + ";" +
+ Util.BoolToRBool(exercise.IsSprint) + ";" +
segmentM + ";" + //fixed segments (m)
segmentVariableCm + ";" + //variable segments (cm)
title + ";" +
@@ -995,7 +1009,7 @@ public class RunEncoderGraphExport
public static string PrintCSVHeaderOnExport()
{
- return "fullURL;mass;personHeight;device;tempC;testLength;" +
+ return "fullURL;mass;personHeight;device;tempC;testLength;isSprint;" +
"splitLength;" + //segmentCm on C#, splitLength on R
"splitVariableCm;" +
"title;datetime;triggersOn;triggersOff;comments";
@@ -1142,6 +1156,7 @@ public class RunEncoderGraph
"#personHeight\n" + Util.ConvertToPoint(personHeight / 100.0) + "\n" +
//unused on multiple //send it in meters
"#tempC\n" + tempC + "\n" + //unused on multiple
"#testLength\n" + testLength.ToString() + "\n" + //unused on multiple
+ "#isSprint\n" + Util.BoolToRBool(rex.IsSprint) + "\n" +
"#os\n" + UtilEncoder.OperatingSystemForRGraphs() + "\n" +
"#graphWidth\n" + graphWidth.ToString() + "\n" +
"#graphHeight\n" + graphHeight.ToString() + "\n" +
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]