Spaces:
Running

math-tutor / scripts /20_coverage_all.py
seongui2030
deploy 2026-12-03 20:26
b146445
Raw History Blame Contribute Delete
3.33 kB
"""EBSi(h1ยทh2ยทh3) + AI Hub ๋‹จ์›๋ณ„ ๋ฌธํ•ญ ์ˆ˜๋ฅผ ํ•ฉ์นœ ํ‘œ๋ฅผ ๋งŒ๋“ ๋‹ค.
python scripts\\20_coverage_all.py
์ž…๋ ฅ
data/aihub_normalized/coverage_after.csv AI Hub (unit_id, unit_name, A_low, A_mid, A_high, usable_low, usable_mid, usable_high)
data/ebsi/coverage_ebsi_h1.csv / _h2 / _h3 EBSi ํ•™๋…„๋ณ„ (๊ฐ™์€ ์—ด) โ€” scripts/16_ebsi_units.py build ๊ฒฐ๊ณผ
์ถœ๋ ฅ
data/coverage_all.csv
unit_id, unit_name,
aihub_A, ebsi_h1_A, ebsi_h2_A, ebsi_h3_A, (์ถœ์ฒ˜๋ณ„ A ํ•ฉ)
aihub_usable, ebsi_h1_usable, ebsi_h2_usable, ebsi_h3_usable, (์ถœ์ฒ˜๋ณ„ usable ํ•ฉ = low+mid+high)
A_low, A_mid, A_high, usable_low, usable_mid, usable_high, (์ „์ฒด ํ•ฉ)
usable_total
A = ๊ธ€์ž๋กœ ์™„๋น„, usable = A + B (๊ทธ๋ฆผยท์ƒ์žยท์ด๋ฏธ์ง€ ํ•จ๊ป˜ ํ‘œ์‹œ). C(์ž๋™ ๊ฒฝ๊ณ )๋Š” ๋น ์ง.
๋น„์šฉยท์™ธ๋ถ€ ์“ฐ๊ธฐ ์—†์Œ.
"""
import csv
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
SOURCES = [
("aihub", ROOT / "data/aihub_normalized/coverage_after.csv"),
("ebsi_h1", ROOT / "data/ebsi/coverage_ebsi_h1.csv"),
("ebsi_h2", ROOT / "data/ebsi/coverage_ebsi_h2.csv"),
("ebsi_h3", ROOT / "data/ebsi/coverage_ebsi_h3.csv"),
]
COLS = ["A_low", "A_mid", "A_high", "usable_low", "usable_mid", "usable_high"]
OUT = ROOT / "data/coverage_all.csv"
def read(p):
with open(p, encoding="utf-8-sig", newline="") as f:
return [r for r in csv.DictReader(f) if r.get("unit_id")]
def main():
order, names, tot, per, perA = [], {}, {}, {}, {}
for src, p in SOURCES:
if not p.exists():
raise SystemExit(f"์—†์Œ: {p}")
for r in read(p):
u = r["unit_id"]
if u not in names:
order.append(u)
names[u] = r["unit_name"]
tot[u] = {c: 0 for c in COLS}
for c in COLS:
tot[u][c] += int(r[c] or 0)
per[(src, u)] = sum(int(r[c] or 0) for c in ("usable_low", "usable_mid", "usable_high"))
perA[(src, u)] = sum(int(r[c] or 0) for c in ("A_low", "A_mid", "A_high"))
head = (["unit_id", "unit_name"] + [f"{s}_A" for s, _ in SOURCES] + [f"{s}_usable" for s, _ in SOURCES]
+ COLS + ["usable_total"])
with open(OUT, "w", encoding="utf-8-sig", newline="") as f:
w = csv.writer(f)
w.writerow(head)
for u in order:
t = tot[u]
w.writerow([u, names[u]] + [perA.get((s, u), 0) for s, _ in SOURCES] + [per.get((s, u), 0) for s, _ in SOURCES]
+ [t[c] for c in COLS] + [t["usable_low"] + t["usable_mid"] + t["usable_high"]])
srcsum = {s: sum(per.get((s, u), 0) for u in order) for s, _ in SOURCES}
srcA = {s: sum(perA.get((s, u), 0) for u in order) for s, _ in SOURCES}
print(f"๋‹จ์› {len(order)}๊ฐœ -> {OUT}")
print("์ถœ์ฒ˜๋ณ„ A:", srcA, "| ํ•ฉ", sum(srcA.values()))
print("์ถœ์ฒ˜๋ณ„ usable(A+B):", srcsum, "| ํ•ฉ", sum(srcsum.values()))
print("์ฐธ๊ณ : AI Hub ๋Š” DB ์— A ๋งŒ ์ ์žฌ๋จ(B ๋ฏธ์ ์žฌ). EBSi ๋Š” A+B ๋ชจ๋‘ ์ ์žฌ(B ๋Š” ๋ฌธํ•ญ ์ด๋ฏธ์ง€ ํ•จ๊ป˜ ํ‘œ์‹œ).")
empty = [u for u in order if tot[u]["usable_low"] + tot[u]["usable_mid"] + tot[u]["usable_high"] == 0]
print(f"๋ฌธํ•ญ 0๊ฐœ ๋‹จ์› {len(empty)}๊ฐœ:", " ".join(empty))
if __name__ == "__main__":
main()