diff --git a/api/src/routes/api/stats.js b/api/src/routes/api/stats.js index 5f4805d..868f97c 100644 --- a/api/src/routes/api/stats.js +++ b/api/src/routes/api/stats.js @@ -7,6 +7,9 @@ const wrapRoute = require('../../_helpers/wrapRoute'); // round to this number of meters for privacy reasons const TRACK_LENGTH_ROUNDING = 1000; +// round to this number of seconds for privacy reasons +const TRACK_DURATION_ROUNDING = 120; + router.get( '/', wrapRoute(async (req, res) => { @@ -17,11 +20,17 @@ router.get( const trackStats = await Track.aggregate([ { $addFields: { - trackLength: '$statistics.length', + trackLength: { + $cond: [ + {$lt: ['$statistics.length', 500000]}, + '$statistics.length', + 0, + ], + }, numEvents: '$statistics.numEvents', trackDuration: { $cond: [ - { $and: ['$statistics.recordedUntil', '$statistics.recordedAt'] }, + { $and: ['$statistics.recordedUntil', '$statistics.recordedAt', {$gt: ['$statistics.recordedAt', new Date('2010-01-01')]}] }, { $subtract: ['$statistics.recordedUntil', '$statistics.recordedAt'] }, 0, ], @@ -44,14 +53,14 @@ router.get( : [0,0,0]; const trackLengthPrivatized = Math.floor(trackLength / TRACK_LENGTH_ROUNDING) * TRACK_LENGTH_ROUNDING; + const trackDurationPrivatized = Math.round(trackDuration / 1000 / TRACK_DURATION_ROUNDING) * TRACK_DURATION_ROUNDING; return res.json({ publicTrackCount, - publicTrackLength: trackLengthPrivatized, trackLength: trackLengthPrivatized, + trackDuration: trackDurationPrivatized, numEvents, trackCount, - trackDuration: Math.round(trackDuration / 1000), userCount, }); }), diff --git a/frontend/src/pages/HomePage.js b/frontend/src/pages/HomePage.js index feef8dc..3ad415d 100644 --- a/frontend/src/pages/HomePage.js +++ b/frontend/src/pages/HomePage.js @@ -47,12 +47,12 @@ function Stats() { - {Number(stats?.publicTrackLength / 1000).toFixed(1)} - km track length + {Number(stats?.trackLength / 1000).toFixed(1)} km + track length - {formatDuration(stats?.trackDuration)} - hours recorded + {formatDuration(stats?.trackDuration)} h + recorded {stats?.numEvents}