[chronojump] sprintEncoder export handles sets with different positions and exports instantaneous data
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] sprintEncoder export handles sets with different positions and exports instantaneous data
- Date: Wed, 23 Jun 2021 14:08:48 +0000 (UTC)
commit b420e9312cf5b3713524aa2cdaa657173be292d7
Author: Xavier de Blas <xaviblas gmail com>
Date: Wed Jun 23 16:08:05 2021 +0200
sprintEncoder export handles sets with different positions and exports instantaneous data
r-scripts/sprintEncoder.R | 56 ++++++++++++++++++++++++++++++++++++++------
r-scripts/sprintPhotocells.R | 5 ++--
r-scripts/sprintUtil.R | 39 +++++++++++++++++++++++-------
src/exportFiles/re.cs | 12 ++++++++--
4 files changed, 92 insertions(+), 20 deletions(-)
---
diff --git a/r-scripts/sprintEncoder.R b/r-scripts/sprintEncoder.R
index f34227f13..495be9afb 100644
--- a/r-scripts/sprintEncoder.R
+++ b/r-scripts/sprintEncoder.R
@@ -258,8 +258,13 @@ getSprintFromEncoder <- function(filename, testLength, Mass, Temperature = 25, H
return(list(Vmax = Vmax, K = K, T0 = T0,
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]), rawFmax =
max(totalForce[trimmingSamples$start:trimmingSamples$end]), 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,
+ rawVmax = max(speed[trimmingSamples$start:trimmingSamples$end]),
+ rawAmax = max(accel[trimmingSamples$start:trimmingSamples$end]),
+ rawFmax = max(totalForce[trimmingSamples$start:trimmingSamples$end]),
+ 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))
}
@@ -740,7 +745,8 @@ tryNLS <- function(data){
)
}
-testEncoderCJ <- function(filename, testLength, splitLength, mass, personHeight, tempC, device, title,
datetime, startAccel, triggersOn, triggersOff)
+testEncoderCJ <- function(filename, filenameInstantaneous, testLength, splitLength, splitPositionAll,
+ mass, personHeight, tempC, device, title, datetime, startAccel, triggersOn, triggersOff)
{
sprintRawDynamics = getSprintFromEncoder(filename, testLength, mass, tempC, personHeight, Vw = 0,
device = device, startAccel, splitLength)
#print("sprintRawDynamics:")
@@ -786,7 +792,30 @@ testEncoderCJ <- function(filename, testLength, splitLength, mass, personHeight,
startAccel = startAccel,
plotStartDetection = TRUE)
- exportRow = exportSprintDynamicsPrepareRow(sprintFittedDynamics,
sprintRawDynamics$splitTime, sprintRawDynamics$splitPosition)
+ #splitPositionAll is NULL on (op$singleOrMultiple == "TRUE")
+ exportRow = exportSprintDynamicsPrepareRow(sprintFittedDynamics, sprintRawDynamics$splitTime,
sprintRawDynamics$splitPosition, splitPositionAll)
+
+ if(filenameInstantaneous != "")
+ {
+ #print("sprintRawDynamics lengths:")
+ #print(length(sprintRawDynamics$time))
+ #print(length(sprintRawDynamics$rawPosition))
+ #print(length(sprintRawDynamics$rawSpeed))
+ #print(length(sprintRawDynamics$rawAccel))
+ #print(length(sprintRawDynamics$rawForce))
+ #print(length(sprintRawDynamics$rawPower))
+
+ exportInstantaneous <- cbind (sprintRawDynamics$time, sprintRawDynamics$rawPosition,
+ c(0, sprintRawDynamics$rawSpeed), c(0, 0,
sprintRawDynamics$rawAccel), #0s are to have same length in all variables
+ sprintRawDynamics$rawForce, sprintRawDynamics$rawPower)
+
+ colnames(exportInstantaneous) = c("Time", "Position", "Speed", "Accel", "Force",
"Power")
+
+ 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")
@@ -798,7 +827,7 @@ start <- function(op)
if(op$singleOrMultiple == "TRUE")
{
prepareGraph(op$os, pngFile, op$graphWidth, op$graphHeight)
- exportRow = testEncoderCJ(op$filename, op$testLength, op$splitLength,
+ exportRow = testEncoderCJ(op$filename, "", op$testLength, op$splitLength, NULL,
op$mass, op$personHeight, op$tempC,
op$device, op$title, op$datetime, op$startAccel,
op$triggersOnList, op$triggersOffList)
@@ -809,14 +838,26 @@ 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)
#3) call testEncoderCJ
progressFolder = paste(tempPath, "/chronojump_export_progress", sep ="")
tempGraphsFolder = paste(tempPath, "/chronojump_race_analyzer_export_graphs/", sep ="")
+ tempInstantFolder = paste(tempPath, "/chronojump_race_analyzer_export_instantaneous/", sep ="")
exportDF = NULL
+ #find the colums needed for different split position values
+ splitPositionAll = NULL
+ for(i in 1:length(dataFiles[,1]))
+ {
+ splitPositionAll = c(splitPositionAll, seq(from=dataFiles$splitLength[i],
to=dataFiles$testLength[i], by=dataFiles$splitLength[i]))
+ }
+ splitPositionAll = sort(unique(splitPositionAll))
+ #print("splitPositionAll")
+ #print(splitPositionAll)
+
for(i in 1:length(dataFiles[,1]))
{
print("fullURL")
@@ -824,12 +865,13 @@ start <- function(op)
pngFile <- paste(tempGraphsFolder, i, ".png", sep="") #but remember to graph also when model
fails
prepareGraph(op$os, pngFile, op$graphWidth, op$graphHeight)
- exportRow = testEncoderCJ(as.vector(dataFiles$fullURL[i]), dataFiles$testLength[i],
dataFiles$splitLength[i],
+ exportRow = testEncoderCJ(
+ as.vector(dataFiles$fullURL[i]), paste(tempInstantFolder, i, ".csv", sep =
""),
+ dataFiles$testLength[i], dataFiles$splitLength[i], splitPositionAll,
dataFiles$mass[i], dataFiles$personHeight[i], dataFiles$tempC[i],
dataFiles$device[i], dataFiles$title[i], dataFiles$datetime[i], op$startAccel,
as.numeric(unlist(strsplit(as.character(dataFiles$triggersOn[i]), "\\,"))),
#as.character() because -1 (no triggers) is readed as a number and then the strsplit fails
as.numeric(unlist(strsplit(as.character(dataFiles$triggersOff[i]), "\\,")))
-
)
if(! is.null(exportRow))
diff --git a/r-scripts/sprintPhotocells.R b/r-scripts/sprintPhotocells.R
index cb0e55e19..086ea063a 100644
--- a/r-scripts/sprintPhotocells.R
+++ b/r-scripts/sprintPhotocells.R
@@ -263,9 +263,8 @@ drawSprintFromPhotocells <- function(sprintDynamics, splitTimes, positions, titl
paste("fmax =", round(sprintDynamics$fmax.rel.fitted, digits = 2), "N/kg"),
paste("pmax =", round(sprintDynamics$pmax.rel.fitted, digits = 2), "W/kg")),
text.col = c("black", "black", "black", "magenta", "blue", "red"))
-
- #exportSprintDynamics(sprintDynamics)
- return (exportSprintDynamicsPrepareRow(sprintDynamics, splitTimes, positions))
+
+ return (exportSprintDynamicsPrepareRow(sprintDynamics, splitTimes, positions, NULL))
}
testPhotocellsCJ <- function(positions, splitTimes, mass, personHeight, tempC, personName)
diff --git a/r-scripts/sprintUtil.R b/r-scripts/sprintUtil.R
index 0dea6b32e..893a6761a 100644
--- a/r-scripts/sprintUtil.R
+++ b/r-scripts/sprintUtil.R
@@ -99,15 +99,38 @@ getDynamicsFromSprint <- function(K, Vmax, Mass, T0 = 0, Temperature = 25, Heigh
p.fitted = p.fitted ))
}
-exportSprintDynamics <- function(sprintDynamics)
+exportSprintDynamicsPrepareRow <- function(sprintDynamics, splitTime, splitPosition, splitPositionAll)
{
- exportRow = exportSprintDynamicsPrepareRow (sprintDynamics)
- exportSprintDynamicsWriteRow (exportRow)
-}
-exportSprintDynamicsPrepareRow <- function(sprintDynamics, splitTime, splitPosition)
-{
- splits = as.list(splitTime)
- names(splits) = paste(splitPosition, "m", sep="")
+ splits = NULL
+
+ #print("exportSprintDynamicsPrepareRow splitPositionAll:")
+ #print(splitPositionAll)
+
+ if(is.null(splitPositionAll))
+ {
+ splits = as.list(splitTime)
+ names(splits) = paste(splitPosition, "m", sep="")
+ } else
+ {
+ splitTimeVector = NULL
+ for(i in 1:length(splitPositionAll))
+ {
+ pos = match(splitPositionAll[i], splitPosition)
+ if(is.na(pos)) # current set to export has not this position
+ {
+ splitTimeVector = c(splitTimeVector, NA) #create an NA "value"
+ } else {
+ splitTimeVector = c(splitTimeVector, splitTime[pos])
+ }
+ }
+
+ splits = as.list(splitTimeVector)
+ names(splits) = paste(splitPositionAll, "m", sep="")
+ }
+
+ #print("exportSprintDynamicsPrepareRow names(splits):")
+ #print(names(splits))
+
raw = c(list(Mass = sprintDynamics$Mass,
Height = sprintDynamics$Height,
Temperature = sprintDynamics$Temperature,
diff --git a/src/exportFiles/re.cs b/src/exportFiles/re.cs
index 4680bd21f..961c39950 100644
--- a/src/exportFiles/re.cs
+++ b/src/exportFiles/re.cs
@@ -72,11 +72,16 @@ public class RunEncoderExport : ExportFiles
private string getTempGraphsDir() {
return Path.Combine(Path.GetTempPath(), "chronojump_race_analyzer_export_graphs");
}
+
+ private string getTempExportInstantDir() {
+ return Path.Combine(Path.GetTempPath(), "chronojump_race_analyzer_export_instantaneous");
+ }
protected override void createOrEmptyDirs()
{
createOrEmptyDir(getTempProgressDir());
createOrEmptyDir(getTempGraphsDir());
+ createOrEmptyDir(getTempExportInstantDir());
}
protected override bool getData ()
@@ -207,8 +212,11 @@ public class RunEncoderExport : ExportFiles
return false;
//copy the images if needed
- if(includeImages && ! copyImages(getTempGraphsDir(), exportURL,
- "chronojump_race_analyzer_export_graphs"))
+ if(includeImages && (
+ ! copyImages(getTempGraphsDir(), exportURL,
+ "chronojump_race_analyzer_export_graphs") ||
+ ! copyImages(getTempExportInstantDir(), exportURL,
+ "chronojump_race_analyzer_export_instantaneous")) )
return false;
// copy the CSV
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]