aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modern/src/common/converter.js13
-rw-r--r--modern/src/reports/ChartReportPage.js19
2 files changed, 11 insertions, 21 deletions
diff --git a/modern/src/common/converter.js b/modern/src/common/converter.js
index 8fdb4b86..e48b0760 100644
--- a/modern/src/common/converter.js
+++ b/modern/src/common/converter.js
@@ -1,4 +1,4 @@
-const speedConverter = (value, unit) => {
+export const speedConverter = (value, unit) => {
let factor;
switch (unit) {
case 'kmh':
@@ -11,14 +11,3 @@ const speedConverter = (value, unit) => {
}
return (value * factor).toFixed(2);
};
-
-export const getConverter = (key) => {
- switch (key) {
- case 'speed':
- return speedConverter;
- default:
- return function (value) {
- return value;
- }
- }
-}; \ No newline at end of file
diff --git a/modern/src/reports/ChartReportPage.js b/modern/src/reports/ChartReportPage.js
index 19ec9c12..21c069ca 100644
--- a/modern/src/reports/ChartReportPage.js
+++ b/modern/src/reports/ChartReportPage.js
@@ -4,7 +4,7 @@ import ReportFilter from './ReportFilter';
import ReportLayoutPage from './ReportLayoutPage';
import { useAttributePreference } from '../common/preferences';
import { formatDate } from '../common/formatter';
-import { getConverter } from '../common/converter';
+import { speedConverter } from '../common/converter';
import {LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts';
const ReportFilterForm = ({ setItems }) => {
@@ -16,17 +16,18 @@ const ReportFilterForm = ({ setItems }) => {
const response = await fetch(`/api/reports/route?${query.toString()}`, { headers });
if (response.ok) {
- const data = await response.json();
+ const positions = await response.json();
- let formattedData = data.map(obj => {
- return Object.assign(
- obj,
- {speed: Number(getConverter('speed')(obj.speed, speedUnit))},
- {fixTime: formatDate(obj.fixTime)}
- );
+ let formattedPositions = positions.map(position => {
+ return {
+ speed:Number(speedConverter(position.speed, speedUnit)),
+ altitude:position.altitude,
+ accuracy:position.accuracy,
+ fixTime:formatDate(position.fixTime)
+ }
});
- setItems(formattedData);
+ setItems(formattedPositions);
}
}