"""Dummy data for the agent evaluation: where 10,000 customer contacts went before and after the fixes, the two bars
the agent had to clear, and eight weeks of scores with the fixes that moved them. Every name, figure and date is
invented.

Usage: python3 generate.py (writes data.json next to this file)
"""
import json
import os

# Each round: contacts, then where they went. Closed and escalated split into right and wrong outcomes.
ROUNDS = {
    "Before fixes": {"dropped": 620, "abandoned": 1380, "closedRight": 4410, "closedWrong": 940, "missed": 850,
                     "escalatedNeeded": 980, "escalatedNot": 820},
    "After fixes": {"dropped": 310, "abandoned": 640, "closedRight": 7280, "closedWrong": 260, "missed": 190,
                    "escalatedNeeded": 1170, "escalatedNot": 150},
}
BARS = {"resolution": 0.85, "justification": 0.85}
# Week, resolution, justification, rollout share, fix shipped that week
WEEKS = [
    (1, 0.711, 0.544, 0.15, None),
    (2, 0.738, 0.602, 0.15, "Fix 1: answer from the order's tracking events"),
    (3, 0.774, 0.655, 0.15, "Fix 2: hand off on refund requests"),
    (4, 0.809, 0.712, 0.15, "Fix 3: confirm the order before answering"),
    (5, 0.836, 0.781, 0.15, "Fix 4: stop escalating address changes"),
    (6, 0.861, 0.842, 0.15, "Fix 5: shorter first reply"),
    (7, 0.902, 0.874, 0.15, None),
    (8, 0.942, 0.886, 1.0, None),
]


def main():
    rounds = []
    for name, r in ROUNDS.items():
        total = sum(r.values())
        closed = r["closedRight"] + r["closedWrong"] + r["missed"]
        escalated = r["escalatedNeeded"] + r["escalatedNot"]
        rounds.append({"name": name, "total": total, **r,
                       "resolution": round(r["closedRight"] / closed, 3),
                       "justification": round(r["escalatedNeeded"] / escalated, 3)})
    out = {"rounds": rounds, "bars": BARS, "hold": 0.15,
           "weeks": [{"week": w, "resolution": a, "justification": b, "rollout": c, "fix": f} for w, a, b, c, f in WEEKS]}
    with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "data.json"), "w") as f:
        json.dump(out, f, separators=(",", ":"))


if __name__ == "__main__":
    main()
