birgermoell commited on
Commit
cf66d45
·
verified ·
1 Parent(s): 629f09b

Add 108 offline Harbor tasks for class-test

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. tasks/class-test/class-test-distractors-d1-e0000/environment/Dockerfile +3 -0
  2. tasks/class-test/class-test-distractors-d1-e0000/environment/workdir/distractor_notes.md +7 -0
  3. tasks/class-test/class-test-distractors-d1-e0000/environment/workdir/key.csv +7 -0
  4. tasks/class-test/class-test-distractors-d1-e0000/environment/workdir/responses.csv +57 -0
  5. tasks/class-test/class-test-distractors-d1-e0000/instruction.md +13 -0
  6. tasks/class-test/class-test-distractors-d1-e0000/solution/oracle.py +162 -0
  7. tasks/class-test/class-test-distractors-d1-e0000/solution/solve.sh +4 -0
  8. tasks/class-test/class-test-distractors-d1-e0000/task.toml +25 -0
  9. tasks/class-test/class-test-distractors-d1-e0000/tests/checks.json +143 -0
  10. tasks/class-test/class-test-distractors-d1-e0000/tests/test.sh +3 -0
  11. tasks/class-test/class-test-distractors-d1-e0000/tests/verify.py +116 -0
  12. tasks/class-test/class-test-distractors-d1-e0012/environment/Dockerfile +3 -0
  13. tasks/class-test/class-test-distractors-d1-e0012/environment/workdir/distractor_notes.md +7 -0
  14. tasks/class-test/class-test-distractors-d1-e0012/environment/workdir/key.csv +7 -0
  15. tasks/class-test/class-test-distractors-d1-e0012/environment/workdir/responses.csv +42 -0
  16. tasks/class-test/class-test-distractors-d1-e0012/instruction.md +13 -0
  17. tasks/class-test/class-test-distractors-d1-e0012/solution/oracle.py +162 -0
  18. tasks/class-test/class-test-distractors-d1-e0012/solution/solve.sh +4 -0
  19. tasks/class-test/class-test-distractors-d1-e0012/task.toml +25 -0
  20. tasks/class-test/class-test-distractors-d1-e0012/tests/checks.json +146 -0
  21. tasks/class-test/class-test-distractors-d1-e0012/tests/test.sh +3 -0
  22. tasks/class-test/class-test-distractors-d1-e0012/tests/verify.py +116 -0
  23. tasks/class-test/class-test-distractors-d1-t0000/environment/Dockerfile +3 -0
  24. tasks/class-test/class-test-distractors-d1-t0000/environment/workdir/distractor_notes.md +7 -0
  25. tasks/class-test/class-test-distractors-d1-t0000/environment/workdir/key.csv +7 -0
  26. tasks/class-test/class-test-distractors-d1-t0000/environment/workdir/responses.csv +37 -0
  27. tasks/class-test/class-test-distractors-d1-t0000/instruction.md +13 -0
  28. tasks/class-test/class-test-distractors-d1-t0000/solution/oracle.py +162 -0
  29. tasks/class-test/class-test-distractors-d1-t0000/solution/solve.sh +4 -0
  30. tasks/class-test/class-test-distractors-d1-t0000/task.toml +25 -0
  31. tasks/class-test/class-test-distractors-d1-t0000/tests/checks.json +141 -0
  32. tasks/class-test/class-test-distractors-d1-t0000/tests/test.sh +3 -0
  33. tasks/class-test/class-test-distractors-d1-t0000/tests/verify.py +116 -0
  34. tasks/class-test/class-test-distractors-d1-t0012/environment/Dockerfile +3 -0
  35. tasks/class-test/class-test-distractors-d1-t0012/environment/workdir/distractor_notes.md +7 -0
  36. tasks/class-test/class-test-distractors-d1-t0012/environment/workdir/key.csv +7 -0
  37. tasks/class-test/class-test-distractors-d1-t0012/environment/workdir/responses.csv +57 -0
  38. tasks/class-test/class-test-distractors-d1-t0012/instruction.md +13 -0
  39. tasks/class-test/class-test-distractors-d1-t0012/solution/oracle.py +162 -0
  40. tasks/class-test/class-test-distractors-d1-t0012/solution/solve.sh +4 -0
  41. tasks/class-test/class-test-distractors-d1-t0012/task.toml +25 -0
  42. tasks/class-test/class-test-distractors-d1-t0012/tests/checks.json +143 -0
  43. tasks/class-test/class-test-distractors-d1-t0012/tests/test.sh +3 -0
  44. tasks/class-test/class-test-distractors-d1-t0012/tests/verify.py +116 -0
  45. tasks/class-test/class-test-distractors-d1-t0024/environment/Dockerfile +3 -0
  46. tasks/class-test/class-test-distractors-d1-t0024/environment/workdir/distractor_notes.md +7 -0
  47. tasks/class-test/class-test-distractors-d1-t0024/environment/workdir/key.csv +7 -0
  48. tasks/class-test/class-test-distractors-d1-t0024/environment/workdir/responses.csv +36 -0
  49. tasks/class-test/class-test-distractors-d1-t0024/instruction.md +13 -0
  50. tasks/class-test/class-test-distractors-d1-t0024/solution/oracle.py +162 -0
