Skip to content

Commit

Permalink
[Task] #77, calculate more Status data
Browse files Browse the repository at this point in the history
  • Loading branch information
Type-Style committed Aug 26, 2024
1 parent f76fe8e commit 2d57a38
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
7 changes: 2 additions & 5 deletions src/client/components/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import L from 'leaflet';
import 'leaflet-rotatedmarker';
import 'leaflet/dist/leaflet.css';
import "../css/map.css";
import { getMaxSpeed } from "../helper/maxSpeed";
leafletPolycolor(L);


Expand Down Expand Up @@ -34,11 +35,7 @@ const MultiColorPolyline = ({ cleanEntries }: { cleanEntries: Models.IEntry[] })
}

if (useRelativeColors) {
maxSpeed = cleanEntries.reduce((maxSpeed, entry) => {
// compare the current entry's GPS speed with the maxSpeed found so far
return Math.max(maxSpeed, entry.speed.gps);
}, cleanEntries[0].speed.gps);
maxSpeed *= 3.6; // convert M/S to KM/h
maxSpeed = getMaxSpeed(cleanEntries);
}

return cleanEntries.map((entry, index) => {
Expand Down
41 changes: 39 additions & 2 deletions src/client/components/Status.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import { getMaxSpeed } from "../helper/maxSpeed";
//import * as css from "../css/status.module.css";
function getStatusData(entries) {
const cleanEntries = entries.filter((entry: Models.IEntry) => !entry.ignore);
Expand Down Expand Up @@ -26,16 +27,50 @@ function getStatusData(entries) {
return value;
}


function getVertical() {
let up = 0, down = 0;

for (let index = 0; index < cleanEntries.length; index++) {
const entry = cleanEntries[index];
if (!entry.distance) { continue; }

const vertical = parseFloat(entry.distance.vertical);

if (vertical > 0) {
up += vertical;
} else if (vertical < 0) {
down += vertical;
}
}

return [up, down];
}

function getDistance() {
return cleanEntries.reduce((accumulatorValue:number, entry) => {
console.log(accumulatorValue);
if (!entry.distance ) { return accumulatorValue }
return accumulatorValue + parseFloat(entry.distance.horizontal);
}, 0) / 1000;
}

const ignoredEntries = entries.length - cleanEntries.length;
const uploadMean = getMean("time.uploadDuration").toFixed(3);
const speedGPSMean = (getMean("speed.gps") * 3.6).toFixed(1);
const speedCalcMean = (getMean("speed.horizontal") * 3.6).toFixed(1);
const verticalCalc = getVertical();
const maxSpeed = getMaxSpeed(cleanEntries);
const distance = getDistance().toFixed(2);

return {
ignoredEntries,
uploadMean,
speedGPSMean,
speedCalcMean
speedCalcMean,
maxSpeed,
verticalCalc,
distance
}
}

Expand All @@ -51,7 +86,9 @@ function Map({ entries }: { entries: Models.IEntry[] }) {
<li>datapoints: {entries.length - statusData.ignoredEntries}<i>({statusData.ignoredEntries})</i></li>
<li>Ø upload: {statusData.uploadMean}s </li>
<li>Ø speed: GPS: {statusData.speedGPSMean}km/h Calc: {statusData.speedCalcMean == "NaN" ? " - " : statusData.speedCalcMean}km/h </li>
<li></li>
<li>maxSpeed: {statusData.maxSpeed}</li>
<li>vertcial: {statusData.verticalCalc[0]} up, {statusData.verticalCalc[1]} down</li>
<li>distance {statusData.distance}km</li>
</ul>
)
}
Expand Down
7 changes: 7 additions & 0 deletions src/client/helper/maxSpeed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const getMaxSpeed = function (cleanEntries:Models.IEntry[]) {
let maxSpeed = cleanEntries.reduce((maxSpeed, entry:Models.IEntry) => {
// compare the current entry's GPS speed with the maxSpeed found so far
return Math.max(maxSpeed, entry.speed.gps);
}, cleanEntries[0].speed.gps);
return maxSpeed *= 3.6; // convert M/S to KM/h
};

0 comments on commit 2d57a38

Please sign in to comment.