added linear slider

This commit is contained in:
2026-06-15 07:50:41 +03:00
parent d28391c71f
commit ab2a3bb035
7 changed files with 239 additions and 16 deletions
+58 -3
View File
@@ -18,6 +18,7 @@ from .config import (
logger = logging.getLogger(__name__)
_BATCH_SIZE = 100
_MAX_PROFILE_POINTS = 500
_CACHE: dict[tuple[float, float], Optional[float]] = {}
_probe_checked_at = 0.0
_probe_ok = False
@@ -251,12 +252,66 @@ def resample_track_path(
return samples
def resample_track_path_count(
points: list[dict[str, Any]], count: int
) -> list[dict[str, float]]:
"""Sample exactly `count` points evenly spaced along polyline."""
if not points or count < 2:
return []
cleaned: list[tuple[float, float]] = []
for p in points:
lat = p.get("lat")
lon = p.get("lon")
if lat is None or lon is None:
continue
lat_f, lon_f = float(lat), float(lon)
if not cleaned or haversine_m(cleaned[-1][0], cleaned[-1][1], lat_f, lon_f) > 0.5:
cleaned.append((lat_f, lon_f))
if not cleaned:
return []
if len(cleaned) == 1:
return [{"lat": cleaned[0][0], "lon": cleaned[0][1], "dist_m": 0.0}]
cum = [0.0]
for i in range(1, len(cleaned)):
cum.append(
cum[-1]
+ haversine_m(
cleaned[i - 1][0], cleaned[i - 1][1], cleaned[i][0], cleaned[i][1]
)
)
total = cum[-1]
if total < 1e-6:
return [{"lat": cleaned[0][0], "lon": cleaned[0][1], "dist_m": 0.0}]
n = max(2, min(_MAX_PROFILE_POINTS, int(count)))
samples: list[dict[str, float]] = []
for i in range(n):
dist = (total * i) / (n - 1)
lat, lon = _interp_at_dist(cleaned, cum, dist)
samples.append({"lat": lat, "lon": lon, "dist_m": round(dist, 1)})
return samples
def build_elevation_profile(
points: list[dict[str, Any]], step_m: float = 10.0
points: list[dict[str, Any]],
step_m: float = 10.0,
target_points: int | None = None,
) -> dict[str, Any]:
"""Resample track and fetch terrain elevations."""
step_m = max(5.0, min(10.0, float(step_m)))
samples = resample_track_path(points, step_m)
if target_points is not None:
n = max(2, min(_MAX_PROFILE_POINTS, int(target_points)))
samples = resample_track_path_count(points, n)
if len(samples) > 1:
step_m = round(
(samples[-1]["dist_m"] - samples[0]["dist_m"]) / (len(samples) - 1),
2,
)
else:
step_m = 0.0
else:
step_m = max(5.0, min(10.0, float(step_m)))
samples = resample_track_path(points, step_m)
if not samples:
return {
"step_m": step_m,