From b05ab63f2820c3243832d2b98cdbbba17fd1839f Mon Sep 17 00:00:00 2001 From: Victor Goncharov Date: Wed, 4 Jun 2025 00:09:23 +0200 Subject: [PATCH 1/3] Update application_helper.rb Fixed `point_speed` in `application_helper.rb` to properly convert velocity from m/s to km/h, round to 1 decimal, and safely handle nil or zero values. --- app/helpers/application_helper.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 47d40698..329b731d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -169,9 +169,9 @@ module ApplicationHelper end def point_speed(speed) - return speed if speed.to_i <= 0 - - speed * 3.6 + return "–" if speed.nil? || speed.to_f <= 0 + speed = speed.to_f + "#{(speed * 3.6).round(1)}" end def days_left(active_until) From 69b628a487e7fc643958750224e4b1c0ff302a27 Mon Sep 17 00:00:00 2001 From: Victor Goncharov Date: Wed, 4 Jun 2025 00:12:32 +0200 Subject: [PATCH 2/3] Update helpers.js Updated `formatSpeed` in `helpers.js` to correctly assume incoming speed is in m/s and convert to km/h before formatting. --- app/javascript/maps/helpers.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/javascript/maps/helpers.js b/app/javascript/maps/helpers.js index 403aa698..a4cb806d 100644 --- a/app/javascript/maps/helpers.js +++ b/app/javascript/maps/helpers.js @@ -66,15 +66,18 @@ export function formatDate(timestamp, timezone) { return date.toLocaleString(locale, { timeZone: timezone }); } -export function formatSpeed(speedKmh, unit = 'km') { +export function formatSpeed(speedMs, unit = 'km') { + const speedKmh = speedMs * 3.6; // Convert m/s to km/h + if (unit === 'km') { return `${Math.round(speedKmh)} km/h`; } else { - const speedMph = speedKmh * 0.621371; // Convert km/h to mph + const speedMph = speedKmh * 0.621371; return `${Math.round(speedMph)} mph`; } } + export function haversineDistance(lat1, lon1, lat2, lon2, unit = 'km') { // Haversine formula to calculate the distance between two points const toRad = (x) => (x * Math.PI) / 180; From f837986b6bd11803c9e3c09d87c2853f31253d12 Mon Sep 17 00:00:00 2001 From: Victor Goncharov Date: Wed, 4 Jun 2025 00:14:29 +0200 Subject: [PATCH 3/3] Update _point.html.erb Patched `_point.html.erb` to use `point_speed(point.velocity)` for consistent and accurate speed display with units. --- app/views/points/_point.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/points/_point.html.erb b/app/views/points/_point.html.erb index 30b9a861..41ea2b67 100644 --- a/app/views/points/_point.html.erb +++ b/app/views/points/_point.html.erb @@ -13,7 +13,7 @@ } %> - <%= point.velocity %> + <%= point_speed(point.velocity) %> <%= human_datetime_with_seconds(point.recorded_at) %> <%= point.lat %>, <%= point.lon %>