# Check what makes a continuous drive trainable: continuity across file joins, and motion data on the video clock.
# usage: python check_drive.py roaddata-continuous-driving-cudr_0002
import csv, json, sys
d = sys.argv[1]
drive = json.load(open(f"{d}/drive.json"))
print(drive["drive_id"], "|", drive["time_of_day"], drive["weather"], "|", f'{drive["duration_s"] / 60:.1f} min of video')
segs = list(csv.DictReader(open(f"{d}/segments.csv")))
gaps = [float(s["wall_gap_to_next_s"]) for s in segs if s["wall_gap_to_next_s"]]
print(f"joins between recording files: {len(gaps)}, longest gap {max(gaps):.2f} s;",
      f"longest frame gap inside a file {max(float(s['max_frame_gap_s']) for s in segs):.3f} s")
rows = list(csv.DictReader(open(f"{d}/gnss_imu_10hz.csv")))
fix = sum(r["gnss_fix"] == "1" for r in rows) / len(rows)
speed = [float(r["speed_mps"]) for r in rows]
print(f"motion rows at 10 Hz, stamped on the video clock: {rows[0]['video_t_s']} s to {rows[-1]['video_t_s']} s;",
      f"satellite fix {fix:.0%} of rows; speed {min(speed):.1f} to {max(speed):.1f} m/s")
