Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ def speed_text_color(speed)
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)
Expand Down
7 changes: 5 additions & 2 deletions app/javascript/maps/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion app/views/points/_point.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down