fix: DEM elevation overcounting and add hysteresis-only recalculation button

- dem.py: apply 45s median filter before hysteresis to suppress SRTM
  tile-boundary steps that were accumulating through the 5m threshold;
  raise DEM hysteresis threshold from 5m to 10m
- dem.py: back up elevation_m as elevation_m_original in timeseries
  before the first DEM overwrite, so original sensor data is preserved
- dem.py: add recalculate_elevation_hysteresis() — recomputes gain/loss
  from original recorded elevation (reads elevation_m_original if a DEM
  run already replaced elevation_m) using source-aware thresholds
  (5m barometric, 10m GPS/unknown); does not touch the elevation array
- edit/server.py, serve/server.py: split /recalculate-elevation into
  two endpoints: /recalculate-elevation/dem and
  /recalculate-elevation/hysteresis
- EditDrawer.svelte: replace single DEM button with two side-by-side
  buttons — "Recalculate (hysteresis)" (fast, offline) and
  "Recalculate (DEM)" (SRTM lookup)
This commit is contained in:
Davide Scaini
2026-04-20 21:41:23 +02:00
parent 2b7a37ed41
commit ebac3f50f4
4 changed files with 215 additions and 42 deletions
+26 -14
View File
@@ -24,8 +24,8 @@
let confirmDelete = false;
let deleting = false;
// Elevation recalculation from DEM
let recalculating = false;
// Elevation recalculation
let recalculating: '' | 'dem' | 'hysteresis' = '';
let recalcStatus = '';
let recalcOk = false;
@@ -124,12 +124,12 @@
: [...hideStats, key];
}
async function recalculateElevation() {
recalculating = true;
async function recalculateElevation(method: 'dem' | 'hysteresis') {
recalculating = method;
recalcStatus = '';
recalcOk = false;
try {
const res = await fetch(`${api}/recalculate-elevation`, { method: 'POST' });
const res = await fetch(`${api}/recalculate-elevation/${method}`, { method: 'POST' });
const d = await res.json();
if (!res.ok) throw new Error(d.detail ?? await res.text());
recalcOk = true;
@@ -140,7 +140,7 @@
recalcStatus = e.message;
recalcOk = false;
} finally {
recalculating = false;
recalculating = '';
}
}
@@ -292,14 +292,26 @@
<!-- Elevation recalculation -->
<div class="mb-4">
<p class="text-xs text-zinc-500 mb-2">Elevation</p>
<button
type="button"
class="w-full flex items-center justify-center gap-2 px-3 py-2 rounded-lg border border-zinc-700 text-xs text-zinc-400 hover:border-zinc-500 hover:text-zinc-200 transition-colors disabled:opacity-40"
disabled={recalculating}
on:click={recalculateElevation}
>
{recalculating ? 'Querying terrain data…' : '⛰ Recalculate from terrain map (DEM)'}
</button>
<div class="flex gap-2">
<button
type="button"
class="flex-1 flex items-center justify-center gap-1 px-3 py-2 rounded-lg border border-zinc-700 text-xs text-zinc-400 hover:border-zinc-500 hover:text-zinc-200 transition-colors disabled:opacity-40"
disabled={recalculating !== ''}
on:click={() => recalculateElevation('hysteresis')}
title="Recompute from the original recorded elevation using noise-filtering (fast, no network)"
>
{recalculating === 'hysteresis' ? 'Computing…' : '📐 Recalculate (hysteresis)'}
</button>
<button
type="button"
class="flex-1 flex items-center justify-center gap-1 px-3 py-2 rounded-lg border border-zinc-700 text-xs text-zinc-400 hover:border-zinc-500 hover:text-zinc-200 transition-colors disabled:opacity-40"
disabled={recalculating !== ''}
on:click={() => recalculateElevation('dem')}
title="Replace elevation with SRTM terrain data from the internet (slower, most accurate for GPS-only devices)"
>
{recalculating === 'dem' ? 'Querying terrain…' : '⛰ Recalculate (DEM)'}
</button>
</div>
{#if recalcStatus}
<p class="text-xs mt-1.5 text-center" class:text-green-400={recalcOk} class:text-red-400={!recalcOk}>
{recalcStatus}