from common import *
import json
g=pd.read_parquet(R/'games.parquet')
chosen=['Erik Asmussen','Endlessfluff Games','Blendo Games','Big Robot Ltd','BeautiFun Games','Abbey Games','Harvester Games','Freebird Games','Daniel Mullins Games','Suspicious Developments','David Szymanski','Nolla Games','Rad Codex','Studio Fizbin','Tuatara Games','Desert Fox','a327ex','Zachtronics']
x=g[g.credit.isin(chosen)].copy();x.to_csv(R/'selected_case_records.csv',index=False,columns=['developer_id','credit','developer_page_url','developer_link_type','appid','name','date','reviews','pct','price','mature','review_band','game_url'])
text=['# Linked case atlas','', 'Current September 5 review totals, not equal-age outcomes or financial returns. These are named-credit, currently paid catalogs; free work, joint credits, renamed developers and absent games can be omitted. Young titles are explicitly flagged.','']
for name in chosen:
    a=x[x.credit.eq(name)].sort_values('date')
    if a.empty:continue
    url=a.developer_page_url.iloc[0];text.extend([f'## [{name}]({url})','', '| Game | Recorded date | Reviews | Positive | Maturity |','|---|---|---:|---:|---|'])
    for row in a.itertuples():
        title=row.name.replace('|','\\|');text.append(f'| [{title}]({row.game_url}) | {row.date:%Y-%m-%d} | {row.reviews:,} | {row.pct}% | {"At least one year" if row.mature else "Under one year; excluded from mature sequences"} |')
    text.append('')
(R/'case_atlas.md').write_text('\n'.join(text))
x[['credit','developer_page_url','developer_link_type']].drop_duplicates().to_csv(R/'developer_links.csv',index=False)
print('Linked case atlas',x.credit.nunique(),'developer names',len(x),'games')
