This commit is contained in:
Victor Goncharov 2025-12-30 19:30:11 +01:00 committed by GitHub
commit eeebd31e44
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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>