Halte als Punkte auf der Strecke, Ortsnamen ohne Punkt; Doppelte im Ausland entfernt; bereit erst wenn alle Länder berechnet

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X48pE4bzjHej8w9HyZXCjb
This commit is contained in:
Claude
2026-10-22 08:09:09 +02:00
parent deaa6aa9cd
commit ae50ac39ac
4 changed files with 32 additions and 3 deletions
+16 -1
View File
@@ -35,6 +35,7 @@ class Source:
self.rt_error: str | None = None
self.rt_tried_at: float | None = None
self.on_disk = False # ein aufbereiteter Fahrplan liegt bereit (wird gleich geladen)
self.loaded_at = 0.0
@property
def has_rt(self) -> bool:
@@ -84,6 +85,7 @@ def watch_feeds():
log.info("[%s] Lade Fahrplan %s …", src.name, want)
t = time.time()
src.feed = Feed(C.FEEDS_DIR / src.name / want)
src.loaded_at = time.time()
log.info("[%s] Fahrplan %s geladen in %.0f s (%d Fahrten)", src.name, want, time.time() - t,
len(src.feed.trip_ids))
try: # Echtzeit sofort holen statt auf den nächsten Abruf zu warten
@@ -138,6 +140,18 @@ def compute_positions():
f["path"] = src.feed.track(f.pop("_ti"), dists, STEP)
del f["_dist"]
feats += cur
# Im übrigen Ausland (Luxemburg, Österreich, …) zeigen alle Fahrpläne ihre Züge -> dort Doppelte
# (gleiche Linie, gleiche ~500-m-Zelle) entfernen, bevorzugt den mit Echtzeit behalten
seen, out = set(), []
for f in sorted(feats, key=lambda f: f["properties"]["delay"] is None):
x, y = f["geometry"]["coordinates"]
if border.country(x, y) is None:
line, cx, cy = f["properties"]["line"], round(x * 200), round(y * 200)
if any((line, cx + i, cy + j) in seen for i in (-1, 0, 1) for j in (-1, 0, 1)):
continue
seen.add((line, cx, cy))
out.append(f)
feats = out
S.vehicles = json.dumps({"type": "FeatureCollection", "ts": now, "features": feats},
separators=(",", ":")).encode()
S.vehicles_gz = gzip.compress(S.vehicles, 5)
@@ -194,7 +208,8 @@ def status():
return {
"loaded": bool(loaded),
# erst "bereit", wenn Positionen mit (dem ersten Versuch) Echtzeit berechnet sind
"ready": bool(loaded and not pending and S.computed_at and all(s.rt_tried_at and S.computed_at >= s.rt_tried_at for s in rt)),
"ready": bool(loaded and not pending and S.computed_at
and all(S.computed_at >= s.loaded_at for s in loaded) and all(s.rt_tried_at and S.computed_at >= s.rt_tried_at for s in rt)),
"vehicles": S.count,
"rt_ok": bool(ok) and len(ok) == len(loaded),
"rt_some": bool(ok),