"""Optional learner starter. Fill the three TODO functions before running.

Run from the extracted course folder: python learner_analysis.py
Then: python check_learner.py
This writes YOUR answers to learner_results.json. Never change the raw fixture.
"""
import csv
import json
from pathlib import Path
ROOT=Path(__file__).resolve().parent

def shipment_summary(rows):
    """Return late_count, late_denominator, actual_mean, actual_median,
    and satisfaction_missing. rows are DictReader strings; blank rating is missing.
    Do not treat missing satisfaction as an invalid shipment timing row.
    """
    raise NotImplementedError('TODO: calculate the shipment summaries from clean rows')

def trial_summary(rows):
    """Return trial_difference, trial_ci_low, trial_ci_high, trial_p.
    Compare checklist minus control. Use independent-samples Welch (equal_var=False).
    Hints: convert duration_minutes to floats; separate by group; scipy.stats.ttest_ind
    returns confidence_interval(confidence_level=0.95). Explain assumptions separately.
    """
    raise NotImplementedError('TODO: compute the trial contrast and compatible interval')

def analysis_note():
    """Write your own short limitations note. This is not automatically graded."""
    raise NotImplementedError('TODO: explain simulation, independence and practical threshold')

def main():
    with (ROOT/'data/shipments_clean.csv').open(newline='') as f:shipments=list(csv.DictReader(f))
    with (ROOT/'data/checklist_trial.csv').open(newline='') as f:trial=list(csv.DictReader(f))
    result={**shipment_summary(shipments),**trial_summary(trial),'synthetic':True,
            'contrast':'checklist_minus_control','limitations':analysis_note()}
    path=ROOT/'learner_results.json';path.write_text(json.dumps(result,indent=2,allow_nan=False)+'\n')
    print(f'Wrote your calculations to {path.name}; run python check_learner.py')
if __name__=='__main__':main()
