Compare commits

...

4 commits

Author SHA1 Message Date
Victor Goncharov
97f808ad78
Merge f837986b6b into 3f0aaa09f5 2025-12-26 15:16:37 +01:00
Victor Goncharov
f837986b6b
Update _point.html.erb
Patched `_point.html.erb` to use `point_speed(point.velocity)` for consistent and accurate speed display with units.
2025-06-04 00:14:29 +02:00
Victor Goncharov
69b628a487
Update helpers.js
Updated `formatSpeed` in `helpers.js` to correctly assume incoming speed is in m/s and convert to km/h before formatting.
2025-06-04 00:12:32 +02:00
Victor Goncharov
b05ab63f28
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.
2025-06-04 00:09:23 +02:00
3 changed files with 9 additions and 6 deletions

View file

@ -96,9 +96,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)

View file

@ -90,15 +90,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;

View file

@ -13,7 +13,7 @@
}
%>
</td>
<td class='<%= speed_text_color(point.velocity) %>'><%= point.velocity %></td>
<td class='<%= speed_text_color(point.velocity) %>'><%= point_speed(point.velocity) %></td>
<td><%= human_datetime_with_seconds(point.recorded_at) %></td>
<td><%= point.lat %>, <%= point.lon %></td>
<td></td>