# -*- coding: utf-8 -*-
# claimedBy の「宮内（杉本）」等を主担当名へ正規化（集計が割れないように）。salesReps注記は保持。
import json, os, re
SRC=os.path.join(os.path.dirname(os.path.abspath(__file__)),"meiten-master.json")
j=json.load(open(SRC,encoding="utf-8"))
n=0
for s in j["stores"]:
    cb=s.get("claimedBy")
    if cb and ("（" in cb or "(" in cb):
        base=re.split(r"[（(]",cb)[0].strip()
        if base and base!=cb: s["claimedBy"]=base; n+=1
json.dump(j,open(SRC,"w",encoding="utf-8"),ensure_ascii=False,indent=2)
from collections import Counter
print("normalized:",n)
print("担当別:", dict(sorted(Counter(s.get("claimedBy") for s in j["stores"]).items(), key=lambda x:-x[1])))