tasks/class-test/class-test-distractors-d1-e0000/environment/Dockerfile ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ FROM python:3.12-slim
2
+ WORKDIR /app
3
+ COPY workdir/ /app/
tasks/class-test/class-test-distractors-d1-e0000/environment/workdir/distractor_notes.md ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ # Distractor analysis: definitions
2
+
3
+ For each item, the key is the correct option and the other options are its distractors. `N` is the number of students who sat the test.
4
+
5
+ - The count of an option is the number of students who chose it.
6
+ - A distractor is non-functioning if it was chosen by under 5% of the `N` students (count divided by `N` below 0.05).
7
+ - A distractor beats the key if it was chosen by more students than the key was.
tasks/class-test/class-test-distractors-d1-e0000/environment/workdir/key.csv ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ item,key
2
+ Q1,D
3
+ Q2,D
4
+ Q3,B
5
+ Q4,D
6
+ Q5,D
7
+ Q6,A
tasks/class-test/class-test-distractors-d1-e0000/environment/workdir/responses.csv ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ student_id,class,Q1,Q2,Q3,Q4,Q5,Q6
2
+ S004,10P,D,C,B,A,D,C
3
+ S084,10R,A,D,B,A,D,D
4
+ S211,10R,D,D,D,A,D,D
5
+ S370,10Q,D,D,A,B,A,D
6
+ S263,10Q,D,D,B,A,B,A
7
+ S292,10P,D,C,A,C,D,A
8
+ S360,10R,A,D,B,A,D,A
9
+ S251,10R,D,D,C,A,D,A
10
+ S204,10R,D,D,B,C,D,D
11
+ S392,10P,D,D,B,D,B,C
12
+ S277,10P,D,D,B,C,B,A
13
+ S237,10Q,D,D,A,B,D,A
14
+ S107,10R,D,D,A,C,D,C
15
+ S332,10Q,D,D,B,D,D,D
16
+ S055,10Q,D,D,D,D,D,A
17
+ S236,10Q,D,D,B,C,D,A
18
+ S221,10P,D,D,B,A,A,A
19
+ S166,10R,D,C,B,D,A,A
20
+ S165,10P,A,D,A,C,D,C
21
+ S274,10P,A,D,A,A,D,D
22
+ S327,10R,D,D,A,B,D,D
23
+ S005,10Q,D,D,B,A,B,A
24
+ S024,10Q,D,D,A,C,D,D
25
+ S083,10Q,D,D,C,A,B,A
26
+ S153,10R,D,D,B,B,B,A
27
+ S149,10P,D,C,D,C,A,A
28
+ S311,10P,B,D,B,A,D,D
29
+ S152,10Q,A,D,C,D,D,C
30
+ S270,10R,B,D,C,D,D,A
31
+ S361,10Q,D,D,D,C,A,D
32
+ S117,10P,A,C,B,D,D,A
33
+ S290,10Q,D,D,B,A,D,D
34
+ S199,10R,B,D,D,C,D,D
35
+ S247,10P,B,D,B,D,D,D
36
+ S287,10Q,D,D,B,B,A,A
37
+ S337,10Q,D,D,A,D,D,B
38
+ S330,10R,D,D,B,C,D,B
39
+ S378,10Q,D,D,B,B,D,B
40
+ S301,10Q,D,B,B,A,D,D
41
+ S397,10P,D,D,B,A,D,C
42
+ S222,10R,A,A,B,C,D,B
43
+ S123,10P,D,C,B,A,D,D
44
+ S195,10P,D,D,B,D,D,A
45
+ S282,10Q,D,D,D,B,D,D
46
+ S375,10R,D,D,A,A,D,A
47
+ S059,10Q,D,D,B,B,B,A
48
+ S354,10R,A,D,A,A,D,B
49
+ S261,10P,D,D,B,A,D,D
50
+ S350,10P,D,D,B,D,A,A
51
+ S209,10Q,D,D,D,A,D,C
52
+ S235,10R,B,D,D,A,A,A
53
+ S303,10Q,D,D,D,B,D,A
54
+ S284,10Q,D,D,B,A,B,A
55
+ S227,10P,D,D,B,A,D,B
56
+ S275,10P,D,D,D,A,B,D
57
+ S190,10Q,D,D,B,A,B,A
tasks/class-test/class-test-distractors-d1-e0000/instruction.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Class test: distractor analysis
2
+
3
+ `responses.csv` holds the option each student chose on each of the 6 items of a multiple-choice test (three classes, rows in no particular order). `key.csv` gives the correct option of each item. `distractor_notes.md` gives the definitions: follow them exactly. Analyse all classes together.
4
+
5
+ Write `answer.json` in this folder, a JSON object with:
6
+
7
+ - `items`: an object keyed by item (`Q1` to `Q6`). Each value has
8
+ - `counts`: a list of integers, the count of each option in the order A, B, C, D.
9
+ - `non_functioning`: a list of the option letters of the item's non-functioning distractors (any order; an empty list if none).
10
+ - `has_non_functioning`: list of the items that have at least one non-functioning distractor (any order).
11
+ - `key_beaten`: list of the items where at least one distractor beats the key (any order).
12
+
13
+ Numbers are accepted within one unit of the last decimal place asked for.
tasks/class-test/class-test-distractors-d1-e0000/solution/oracle.py ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Reference solution for Class Test. Works only from the files in the current directory."""
3
+ import csv, json, math, os, re
4
+ from decimal import Decimal, ROUND_HALF_UP
5
+ from fractions import Fraction
6
+
7
+ def rows(name):
8
+ with open(name, newline="") as f: return list(csv.DictReader(f))
9
+
10
+ def text(name):
11
+ with open(name) as f: return f.read()
12
+
13
+ def item_cols(row):
14
+ return sorted([c for c in row if re.match(r"^Q\d+$", c)], key=lambda c: int(c[1:]))
15
+
16
+ # ---------------------------------------------------------------- marking
17
+ def marking():
18
+ scheme = text("marking_scheme.md")
19
+ penalty = Fraction(0)
20
+ if "one quarter" in scheme: penalty = Fraction(1, 4)
21
+ elif "one half" in scheme: penalty = Fraction(1, 2)
22
+ bounds = [(g, int(lo)) for g, lo in re.findall(r"^\| ([A-D]) \| (\d+) or more \|", scheme, re.M)]
23
+ bounds.sort(key=lambda b: -b[1])
24
+ key = dict((r["item"], (r["key"].strip(), int(r["marks"]))) for r in rows("answer_key.csv"))
25
+ live = [q for q in key if key[q][0] != "VOID"]
26
+ top = sum(key[q][1] for q in live)
27
+ ans = {"max_marks": top, "students": {}, "grade_u": [], "grade_counts": dict((g, 0) for g in "ABCDU")}
28
+ pcts = []
29
+ for r in rows("answer_sheets.csv"):
30
+ total = Fraction(0)
31
+ for q in live:
32
+ a = r[q].strip()
33
+ if a == "": continue
34
+ if a == key[q][0]: total += key[q][1]
35
+ else: total -= penalty * key[q][1]
36
+ if total < 0: total = Fraction(0)
37
+ pct = total * 100 / top
38
+ grade = "U"
39
+ for g, lo in bounds:
40
+ if pct >= lo:
41
+ grade = g; break
42
+ ans["students"][r["student_id"]] = {"marks": float(total), "percent": round(float(pct), 1), "grade": grade}
43
+ ans["grade_counts"][grade] += 1
44
+ if grade == "U": ans["grade_u"].append(r["student_id"])
45
+ pcts.append(pct)
46
+ ans["mean_percent"] = round(float(sum(pcts) / len(pcts)), 1)
47
+ return ans
48
+
49
+ # ---------------------------------------------------------------- item analysis
50
+ def item_analysis():
51
+ if os.path.exists("scores.csv"):
52
+ data = rows("scores.csv"); items = item_cols(data[0])
53
+ score = dict((r["student_id"], [int(r[q]) for q in items]) for r in data)
54
+ else:
55
+ key = dict((r["item"], r["key"].strip()) for r in rows("key.csv"))
56
+ data = [r for r in rows("responses.csv") if r.get("status", "present") != "absent"]
57
+ items = item_cols(data[0])
58
+ score = dict((r["student_id"], [1 if r[q].strip() == key[q] else 0 for q in items]) for r in data)
59
+ n, k = len(score), len(items)
60
+ total = dict((s, sum(v)) for s, v in score.items())
61
+ order = sorted(score, key=lambda s: s)
62
+ order.sort(key=lambda s: total[s], reverse=True) # stable: equal totals stay in id order
63
+ g = int((Decimal(27) * n / Decimal(100)).quantize(Decimal(1), rounding=ROUND_HALF_UP))
64
+ upper, lower = order[:g], order[n - g:]
65
+ mean_t = sum(total.values()) / n
66
+ var_t = sum((t - mean_t) ** 2 for t in total.values()) / n
67
+ ans = {"n_group": g, "n_students": n, "items": {}, "poor_discrimination": [], "too_easy": [], "too_hard": [], "needs_review": []}
68
+ sum_pq = 0.0
69
+ for j, q in enumerate(items):
70
+ right = [s for s in score if score[s][j] == 1]; wrong = [s for s in score if score[s][j] == 0]
71
+ p = len(right) / n
72
+ disc = (sum(score[s][j] for s in upper) - sum(score[s][j] for s in lower)) / g
73
+ m1 = sum(total[s] for s in right) / len(right); m0 = sum(total[s] for s in wrong) / len(wrong)
74
+ rpb = (m1 - m0) / math.sqrt(var_t) * math.sqrt(p * (1 - p))
75
+ sum_pq += p * (1 - p)
76
+ ans["items"][q] = {"facility": round(p, 3), "discrimination": round(disc, 3), "point_biserial": round(rpb, 3)}
77
+ if disc < 0.20: ans["poor_discrimination"].append(q)
78
+ if p > 0.85: ans["too_easy"].append(q)
79
+ if p < 0.30: ans["too_hard"].append(q)
80
+ if rpb < 0.20: ans["needs_review"].append(q)
81
+ ans["kr20"] = round(k / (k - 1) * (1 - sum_pq / var_t), 3)
82
+ return ans
83
+
84
+ # ---------------------------------------------------------------- distractors
85
+ def distractors():
86
+ keys = rows("key.csv")
87
+ data = [r for r in rows("responses.csv") if r.get("status", "present") != "absent"]
88
+ n = len(data)
89
+ ans = {"items": {}, "has_non_functioning": [], "key_beaten": [], "n_students": n}
90
+ for kr in keys:
91
+ q, key = kr["item"], kr["key"].strip()
92
+ opts = "ABCDE"[:int(kr.get("n_options") or 4)]
93
+ tally = dict((o, 0) for o in opts); omitted = 0
94
+ for r in data:
95
+ a = r[q].strip()
96
+ if a == "": omitted += 1
97
+ else: tally[a] += 1
98
+ dead = [o for o in opts if o != key and Fraction(tally[o], n) < Fraction(5, 100)]
99
+ others = sorted([o for o in opts if o != key], key=lambda o: -tally[o])
100
+ ans["items"][q] = {"counts": [tally[o] for o in opts], "non_functioning": dead, "omitted": omitted,
101
+ "key_pct": round(100.0 * tally[key] / n, 1), "top_distractor": others[0]}
102
+ if dead: ans["has_non_functioning"].append(q)
103
+ if tally[others[0]] > tally[key]: ans["key_beaten"].append(q)
104
+ return ans
105
+
106
+ # ---------------------------------------------------------------- moderation
107
+ def stats(xs):
108
+ m = sum(xs) / len(xs)
109
+ return m, math.sqrt(sum((x - m) ** 2 for x in xs) / len(xs))
110
+
111
+ def moderation():
112
+ notes = text("moderation_notes.md")
113
+ top = float(re.search(r"marked out of (\d+)", notes).group(1))
114
+ tm = float(re.search(r"target mean is (\d+)", notes).group(1))
115
+ ts = float(re.search(r"target standard deviation is (\d+)", notes).group(1))
116
+ def limit(v): return min(top, max(0.0, v))
117
+ if os.path.exists("scripts.csv"):
118
+ tol = float(re.search(r"more than ([\d.]+) marks", notes).group(1))
119
+ scripts = rows("scripts.csv")
120
+ mark = dict((r["student_id"], float(r["mark"])) for r in scripts)
121
+ marker = dict((r["student_id"], r["marker"]) for r in scripts)
122
+ diffs = {}
123
+ for r in rows("moderation_sample.csv"):
124
+ diffs.setdefault(marker[r["student_id"]], []).append(float(r["moderator_mark"]) - mark[r["student_id"]])
125
+ ans = {"markers": {}, "adjusted_markers": [], "students": {}, "clamped": []}
126
+ shift = {}
127
+ for m in sorted(set(marker.values())):
128
+ md = sum(diffs[m]) / len(diffs[m])
129
+ ans["markers"][m] = {"mean_difference": round(md, 2)}
130
+ shift[m] = md if (md > tol or md < -tol) else 0.0
131
+ if shift[m]: ans["adjusted_markers"].append(m)
132
+ adj = dict((s, mark[s] + shift[marker[s]]) for s in mark)
133
+ M, SD = stats(list(adj.values()))
134
+ ans["cohort_mean"], ans["cohort_sd"] = round(M, 2), round(SD, 2)
135
+ for s, x in adj.items():
136
+ v = tm + (x - M) / SD * ts
137
+ ans["students"][s] = {"final": round(limit(v), 1)}
138
+ if v > top or v < 0: ans["clamped"].append(s)
139
+ return ans
140
+ data = rows("marks.csv")
141
+ if "group" not in data[0]:
142
+ xs = [float(r["mark"]) for r in data]
143
+ M, SD = stats(xs)
144
+ return {"raw_mean": round(M, 2), "raw_sd": round(SD, 2),
145
+ "students": dict((r["student_id"], {"scaled": round(tm + (float(r["mark"]) - M) / SD * ts, 1)}) for r in data)}
146
+ ans = {"groups": {}, "students": {}, "clamped": [], "absent": [r["student_id"] for r in data if r["mark"].strip() == ""]}
147
+ present = [r for r in data if r["mark"].strip() != ""]
148
+ for g in sorted(set(r["group"] for r in present)):
149
+ mine = [r for r in present if r["group"] == g]
150
+ M, SD = stats([float(r["mark"]) for r in mine])
151
+ ans["groups"][g] = {"raw_mean": round(M, 2), "raw_sd": round(SD, 2)}
152
+ for r in mine:
153
+ v = tm + (float(r["mark"]) - M) / SD * ts
154
+ ans["students"][r["student_id"]] = {"scaled": round(limit(v), 1)}
155
+ if v > top or v < 0: ans["clamped"].append(r["student_id"])
156
+ return ans
157
+
158
+ if os.path.exists("answer_sheets.csv"): answer = marking()
159
+ elif os.path.exists("item_analysis_notes.md"): answer = item_analysis()
160
+ elif os.path.exists("distractor_notes.md"): answer = distractors()
161
+ else: answer = moderation()
162
+ with open("answer.json", "w") as f: json.dump(answer, f, indent=1)
tasks/class-test/class-test-distractors-d1-e0000/solution/solve.sh ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+ cd /app
4
+ python3 /solution/oracle.py
tasks/class-test/class-test-distractors-d1-e0000/task.toml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version = "1.0"
2
+
3
+ [metadata]
4
+ author_name = "Renaissance Labs"
5
+ author_email = "unknown"
6
+ difficulty = "easy"
7
+ category = "class-test"
8
+ tags = ["class-test", "distractors", "isced-0111", "eval"]
9
+ isced_f = "0111"
10
+ family = "distractors"
11
+ split = "eval"
12
+ seed = 10000
13
+
14
+ [verifier]
15
+ timeout_sec = 120.0
16
+
17
+ [agent]
18
+ timeout_sec = 900.0
19
+
20
+ [environment]
21
+ build_timeout_sec = 600.0
22
+ cpus = 1
23
+ memory_mb = 1024
24
+ storage_mb = 2048
25
+ allow_internet = false
tasks/class-test/class-test-distractors-d1-e0000/tests/checks.json ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "path": "items.Q1.counts",
4
+ "type": "list",
5
+ "value": [
6
+ 8,
7
+ 5,
8
+ 0,
9
+ 43
10
+ ],
11
+ "item": "int",
12
+ "weight": 1.0
13
+ },
14
+ {
15
+ "path": "items.Q1.non_functioning",
16
+ "type": "set",
17
+ "value": [
18
+ "C"
19
+ ],
20
+ "item": "str",
21
+ "weight": 1.0
22
+ },
23
+ {
24
+ "path": "items.Q2.counts",
25
+ "type": "list",
26
+ "value": [
27
+ 1,
28
+ 1,
29
+ 6,
30
+ 48
31
+ ],
32
+ "item": "int",
33
+ "weight": 1.0
34
+ },
35
+ {
36
+ "path": "items.Q2.non_functioning",
37
+ "type": "set",
38
+ "value": [
39
+ "A",
40
+ "B"
41
+ ],
42
+ "item": "str",
43
+ "weight": 1.0
44
+ },
45
+ {
46
+ "path": "items.Q3.counts",
47
+ "type": "list",
48
+ "value": [
49
+ 11,
50
+ 31,
51
+ 4,
52
+ 10
53
+ ],
54
+ "item": "int",
55
+ "weight": 1.0
56
+ },
57
+ {
58
+ "path": "items.Q3.non_functioning",
59
+ "type": "set",
60
+ "value": [],
61
+ "item": "str",
62
+ "weight": 1.0
63
+ },
64
+ {
65
+ "path": "items.Q4.counts",
66
+ "type": "list",
67
+ "value": [
68
+ 24,
69
+ 9,
70
+ 12,
71
+ 11
72
+ ],
73
+ "item": "int",
74
+ "weight": 1.0
75
+ },
76
+ {
77
+ "path": "items.Q4.non_functioning",
78
+ "type": "set",
79
+ "value": [],
80
+ "item": "str",
81
+ "weight": 1.0
82
+ },
83
+ {
84
+ "path": "items.Q5.counts",
85
+ "type": "list",
86
+ "value": [
87
+ 8,
88
+ 10,
89
+ 0,
90
+ 38
91
+ ],
92
+ "item": "int",
93
+ "weight": 1.0
94
+ },
95
+ {
96
+ "path": "items.Q5.non_functioning",
97
+ "type": "set",
98
+ "value": [
99
+ "C"
100
+ ],
101
+ "item": "str",
102
+ "weight": 1.0
103
+ },
104
+ {
105
+ "path": "items.Q6.counts",
106
+ "type": "list",
107
+ "value": [
108
+ 25,
109
+ 6,
110
+ 7,
111
+ 18
112
+ ],
113
+ "item": "int",
114
+ "weight": 1.0
115
+ },
116
+ {
117
+ "path": "items.Q6.non_functioning",
118
+ "type": "set",
119
+ "value": [],
120
+ "item": "str",
121
+ "weight": 1.0
122
+ },
123
+ {
124
+ "path": "has_non_functioning",
125
+ "type": "set",
126
+ "value": [
127
+ "Q1",
128
+ "Q2",
129
+ "Q5"
130
+ ],
131
+ "item": "str",
132
+ "weight": 2
133
+ },
134
+ {
135
+ "path": "key_beaten",
136
+ "type": "set",
137
+ "value": [
138
+ "Q4"
139
+ ],
140
+ "item": "str",
141
+ "weight": 2
142
+ }
143
+ ]
tasks/class-test/class-test-distractors-d1-e0000/tests/test.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #!/bin/bash
2
+ mkdir -p /logs/verifier
3
+ python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt
tasks/class-test/class-test-distractors-d1-e0000/tests/verify.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Verifier for Renaissance Labs practice environments. Standard library only.
3
+
4
+ Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1].
5
+ The reward is the weighted share of checks that pass. A missing, unreadable or non-object
6
+ answer scores 0. Each check addresses one value in the answer by a dotted path.
7
+
8
+ Check types
9
+ int exact integer (a float with integral value is accepted; booleans are not)
10
+ number within abs_tol of value (default 1e-9); booleans and strings are rejected
11
+ str equal after trimming and case-folding
12
+ bool exact boolean
13
+ list ordered list; items compared as int/number/str according to "item" (default str)
14
+ set unordered collection of distinct strings (or ints)
15
+ custom a function in validators.py: name(answer, args) -> bool or float in [0, 1]
16
+ """
17
+ import argparse, json, math, os, sys
18
+
19
+ MISSING = object()
20
+
21
+ def lookup(obj, path):
22
+ cur = obj
23
+ for part in path.split("."):
24
+ if isinstance(cur, dict):
25
+ if part not in cur: return MISSING
26
+ cur = cur[part]
27
+ elif isinstance(cur, list):
28
+ try: cur = cur[int(part)]
29
+ except (ValueError, IndexError): return MISSING
30
+ else:
31
+ return MISSING
32
+ return cur
33
+
34
+ def is_num(x):
35
+ return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x)))
36
+
37
+ def eq_int(got, want):
38
+ return is_num(got) and float(got) == float(int(got)) and int(got) == want
39
+
40
+ def eq_num(got, want, tol):
41
+ return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12
42
+
43
+ def eq_str(got, want):
44
+ return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold()
45
+
46
+ def eq_item(got, want, kind, tol):
47
+ if kind == "int": return eq_int(got, want)
48
+ if kind == "number": return eq_num(got, want, tol)
49
+ return eq_str(got, want)
50
+
51
+ def run_check(answer, chk, validators):
52
+ t = chk["type"]
53
+ if t == "custom":
54
+ fn = getattr(validators, chk["name"], None) if validators else None
55
+ if fn is None: return 0.0
56
+ try: r = fn(answer, chk.get("args", {}))
57
+ except Exception: return 0.0
58
+ if r is True: return 1.0
59
+ if r is False or r is None: return 0.0
60
+ return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0
61
+ got = lookup(answer, chk["path"])
62
+ if got is MISSING: return 0.0
63
+ want, tol = chk["value"], chk.get("abs_tol", 1e-9)
64
+ if t == "int": ok = eq_int(got, want)
65
+ elif t == "number": ok = eq_num(got, want, tol)
66
+ elif t == "str": ok = eq_str(got, want)
67
+ elif t == "bool": ok = isinstance(got, bool) and got is want
68
+ elif t == "list":
69
+ ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want))
70
+ elif t == "set":
71
+ kind = chk.get("item", "str")
72
+ if not isinstance(got, list): ok = False
73
+ else:
74
+ norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None)
75
+ g = [norm(x) for x in got]; w = [norm(x) for x in want]
76
+ ok = None not in g and len(g) == len(set(g)) and set(g) == set(w)
77
+ else: ok = False
78
+ return 1.0 if ok else 0.0
79
+
80
+ def grade(answer, checks, validators=None):
81
+ """Return (reward, details). answer is the parsed JSON, or None if it could not be read."""
82
+ if not isinstance(answer, dict):
83
+ return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks]
84
+ total = sum(c.get("weight", 1.0) for c in checks)
85
+ got, details = 0.0, []
86
+ for c in checks:
87
+ s = run_check(answer, c, validators)
88
+ got += s * c.get("weight", 1.0)
89
+ details.append({"check": c.get("path", c.get("name")), "score": s})
90
+ return (round(got / total, 6) if total else 0.0), details
91
+
92
+ def main():
93
+ ap = argparse.ArgumentParser()
94
+ ap.add_argument("--answer", default="/app/answer.json")
95
+ ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json"))
96
+ ap.add_argument("--out", default="/logs/verifier")
97
+ a = ap.parse_args()
98
+ checks = json.load(open(a.checks))
99
+ try:
100
+ with open(a.answer) as f: answer = json.load(f)
101
+ except Exception:
102
+ answer = None
103
+ validators = None
104
+ here = os.path.dirname(os.path.abspath(__file__))
105
+ if os.path.exists(os.path.join(here, "validators.py")):
106
+ sys.path.insert(0, here)
107
+ import validators # noqa
108
+ reward, details = grade(answer, checks, validators)
109
+ os.makedirs(a.out, exist_ok=True)
110
+ with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward))
111
+ with open(os.path.join(a.out, "reward.json"), "w") as f:
112
+ json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f)
113
+ print("reward", reward)
114
+
115
+ if __name__ == "__main__":
116
+ main()
tasks/class-test/class-test-distractors-d1-e0012/environment/Dockerfile ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ FROM python:3.12-slim
2
+ WORKDIR /app
3
+ COPY workdir/ /app/
tasks/class-test/class-test-distractors-d1-e0012/environment/workdir/distractor_notes.md ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ # Distractor analysis: definitions
2
+
3
+ For each item, the key is the correct option and the other options are its distractors. `N` is the number of students who sat the test.
4
+
5
+ - The count of an option is the number of students who chose it.
6
+ - A distractor is non-functioning if it was chosen by under 5% of the `N` students (count divided by `N` below 0.05).
7
+ - A distractor beats the key if it was chosen by more students than the key was.
tasks/class-test/class-test-distractors-d1-e0012/environment/workdir/key.csv ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ item,key
2
+ Q1,B
3
+ Q2,B
4
+ Q3,C
5
+ Q4,C
6
+ Q5,C
7
+ Q6,C
tasks/class-test/class-test-distractors-d1-e0012/environment/workdir/responses.csv ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ student_id,class,Q1,Q2,Q3,Q4,Q5,Q6
2
+ S384,10Q,A,B,B,C,D,B
3
+ S016,10R,D,C,C,C,A,D
4
+ S219,10P,B,D,C,C,C,D
5
+ S207,10R,B,C,A,C,C,B
6
+ S254,10Q,A,C,C,C,C,B
7
+ S218,10R,A,D,B,D,C,B
8
+ S379,10Q,B,D,C,C,D,A
9
+ S228,10P,B,B,A,C,C,B
10
+ S305,10Q,B,C,C,C,C,B
11
+ S056,10Q,D,C,A,C,C,B
12
+ S240,10R,C,D,A,D,C,C
13
+ S128,10P,B,B,C,C,C,B
14
+ S099,10R,B,B,C,C,C,C
15
+ S088,10P,B,C,C,C,C,B
16
+ S290,10R,D,B,C,C,C,B
17
+ S248,10Q,B,B,C,C,C,A
18
+ S054,10Q,B,C,C,D,C,B
19
+ S268,10R,D,B,B,D,C,B
20
+ S101,10R,B,B,A,D,C,B
21
+ S044,10R,B,B,B,C,C,B
22
+ S257,10Q,B,D,A,C,C,C
23
+ S359,10R,D,B,C,C,A,B
24
+ S235,10Q,B,D,C,D,D,B
25
+ S041,10Q,B,D,C,C,C,C
26
+ S253,10Q,C,B,A,D,D,B
27
+ S279,10Q,B,B,C,D,C,B
28
+ S031,10Q,C,D,C,C,A,B
29
+ S026,10R,B,B,C,C,C,B
30
+ S093,10Q,B,C,C,C,A,B
31
+ S215,10R,C,C,C,C,C,A
32
+ S119,10R,D,B,C,C,C,C
33
+ S315,10R,B,B,C,C,D,D
34
+ S133,10P,D,D,C,C,C,B
35
+ S291,10Q,B,B,C,C,A,B
36
+ S166,10Q,B,B,B,C,C,B
37
+ S300,10P,B,B,C,C,C,B
38
+ S298,10R,B,B,B,C,C,B
39
+ S050,10Q,B,D,C,D,C,B
40
+ S269,10R,B,C,A,C,D,B
41
+ S350,10P,B,C,C,C,D,B
42
+ S169,10Q,C,B,C,C,C,B
tasks/class-test/class-test-distractors-d1-e0012/instruction.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Class test: distractor analysis
2
+
3
+ `responses.csv` holds the option each student chose on each of the 6 items of a multiple-choice test (three classes, rows in no particular order). `key.csv` gives the correct option of each item. `distractor_notes.md` gives the definitions: follow them exactly. Analyse all classes together.
4
+
5
+ Write `answer.json` in this folder, a JSON object with:
6
+
7
+ - `items`: an object keyed by item (`Q1` to `Q6`). Each value has
8
+ - `counts`: a list of integers, the count of each option in the order A, B, C, D.
9
+ - `non_functioning`: a list of the option letters of the item's non-functioning distractors (any order; an empty list if none).
10
+ - `has_non_functioning`: list of the items that have at least one non-functioning distractor (any order).
11
+ - `key_beaten`: list of the items where at least one distractor beats the key (any order).
12
+
13
+ Numbers are accepted within one unit of the last decimal place asked for.
tasks/class-test/class-test-distractors-d1-e0012/solution/oracle.py ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Reference solution for Class Test. Works only from the files in the current directory."""
3
+ import csv, json, math, os, re
4
+ from decimal import Decimal, ROUND_HALF_UP
5
+ from fractions import Fraction
6
+
7
+ def rows(name):
8
+ with open(name, newline="") as f: return list(csv.DictReader(f))
9
+
10
+ def text(name):
11
+ with open(name) as f: return f.read()
12
+
13
+ def item_cols(row):
14
+ return sorted([c for c in row if re.match(r"^Q\d+$", c)], key=lambda c: int(c[1:]))
15
+
16
+ # ---------------------------------------------------------------- marking
17
+ def marking():
18
+ scheme = text("marking_scheme.md")
19
+ penalty = Fraction(0)
20
+ if "one quarter" in scheme: penalty = Fraction(1, 4)
21
+ elif "one half" in scheme: penalty = Fraction(1, 2)
22
+ bounds = [(g, int(lo)) for g, lo in re.findall(r"^\| ([A-D]) \| (\d+) or more \|", scheme, re.M)]
23
+ bounds.sort(key=lambda b: -b[1])
24
+ key = dict((r["item"], (r["key"].strip(), int(r["marks"]))) for r in rows("answer_key.csv"))
25
+ live = [q for q in key if key[q][0] != "VOID"]
26
+ top = sum(key[q][1] for q in live)
27
+ ans = {"max_marks": top, "students": {}, "grade_u": [], "grade_counts": dict((g, 0) for g in "ABCDU")}
28
+ pcts = []
29
+ for r in rows("answer_sheets.csv"):
30
+ total = Fraction(0)
31
+ for q in live:
32
+ a = r[q].strip()
33
+ if a == "": continue
34
+ if a == key[q][0]: total += key[q][1]
35
+ else: total -= penalty * key[q][1]
36
+ if total < 0: total = Fraction(0)
37
+ pct = total * 100 / top
38
+ grade = "U"
39
+ for g, lo in bounds:
40
+ if pct >= lo:
41
+ grade = g; break
42
+ ans["students"][r["student_id"]] = {"marks": float(total), "percent": round(float(pct), 1), "grade": grade}
43
+ ans["grade_counts"][grade] += 1
44
+ if grade == "U": ans["grade_u"].append(r["student_id"])
45
+ pcts.append(pct)
46
+ ans["mean_percent"] = round(float(sum(pcts) / len(pcts)), 1)
47
+ return ans
48
+
49
+ # ---------------------------------------------------------------- item analysis
50
+ def item_analysis():
51
+ if os.path.exists("scores.csv"):
52
+ data = rows("scores.csv"); items = item_cols(data[0])
53
+ score = dict((r["student_id"], [int(r[q]) for q in items]) for r in data)
54
+ else:
55
+ key = dict((r["item"], r["key"].strip()) for r in rows("key.csv"))
56
+ data = [r for r in rows("responses.csv") if r.get("status", "present") != "absent"]
57
+ items = item_cols(data[0])
58
+ score = dict((r["student_id"], [1 if r[q].strip() == key[q] else 0 for q in items]) for r in data)
59
+ n, k = len(score), len(items)
60
+ total = dict((s, sum(v)) for s, v in score.items())
61
+ order = sorted(score, key=lambda s: s)
62
+ order.sort(key=lambda s: total[s], reverse=True) # stable: equal totals stay in id order
63
+ g = int((Decimal(27) * n / Decimal(100)).quantize(Decimal(1), rounding=ROUND_HALF_UP))
64
+ upper, lower = order[:g], order[n - g:]
65
+ mean_t = sum(total.values()) / n
66
+ var_t = sum((t - mean_t) ** 2 for t in total.values()) / n
67
+ ans = {"n_group": g, "n_students": n, "items": {}, "poor_discrimination": [], "too_easy": [], "too_hard": [], "needs_review": []}
68
+ sum_pq = 0.0
69
+ for j, q in enumerate(items):
70
+ right = [s for s in score if score[s][j] == 1]; wrong = [s for s in score if score[s][j] == 0]
71
+ p = len(right) / n
72
+ disc = (sum(score[s][j] for s in upper) - sum(score[s][j] for s in lower)) / g
73
+ m1 = sum(total[s] for s in right) / len(right); m0 = sum(total[s] for s in wrong) / len(wrong)
74
+ rpb = (m1 - m0) / math.sqrt(var_t) * math.sqrt(p * (1 - p))
75
+ sum_pq += p * (1 - p)
76
+ ans["items"][q] = {"facility": round(p, 3), "discrimination": round(disc, 3), "point_biserial": round(rpb, 3)}
77
+ if disc < 0.20: ans["poor_discrimination"].append(q)
78
+ if p > 0.85: ans["too_easy"].append(q)
79
+ if p < 0.30: ans["too_hard"].append(q)
80
+ if rpb < 0.20: ans["needs_review"].append(q)
81
+ ans["kr20"] = round(k / (k - 1) * (1 - sum_pq / var_t), 3)
82
+ return ans
83
+
84
+ # ---------------------------------------------------------------- distractors
85
+ def distractors():
86
+ keys = rows("key.csv")
87
+ data = [r for r in rows("responses.csv") if r.get("status", "present") != "absent"]
88
+ n = len(data)
89
+ ans = {"items": {}, "has_non_functioning": [], "key_beaten": [], "n_students": n}
90
+ for kr in keys:
91
+ q, key = kr["item"], kr["key"].strip()
92
+ opts = "ABCDE"[:int(kr.get("n_options") or 4)]
93
+ tally = dict((o, 0) for o in opts); omitted = 0
94
+ for r in data:
95
+ a = r[q].strip()
96
+ if a == "": omitted += 1
97
+ else: tally[a] += 1
98
+ dead = [o for o in opts if o != key and Fraction(tally[o], n) < Fraction(5, 100)]
99
+ others = sorted([o for o in opts if o != key], key=lambda o: -tally[o])
100
+ ans["items"][q] = {"counts": [tally[o] for o in opts], "non_functioning": dead, "omitted": omitted,
101
+ "key_pct": round(100.0 * tally[key] / n, 1), "top_distractor": others[0]}
102
+ if dead: ans["has_non_functioning"].append(q)
103
+ if tally[others[0]] > tally[key]: ans["key_beaten"].append(q)
104
+ return ans
105
+
106
+ # ---------------------------------------------------------------- moderation
107
+ def stats(xs):
108
+ m = sum(xs) / len(xs)
109
+ return m, math.sqrt(sum((x - m) ** 2 for x in xs) / len(xs))
110
+
111
+ def moderation():
112
+ notes = text("moderation_notes.md")
113
+ top = float(re.search(r"marked out of (\d+)", notes).group(1))
114
+ tm = float(re.search(r"target mean is (\d+)", notes).group(1))
115
+ ts = float(re.search(r"target standard deviation is (\d+)", notes).group(1))
116
+ def limit(v): return min(top, max(0.0, v))
117
+ if os.path.exists("scripts.csv"):
118
+ tol = float(re.search(r"more than ([\d.]+) marks", notes).group(1))
119
+ scripts = rows("scripts.csv")
120
+ mark = dict((r["student_id"], float(r["mark"])) for r in scripts)
121
+ marker = dict((r["student_id"], r["marker"]) for r in scripts)
122
+ diffs = {}
123
+ for r in rows("moderation_sample.csv"):
124
+ diffs.setdefault(marker[r["student_id"]], []).append(float(r["moderator_mark"]) - mark[r["student_id"]])
125
+ ans = {"markers": {}, "adjusted_markers": [], "students": {}, "clamped": []}
126
+ shift = {}
127
+ for m in sorted(set(marker.values())):
128
+ md = sum(diffs[m]) / len(diffs[m])
129
+ ans["markers"][m] = {"mean_difference": round(md, 2)}
130
+ shift[m] = md if (md > tol or md < -tol) else 0.0
131
+ if shift[m]: ans["adjusted_markers"].append(m)
132
+ adj = dict((s, mark[s] + shift[marker[s]]) for s in mark)
133
+ M, SD = stats(list(adj.values()))
134
+ ans["cohort_mean"], ans["cohort_sd"] = round(M, 2), round(SD, 2)
135
+ for s, x in adj.items():
136
+ v = tm + (x - M) / SD * ts
137
+ ans["students"][s] = {"final": round(limit(v), 1)}
138
+ if v > top or v < 0: ans["clamped"].append(s)
139
+ return ans
140
+ data = rows("marks.csv")
141
+ if "group" not in data[0]:
142
+ xs = [float(r["mark"]) for r in data]
143
+ M, SD = stats(xs)
144
+ return {"raw_mean": round(M, 2), "raw_sd": round(SD, 2),
145
+ "students": dict((r["student_id"], {"scaled": round(tm + (float(r["mark"]) - M) / SD * ts, 1)}) for r in data)}
146
+ ans = {"groups": {}, "students": {}, "clamped": [], "absent": [r["student_id"] for r in data if r["mark"].strip() == ""]}
147
+ present = [r for r in data if r["mark"].strip() != ""]
148
+ for g in sorted(set(r["group"] for r in present)):
149
+ mine = [r for r in present if r["group"] == g]
150
+ M, SD = stats([float(r["mark"]) for r in mine])
151
+ ans["groups"][g] = {"raw_mean": round(M, 2), "raw_sd": round(SD, 2)}
152
+ for r in mine:
153
+ v = tm + (float(r["mark"]) - M) / SD * ts
154
+ ans["students"][r["student_id"]] = {"scaled": round(limit(v), 1)}
155
+ if v > top or v < 0: ans["clamped"].append(r["student_id"])
156
+ return ans
157
+
158
+ if os.path.exists("answer_sheets.csv"): answer = marking()
159
+ elif os.path.exists("item_analysis_notes.md"): answer = item_analysis()
160
+ elif os.path.exists("distractor_notes.md"): answer = distractors()
161
+ else: answer = moderation()
162
+ with open("answer.json", "w") as f: json.dump(answer, f, indent=1)
tasks/class-test/class-test-distractors-d1-e0012/solution/solve.sh ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+ cd /app
4
+ python3 /solution/oracle.py
tasks/class-test/class-test-distractors-d1-e0012/task.toml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version = "1.0"
2
+
3
+ [metadata]
4
+ author_name = "Renaissance Labs"
5
+ author_email = "unknown"
6
+ difficulty = "easy"
7
+ category = "class-test"
8
+ tags = ["class-test", "distractors", "isced-0111", "eval"]
9
+ isced_f = "0111"
10
+ family = "distractors"
11
+ split = "eval"
12
+ seed = 10012
13
+
14
+ [verifier]
15
+ timeout_sec = 120.0
16
+
17
+ [agent]
18
+ timeout_sec = 900.0
19
+
20
+ [environment]
21
+ build_timeout_sec = 600.0
22
+ cpus = 1
23
+ memory_mb = 1024
24
+ storage_mb = 2048
25
+ allow_internet = false
tasks/class-test/class-test-distractors-d1-e0012/tests/checks.json ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "path": "items.Q1.counts",
4
+ "type": "list",
5
+ "value": [
6
+ 3,
7
+ 26,
8
+ 5,
9
+ 7
10
+ ],
11
+ "item": "int",
12
+ "weight": 1.0
13
+ },
14
+ {
15
+ "path": "items.Q1.non_functioning",
16
+ "type": "set",
17
+ "value": [],
18
+ "item": "str",
19
+ "weight": 1.0
20
+ },
21
+ {
22
+ "path": "items.Q2.counts",
23
+ "type": "list",
24
+ "value": [
25
+ 0,
26
+ 20,
27
+ 11,
28
+ 10
29
+ ],
30
+ "item": "int",
31
+ "weight": 1.0
32
+ },
33
+ {
34
+ "path": "items.Q2.non_functioning",
35
+ "type": "set",
36
+ "value": [
37
+ "A"
38
+ ],
39
+ "item": "str",
40
+ "weight": 1.0
41
+ },
42
+ {
43
+ "path": "items.Q3.counts",
44
+ "type": "list",
45
+ "value": [
46
+ 8,
47
+ 6,
48
+ 27,
49
+ 0
50
+ ],
51
+ "item": "int",
52
+ "weight": 1.0
53
+ },
54
+ {
55
+ "path": "items.Q3.non_functioning",
56
+ "type": "set",
57
+ "value": [
58
+ "D"
59
+ ],
60
+ "item": "str",
61
+ "weight": 1.0
62
+ },
63
+ {
64
+ "path": "items.Q4.counts",
65
+ "type": "list",
66
+ "value": [
67
+ 0,
68
+ 0,
69
+ 32,
70
+ 9
71
+ ],
72
+ "item": "int",
73
+ "weight": 1.0
74
+ },
75
+ {
76
+ "path": "items.Q4.non_functioning",
77
+ "type": "set",
78
+ "value": [
79
+ "A",
80
+ "B"
81
+ ],
82
+ "item": "str",
83
+ "weight": 1.0
84
+ },
85
+ {
86
+ "path": "items.Q5.counts",
87
+ "type": "list",
88
+ "value": [
89
+ 5,
90
+ 0,
91
+ 29,
92
+ 7
93
+ ],
94
+ "item": "int",
95
+ "weight": 1.0
96
+ },
97
+ {
98
+ "path": "items.Q5.non_functioning",
99
+ "type": "set",
100
+ "value": [
101
+ "B"
102
+ ],
103
+ "item": "str",
104
+ "weight": 1.0
105
+ },
106
+ {
107
+ "path": "items.Q6.counts",
108
+ "type": "list",
109
+ "value": [
110
+ 3,
111
+ 30,
112
+ 5,
113
+ 3
114
+ ],
115
+ "item": "int",
116
+ "weight": 1.0
117
+ },
118
+ {
119
+ "path": "items.Q6.non_functioning",
120
+ "type": "set",
121
+ "value": [],
122
+ "item": "str",
123
+ "weight": 1.0
124
+ },
125
+ {
126
+ "path": "has_non_functioning",
127
+ "type": "set",
128
+ "value": [
129
+ "Q2",
130
+ "Q3",
131
+ "Q4",
132
+ "Q5"
133
+ ],
134
+ "item": "str",
135
+ "weight": 2
136
+ },
137
+ {
138
+ "path": "key_beaten",
139
+ "type": "set",
140
+ "value": [
141
+ "Q6"
142
+ ],
143
+ "item": "str",
144
+ "weight": 2
145
+ }
146
+ ]
tasks/class-test/class-test-distractors-d1-e0012/tests/test.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #!/bin/bash
2
+ mkdir -p /logs/verifier
3
+ python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt
tasks/class-test/class-test-distractors-d1-e0012/tests/verify.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Verifier for Renaissance Labs practice environments. Standard library only.
3
+
4
+ Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1].
5
+ The reward is the weighted share of checks that pass. A missing, unreadable or non-object
6
+ answer scores 0. Each check addresses one value in the answer by a dotted path.
7
+
8
+ Check types
9
+ int exact integer (a float with integral value is accepted; booleans are not)
10
+ number within abs_tol of value (default 1e-9); booleans and strings are rejected
11
+ str equal after trimming and case-folding
12
+ bool exact boolean
13
+ list ordered list; items compared as int/number/str according to "item" (default str)
14
+ set unordered collection of distinct strings (or ints)
15
+ custom a function in validators.py: name(answer, args) -> bool or float in [0, 1]
16
+ """
17
+ import argparse, json, math, os, sys
18
+
19
+ MISSING = object()
20
+
21
+ def lookup(obj, path):
22
+ cur = obj
23
+ for part in path.split("."):
24
+ if isinstance(cur, dict):
25
+ if part not in cur: return MISSING
26
+ cur = cur[part]
27
+ elif isinstance(cur, list):
28
+ try: cur = cur[int(part)]
29
+ except (ValueError, IndexError): return MISSING
30
+ else:
31
+ return MISSING
32
+ return cur
33
+
34
+ def is_num(x):
35
+ return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x)))
36
+
37
+ def eq_int(got, want):
38
+ return is_num(got) and float(got) == float(int(got)) and int(got) == want
39
+
40
+ def eq_num(got, want, tol):
41
+ return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12
42
+
43
+ def eq_str(got, want):
44
+ return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold()
45
+
46
+ def eq_item(got, want, kind, tol):
47
+ if kind == "int": return eq_int(got, want)
48
+ if kind == "number": return eq_num(got, want, tol)
49
+ return eq_str(got, want)
50
+
51
+ def run_check(answer, chk, validators):
52
+ t = chk["type"]
53
+ if t == "custom":
54
+ fn = getattr(validators, chk["name"], None) if validators else None
55
+ if fn is None: return 0.0
56
+ try: r = fn(answer, chk.get("args", {}))
57
+ except Exception: return 0.0
58
+ if r is True: return 1.0
59
+ if r is False or r is None: return 0.0
60
+ return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0
61
+ got = lookup(answer, chk["path"])
62
+ if got is MISSING: return 0.0
63
+ want, tol = chk["value"], chk.get("abs_tol", 1e-9)
64
+ if t == "int": ok = eq_int(got, want)
65
+ elif t == "number": ok = eq_num(got, want, tol)
66
+ elif t == "str": ok = eq_str(got, want)
67
+ elif t == "bool": ok = isinstance(got, bool) and got is want
68
+ elif t == "list":
69
+ ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want))
70
+ elif t == "set":
71
+ kind = chk.get("item", "str")
72
+ if not isinstance(got, list): ok = False
73
+ else:
74
+ norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None)
75
+ g = [norm(x) for x in got]; w = [norm(x) for x in want]
76
+ ok = None not in g and len(g) == len(set(g)) and set(g) == set(w)
77
+ else: ok = False
78
+ return 1.0 if ok else 0.0
79
+
80
+ def grade(answer, checks, validators=None):
81
+ """Return (reward, details). answer is the parsed JSON, or None if it could not be read."""
82
+ if not isinstance(answer, dict):
83
+ return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks]
84
+ total = sum(c.get("weight", 1.0) for c in checks)
85
+ got, details = 0.0, []
86
+ for c in checks:
87
+ s = run_check(answer, c, validators)
88
+ got += s * c.get("weight", 1.0)
89
+ details.append({"check": c.get("path", c.get("name")), "score": s})
90
+ return (round(got / total, 6) if total else 0.0), details
91
+
92
+ def main():
93
+ ap = argparse.ArgumentParser()
94
+ ap.add_argument("--answer", default="/app/answer.json")
95
+ ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json"))
96
+ ap.add_argument("--out", default="/logs/verifier")
97
+ a = ap.parse_args()
98
+ checks = json.load(open(a.checks))
99
+ try:
100
+ with open(a.answer) as f: answer = json.load(f)
101
+ except Exception:
102
+ answer = None
103
+ validators = None
104
+ here = os.path.dirname(os.path.abspath(__file__))
105
+ if os.path.exists(os.path.join(here, "validators.py")):
106
+ sys.path.insert(0, here)
107
+ import validators # noqa
108
+ reward, details = grade(answer, checks, validators)
109
+ os.makedirs(a.out, exist_ok=True)
110
+ with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward))
111
+ with open(os.path.join(a.out, "reward.json"), "w") as f:
112
+ json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f)
113
+ print("reward", reward)
114
+
115
+ if __name__ == "__main__":
116
+ main()
tasks/class-test/class-test-distractors-d1-t0000/environment/Dockerfile ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ FROM python:3.12-slim
2
+ WORKDIR /app
3
+ COPY workdir/ /app/
tasks/class-test/class-test-distractors-d1-t0000/environment/workdir/distractor_notes.md ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ # Distractor analysis: definitions
2
+
3
+ For each item, the key is the correct option and the other options are its distractors. `N` is the number of students who sat the test.
4
+
5
+ - The count of an option is the number of students who chose it.
6
+ - A distractor is non-functioning if it was chosen by under 5% of the `N` students (count divided by `N` below 0.05).
7
+ - A distractor beats the key if it was chosen by more students than the key was.
tasks/class-test/class-test-distractors-d1-t0000/environment/workdir/key.csv ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ item,key
2
+ Q1,D
3
+ Q2,B
4
+ Q3,D
5
+ Q4,C
6
+ Q5,D
7
+ Q6,C
tasks/class-test/class-test-distractors-d1-t0000/environment/workdir/responses.csv ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ student_id,class,Q1,Q2,Q3,Q4,Q5,Q6
2
+ S144,10Q,C,C,C,C,D,A
3
+ S077,10R,D,B,A,C,D,A
4
+ S096,10Q,D,C,D,C,B,C
5
+ S180,10P,D,D,D,B,D,B
6
+ S117,10Q,C,B,A,B,B,B
7
+ S133,10R,D,D,A,C,D,B
8
+ S234,10P,C,B,D,A,B,C
9
+ S205,10R,D,C,C,C,D,C
10
+ S021,10Q,D,B,D,C,D,B
11
+ S286,10Q,C,B,C,A,A,C
12
+ S092,10Q,D,C,D,B,D,B
13
+ S216,10P,D,C,A,C,D,D
14
+ S389,10R,C,D,D,C,D,D
15
+ S068,10Q,C,A,B,C,D,B
16
+ S113,10R,A,A,A,C,D,B
17
+ S228,10P,C,D,A,B,A,B
18
+ S184,10Q,C,C,B,D,D,A
19
+ S100,10R,D,B,A,C,D,B
20
+ S162,10P,D,B,D,B,D,B
21
+ S055,10Q,D,C,D,C,D,B
22
+ S146,10P,D,C,D,D,D,D
23
+ S264,10Q,A,D,A,D,A,B
24
+ S089,10Q,C,B,A,A,D,C
25
+ S305,10P,D,B,A,C,D,B
26
+ S321,10P,D,B,A,C,D,A
27
+ S095,10Q,C,D,A,C,D,D
28
+ S209,10R,D,C,D,C,D,A
29
+ S231,10P,C,D,B,C,D,C
30
+ S172,10P,D,C,D,B,A,D
31
+ S185,10P,D,C,D,C,B,B
32
+ S255,10P,C,C,D,D,D,B
33
+ S087,10Q,C,C,B,D,D,B
34
+ S342,10P,D,D,C,C,B,D
35
+ S140,10Q,A,C,A,C,D,C
36
+ S062,10P,A,B,B,C,A,C
37
+ S147,10Q,C,C,A,B,D,A
tasks/class-test/class-test-distractors-d1-t0000/instruction.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Class test: distractor analysis
2
+
3
+ `responses.csv` holds the option each student chose on each of the 6 items of a multiple-choice test (three classes, rows in no particular order). `key.csv` gives the correct option of each item. `distractor_notes.md` gives the definitions: follow them exactly. Analyse all classes together.
4
+
5
+ Write `answer.json` in this folder, a JSON object with:
6
+
7
+ - `items`: an object keyed by item (`Q1` to `Q6`). Each value has
8
+ - `counts`: a list of integers, the count of each option in the order A, B, C, D.
9
+ - `non_functioning`: a list of the option letters of the item's non-functioning distractors (any order; an empty list if none).
10
+ - `has_non_functioning`: list of the items that have at least one non-functioning distractor (any order).
11
+ - `key_beaten`: list of the items where at least one distractor beats the key (any order).
12
+
13
+ Numbers are accepted within one unit of the last decimal place asked for.
tasks/class-test/class-test-distractors-d1-t0000/solution/oracle.py ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Reference solution for Class Test. Works only from the files in the current directory."""
3
+ import csv, json, math, os, re
4
+ from decimal import Decimal, ROUND_HALF_UP
5
+ from fractions import Fraction
6
+
7
+ def rows(name):
8
+ with open(name, newline="") as f: return list(csv.DictReader(f))
9
+
10
+ def text(name):
11
+ with open(name) as f: return f.read()
12
+
13
+ def item_cols(row):
14
+ return sorted([c for c in row if re.match(r"^Q\d+$", c)], key=lambda c: int(c[1:]))
15
+
16
+ # ---------------------------------------------------------------- marking
17
+ def marking():
18
+ scheme = text("marking_scheme.md")
19
+ penalty = Fraction(0)
20
+ if "one quarter" in scheme: penalty = Fraction(1, 4)
21
+ elif "one half" in scheme: penalty = Fraction(1, 2)
22
+ bounds = [(g, int(lo)) for g, lo in re.findall(r"^\| ([A-D]) \| (\d+) or more \|", scheme, re.M)]
23
+ bounds.sort(key=lambda b: -b[1])
24
+ key = dict((r["item"], (r["key"].strip(), int(r["marks"]))) for r in rows("answer_key.csv"))
25
+ live = [q for q in key if key[q][0] != "VOID"]
26
+ top = sum(key[q][1] for q in live)
27
+ ans = {"max_marks": top, "students": {}, "grade_u": [], "grade_counts": dict((g, 0) for g in "ABCDU")}
28
+ pcts = []
29
+ for r in rows("answer_sheets.csv"):
30
+ total = Fraction(0)
31
+ for q in live:
32
+ a = r[q].strip()
33
+ if a == "": continue
34
+ if a == key[q][0]: total += key[q][1]
35
+ else: total -= penalty * key[q][1]
36
+ if total < 0: total = Fraction(0)
37
+ pct = total * 100 / top
38
+ grade = "U"
39
+ for g, lo in bounds:
40
+ if pct >= lo:
41
+ grade = g; break
42
+ ans["students"][r["student_id"]] = {"marks": float(total), "percent": round(float(pct), 1), "grade": grade}
43
+ ans["grade_counts"][grade] += 1
44
+ if grade == "U": ans["grade_u"].append(r["student_id"])
45
+ pcts.append(pct)
46
+ ans["mean_percent"] = round(float(sum(pcts) / len(pcts)), 1)
47
+ return ans
48
+
49
+ # ---------------------------------------------------------------- item analysis
50
+ def item_analysis():
51
+ if os.path.exists("scores.csv"):
52
+ data = rows("scores.csv"); items = item_cols(data[0])
53
+ score = dict((r["student_id"], [int(r[q]) for q in items]) for r in data)
54
+ else:
55
+ key = dict((r["item"], r["key"].strip()) for r in rows("key.csv"))
56
+ data = [r for r in rows("responses.csv") if r.get("status", "present") != "absent"]
57
+ items = item_cols(data[0])
58
+ score = dict((r["student_id"], [1 if r[q].strip() == key[q] else 0 for q in items]) for r in data)
59
+ n, k = len(score), len(items)
60
+ total = dict((s, sum(v)) for s, v in score.items())
61
+ order = sorted(score, key=lambda s: s)
62
+ order.sort(key=lambda s: total[s], reverse=True) # stable: equal totals stay in id order
63
+ g = int((Decimal(27) * n / Decimal(100)).quantize(Decimal(1), rounding=ROUND_HALF_UP))
64
+ upper, lower = order[:g], order[n - g:]
65
+ mean_t = sum(total.values()) / n
66
+ var_t = sum((t - mean_t) ** 2 for t in total.values()) / n
67
+ ans = {"n_group": g, "n_students": n, "items": {}, "poor_discrimination": [], "too_easy": [], "too_hard": [], "needs_review": []}
68
+ sum_pq = 0.0
69
+ for j, q in enumerate(items):
70
+ right = [s for s in score if score[s][j] == 1]; wrong = [s for s in score if score[s][j] == 0]
71
+ p = len(right) / n
72
+ disc = (sum(score[s][j] for s in upper) - sum(score[s][j] for s in lower)) / g
73
+ m1 = sum(total[s] for s in right) / len(right); m0 = sum(total[s] for s in wrong) / len(wrong)
74
+ rpb = (m1 - m0) / math.sqrt(var_t) * math.sqrt(p * (1 - p))
75
+ sum_pq += p * (1 - p)
76
+ ans["items"][q] = {"facility": round(p, 3), "discrimination": round(disc, 3), "point_biserial": round(rpb, 3)}
77
+ if disc < 0.20: ans["poor_discrimination"].append(q)
78
+ if p > 0.85: ans["too_easy"].append(q)
79
+ if p < 0.30: ans["too_hard"].append(q)
80
+ if rpb < 0.20: ans["needs_review"].append(q)
81
+ ans["kr20"] = round(k / (k - 1) * (1 - sum_pq / var_t), 3)
82
+ return ans
83
+
84
+ # ---------------------------------------------------------------- distractors
85
+ def distractors():
86
+ keys = rows("key.csv")
87
+ data = [r for r in rows("responses.csv") if r.get("status", "present") != "absent"]
88
+ n = len(data)
89
+ ans = {"items": {}, "has_non_functioning": [], "key_beaten": [], "n_students": n}
90
+ for kr in keys:
91
+ q, key = kr["item"], kr["key"].strip()
92
+ opts = "ABCDE"[:int(kr.get("n_options") or 4)]
93
+ tally = dict((o, 0) for o in opts); omitted = 0
94
+ for r in data:
95
+ a = r[q].strip()
96
+ if a == "": omitted += 1
97
+ else: tally[a] += 1
98
+ dead = [o for o in opts if o != key and Fraction(tally[o], n) < Fraction(5, 100)]
99
+ others = sorted([o for o in opts if o != key], key=lambda o: -tally[o])
100
+ ans["items"][q] = {"counts": [tally[o] for o in opts], "non_functioning": dead, "omitted": omitted,
101
+ "key_pct": round(100.0 * tally[key] / n, 1), "top_distractor": others[0]}
102
+ if dead: ans["has_non_functioning"].append(q)
103
+ if tally[others[0]] > tally[key]: ans["key_beaten"].append(q)
104
+ return ans
105
+
106
+ # ---------------------------------------------------------------- moderation
107
+ def stats(xs):
108
+ m = sum(xs) / len(xs)
109
+ return m, math.sqrt(sum((x - m) ** 2 for x in xs) / len(xs))
110
+
111
+ def moderation():
112
+ notes = text("moderation_notes.md")
113
+ top = float(re.search(r"marked out of (\d+)", notes).group(1))
114
+ tm = float(re.search(r"target mean is (\d+)", notes).group(1))
115
+ ts = float(re.search(r"target standard deviation is (\d+)", notes).group(1))
116
+ def limit(v): return min(top, max(0.0, v))
117
+ if os.path.exists("scripts.csv"):
118
+ tol = float(re.search(r"more than ([\d.]+) marks", notes).group(1))
119
+ scripts = rows("scripts.csv")
120
+ mark = dict((r["student_id"], float(r["mark"])) for r in scripts)
121
+ marker = dict((r["student_id"], r["marker"]) for r in scripts)
122
+ diffs = {}
123
+ for r in rows("moderation_sample.csv"):
124
+ diffs.setdefault(marker[r["student_id"]], []).append(float(r["moderator_mark"]) - mark[r["student_id"]])
125
+ ans = {"markers": {}, "adjusted_markers": [], "students": {}, "clamped": []}
126
+ shift = {}
127
+ for m in sorted(set(marker.values())):
128
+ md = sum(diffs[m]) / len(diffs[m])
129
+ ans["markers"][m] = {"mean_difference": round(md, 2)}
130
+ shift[m] = md if (md > tol or md < -tol) else 0.0
131
+ if shift[m]: ans["adjusted_markers"].append(m)
132
+ adj = dict((s, mark[s] + shift[marker[s]]) for s in mark)
133
+ M, SD = stats(list(adj.values()))
134
+ ans["cohort_mean"], ans["cohort_sd"] = round(M, 2), round(SD, 2)
135
+ for s, x in adj.items():
136
+ v = tm + (x - M) / SD * ts
137
+ ans["students"][s] = {"final": round(limit(v), 1)}
138
+ if v > top or v < 0: ans["clamped"].append(s)
139
+ return ans
140
+ data = rows("marks.csv")
141
+ if "group" not in data[0]:
142
+ xs = [float(r["mark"]) for r in data]
143
+ M, SD = stats(xs)
144
+ return {"raw_mean": round(M, 2), "raw_sd": round(SD, 2),
145
+ "students": dict((r["student_id"], {"scaled": round(tm + (float(r["mark"]) - M) / SD * ts, 1)}) for r in data)}
146
+ ans = {"groups": {}, "students": {}, "clamped": [], "absent": [r["student_id"] for r in data if r["mark"].strip() == ""]}
147
+ present = [r for r in data if r["mark"].strip() != ""]
148
+ for g in sorted(set(r["group"] for r in present)):
149
+ mine = [r for r in present if r["group"] == g]
150
+ M, SD = stats([float(r["mark"]) for r in mine])
151
+ ans["groups"][g] = {"raw_mean": round(M, 2), "raw_sd": round(SD, 2)}
152
+ for r in mine:
153
+ v = tm + (float(r["mark"]) - M) / SD * ts
154
+ ans["students"][r["student_id"]] = {"scaled": round(limit(v), 1)}
155
+ if v > top or v < 0: ans["clamped"].append(r["student_id"])
156
+ return ans
157
+
158
+ if os.path.exists("answer_sheets.csv"): answer = marking()
159
+ elif os.path.exists("item_analysis_notes.md"): answer = item_analysis()
160
+ elif os.path.exists("distractor_notes.md"): answer = distractors()
161
+ else: answer = moderation()
162
+ with open("answer.json", "w") as f: json.dump(answer, f, indent=1)
tasks/class-test/class-test-distractors-d1-t0000/solution/solve.sh ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+ cd /app
4
+ python3 /solution/oracle.py
tasks/class-test/class-test-distractors-d1-t0000/task.toml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version = "1.0"
2
+
3
+ [metadata]
4
+ author_name = "Renaissance Labs"
5
+ author_email = "unknown"
6
+ difficulty = "easy"
7
+ category = "class-test"
8
+ tags = ["class-test", "distractors", "isced-0111", "train"]
9
+ isced_f = "0111"
10
+ family = "distractors"
11
+ split = "train"
12
+ seed = 0
13
+
14
+ [verifier]
15
+ timeout_sec = 120.0
16
+
17
+ [agent]
18
+ timeout_sec = 900.0
19
+
20
+ [environment]
21
+ build_timeout_sec = 600.0
22
+ cpus = 1
23
+ memory_mb = 1024
24
+ storage_mb = 2048
25
+ allow_internet = false
tasks/class-test/class-test-distractors-d1-t0000/tests/checks.json ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "path": "items.Q1.counts",
4
+ "type": "list",
5
+ "value": [
6
+ 4,
7
+ 0,
8
+ 14,
9
+ 18
10
+ ],
11
+ "item": "int",
12
+ "weight": 1.0
13
+ },
14
+ {
15
+ "path": "items.Q1.non_functioning",
16
+ "type": "set",
17
+ "value": [
18
+ "B"
19
+ ],
20
+ "item": "str",
21
+ "weight": 1.0
22
+ },
23
+ {
24
+ "path": "items.Q2.counts",
25
+ "type": "list",
26
+ "value": [
27
+ 2,
28
+ 11,
29
+ 15,
30
+ 8
31
+ ],
32
+ "item": "int",
33
+ "weight": 1.0
34
+ },
35
+ {
36
+ "path": "items.Q2.non_functioning",
37
+ "type": "set",
38
+ "value": [],
39
+ "item": "str",
40
+ "weight": 1.0
41
+ },
42
+ {
43
+ "path": "items.Q3.counts",
44
+ "type": "list",
45
+ "value": [
46
+ 14,
47
+ 5,
48
+ 4,
49
+ 13
50
+ ],
51
+ "item": "int",
52
+ "weight": 1.0
53
+ },
54
+ {
55
+ "path": "items.Q3.non_functioning",
56
+ "type": "set",
57
+ "value": [],
58
+ "item": "str",
59
+ "weight": 1.0
60
+ },
61
+ {
62
+ "path": "items.Q4.counts",
63
+ "type": "list",
64
+ "value": [
65
+ 3,
66
+ 7,
67
+ 21,
68
+ 5
69
+ ],
70
+ "item": "int",
71
+ "weight": 1.0
72
+ },
73
+ {
74
+ "path": "items.Q4.non_functioning",
75
+ "type": "set",
76
+ "value": [],
77
+ "item": "str",
78
+ "weight": 1.0
79
+ },
80
+ {
81
+ "path": "items.Q5.counts",
82
+ "type": "list",
83
+ "value": [
84
+ 5,
85
+ 5,
86
+ 0,
87
+ 26
88
+ ],
89
+ "item": "int",
90
+ "weight": 1.0
91
+ },
92
+ {
93
+ "path": "items.Q5.non_functioning",
94
+ "type": "set",
95
+ "value": [
96
+ "C"
97
+ ],
98
+ "item": "str",
99
+ "weight": 1.0
100
+ },
101
+ {
102
+ "path": "items.Q6.counts",
103
+ "type": "list",
104
+ "value": [
105
+ 6,
106
+ 16,
107
+ 8,
108
+ 6
109
+ ],
110
+ "item": "int",
111
+ "weight": 1.0
112
+ },
113
+ {
114
+ "path": "items.Q6.non_functioning",
115
+ "type": "set",
116
+ "value": [],
117
+ "item": "str",
118
+ "weight": 1.0
119
+ },
120
+ {
121
+ "path": "has_non_functioning",
122
+ "type": "set",
123
+ "value": [
124
+ "Q1",
125
+ "Q5"
126
+ ],
127
+ "item": "str",
128
+ "weight": 2
129
+ },
130
+ {
131
+ "path": "key_beaten",
132
+ "type": "set",
133
+ "value": [
134
+ "Q2",
135
+ "Q3",
136
+ "Q6"
137
+ ],
138
+ "item": "str",
139
+ "weight": 2
140
+ }
141
+ ]
tasks/class-test/class-test-distractors-d1-t0000/tests/test.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #!/bin/bash
2
+ mkdir -p /logs/verifier
3
+ python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt
tasks/class-test/class-test-distractors-d1-t0000/tests/verify.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Verifier for Renaissance Labs practice environments. Standard library only.
3
+
4
+ Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1].
5
+ The reward is the weighted share of checks that pass. A missing, unreadable or non-object
6
+ answer scores 0. Each check addresses one value in the answer by a dotted path.
7
+
8
+ Check types
9
+ int exact integer (a float with integral value is accepted; booleans are not)
10
+ number within abs_tol of value (default 1e-9); booleans and strings are rejected
11
+ str equal after trimming and case-folding
12
+ bool exact boolean
13
+ list ordered list; items compared as int/number/str according to "item" (default str)
14
+ set unordered collection of distinct strings (or ints)
15
+ custom a function in validators.py: name(answer, args) -> bool or float in [0, 1]
16
+ """
17
+ import argparse, json, math, os, sys
18
+
19
+ MISSING = object()
20
+
21
+ def lookup(obj, path):
22
+ cur = obj
23
+ for part in path.split("."):
24
+ if isinstance(cur, dict):
25
+ if part not in cur: return MISSING
26
+ cur = cur[part]
27
+ elif isinstance(cur, list):
28
+ try: cur = cur[int(part)]
29
+ except (ValueError, IndexError): return MISSING
30
+ else:
31
+ return MISSING
32
+ return cur
33
+
34
+ def is_num(x):
35
+ return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x)))
36
+
37
+ def eq_int(got, want):
38
+ return is_num(got) and float(got) == float(int(got)) and int(got) == want
39
+
40
+ def eq_num(got, want, tol):
41
+ return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12
42
+
43
+ def eq_str(got, want):
44
+ return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold()
45
+
46
+ def eq_item(got, want, kind, tol):
47
+ if kind == "int": return eq_int(got, want)
48
+ if kind == "number": return eq_num(got, want, tol)
49
+ return eq_str(got, want)
50
+
51
+ def run_check(answer, chk, validators):
52
+ t = chk["type"]
53
+ if t == "custom":
54
+ fn = getattr(validators, chk["name"], None) if validators else None
55
+ if fn is None: return 0.0
56
+ try: r = fn(answer, chk.get("args", {}))
57
+ except Exception: return 0.0
58
+ if r is True: return 1.0
59
+ if r is False or r is None: return 0.0
60
+ return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0
61
+ got = lookup(answer, chk["path"])
62
+ if got is MISSING: return 0.0
63
+ want, tol = chk["value"], chk.get("abs_tol", 1e-9)
64
+ if t == "int": ok = eq_int(got, want)
65
+ elif t == "number": ok = eq_num(got, want, tol)
66
+ elif t == "str": ok = eq_str(got, want)
67
+ elif t == "bool": ok = isinstance(got, bool) and got is want
68
+ elif t == "list":
69
+ ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want))
70
+ elif t == "set":
71
+ kind = chk.get("item", "str")
72
+ if not isinstance(got, list): ok = False
73
+ else:
74
+ norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None)
75
+ g = [norm(x) for x in got]; w = [norm(x) for x in want]
76
+ ok = None not in g and len(g) == len(set(g)) and set(g) == set(w)
77
+ else: ok = False
78
+ return 1.0 if ok else 0.0
79
+
80
+ def grade(answer, checks, validators=None):
81
+ """Return (reward, details). answer is the parsed JSON, or None if it could not be read."""
82
+ if not isinstance(answer, dict):
83
+ return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks]
84
+ total = sum(c.get("weight", 1.0) for c in checks)
85
+ got, details = 0.0, []
86
+ for c in checks:
87
+ s = run_check(answer, c, validators)
88
+ got += s * c.get("weight", 1.0)
89
+ details.append({"check": c.get("path", c.get("name")), "score": s})
90
+ return (round(got / total, 6) if total else 0.0), details
91
+
92
+ def main():
93
+ ap = argparse.ArgumentParser()
94
+ ap.add_argument("--answer", default="/app/answer.json")
95
+ ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json"))
96
+ ap.add_argument("--out", default="/logs/verifier")
97
+ a = ap.parse_args()
98
+ checks = json.load(open(a.checks))
99
+ try:
100
+ with open(a.answer) as f: answer = json.load(f)
101
+ except Exception:
102
+ answer = None
103
+ validators = None
104
+ here = os.path.dirname(os.path.abspath(__file__))
105
+ if os.path.exists(os.path.join(here, "validators.py")):
106
+ sys.path.insert(0, here)
107
+ import validators # noqa
108
+ reward, details = grade(answer, checks, validators)
109
+ os.makedirs(a.out, exist_ok=True)
110
+ with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward))
111
+ with open(os.path.join(a.out, "reward.json"), "w") as f:
112
+ json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f)
113
+ print("reward", reward)
114
+
115
+ if __name__ == "__main__":
116
+ main()
tasks/class-test/class-test-distractors-d1-t0012/environment/Dockerfile ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ FROM python:3.12-slim
2
+ WORKDIR /app
3
+ COPY workdir/ /app/
tasks/class-test/class-test-distractors-d1-t0012/environment/workdir/distractor_notes.md ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ # Distractor analysis: definitions
2
+
3
+ For each item, the key is the correct option and the other options are its distractors. `N` is the number of students who sat the test.
4
+
5
+ - The count of an option is the number of students who chose it.
6
+ - A distractor is non-functioning if it was chosen by under 5% of the `N` students (count divided by `N` below 0.05).
7
+ - A distractor beats the key if it was chosen by more students than the key was.
tasks/class-test/class-test-distractors-d1-t0012/environment/workdir/key.csv ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ item,key
2
+ Q1,C
3
+ Q2,C
4
+ Q3,D
5
+ Q4,C
6
+ Q5,B
7
+ Q6,A
tasks/class-test/class-test-distractors-d1-t0012/environment/workdir/responses.csv ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ student_id,class,Q1,Q2,Q3,Q4,Q5,Q6
2
+ S078,10P,B,D,D,C,B,A
3
+ S279,10Q,C,D,A,C,B,A
4
+ S319,10R,C,A,A,A,A,A
5
+ S377,10P,C,D,D,C,B,A
6
+ S380,10P,C,C,A,D,B,A
7
+ S177,10R,C,C,A,C,B,C
8
+ S066,10Q,D,B,B,C,B,A
9
+ S027,10P,C,D,D,D,A,D
10
+ S193,10Q,A,C,D,C,A,D
11
+ S140,10Q,C,D,D,A,A,A
12
+ S149,10Q,C,B,D,A,B,C
13
+ S117,10R,C,D,A,A,B,A
14
+ S141,10P,A,D,D,C,B,A
15
+ S382,10R,C,D,D,B,B,C
16
+ S385,10R,B,C,C,C,B,C
17
+ S207,10R,B,D,D,C,B,A
18
+ S363,10R,C,D,D,C,B,A
19
+ S153,10Q,C,B,D,D,A,C
20
+ S075,10P,B,C,D,C,A,A
21
+ S364,10R,D,B,D,C,B,C
22
+ S085,10Q,C,D,D,B,B,A
23
+ S309,10P,C,D,D,C,A,A
24
+ S169,10R,C,B,A,C,B,D
25
+ S297,10Q,B,C,D,C,B,C
26
+ S225,10Q,C,D,B,B,A,A
27
+ S330,10P,B,D,A,C,B,A
28
+ S082,10Q,C,B,D,A,B,D
29
+ S349,10P,C,C,D,B,B,A
30
+ S014,10Q,C,D,D,C,B,A
31
+ S223,10Q,C,C,D,B,B,D
32
+ S118,10Q,C,A,D,C,A,A
33
+ S112,10R,A,D,D,C,A,C
34
+ S394,10P,C,D,D,D,B,D
35
+ S357,10Q,B,A,A,C,C,A
36
+ S209,10P,C,D,D,C,B,D
37
+ S128,10Q,C,A,D,C,B,D
38
+ S369,10Q,C,B,D,C,A,A
39
+ S098,10P,A,D,D,A,A,D
40
+ S190,10P,B,D,D,B,B,A
41
+ S242,10P,C,A,A,C,A,A
42
+ S266,10R,C,B,D,B,B,D
43
+ S214,10R,A,B,D,C,B,D
44
+ S137,10P,B,C,D,C,B,A
45
+ S178,10Q,C,B,D,C,B,A
46
+ S328,10Q,C,B,D,C,B,C
47
+ S331,10P,C,C,D,C,B,C
48
+ S186,10Q,A,C,D,B,B,D
49
+ S201,10P,C,A,A,C,B,A
50
+ S088,10P,B,C,D,C,B,A
51
+ S397,10R,B,C,D,C,B,A
52
+ S061,10P,A,D,D,C,A,A
53
+ S139,10R,C,D,D,A,A,D
54
+ S296,10P,C,C,B,C,A,A
55
+ S047,10R,D,D,A,C,B,C
56
+ S125,10P,A,D,D,C,A,A
57
+ S006,10R,C,C,D,C,B,C
tasks/class-test/class-test-distractors-d1-t0012/instruction.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Class test: distractor analysis
2
+
3
+ `responses.csv` holds the option each student chose on each of the 6 items of a multiple-choice test (three classes, rows in no particular order). `key.csv` gives the correct option of each item. `distractor_notes.md` gives the definitions: follow them exactly. Analyse all classes together.
4
+
5
+ Write `answer.json` in this folder, a JSON object with:
6
+
7
+ - `items`: an object keyed by item (`Q1` to `Q6`). Each value has
8
+ - `counts`: a list of integers, the count of each option in the order A, B, C, D.
9
+ - `non_functioning`: a list of the option letters of the item's non-functioning distractors (any order; an empty list if none).
10
+ - `has_non_functioning`: list of the items that have at least one non-functioning distractor (any order).
11
+ - `key_beaten`: list of the items where at least one distractor beats the key (any order).
12
+
13
+ Numbers are accepted within one unit of the last decimal place asked for.
tasks/class-test/class-test-distractors-d1-t0012/solution/oracle.py ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Reference solution for Class Test. Works only from the files in the current directory."""
3
+ import csv, json, math, os, re
4
+ from decimal import Decimal, ROUND_HALF_UP
5
+ from fractions import Fraction
6
+
7
+ def rows(name):
8
+ with open(name, newline="") as f: return list(csv.DictReader(f))
9
+
10
+ def text(name):
11
+ with open(name) as f: return f.read()
12
+
13
+ def item_cols(row):
14
+ return sorted([c for c in row if re.match(r"^Q\d+$", c)], key=lambda c: int(c[1:]))
15
+
16
+ # ---------------------------------------------------------------- marking
17
+ def marking():
18
+ scheme = text("marking_scheme.md")
19
+ penalty = Fraction(0)
20
+ if "one quarter" in scheme: penalty = Fraction(1, 4)
21
+ elif "one half" in scheme: penalty = Fraction(1, 2)
22
+ bounds = [(g, int(lo)) for g, lo in re.findall(r"^\| ([A-D]) \| (\d+) or more \|", scheme, re.M)]
23
+ bounds.sort(key=lambda b: -b[1])
24
+ key = dict((r["item"], (r["key"].strip(), int(r["marks"]))) for r in rows("answer_key.csv"))
25
+ live = [q for q in key if key[q][0] != "VOID"]
26
+ top = sum(key[q][1] for q in live)
27
+ ans = {"max_marks": top, "students": {}, "grade_u": [], "grade_counts": dict((g, 0) for g in "ABCDU")}
28
+ pcts = []
29
+ for r in rows("answer_sheets.csv"):
30
+ total = Fraction(0)
31
+ for q in live:
32
+ a = r[q].strip()
33
+ if a == "": continue
34
+ if a == key[q][0]: total += key[q][1]
35
+ else: total -= penalty * key[q][1]
36
+ if total < 0: total = Fraction(0)
37
+ pct = total * 100 / top
38
+ grade = "U"
39
+ for g, lo in bounds:
40
+ if pct >= lo:
41
+ grade = g; break
42
+ ans["students"][r["student_id"]] = {"marks": float(total), "percent": round(float(pct), 1), "grade": grade}
43
+ ans["grade_counts"][grade] += 1
44
+ if grade == "U": ans["grade_u"].append(r["student_id"])
45
+ pcts.append(pct)
46
+ ans["mean_percent"] = round(float(sum(pcts) / len(pcts)), 1)
47
+ return ans
48
+
49
+ # ---------------------------------------------------------------- item analysis
50
+ def item_analysis():
51
+ if os.path.exists("scores.csv"):
52
+ data = rows("scores.csv"); items = item_cols(data[0])
53
+ score = dict((r["student_id"], [int(r[q]) for q in items]) for r in data)
54
+ else:
55
+ key = dict((r["item"], r["key"].strip()) for r in rows("key.csv"))
56
+ data = [r for r in rows("responses.csv") if r.get("status", "present") != "absent"]
57
+ items = item_cols(data[0])
58
+ score = dict((r["student_id"], [1 if r[q].strip() == key[q] else 0 for q in items]) for r in data)
59
+ n, k = len(score), len(items)
60
+ total = dict((s, sum(v)) for s, v in score.items())
61
+ order = sorted(score, key=lambda s: s)
62
+ order.sort(key=lambda s: total[s], reverse=True) # stable: equal totals stay in id order
63
+ g = int((Decimal(27) * n / Decimal(100)).quantize(Decimal(1), rounding=ROUND_HALF_UP))
64
+ upper, lower = order[:g], order[n - g:]
65
+ mean_t = sum(total.values()) / n
66
+ var_t = sum((t - mean_t) ** 2 for t in total.values()) / n
67
+ ans = {"n_group": g, "n_students": n, "items": {}, "poor_discrimination": [], "too_easy": [], "too_hard": [], "needs_review": []}
68
+ sum_pq = 0.0
69
+ for j, q in enumerate(items):
70
+ right = [s for s in score if score[s][j] == 1]; wrong = [s for s in score if score[s][j] == 0]
71
+ p = len(right) / n
72
+ disc = (sum(score[s][j] for s in upper) - sum(score[s][j] for s in lower)) / g
73
+ m1 = sum(total[s] for s in right) / len(right); m0 = sum(total[s] for s in wrong) / len(wrong)
74
+ rpb = (m1 - m0) / math.sqrt(var_t) * math.sqrt(p * (1 - p))
75
+ sum_pq += p * (1 - p)
76
+ ans["items"][q] = {"facility": round(p, 3), "discrimination": round(disc, 3), "point_biserial": round(rpb, 3)}
77
+ if disc < 0.20: ans["poor_discrimination"].append(q)
78
+ if p > 0.85: ans["too_easy"].append(q)
79
+ if p < 0.30: ans["too_hard"].append(q)
80
+ if rpb < 0.20: ans["needs_review"].append(q)
81
+ ans["kr20"] = round(k / (k - 1) * (1 - sum_pq / var_t), 3)
82
+ return ans
83
+
84
+ # ---------------------------------------------------------------- distractors
85
+ def distractors():
86
+ keys = rows("key.csv")
87
+ data = [r for r in rows("responses.csv") if r.get("status", "present") != "absent"]
88
+ n = len(data)
89
+ ans = {"items": {}, "has_non_functioning": [], "key_beaten": [], "n_students": n}
90
+ for kr in keys:
91
+ q, key = kr["item"], kr["key"].strip()
92
+ opts = "ABCDE"[:int(kr.get("n_options") or 4)]
93
+ tally = dict((o, 0) for o in opts); omitted = 0
94
+ for r in data:
95
+ a = r[q].strip()
96
+ if a == "": omitted += 1
97
+ else: tally[a] += 1
98
+ dead = [o for o in opts if o != key and Fraction(tally[o], n) < Fraction(5, 100)]
99
+ others = sorted([o for o in opts if o != key], key=lambda o: -tally[o])
100
+ ans["items"][q] = {"counts": [tally[o] for o in opts], "non_functioning": dead, "omitted": omitted,
101
+ "key_pct": round(100.0 * tally[key] / n, 1), "top_distractor": others[0]}
102
+ if dead: ans["has_non_functioning"].append(q)
103
+ if tally[others[0]] > tally[key]: ans["key_beaten"].append(q)
104
+ return ans
105
+
106
+ # ---------------------------------------------------------------- moderation
107
+ def stats(xs):
108
+ m = sum(xs) / len(xs)
109
+ return m, math.sqrt(sum((x - m) ** 2 for x in xs) / len(xs))
110
+
111
+ def moderation():
112
+ notes = text("moderation_notes.md")
113
+ top = float(re.search(r"marked out of (\d+)", notes).group(1))
114
+ tm = float(re.search(r"target mean is (\d+)", notes).group(1))
115
+ ts = float(re.search(r"target standard deviation is (\d+)", notes).group(1))
116
+ def limit(v): return min(top, max(0.0, v))
117
+ if os.path.exists("scripts.csv"):
118
+ tol = float(re.search(r"more than ([\d.]+) marks", notes).group(1))
119
+ scripts = rows("scripts.csv")
120
+ mark = dict((r["student_id"], float(r["mark"])) for r in scripts)
121
+ marker = dict((r["student_id"], r["marker"]) for r in scripts)
122
+ diffs = {}
123
+ for r in rows("moderation_sample.csv"):
124
+ diffs.setdefault(marker[r["student_id"]], []).append(float(r["moderator_mark"]) - mark[r["student_id"]])
125
+ ans = {"markers": {}, "adjusted_markers": [], "students": {}, "clamped": []}
126
+ shift = {}
127
+ for m in sorted(set(marker.values())):
128
+ md = sum(diffs[m]) / len(diffs[m])
129
+ ans["markers"][m] = {"mean_difference": round(md, 2)}
130
+ shift[m] = md if (md > tol or md < -tol) else 0.0
131
+ if shift[m]: ans["adjusted_markers"].append(m)
132
+ adj = dict((s, mark[s] + shift[marker[s]]) for s in mark)
133
+ M, SD = stats(list(adj.values()))
134
+ ans["cohort_mean"], ans["cohort_sd"] = round(M, 2), round(SD, 2)
135
+ for s, x in adj.items():
136
+ v = tm + (x - M) / SD * ts
137
+ ans["students"][s] = {"final": round(limit(v), 1)}
138
+ if v > top or v < 0: ans["clamped"].append(s)
139
+ return ans
140
+ data = rows("marks.csv")
141
+ if "group" not in data[0]:
142
+ xs = [float(r["mark"]) for r in data]
143
+ M, SD = stats(xs)
144
+ return {"raw_mean": round(M, 2), "raw_sd": round(SD, 2),
145
+ "students": dict((r["student_id"], {"scaled": round(tm + (float(r["mark"]) - M) / SD * ts, 1)}) for r in data)}
146
+ ans = {"groups": {}, "students": {}, "clamped": [], "absent": [r["student_id"] for r in data if r["mark"].strip() == ""]}
147
+ present = [r for r in data if r["mark"].strip() != ""]
148
+ for g in sorted(set(r["group"] for r in present)):
149
+ mine = [r for r in present if r["group"] == g]
150
+ M, SD = stats([float(r["mark"]) for r in mine])
151
+ ans["groups"][g] = {"raw_mean": round(M, 2), "raw_sd": round(SD, 2)}
152
+ for r in mine:
153
+ v = tm + (float(r["mark"]) - M) / SD * ts
154
+ ans["students"][r["student_id"]] = {"scaled": round(limit(v), 1)}
155
+ if v > top or v < 0: ans["clamped"].append(r["student_id"])
156
+ return ans
157
+
158
+ if os.path.exists("answer_sheets.csv"): answer = marking()
159
+ elif os.path.exists("item_analysis_notes.md"): answer = item_analysis()
160
+ elif os.path.exists("distractor_notes.md"): answer = distractors()
161
+ else: answer = moderation()
162
+ with open("answer.json", "w") as f: json.dump(answer, f, indent=1)
tasks/class-test/class-test-distractors-d1-t0012/solution/solve.sh ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+ cd /app
4
+ python3 /solution/oracle.py
tasks/class-test/class-test-distractors-d1-t0012/task.toml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version = "1.0"
2
+
3
+ [metadata]
4
+ author_name = "Renaissance Labs"
5
+ author_email = "unknown"
6
+ difficulty = "easy"
7
+ category = "class-test"
8
+ tags = ["class-test", "distractors", "isced-0111", "train"]
9
+ isced_f = "0111"
10
+ family = "distractors"
11
+ split = "train"
12
+ seed = 12
13
+
14
+ [verifier]
15
+ timeout_sec = 120.0
16
+
17
+ [agent]
18
+ timeout_sec = 900.0
19
+
20
+ [environment]
21
+ build_timeout_sec = 600.0
22
+ cpus = 1
23
+ memory_mb = 1024
24
+ storage_mb = 2048
25
+ allow_internet = false
tasks/class-test/class-test-distractors-d1-t0012/tests/checks.json ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "path": "items.Q1.counts",
4
+ "type": "list",
5
+ "value": [
6
+ 8,
7
+ 11,
8
+ 34,
9
+ 3
10
+ ],
11
+ "item": "int",
12
+ "weight": 1.0
13
+ },
14
+ {
15
+ "path": "items.Q1.non_functioning",
16
+ "type": "set",
17
+ "value": [],
18
+ "item": "str",
19
+ "weight": 1.0
20
+ },
21
+ {
22
+ "path": "items.Q2.counts",
23
+ "type": "list",
24
+ "value": [
25
+ 6,
26
+ 11,
27
+ 15,
28
+ 24
29
+ ],
30
+ "item": "int",
31
+ "weight": 1.0
32
+ },
33
+ {
34
+ "path": "items.Q2.non_functioning",
35
+ "type": "set",
36
+ "value": [],
37
+ "item": "str",
38
+ "weight": 1.0
39
+ },
40
+ {
41
+ "path": "items.Q3.counts",
42
+ "type": "list",
43
+ "value": [
44
+ 11,
45
+ 3,
46
+ 1,
47
+ 41
48
+ ],
49
+ "item": "int",
50
+ "weight": 1.0
51
+ },
52
+ {
53
+ "path": "items.Q3.non_functioning",
54
+ "type": "set",
55
+ "value": [
56
+ "C"
57
+ ],
58
+ "item": "str",
59
+ "weight": 1.0
60
+ },
61
+ {
62
+ "path": "items.Q4.counts",
63
+ "type": "list",
64
+ "value": [
65
+ 7,
66
+ 8,
67
+ 37,
68
+ 4
69
+ ],
70
+ "item": "int",
71
+ "weight": 1.0
72
+ },
73
+ {
74
+ "path": "items.Q4.non_functioning",
75
+ "type": "set",
76
+ "value": [],
77
+ "item": "str",
78
+ "weight": 1.0
79
+ },
80
+ {
81
+ "path": "items.Q5.counts",
82
+ "type": "list",
83
+ "value": [
84
+ 17,
85
+ 38,
86
+ 1,
87
+ 0
88
+ ],
89
+ "item": "int",
90
+ "weight": 1.0
91
+ },
92
+ {
93
+ "path": "items.Q5.non_functioning",
94
+ "type": "set",
95
+ "value": [
96
+ "C",
97
+ "D"
98
+ ],
99
+ "item": "str",
100
+ "weight": 1.0
101
+ },
102
+ {
103
+ "path": "items.Q6.counts",
104
+ "type": "list",
105
+ "value": [
106
+ 31,
107
+ 0,
108
+ 12,
109
+ 13
110
+ ],
111
+ "item": "int",
112
+ "weight": 1.0
113
+ },
114
+ {
115
+ "path": "items.Q6.non_functioning",
116
+ "type": "set",
117
+ "value": [
118
+ "B"
119
+ ],
120
+ "item": "str",
121
+ "weight": 1.0
122
+ },
123
+ {
124
+ "path": "has_non_functioning",
125
+ "type": "set",
126
+ "value": [
127
+ "Q3",
128
+ "Q5",
129
+ "Q6"
130
+ ],
131
+ "item": "str",
132
+ "weight": 2
133
+ },
134
+ {
135
+ "path": "key_beaten",
136
+ "type": "set",
137
+ "value": [
138
+ "Q2"
139
+ ],
140
+ "item": "str",
141
+ "weight": 2
142
+ }
143
+ ]
tasks/class-test/class-test-distractors-d1-t0012/tests/test.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #!/bin/bash
2
+ mkdir -p /logs/verifier
3
+ python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt
tasks/class-test/class-test-distractors-d1-t0012/tests/verify.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Verifier for Renaissance Labs practice environments. Standard library only.
3
+
4
+ Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1].
5
+ The reward is the weighted share of checks that pass. A missing, unreadable or non-object
6
+ answer scores 0. Each check addresses one value in the answer by a dotted path.
7
+
8
+ Check types
9
+ int exact integer (a float with integral value is accepted; booleans are not)
10
+ number within abs_tol of value (default 1e-9); booleans and strings are rejected
11
+ str equal after trimming and case-folding
12
+ bool exact boolean
13
+ list ordered list; items compared as int/number/str according to "item" (default str)
14
+ set unordered collection of distinct strings (or ints)
15
+ custom a function in validators.py: name(answer, args) -> bool or float in [0, 1]
16
+ """
17
+ import argparse, json, math, os, sys
18
+
19
+ MISSING = object()
20
+
21
+ def lookup(obj, path):
22
+ cur = obj
23
+ for part in path.split("."):
24
+ if isinstance(cur, dict):
25
+ if part not in cur: return MISSING
26
+ cur = cur[part]
27
+ elif isinstance(cur, list):
28
+ try: cur = cur[int(part)]
29
+ except (ValueError, IndexError): return MISSING
30
+ else:
31
+ return MISSING
32
+ return cur
33
+
34
+ def is_num(x):
35
+ return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x)))
36
+
37
+ def eq_int(got, want):
38
+ return is_num(got) and float(got) == float(int(got)) and int(got) == want
39
+
40
+ def eq_num(got, want, tol):
41
+ return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12
42
+
43
+ def eq_str(got, want):
44
+ return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold()
45
+
46
+ def eq_item(got, want, kind, tol):
47
+ if kind == "int": return eq_int(got, want)
48
+ if kind == "number": return eq_num(got, want, tol)
49
+ return eq_str(got, want)
50
+
51
+ def run_check(answer, chk, validators):
52
+ t = chk["type"]
53
+ if t == "custom":
54
+ fn = getattr(validators, chk["name"], None) if validators else None
55
+ if fn is None: return 0.0
56
+ try: r = fn(answer, chk.get("args", {}))
57
+ except Exception: return 0.0
58
+ if r is True: return 1.0
59
+ if r is False or r is None: return 0.0
60
+ return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0
61
+ got = lookup(answer, chk["path"])
62
+ if got is MISSING: return 0.0
63
+ want, tol = chk["value"], chk.get("abs_tol", 1e-9)
64
+ if t == "int": ok = eq_int(got, want)
65
+ elif t == "number": ok = eq_num(got, want, tol)
66
+ elif t == "str": ok = eq_str(got, want)
67
+ elif t == "bool": ok = isinstance(got, bool) and got is want
68
+ elif t == "list":
69
+ ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want))
70
+ elif t == "set":
71
+ kind = chk.get("item", "str")
72
+ if not isinstance(got, list): ok = False
73
+ else:
74
+ norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None)
75
+ g = [norm(x) for x in got]; w = [norm(x) for x in want]
76
+ ok = None not in g and len(g) == len(set(g)) and set(g) == set(w)
77
+ else: ok = False
78
+ return 1.0 if ok else 0.0
79
+
80
+ def grade(answer, checks, validators=None):
81
+ """Return (reward, details). answer is the parsed JSON, or None if it could not be read."""
82
+ if not isinstance(answer, dict):
83
+ return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks]
84
+ total = sum(c.get("weight", 1.0) for c in checks)
85
+ got, details = 0.0, []
86
+ for c in checks:
87
+ s = run_check(answer, c, validators)
88
+ got += s * c.get("weight", 1.0)
89
+ details.append({"check": c.get("path", c.get("name")), "score": s})
90
+ return (round(got / total, 6) if total else 0.0), details
91
+
92
+ def main():
93
+ ap = argparse.ArgumentParser()
94
+ ap.add_argument("--answer", default="/app/answer.json")
95
+ ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json"))
96
+ ap.add_argument("--out", default="/logs/verifier")
97
+ a = ap.parse_args()
98
+ checks = json.load(open(a.checks))
99
+ try:
100
+ with open(a.answer) as f: answer = json.load(f)
101
+ except Exception:
102
+ answer = None
103
+ validators = None
104
+ here = os.path.dirname(os.path.abspath(__file__))
105
+ if os.path.exists(os.path.join(here, "validators.py")):
106
+ sys.path.insert(0, here)
107
+ import validators # noqa
108
+ reward, details = grade(answer, checks, validators)
109
+ os.makedirs(a.out, exist_ok=True)
110
+ with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward))
111
+ with open(os.path.join(a.out, "reward.json"), "w") as f:
112
+ json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f)
113
+ print("reward", reward)
114
+
115
+ if __name__ == "__main__":
116
+ main()
tasks/class-test/class-test-distractors-d1-t0024/environment/Dockerfile ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ FROM python:3.12-slim
2
+ WORKDIR /app
3
+ COPY workdir/ /app/
tasks/class-test/class-test-distractors-d1-t0024/environment/workdir/distractor_notes.md ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ # Distractor analysis: definitions
2
+
3
+ For each item, the key is the correct option and the other options are its distractors. `N` is the number of students who sat the test.
4
+
5
+ - The count of an option is the number of students who chose it.
6
+ - A distractor is non-functioning if it was chosen by under 5% of the `N` students (count divided by `N` below 0.05).
7
+ - A distractor beats the key if it was chosen by more students than the key was.
tasks/class-test/class-test-distractors-d1-t0024/environment/workdir/key.csv ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ item,key
2
+ Q1,B
3
+ Q2,C
4
+ Q3,B
5
+ Q4,D
6
+ Q5,C
7
+ Q6,A
tasks/class-test/class-test-distractors-d1-t0024/environment/workdir/responses.csv ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ student_id,class,Q1,Q2,Q3,Q4,Q5,Q6
2
+ S270,10P,B,C,A,D,A,A
3
+ S107,10Q,B,C,A,D,C,A
4
+ S190,10P,B,A,D,D,C,A
5
+ S102,10R,B,B,B,D,A,A
6
+ S372,10P,D,A,B,D,C,A
7
+ S130,10P,A,C,B,D,C,A
8
+ S275,10R,A,C,A,D,C,C
9
+ S218,10Q,B,C,A,D,C,C
10
+ S264,10P,B,C,B,D,A,A
11
+ S147,10P,B,C,B,D,C,A
12
+ S124,10Q,A,C,B,D,A,A
13
+ S267,10P,B,B,B,B,C,C
14
+ S362,10P,B,C,B,D,C,A
15
+ S329,10Q,B,C,B,D,A,A
16
+ S273,10R,B,C,B,C,A,A
17
+ S208,10Q,D,C,D,D,A,A
18
+ S085,10P,B,A,B,C,C,A
19
+ S344,10P,B,A,B,D,A,A
20
+ S070,10R,B,B,D,A,A,A
21
+ S173,10R,B,C,D,D,A,C
22
+ S158,10R,B,B,B,A,A,C
23
+ S296,10Q,A,C,C,C,A,A
24
+ S314,10R,D,B,C,D,A,C
25
+ S053,10Q,B,C,B,C,A,C
26
+ S090,10R,A,C,B,D,A,A
27
+ S089,10P,A,A,C,D,A,A
28
+ S105,10R,A,B,C,D,C,A
29
+ S386,10Q,B,C,B,D,A,A
30
+ S378,10R,B,C,D,C,C,A
31
+ S007,10Q,C,C,B,D,A,A
32
+ S116,10Q,B,C,B,D,C,A
33
+ S383,10Q,D,C,B,D,C,A
34
+ S040,10P,B,C,B,D,C,A
35
+ S073,10Q,A,B,B,D,C,C
36
+ S152,10P,B,D,B,D,A,A
tasks/class-test/class-test-distractors-d1-t0024/instruction.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Class test: distractor analysis
2
+
3
+ `responses.csv` holds the option each student chose on each of the 6 items of a multiple-choice test (three classes, rows in no particular order). `key.csv` gives the correct option of each item. `distractor_notes.md` gives the definitions: follow them exactly. Analyse all classes together.
4
+
5
+ Write `answer.json` in this folder, a JSON object with:
6
+
7
+ - `items`: an object keyed by item (`Q1` to `Q6`). Each value has
8
+ - `counts`: a list of integers, the count of each option in the order A, B, C, D.
9
+ - `non_functioning`: a list of the option letters of the item's non-functioning distractors (any order; an empty list if none).
10
+ - `has_non_functioning`: list of the items that have at least one non-functioning distractor (any order).
11
+ - `key_beaten`: list of the items where at least one distractor beats the key (any order).
12
+
13
+ Numbers are accepted within one unit of the last decimal place asked for.
tasks/class-test/class-test-distractors-d1-t0024/solution/oracle.py ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Reference solution for Class Test. Works only from the files in the current directory."""
3
+ import csv, json, math, os, re
4
+ from decimal import Decimal, ROUND_HALF_UP
5
+ from fractions import Fraction
6
+
7
+ def rows(name):
8
+ with open(name, newline="") as f: return list(csv.DictReader(f))
9
+
10
+ def text(name):
11
+ with open(name) as f: return f.read()
12
+
13
+ def item_cols(row):
14
+ return sorted([c for c in row if re.match(r"^Q\d+$", c)], key=lambda c: int(c[1:]))
15
+
16
+ # ---------------------------------------------------------------- marking
17
+ def marking():
18
+ scheme = text("marking_scheme.md")
19
+ penalty = Fraction(0)
20
+ if "one quarter" in scheme: penalty = Fraction(1, 4)
21
+ elif "one half" in scheme: penalty = Fraction(1, 2)
22
+ bounds = [(g, int(lo)) for g, lo in re.findall(r"^\| ([A-D]) \| (\d+) or more \|", scheme, re.M)]
23
+ bounds.sort(key=lambda b: -b[1])
24
+ key = dict((r["item"], (r["key"].strip(), int(r["marks"]))) for r in rows("answer_key.csv"))
25
+ live = [q for q in key if key[q][0] != "VOID"]
26
+ top = sum(key[q][1] for q in live)
27
+ ans = {"max_marks": top, "students": {}, "grade_u": [], "grade_counts": dict((g, 0) for g in "ABCDU")}
28
+ pcts = []
29
+ for r in rows("answer_sheets.csv"):
30
+ total = Fraction(0)
31
+ for q in live:
32
+ a = r[q].strip()
33
+ if a == "": continue
34
+ if a == key[q][0]: total += key[q][1]
35
+ else: total -= penalty * key[q][1]
36
+ if total < 0: total = Fraction(0)
37
+ pct = total * 100 / top
38
+ grade = "U"
39
+ for g, lo in bounds:
40
+ if pct >= lo:
41
+ grade = g; break
42
+ ans["students"][r["student_id"]] = {"marks": float(total), "percent": round(float(pct), 1), "grade": grade}
43
+ ans["grade_counts"][grade] += 1
44
+ if grade == "U": ans["grade_u"].append(r["student_id"])
45
+ pcts.append(pct)
46
+ ans["mean_percent"] = round(float(sum(pcts) / len(pcts)), 1)
47
+ return ans
48
+
49
+ # ---------------------------------------------------------------- item analysis
50
+ def item_analysis():
51
+ if os.path.exists("scores.csv"):
52
+ data = rows("scores.csv"); items = item_cols(data[0])
53
+ score = dict((r["student_id"], [int(r[q]) for q in items]) for r in data)
54
+ else:
55
+ key = dict((r["item"], r["key"].strip()) for r in rows("key.csv"))
56
+ data = [r for r in rows("responses.csv") if r.get("status", "present") != "absent"]
57
+ items = item_cols(data[0])
58
+ score = dict((r["student_id"], [1 if r[q].strip() == key[q] else 0 for q in items]) for r in data)
59
+ n, k = len(score), len(items)
60
+ total = dict((s, sum(v)) for s, v in score.items())
61
+ order = sorted(score, key=lambda s: s)
62
+ order.sort(key=lambda s: total[s], reverse=True) # stable: equal totals stay in id order
63
+ g = int((Decimal(27) * n / Decimal(100)).quantize(Decimal(1), rounding=ROUND_HALF_UP))
64
+ upper, lower = order[:g], order[n - g:]
65
+ mean_t = sum(total.values()) / n
66
+ var_t = sum((t - mean_t) ** 2 for t in total.values()) / n
67
+ ans = {"n_group": g, "n_students": n, "items": {}, "poor_discrimination": [], "too_easy": [], "too_hard": [], "needs_review": []}
68
+ sum_pq = 0.0
69
+ for j, q in enumerate(items):
70
+ right = [s for s in score if score[s][j] == 1]; wrong = [s for s in score if score[s][j] == 0]
71
+ p = len(right) / n
72
+ disc = (sum(score[s][j] for s in upper) - sum(score[s][j] for s in lower)) / g
73
+ m1 = sum(total[s] for s in right) / len(right); m0 = sum(total[s] for s in wrong) / len(wrong)
74
+ rpb = (m1 - m0) / math.sqrt(var_t) * math.sqrt(p * (1 - p))
75
+ sum_pq += p * (1 - p)
76
+ ans["items"][q] = {"facility": round(p, 3), "discrimination": round(disc, 3), "point_biserial": round(rpb, 3)}
77
+ if disc < 0.20: ans["poor_discrimination"].append(q)
78
+ if p > 0.85: ans["too_easy"].append(q)
79
+ if p < 0.30: ans["too_hard"].append(q)
80
+ if rpb < 0.20: ans["needs_review"].append(q)
81
+ ans["kr20"] = round(k / (k - 1) * (1 - sum_pq / var_t), 3)
82
+ return ans
83
+
84
+ # ---------------------------------------------------------------- distractors
85
+ def distractors():
86
+ keys = rows("key.csv")
87
+ data = [r for r in rows("responses.csv") if r.get("status", "present") != "absent"]
88
+ n = len(data)
89
+ ans = {"items": {}, "has_non_functioning": [], "key_beaten": [], "n_students": n}
90
+ for kr in keys:
91
+ q, key = kr["item"], kr["key"].strip()
92
+ opts = "ABCDE"[:int(kr.get("n_options") or 4)]
93
+ tally = dict((o, 0) for o in opts); omitted = 0
94
+ for r in data:
95
+ a = r[q].strip()
96
+ if a == "": omitted += 1
97
+ else: tally[a] += 1
98
+ dead = [o for o in opts if o != key and Fraction(tally[o], n) < Fraction(5, 100)]
99
+ others = sorted([o for o in opts if o != key], key=lambda o: -tally[o])
100
+ ans["items"][q] = {"counts": [tally[o] for o in opts], "non_functioning": dead, "omitted": omitted,
101
+ "key_pct": round(100.0 * tally[key] / n, 1), "top_distractor": others[0]}
102
+ if dead: ans["has_non_functioning"].append(q)
103
+ if tally[others[0]] > tally[key]: ans["key_beaten"].append(q)
104
+ return ans
105
+
106
+ # ---------------------------------------------------------------- moderation
107
+ def stats(xs):
108
+ m = sum(xs) / len(xs)
109
+ return m, math.sqrt(sum((x - m) ** 2 for x in xs) / len(xs))
110
+
111
+ def moderation():
112
+ notes = text("moderation_notes.md")
113
+ top = float(re.search(r"marked out of (\d+)", notes).group(1))
114
+ tm = float(re.search(r"target mean is (\d+)", notes).group(1))
115
+ ts = float(re.search(r"target standard deviation is (\d+)", notes).group(1))
116
+ def limit(v): return min(top, max(0.0, v))
117
+ if os.path.exists("scripts.csv"):
118
+ tol = float(re.search(r"more than ([\d.]+) marks", notes).group(1))
119
+ scripts = rows("scripts.csv")
120
+ mark = dict((r["student_id"], float(r["mark"])) for r in scripts)
121
+ marker = dict((r["student_id"], r["marker"]) for r in scripts)
122
+ diffs = {}
123
+ for r in rows("moderation_sample.csv"):
124
+ diffs.setdefault(marker[r["student_id"]], []).append(float(r["moderator_mark"]) - mark[r["student_id"]])
125
+ ans = {"markers": {}, "adjusted_markers": [], "students": {}, "clamped": []}
126
+ shift = {}
127
+ for m in sorted(set(marker.values())):
128
+ md = sum(diffs[m]) / len(diffs[m])
129
+ ans["markers"][m] = {"mean_difference": round(md, 2)}
130
+ shift[m] = md if (md > tol or md < -tol) else 0.0
131
+ if shift[m]: ans["adjusted_markers"].append(m)
132
+ adj = dict((s, mark[s] + shift[marker[s]]) for s in mark)
133
+ M, SD = stats(list(adj.values()))
134
+ ans["cohort_mean"], ans["cohort_sd"] = round(M, 2), round(SD, 2)
135
+ for s, x in adj.items():
136
+ v = tm + (x - M) / SD * ts
137
+ ans["students"][s] = {"final": round(limit(v), 1)}
138
+ if v > top or v < 0: ans["clamped"].append(s)
139
+ return ans
140
+ data = rows("marks.csv")
141
+ if "group" not in data[0]:
142
+ xs = [float(r["mark"]) for r in data]
143
+ M, SD = stats(xs)
144
+ return {"raw_mean": round(M, 2), "raw_sd": round(SD, 2),
145
+ "students": dict((r["student_id"], {"scaled": round(tm + (float(r["mark"]) - M) / SD * ts, 1)}) for r in data)}
146
+ ans = {"groups": {}, "students": {}, "clamped": [], "absent": [r["student_id"] for r in data if r["mark"].strip() == ""]}
147
+ present = [r for r in data if r["mark"].strip() != ""]
148
+ for g in sorted(set(r["group"] for r in present)):
149
+ mine = [r for r in present if r["group"] == g]
150
+ M, SD = stats([float(r["mark"]) for r in mine])
151
+ ans["groups"][g] = {"raw_mean": round(M, 2), "raw_sd": round(SD, 2)}
152
+ for r in mine:
153
+ v = tm + (float(r["mark"]) - M) / SD * ts
154
+ ans["students"][r["student_id"]] = {"scaled": round(limit(v), 1)}
155
+ if v > top or v < 0: ans["clamped"].append(r["student_id"])
156
+ return ans
157
+
158
+ if os.path.exists("answer_sheets.csv"): answer = marking()
159
+ elif os.path.exists("item_analysis_notes.md"): answer = item_analysis()
160
+ elif os.path.exists("distractor_notes.md"): answer = distractors()
161
+ else: answer = moderation()
162
+ with open("answer.json", "w") as f: json.dump(answer, f, indent=1)