Commit 2a26faae authored by Clouard Regis's avatar Clouard Regis
Browse files

Fix bug on Pace (RK)

parent 031c0a9c
......@@ -43,18 +43,12 @@ function deltaDistanceCalculator(idealDistance, realDistance) {
return distanceString;
}
function RKCalculator(timeInMilliseconds, distanceInMeter) {
let timeInS = timeInMilliseconds / 1000.0;
let mins = timeInS / 60;
let distInKm = distanceInMeter / 1000.0;
return (Math.round(mins / distInKm * 10) / 10).toFixed(1);
function computePace(timeInMilliseconds, distanceInMeter) {
return ((timeInMilliseconds) / (60 * distanceInMeter)).toFixed(1);
}
function speedCalculator(timeInMilliseconds, distanceInMeter) {
let timeInS = timeInMilliseconds / 1000.0;
let hrs = timeInS / 3600;
let distInKm = distanceInMeter / 1000.0;
return (Math.round(distInKm / hrs * 10) / 10).toFixed(1);
function computeSpeed(timeInMilliseconds, distanceInMeter) {
return (3600 * distanceInMeter / timeInMilliseconds).toFixed(1);
}
function renderTimeSheet(distances) {
......@@ -93,7 +87,7 @@ function renderTimeSheet(distances) {
let body = document.createElement("tbody");
let rows = [];
let cps = timeSheetData[0][1];
let totalDistance = 0;
let totalTheoreticalDistance = 0;
for (let i = 0; i < cps.length; i++) {
const index = cps[i]["controlPoint"];
let controlCell = document.createElement("th");
......@@ -104,11 +98,11 @@ function renderTimeSheet(distances) {
} else if (index === timeSheetData[0][1].length - 1) {
controlCell.innerHTML = translations.finish;
lengthCell.innerHTML = distances[i];
totalDistance += distances[i];
totalTheoreticalDistance += distances[i];
} else {
controlCell.innerHTML = index;
lengthCell.innerHTML = distances[i];
totalDistance += distances[i];
totalTheoreticalDistance += distances[i];
}
let row = document.createElement("tr");
row.appendChild(controlCell);
......@@ -119,7 +113,7 @@ function renderTimeSheet(distances) {
let totalTitleCell = document.createElement("th");
totalTitleCell.innerHTML = translations.total;
let totalLengthCell = document.createElement("th");
totalLengthCell.innerHTML = totalDistance.toString();
totalLengthCell.innerHTML = totalTheoreticalDistance.toString();
let totalsRow = document.createElement("tr");
totalsRow.appendChild(totalTitleCell);
totalsRow.appendChild(totalLengthCell);
......@@ -146,12 +140,11 @@ function renderTimeSheet(distances) {
cell = document.createElement("th");
cell.setAttribute("scope", "col");
cell.className = "align-middle";
cell.innerHTML = translations.RK + " (min/km) / <br>" + translations.speed + " (km/h)";
cell.innerHTML = translations.pace + " (min/km) / <br>" + translations.speed + " (km/h)";
headRow2.appendChild(cell);
let orienteerTotalDistance = 0;
let orienteerTotalTime = 0;
let time, orienteerDistance;
for (let i = 0; i < orienteerData[1].length; i++) {
let index = i;
......@@ -163,12 +156,12 @@ function renderTimeSheet(distances) {
let paceCell = document.createElement("td");
paceCell.setAttribute("scope", "col");
if (i > 0) {
time = orienteerData[2][i];
let time = orienteerData[2][i];
if (time > 0) {
orienteerDistance = orienteerData[3][i]
let orienteerDistance = orienteerData[3][i]
timeCell.innerHTML = convertTimeToString(time);
distanceCell.innerHTML = deltaDistanceCalculator(orienteerDistance, distances[i]);
paceCell.innerHTML = RKCalculator(time, distances[i]) + " / " + speedCalculator(time, orienteerDistance);
paceCell.innerHTML = computePace(time, distances[i]) + " / " + computeSpeed(time, distances[i]);
orienteerTotalDistance += orienteerDistance;
orienteerTotalTime += time;
} else {
......@@ -191,10 +184,10 @@ function renderTimeSheet(distances) {
speedMeanCell.setAttribute("scope", "col");
totalTimeCell.innerHTML = convertTimeToString(orienteerTotalTime);
totalDistanceCell.innerHTML = deltaDistanceCalculator(orienteerTotalDistance, totalDistance);
speedMeanCell.innerHTML = RKCalculator(orienteerTotalTime, totalDistance).toString()
totalDistanceCell.innerHTML = deltaDistanceCalculator(orienteerTotalDistance, totalTheoreticalDistance);
speedMeanCell.innerHTML = computePace(orienteerTotalTime, totalTheoreticalDistance).toString()
+ " / "
+ speedCalculator(orienteerTotalTime, orienteerTotalDistance).toString();
+ computeSpeed(orienteerTotalTime, totalTheoreticalDistance).toString();
totalsRow.appendChild(totalTimeCell);
totalsRow.appendChild(totalDistanceCell);
......
......@@ -55,7 +55,7 @@
'distance': '{{ 'timeSheet.distance' | trans | escape('js') }}',
'controlPoint': '{{ 'timeSheet.control.point' | trans | escape('js') }}',
'length': '{{ 'timeSheet.length' | trans | escape('js') }}',
'RK': '{{ 'timeSheet.RK' | trans | escape('js') }}',
'pace': '{{ 'timeSheet.pace' | trans | escape('js') }}',
'total': '{{ 'timeSheet.total' | trans | escape('js') }}',
'mean': '{{ 'timeSheet.mean' | trans | escape('js') }}',
'speed': '{{ 'timeSheet.speed' | trans | escape('js') }}',
......
......@@ -1141,8 +1141,8 @@ such as orienteering, multisport orienteering, trails...</target>
<source>timeSheet.length</source>
<target>Leg length</target>
</trans-unit>
<trans-unit id="lhyW0rQ" resname="timeSheet.RK">
<source>timeSheet.RK</source>
<trans-unit id="lhyW0rQ" resname="timeSheet.pace">
<source>timeSheet.pace</source>
<target>Pace</target>
</trans-unit>
<trans-unit id="pDov3Ci" resname="timeSheet.total">
......
......@@ -943,7 +943,7 @@ de l’Informatique.</target>
</trans-unit>
<trans-unit id="zizLSLK" resname="course.club.name">
<source>course.club.name</source>
<target>Nom du club</target>
<target>Nom du club ou de l'organisme</target>
</trans-unit>
<trans-unit id="b_t16bi" resname="course.no.club.name">
<source>course.no.club.name</source>
......@@ -1233,8 +1233,8 @@ de l’Informatique.</target>
<source>timeSheet.length</source>
<target>Longueur théorique</target>
</trans-unit>
<trans-unit id="lhyW0rQ" resname="timeSheet.RK">
<source>timeSheet.RK</source>
<trans-unit id="lhyW0rQ" resname="timeSheet.pace">
<source>timeSheet.pace</source>
<target>RK</target>
</trans-unit>
<trans-unit id="pDov3Ci" resname="timeSheet.total">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment