"""Schritt 1: Prüfbericht für einen Datenordner. Aufruf: python app/pruefen.py z.B. python app/pruefen.py daten/6 Zeigt, wie viele Frames vollständig sind, was fehlt, und Kennzahlen zu Lenkung und Geschwindigkeit. Verändert nichts an den Daten. """ from __future__ import annotations import sys from itertools import groupby from statistics import mean from dataset import RECORDING_FPS, Dataset, load_dataset def build_report(dataset: Dataset) -> str: lines = [f"Ordner: {dataset.folder}", ""] for recording, group in groupby(dataset.frames, key=lambda f: f.recording): frames = list(group) lines += _recording_report(recording, frames) lines.append("") if dataset.ignored_files: lines.append(f"Ignorierte Dateien (nicht im Format _.jpg/json): {len(dataset.ignored_files)}") lines += [f" {p.name}" for p in dataset.ignored_files[:10]] return "\n".join(lines) def _recording_report(recording: str, frames: list) -> list[str]: numbers = [f.number for f in frames] first, last = min(numbers), max(numbers) complete = [f for f in frames if f.is_complete] only_image = [f.number for f in frames if f.image_path and not f.json_path] only_json = [f.number for f in frames if f.json_path and not f.image_path] broken = [(f.number, f.error) for f in frames if f.error] missing = sorted(set(range(first, last + 1)) - set(numbers)) lines = [ f"=== Aufnahme {recording} ===", f"Frames {first} bis {last} (ca. {(last - first + 1) / RECORDING_FPS:.1f} s bei {RECORDING_FPS} FPS)", f"Vollständig (Bild + JSON): {len(complete)}", f"Nur Bild, kein JSON: {len(only_image)}{_examples(only_image)}", f"Nur JSON, kein Bild: {len(only_json)}{_examples(only_json)}", f"JSON kaputt: {len(broken)}{_examples([n for n, _ in broken])}", f"Nummer fehlt ganz: {len(missing)}{_examples(missing)}", ] if complete: angles = [f.angle for f in complete] speeds = [f.speed for f in complete] right = sum(a > 1 for a in angles) / len(angles) left = sum(a < -1 for a in angles) / len(angles) straight = 1 - right - left stop = [f.number for f in complete if f.speed == 0] backwards = [f.number for f in complete if f.speed < 0] lines += [ "", f"Lenkwinkel: min {min(angles):.1f}°, max {max(angles):.1f}°, Mittel {mean(angles):+.1f}°", f" rechts (> 1°) {right:.0%}, gerade (±1°) {straight:.0%}, links (< -1°) {left:.0%}", f"Speed: min {min(speeds):g}, max {max(speeds):g}, Mittel {mean(speeds):.1f}", f"Speed = 0: {len(stop)} Frames{_examples(stop)}", f"Speed < 0: {len(backwards)} Frames{_examples(backwards)}", ] return lines def _examples(numbers: list[int], limit: int = 8) -> str: """Zeigt die ersten paar Nummern, z.B. ' (1, 5, 8, ...)'.""" if not numbers: return "" shown = ", ".join(str(n) for n in numbers[:limit]) more = ", ..." if len(numbers) > limit else "" return f" ({shown}{more})" if __name__ == "__main__": if len(sys.argv) != 2: print("Aufruf: python app/pruefen.py ") sys.exit(1) print(build_report(load_dataset(sys.argv[1])))