Spaces:
Running

math-tutor / scripts /sim_session.py
seongui2030
deploy 2026-12-03 20:26
b146445
Raw History Blame Contribute Delete
2.67 kB
"""ํ•™์Šต ์—”์ง„ ์‹œ๋ฎฌ๋ ˆ์ด์…˜: ์‹ค์ œ ๋ฌธํ•ญ ํŒŒ์ผ(aihub_A.jsonl)๋กœ ๊ฐ€์ƒ ํ•™์ƒ์ด ํ•œ ์„ธ์…˜์„ ํ‘ธ๋Š” ๊ณผ์ •์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.
DBยทํ‚ค ์—†์ด PC ์—์„œ ๋ฐ”๋กœ ๋Œ๋ ค ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
python scripts\\sim_session.py --file data\\aihub_normalized\\aihub_A.jsonl --unit U12 --level low --acc 0.7 0.5 0.3
--acc : ํ•˜/์ค‘/์ƒ ๋‚œ์ด๋„๋ณ„ ๊ฐ€์ƒ ํ•™์ƒ์˜ ์ •๋‹ต๋ฅ  (๊ธฐ๋ณธ 0.8 0.6 0.4)
"""
import argparse
import json
import random
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from app.engine import LEVEL_KO, LEVELS, Pool, Rules, next_question, record_answer, start_session, summary # noqa: E402
if hasattr(sys.stdout, "reconfigure"):
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
def wrong_answer(q):
return "9" if q["qtype"] == "multiple_choice" else "__์˜ค๋‹ต__"
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--file", type=Path, required=True)
ap.add_argument("--unit", required=True)
ap.add_argument("--level", default="low", choices=LEVELS)
ap.add_argument("--acc", type=float, nargs=3, default=[0.8, 0.6, 0.4])
ap.add_argument("--seed", type=int, default=1)
a = ap.parse_args()
rows = [json.loads(l) for l in a.file.open(encoding="utf-8") if l.strip()]
for r in rows:
r["id"] = r["source_ref"]
pool = Pool(rows)
c = pool.counts(a.unit)
print(f"{a.unit} ๋ฌธํ•ญ ์ˆ˜ ํ•˜ {c['low']} / ์ค‘ {c['mid']} / ์ƒ {c['high']} (ํ•œ ์นธ์ด {Rules().min_pool}๊ฐœ ๋ฏธ๋งŒ์ด๋ฉด ์–‡์€ ์นธ)")
rng = random.Random(a.seed)
s = start_session(pool, a.unit, a.level)
if s.finished:
print("์ด ๋‹จ์›์€ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋‚œ์ด๋„๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค:", sorted(s.flags))
return
acc = dict(zip(LEVELS, a.acc))
while True:
nq = next_question(s, pool, rng=rng)
if nq is None:
break
q, phase = nq
ok = rng.random() < acc[q["difficulty"]]
resp = q["answer"] if ok else wrong_answer(q)
r = record_answer(s, pool, resp)
print(f" {len(s.log)}๋ฒˆ์งธ [{('์žฌ๋„์ „' if phase == 'retry' else '์‚ฌ๋‹ค๋ฆฌ')}] ๋‚œ์ด๋„ {LEVEL_KO[r['level_before']]} "
f"{q['id']:<20} {'์ •๋‹ต' if r['correct'] else '์˜ค๋‹ต'} -> ๋‹ค์Œ ๋‚œ์ด๋„ {LEVEL_KO[r['level_after']]}")
if r["done"]:
break
sm = summary(s)
print(f"๋: {sm['answered']}๋ฌธ์ œ ์ค‘ {sm['correct']}๋ฌธ์ œ ์ •๋‹ต | ์ตœ์ข… ๋‚œ์ด๋„ {LEVEL_KO[sm['final_level']]} | "
f"์žฌ๋„์ „ ํ•ด๊ฒฐ {len(sm['recovered'])} | ๋ฐ˜๋ณต ์˜ค๋‹ต {len(sm['stuck'])} | ํ‘œ์‹œ {sm['flags'] or '์—†์Œ'}")
if __name__ == "__main__":
main()