NSamson1 commited on
Commit
6bdf07a
ยท
verified ยท
1 Parent(s): 1a04fe7

Create scripts/generate_curriculum.py

Browse files
Files changed (1) hide show
  1. scripts/generate_curriculum.py +132 -0
scripts/generate_curriculum.py ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ scripts/generate_curriculum.py
3
+ Expands the seed curriculum with additional generated items and writes
4
+ data/T3.1_Math_Tutor/curriculum_full.json
5
+
6
+ Run once before starting the app:
7
+ python3 scripts/generate_curriculum.py
8
+ """
9
+ from __future__ import annotations
10
+ import json, random, sys
11
+ from pathlib import Path
12
+
13
+ SEED_PATH = Path("data/T3.1_Math_Tutor/curriculum_seed.json")
14
+ OUT_PATH = Path("data/T3.1_Math_Tutor/curriculum_full.json")
15
+
16
+ # โ”€โ”€ Generators โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
17
+
18
+ def _counting_items(n_start: int) -> list[dict]:
19
+ items = []
20
+ for count in range(1, 11):
21
+ diff = max(1, round(count / 2))
22
+ for label in ["apple","star","ball","flower"]:
23
+ items.append({
24
+ "id": f"cnt_gen_{count}_{label}",
25
+ "skill": "counting",
26
+ "difficulty": diff,
27
+ "answer_int": count,
28
+ "stem_en": f"How many {label}s do you see?",
29
+ "stem_fr": f"Combien de {label}s vois-tu ?",
30
+ "stem_kin": f"Ubona {label} zingahe?",
31
+ "stem_sw": f"Unaona {label} ngapi?",
32
+ "visual": f"{label}_{count}",
33
+ })
34
+ return items
35
+
36
+
37
+ def _addition_items() -> list[dict]:
38
+ items = []
39
+ for a in range(0, 8):
40
+ for b in range(0, 8):
41
+ if a + b > 10:
42
+ continue
43
+ diff = max(1, min(9, a + b))
44
+ items.append({
45
+ "id": f"add_gen_{a}_{b}",
46
+ "skill": "addition",
47
+ "difficulty": diff,
48
+ "answer_int": a + b,
49
+ "stem_en": f"{a} + {b} = ?",
50
+ "stem_fr": f"{a} + {b} = ?",
51
+ "stem_kin": f"{a} + {b} = ?",
52
+ "stem_sw": f"{a} + {b} = ?",
53
+ "visual": "",
54
+ })
55
+ return items
56
+
57
+
58
+ def _subtraction_items() -> list[dict]:
59
+ items = []
60
+ for a in range(1, 11):
61
+ for b in range(0, a + 1):
62
+ diff = max(2, min(9, a))
63
+ items.append({
64
+ "id": f"sub_gen_{a}_{b}",
65
+ "skill": "subtraction",
66
+ "difficulty": diff,
67
+ "answer_int": a - b,
68
+ "stem_en": f"{a} - {b} = ?",
69
+ "stem_fr": f"{a} - {b} = ?",
70
+ "stem_kin": f"{a} - {b} = ?",
71
+ "stem_sw": f"{a} - {b} = ?",
72
+ "visual": "",
73
+ })
74
+ return items
75
+
76
+
77
+ def _number_sense_items() -> list[dict]:
78
+ items = []
79
+ for n in range(1, 10):
80
+ items.append({
81
+ "id": f"ns_gen_after_{n}",
82
+ "skill": "number_sense", "difficulty": max(1, n//2),
83
+ "answer_int": n + 1,
84
+ "stem_en": f"What number comes after {n}?",
85
+ "stem_fr": f"Quel nombre vient aprรจs {n} ?",
86
+ "stem_kin": f"Ni umubare ukomeza {n}?",
87
+ "stem_sw": f"Nambari gani inakuja baada ya {n}?",
88
+ "visual": "",
89
+ })
90
+ items.append({
91
+ "id": f"ns_gen_before_{n+1}",
92
+ "skill": "number_sense", "difficulty": max(1, n//2),
93
+ "answer_int": n,
94
+ "stem_en": f"What number comes before {n+1}?",
95
+ "stem_fr": f"Quel nombre vient avant {n+1} ?",
96
+ "stem_kin": f"Ni umubare uba imbere ya {n+1}?",
97
+ "stem_sw": f"Nambari gani inakuja kabla ya {n+1}?",
98
+ "visual": "",
99
+ })
100
+ return items
101
+
102
+
103
+ # โ”€โ”€ Main โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
104
+
105
+ def main():
106
+ with open(SEED_PATH, "r", encoding="utf-8") as f:
107
+ seed = json.load(f)
108
+
109
+ existing_ids = {item["id"] for item in seed}
110
+
111
+ generated = (
112
+ _counting_items(len(seed))
113
+ + _addition_items()
114
+ + _subtraction_items()
115
+ + _number_sense_items()
116
+ )
117
+
118
+ # De-duplicate against seed
119
+ new_items = [i for i in generated if i["id"] not in existing_ids]
120
+ full = seed + new_items
121
+ random.shuffle(full)
122
+
123
+ OUT_PATH.parent.mkdir(parents=True, exist_ok=True)
124
+ with open(OUT_PATH, "w", encoding="utf-8") as f:
125
+ json.dump(full, f, ensure_ascii=False, indent=2)
126
+
127
+ print(f"โœ… Generated {len(full)} items ({len(seed)} seed + {len(new_items)} new)")
128
+ print(f" Saved to {OUT_PATH}")
129
+
130
+
131
+ if __name__ == "__main__":
132
+ main()