#!/bin/sh
# The re-test from the extracted data, for the census (data/main to results/main) and the development set (data/dev
# to results/dev), then the exploratory checks and the declared results. plan/code/run is the registered run: its
# extract step made data/main and data/dev from the public sources data/sources.csv lists, and its measure step ran
# the four commands measure() runs here, in the image env/Dockerfile builds, which is this bundle's environment too.
# Here they run in the verifier's container instead, each set's extracted data copied to a scratch folder first,
# since retest.py and calibration.py write their results beside what they read (deviations.json). Every file in
# code/ is plan/code's, byte for byte, but this one, exploratory.py, and collect.py, written after registration.
set -eu
export PYTHONHASHSEED=0

measure() {  # <set> <the calibration loci it runs on>
    work=$(mktemp -d)
    cp -R "data/$1/retest" "data/$1/calibration" "$work/"
    python code/retest.py "$work/retest" data
    python code/calibration.py measure "$work/calibration" data "$2"
    python code/calibration.py summary "$work/calibration" "$2"
    mkdir -p "results/$1/retest" "results/$1/calibration"
    python code/analysis.py "data/$1/coded/claims.json" "data/$1/coded/mapped.csv" "$work/retest" data/seen_pairs.csv \
        "results/$1" "$work/calibration/$2/summary.json"
    cp "$work/retest/retest_claims.csv" "$work/retest/retest_controls.csv" "$work/retest/retest_neighbours.csv" "results/$1/retest/"
    cp "$work/calibration/$2/measures.csv" "$work/calibration/$2/summary.json" "results/$1/calibration/"
    rm -rf "$work"
}

measure main judged
measure dev dev
python code/exploratory.py data/main results/main
python code/collect.py results
