Skip to content

Commit 88053a2

Browse files
committed
set descent and ascent to 0 when out of bounds (> 32767 meters)
1 parent 92c7a6a commit 88053a2

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- feat(nix): use datasources.settings.datasources to allow merging Grafana sources from multiple modules (#4870 - @JakobLichterfeld)
1414
- fix(nix): correctly set default Grafana dashboard path (#4870 - @JakobLichterfeld)
1515
- feat(nix): allow disabling default Grafana dashboard with setDefaultDashboard option (#4870 - @JakobLichterfeld)
16+
- fix: set descent and ascent to 0 when out of bounds (> 32767 meters) to ensure migration succeeds (#4882 - @swiffer)
1617

1718
#### Build, CI, internal
1819

lib/teslamate/log.ex

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -301,20 +301,16 @@ defmodule TeslaMate.Log do
301301
),
302302
select: %{
303303
elevation_gains:
304-
sum(
305-
fragment(
306-
"CASE WHEN ? > 0 THEN ? ELSE 0 END",
307-
p1.elevation_diff,
308-
p1.elevation_diff
309-
)
304+
fragment(
305+
"COALESCE(NULLIF(LEAST(SUM(CASE WHEN ? > 0 THEN ? ELSE 0 END), 32768), 32768), 0)",
306+
pi.elevation_diff,
307+
p1.elevation_diff
310308
),
311309
elevation_losses:
312-
sum(
313-
fragment(
314-
"CASE WHEN ? < 0 THEN ABS(?) ELSE 0 END",
315-
p1.elevation_diff,
316-
p1.elevation_diff
317-
)
310+
fragment(
311+
"COALESCE(NULLIF(LEAST(SUM(CASE WHEN ? < 0 THEN ABS(?) ELSE 0 END), 32768), 32768), 0)",
312+
pi.elevation_diff,
313+
p1.elevation_diff
318314
)
319315
}
320316

priv/repo/migrations/20250613133700_add_and_calculate_elevation_changes.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ defmodule TeslaMate.Repo.Migrations.AddAndCalculateElevationChanges do
1111
WITH elevation_changes AS (
1212
SELECT
1313
drive_id,
14-
SUM(CASE WHEN elevation_diff > 0 THEN elevation_diff ELSE 0 END) as ascent,
15-
SUM(CASE WHEN elevation_diff < 0 THEN ABS(elevation_diff) ELSE 0 END) as descent
14+
COALESCE(NULLIF(LEAST(SUM(CASE WHEN elevation_diff > 0 THEN elevation_diff ELSE 0 END), 32768), 32768), 0) as ascent,
15+
COALESCE(NULLIF(LEAST(SUM(CASE WHEN elevation_diff < 0 THEN ABS(elevation_diff) ELSE 0 END), 32768), 32768), 0) as descent
1616
FROM (
1717
SELECT
1818
drive_id,

0 commit comments

Comments
 (0)