| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | import base64, json, urllib.request |
| 14 | |
| 15 | def sql(q): |
| 16 | r = urllib.request.Request("http://hzk-surreal:8000/sql", data=q.encode("utf-8")) |
| 17 | r.add_header("Accept", "application/json") |
| 18 | r.add_header("Content-Type", "text/plain; charset=utf-8") |
| 19 | r.add_header("surreal-ns", "hezarfen"); r.add_header("surreal-db", "zeka") |
| 20 | r.add_header("Authorization", "Basic " + base64.b64encode(b"root:root").decode()) |
| 21 | with urllib.request.urlopen(r, timeout=900) as resp: |
| 22 | return json.loads(resp.read().decode("utf-8")) |
| 23 | |
| 24 | subs = {s["id"]: s for s in sql("SELECT id, name, course FROM subject;")[0]["result"]} |
| 25 | crs = {c["id"]: c.get("name") for c in sql("SELECT id, name FROM course;")[0]["result"]} |
| 26 | print("konu: %d | ders: %d" % (len(subs), len(crs))) |
| 27 | |
| 28 | man = json.load(open("/seed/_seed_manifest.json", encoding="utf-8")) |
| 29 | gold = {i["question"]: i for i in man["items"]} |
| 30 | |
| 31 | d = json.load(open("/out/item_dataset.json", encoding="utf-8")) |
| 32 | out, miss = [], 0 |
| 33 | for it in d["items"]: |
| 34 | s = subs.get(it.get("subject")) |
| 35 | g = gold.get(it["question_id"], {}) |
| 36 | if not s: |
| 37 | miss += 1 |
| 38 | mc = g.get("misconception_choice") |
| 39 | trap = g.get("trap_choice") |
| 40 | |
| 41 | mc_text, mc_share, mc_is_key = None, None, None |
| 42 | if isinstance(mc, str): |
| 43 | for dd in it.get("distractor_distribution") or []: |
| 44 | if dd.get("choice_id") == mc: |
| 45 | mc_text = dd.get("text") |
| 46 | mc_share = dd.get("share") |
| 47 | mc_is_key = dd.get("is_key") |
| 48 | break |
| 49 | it2 = dict(it) |
| 50 | it2["subject_name"] = (s or {}).get("name") |
| 51 | it2["course_name"] = crs.get((s or {}).get("course")) |
| 52 | it2["gold"] = { |
| 53 | "misconception_choice_id": mc if isinstance(mc, str) else None, |
| 54 | "misconception_choice_text": mc_text, |
| 55 | "misconception_pick_share": mc_share, |
| 56 | "misconception_is_key": mc_is_key, |
| 57 | "difficulty_band": g.get("difficulty_band"), |
| 58 | "quality_band": g.get("quality_band"), |
| 59 | "irt_a": g.get("a"), "irt_b": g.get("b"), |
| 60 | |
| 61 | |
| 62 | |
| 63 | "dims": g.get("dims"), |
| 64 | "trap_choice_id": trap if isinstance(trap, str) else None, |
| 65 | } |
| 66 | out.append(it2) |
| 67 | |
| 68 | print("konu adi coazulemeyen: %d" % miss) |
| 69 | with open("/out/items_enriched.json", "w", encoding="utf-8") as f: |
| 70 | json.dump({"items": out}, f, ensure_ascii=False) |
| 71 | print("yazildi: /out/items_enriched.json (%d madde)" % len(out)) |
| 72 | has_mc = sum(1 for o in out if o["gold"]["misconception_choice_text"]) |
| 73 | print("altin celdirici metni cozulen: %d" % has_mc) |