import os import numpy as np import matplotlib.pyplot as plt DATA_DIR = "data" # find newest summary file files = [f for f in os.listdir(DATA_DIR) if f.startswith("summary_") and f.endswith(".csv")] if not files: raise FileNotFoundError("No summary files found in 'data/'") latest = max(files, key=lambda f: os.path.getmtime(os.path.join(DATA_DIR, f))) path = os.path.join(DATA_DIR, latest) print(f"Using {path}") starts = [] ends = [] with open(path, "r") as f: next(f) # skip header for line in f: parts = line.strip().split(",") if len(parts) < 2: continue start_ms = float(parts[0]) end_ms = float(parts[1]) starts.append(start_ms) ends.append(end_ms) starts = np.array(starts) ends = np.array(ends) # measurement durations measurement = ends - starts # gap durations (between batches) # drop last batch because there is no next-start to compute gap against gaps = starts[1:] - ends[:-1] # align measurement durations to gaps dimension # (both arrays indexed by batch interval "between measurements") measurement = measurement[:-1] # percentages total = measurement + gaps measurement_pct = (measurement / total) * 100.0 downtime_pct = (gaps / total) * 100.0 # time axis: batch index (no absolute time in summaries) x = np.arange(len(measurement_pct)) # plot plt.figure(figsize=(12, 6)) plt.plot(x, measurement_pct, label="measurement time (%)") plt.plot(x, downtime_pct, label="downtime (%)") plt.xlabel("Batch index") plt.ylabel("Percentage of interval") plt.title(f"Measurement vs. Downtime Percentage ({latest})") plt.grid(True) plt.legend() plt.tight_layout() plt.show()