# Tactiverge Academy — companion code for "Reporting comparisons with uncertainty"
# Lesson: https://tactiverge.win/academy/research-methodology/baseline-comparisons/reporting-comparisons/
# Licence: MIT (see https://tactiverge.win/open-engineering/). Examples appear in lesson order.

# ── Example 1 ────────────────────────────────────────
import math
import statistics

# Made-up lap times in seconds, for illustration only.
baseline = [12.4, 12.9, 12.1, 13.0, 12.6, 12.8, 12.3, 12.7, 12.5, 12.9]
new      = [11.9, 12.5, 12.2, 11.6, 12.8, 12.0, 11.8, 12.4, 12.1, 12.3]

def summarise(name, data):
    n = len(data)
    mean = statistics.mean(data)
    sd = statistics.stdev(data)       # sample standard deviation
    se = sd / math.sqrt(n)            # standard error of the mean
    print(f"{name}: n={n} mean={mean:.2f} s  sd={sd:.2f} s  se={se:.2f} s")
    return mean, se

m_b, se_b = summarise("baseline", baseline)
m_n, se_n = summarise("new     ", new)

diff = m_b - m_n                      # positive = new is faster
se_diff = math.sqrt(se_b**2 + se_n**2)
print(f"difference = {diff:.2f} s, rough 95% range {diff - 2*se_diff:.2f} to {diff + 2*se_diff:.2f} s")
