| 1 | |
| 2 | import base64, json, time, urllib.request |
| 3 | |
| 4 | def sql(q, db="zeka"): |
| 5 | r = urllib.request.Request("http://hzk-surreal:8000/sql", data=q.encode("utf-8")) |
| 6 | r.add_header("Accept", "application/json") |
| 7 | r.add_header("Content-Type", "text/plain; charset=utf-8") |
| 8 | r.add_header("surreal-ns", "hezarfen"); r.add_header("surreal-db", db) |
| 9 | r.add_header("Authorization", "Basic " + base64.b64encode(b"root:root").decode()) |
| 10 | with urllib.request.urlopen(r, timeout=600) as resp: |
| 11 | return json.loads(resp.read().decode("utf-8")) |
| 12 | |
| 13 | t0 = time.time() |
| 14 | qs = sql("SELECT id, correct, subject, text FROM exam_question WHERE kind = 'choice' LIMIT 400;")[0]["result"] |
| 15 | key = {q["id"]: q.get("correct") for q in qs} |
| 16 | ids = list(key) |
| 17 | print("soru cekildi: %d (%.1fs)" % (len(ids), time.time() - t0)) |
| 18 | |
| 19 | t1 = time.time() |
| 20 | rows = [] |
| 21 | CH = 100 |
| 22 | for i in range(0, len(ids), CH): |
| 23 | part = ids[i:i + CH] |
| 24 | lst = ", ".join(part) |
| 25 | res = sql("SELECT question, selected FROM exam_answer WHERE question IN [%s];" % lst) |
| 26 | rows.extend(res[0]["result"]) |
| 27 | print("cevap cekildi: %d (%.1fs)" % (len(rows), time.time() - t1)) |
| 28 | |
| 29 | agg = {} |
| 30 | for r in rows: |
| 31 | q = r.get("question") |
| 32 | if q is None: |
| 33 | continue |
| 34 | n, c = agg.get(q, (0, 0)) |
| 35 | ok = 1 if r.get("selected") is not None and r.get("selected") == key.get(q) else 0 |
| 36 | agg[q] = (n + 1, c + ok) |
| 37 | |
| 38 | ps = sorted((c / n) for n, c in agg.values() if n >= 10) |
| 39 | if ps: |
| 40 | import statistics |
| 41 | print("p-degeri hesaplanan soru: %d" % len(ps)) |
| 42 | print(" min %.2f | %%25 %.2f | medyan %.2f | %%75 %.2f | max %.2f" |
| 43 | % (ps[0], ps[len(ps)//4], statistics.median(ps), ps[3*len(ps)//4], ps[-1])) |
| 44 | print(" cok zor (p<0.30): %d | cok kolay (p>0.90): %d" |
| 45 | % (sum(1 for p in ps if p < .30), sum(1 for p in ps if p > .90))) |
| 46 | n_per = [n for n, _ in agg.values()] |
| 47 | print(" soru basina gozlem: min %d medyan %d max %d" |
| 48 | % (min(n_per), statistics.median(n_per), max(n_per))) |