"""The verdict, from the hand-confirmed table. Sealed before storefronts.csv existed.

    python research/agent-storefronts/rule.py

storefronts.csv columns: host, storefront (yes/no), record (yes/no),
outside_sale (yes/no/blank), evidence_url, note. Only rows with storefront=yes
count; only those with record=yes enter the share.
"""
import csv
from pathlib import Path

HERE = Path(__file__).resolve().parent


def main():
    rows = [r for r in csv.DictReader(open(HERE / "storefronts.csv"))
            if r["storefront"].strip() == "yes"]
    with_record = [r for r in rows if r["record"].strip() == "yes"]
    n = len(with_record)
    k = sum(1 for r in with_record if r["outside_sale"].strip() == "yes")
    print(f"storefronts {len(rows)}; with a public record {n}; "
          f"with at least one outside sale {k}; without a record {len(rows) - n}")
    if n < 5:
        verdict = "inconclusive (fewer than 5 storefronts publish a record)"
    elif k / n >= 0.5:
        verdict = "survived"
    elif k / n < 0.25:
        verdict = "killed"
    else:
        verdict = "inconclusive"
    share = f"{k}/{n} = {k / n:.2f}" if n else "n/a"
    print(f"share {share} -> {verdict}")


if __name__ == "__main__":
    main()
