Repository navigation
Expand file tree
/
Copy pathsession_models.py
More file actions
359 lines (330 loc) · 15.2 KB
/
Copy pathsession_models.py
File metadata and controls
359 lines (330 loc) · 15.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
from collections.abc import Mapping, MutableMapping
from typing import Any, NotRequired, TypedDict, cast
from bank_models import BankQuestion
class AnswerState(TypedDict):
selected: list[str]
pending: list[str]
answered: bool
flagged: bool
suspended: bool
last_confidence: str
last_miss_reason: str
last_recall_failure: NotRequired[str]
answer_event_id: NotRequired[str]
recall_ready: bool
session_tag: str
smart_primary_role: str
smart_selection_reasons: list[str]
smart_utility: float
smart_utility_breakdown: dict[str, float]
smart_policy_version: str
smart_policy_id: str
smart_concept_key: str
smart_root_cause: str
smart_root_cause_confidence: float
smart_supporting_concepts: list[str]
smart_graph_version: str
smart_information_value: float
smart_information_breakdown: dict[str, Any]
smart_question_quality_status: str
smart_question_quality_confidence: float
smart_graph_bottleneck: float
repair_stage: str
repair_concept_key: str
legacy_repair_concept_key: str
prediction_id: str
prediction_snapshot: dict[str, Any]
class SessionAnswerState(AnswerState, total=False):
question_id: str
class QuestionHistoryEvent(TypedDict):
at: str
day: str
question_id: str
question_number: int
question_content_fingerprint: NotRequired[str]
fingerprint_schema_version: NotRequired[int]
fingerprint_domain: NotRequired[str]
fingerprint_algorithm: NotRequired[str]
loader_contract_version: NotRequired[int]
bank_node_id: NotRequired[str]
answer_event_id: NotRequired[str]
correct: bool
confidence: str
miss_reason: str
domain: str
topics: list[str]
objective_code: str
source_label: str
mode: str
trap_words: list[str]
selected: list[str]
correct_letters: list[str]
selected_texts: list[str]
correct_texts: list[str]
wrong_answer_family: str
recall_failure: str
deciding_clue: str
response_seconds: float
raw_response_seconds: float
effective_response_seconds: float
response_time_contaminated: bool
was_due: bool
was_active_weak: bool
session_tag: str
smart_primary_role: str
smart_selection_reasons: list[str]
smart_utility: float
repair_stage: str
repair_concept_key: str
prediction_id: str
predicted_recall_probability: float
predicted_success_probability: float
predicted_learning_gain: float
class SessionAnswerEvent(TypedDict):
question_id: str
question_number: int
question_content_fingerprint: NotRequired[str]
fingerprint_schema_version: NotRequired[int]
fingerprint_domain: NotRequired[str]
fingerprint_algorithm: NotRequired[str]
loader_contract_version: NotRequired[int]
bank_node_id: NotRequired[str]
answer_event_id: NotRequired[str]
domain: str
correct: bool
confidence: str
miss_reason: str
recall_failure: str
deciding_clue: str
was_active_weak: bool
was_due: bool
response_seconds: float
raw_response_seconds: float
effective_response_seconds: float
response_time_contaminated: bool
session_tag: str
smart_primary_role: str
smart_selection_reasons: list[str]
smart_utility: float
repair_stage: str
repair_concept_key: str
prediction_id: str
class QuestProgressState(TypedDict):
key: str
title: str
kind: str
target: int
progress: int
completed: bool
class BuilderContext(TypedDict):
mode: str
count: str
source_label: str
session_source: str
randomize: bool
domain_filter: str
topic_filter: str
status_filter: str
class SessionSnapshot(TypedDict):
schema_version: int
app_version: str
bank_file: str
session_identity_version: NotRequired[int]
session_identity: NotRequired[str]
bank_fingerprint: NotRequired[str]
fingerprint_schema_version: NotRequired[int]
fingerprint_domain: NotRequired[str]
fingerprint_algorithm: NotRequired[str]
loader_contract_version: NotRequired[int]
bank_node_id: NotRequired[str]
question_ids: NotRequired[list[str]]
restore_question_ids: NotRequired[list[str]]
mode: str
builder_context: BuilderContext
builder_identity: NotRequired[str]
builder_identity_version: NotRequired[int]
builder_context_fingerprint: NotRequired[str]
builder_identity_status: NotRequired[str]
source_label: str
question_count: int
question_numbers: list[int]
restore_question_numbers: list[int]
session_base_question_count: int
session_question_limit: int
restore_signature: str
session_signature: str
current_index: int
elapsed_seconds: int
exam_reveal: bool
checkpoints_saved: list[str]
session_rewards: list[str]
unlocked_rewards: list[str]
session_answer_history: list[SessionAnswerEvent]
current_quests: list[QuestProgressState]
quest_completion_keys: list[str]
session_boss_markers: list[int]
session_stealth_markers: list[int]
session_xp_gained: int
answers: list[SessionAnswerState]
class QuestionRuntimeState(BankQuestion, total=False):
selected: list[str]
pending: list[str]
answered: bool
flagged: bool
suspended: bool
last_confidence: str
last_miss_reason: str
last_recall_failure: str
answer_event_id: str
recall_ready: bool
session_tag: str
smart_primary_role: str
smart_selection_reasons: list[str]
smart_utility: float
smart_utility_breakdown: dict[str, float]
smart_policy_version: str
smart_policy_id: str
smart_concept_key: str
smart_root_cause: str
smart_root_cause_confidence: float
smart_supporting_concepts: list[str]
smart_graph_version: str
smart_information_value: float
smart_information_breakdown: dict[str, Any]
smart_question_quality_status: str
smart_question_quality_confidence: float
smart_graph_bottleneck: float
repair_stage: str
repair_concept_key: str
legacy_repair_concept_key: str
prediction_id: str
prediction_snapshot: dict[str, Any]
RuntimeQuestionMapping = MutableMapping[str, Any]
def as_runtime_question(question: Mapping[str, Any] | MutableMapping[str, Any]) -> QuestionRuntimeState:
return cast(QuestionRuntimeState, question)
def answer_state_from_question(question: Mapping[str, Any]) -> AnswerState:
runtime = as_runtime_question(question)
selected = list(runtime.get("selected", []))
return {
"selected": selected,
"pending": list(runtime.get("pending", selected)),
"answered": bool(runtime.get("answered")),
"flagged": bool(runtime.get("flagged")),
"suspended": bool(runtime.get("suspended")),
"last_confidence": str(runtime.get("last_confidence", "") or ""),
"last_miss_reason": str(runtime.get("last_miss_reason", "") or ""),
"last_recall_failure": str(runtime.get("last_recall_failure", "") or ""),
"answer_event_id": str(runtime.get("answer_event_id", "") or ""),
"recall_ready": bool(runtime.get("recall_ready")),
"session_tag": str(runtime.get("session_tag", "") or ""),
"smart_primary_role": str(runtime.get("smart_primary_role", "") or ""),
"smart_selection_reasons": [str(value) for value in runtime.get("smart_selection_reasons", [])],
"smart_utility": float(runtime.get("smart_utility", 0.0) or 0.0),
"smart_utility_breakdown": dict(runtime.get("smart_utility_breakdown") or {}),
"smart_policy_version": str(runtime.get("smart_policy_version", "") or ""),
"smart_policy_id": str(runtime.get("smart_policy_id", "") or ""),
"smart_concept_key": str(runtime.get("smart_concept_key", "") or ""),
"smart_root_cause": str(runtime.get("smart_root_cause", "") or ""),
"smart_root_cause_confidence": float(runtime.get("smart_root_cause_confidence", 0.0) or 0.0),
"smart_supporting_concepts": [str(value) for value in runtime.get("smart_supporting_concepts", [])],
"smart_graph_version": str(runtime.get("smart_graph_version", "") or ""),
"smart_information_value": float(runtime.get("smart_information_value", 0.0) or 0.0),
"smart_information_breakdown": dict(runtime.get("smart_information_breakdown") or {}),
"smart_question_quality_status": str(runtime.get("smart_question_quality_status", "") or ""),
"smart_question_quality_confidence": float(runtime.get("smart_question_quality_confidence", 0.0) or 0.0),
"smart_graph_bottleneck": float(runtime.get("smart_graph_bottleneck", 0.0) or 0.0),
"repair_stage": str(runtime.get("repair_stage", "") or ""),
"repair_concept_key": str(runtime.get("repair_concept_key", "") or ""),
"legacy_repair_concept_key": str(runtime.get("legacy_repair_concept_key", "") or ""),
"prediction_id": str(runtime.get("prediction_id", "") or ""),
"prediction_snapshot": dict(runtime.get("prediction_snapshot") or {}),
}
def apply_answer_state(question: RuntimeQuestionMapping, state: Mapping[str, Any]) -> QuestionRuntimeState:
runtime = as_runtime_question(question)
answer_state = dict(state or {})
selected = [str(letter) for letter in answer_state.get("selected", [])]
runtime["selected"] = selected
runtime["pending"] = [str(letter) for letter in answer_state.get("pending", selected)]
runtime["answered"] = bool(answer_state.get("answered"))
runtime["flagged"] = bool(answer_state.get("flagged"))
runtime["suspended"] = bool(answer_state.get("suspended"))
runtime["last_confidence"] = str(answer_state.get("last_confidence", "") or "")
runtime["last_miss_reason"] = str(answer_state.get("last_miss_reason", "") or "")
runtime["last_recall_failure"] = str(answer_state.get("last_recall_failure", "") or "")
runtime["answer_event_id"] = str(answer_state.get("answer_event_id", "") or "")
runtime["recall_ready"] = bool(answer_state.get("recall_ready"))
runtime["session_tag"] = str(answer_state.get("session_tag", "") or "")
runtime["smart_primary_role"] = str(answer_state.get("smart_primary_role", "") or "")
runtime["smart_selection_reasons"] = [str(value) for value in answer_state.get("smart_selection_reasons", [])]
runtime["smart_utility"] = float(answer_state.get("smart_utility", 0.0) or 0.0)
runtime["smart_utility_breakdown"] = dict(answer_state.get("smart_utility_breakdown") or {})
runtime["smart_policy_version"] = str(answer_state.get("smart_policy_version", "") or "")
runtime["smart_policy_id"] = str(answer_state.get("smart_policy_id", "") or "")
runtime["smart_concept_key"] = str(answer_state.get("smart_concept_key", "") or "")
runtime["smart_root_cause"] = str(answer_state.get("smart_root_cause", "") or "")
runtime["smart_root_cause_confidence"] = float(answer_state.get("smart_root_cause_confidence", 0.0) or 0.0)
runtime["smart_supporting_concepts"] = [str(value) for value in answer_state.get("smart_supporting_concepts", [])]
runtime["smart_graph_version"] = str(answer_state.get("smart_graph_version", "") or "")
runtime["smart_information_value"] = float(answer_state.get("smart_information_value", 0.0) or 0.0)
runtime["smart_information_breakdown"] = dict(answer_state.get("smart_information_breakdown") or {})
runtime["smart_question_quality_status"] = str(answer_state.get("smart_question_quality_status", "") or "")
runtime["smart_question_quality_confidence"] = float(
answer_state.get("smart_question_quality_confidence", 0.0) or 0.0
)
runtime["smart_graph_bottleneck"] = float(answer_state.get("smart_graph_bottleneck", 0.0) or 0.0)
runtime["repair_stage"] = str(answer_state.get("repair_stage", "") or "")
runtime["repair_concept_key"] = str(answer_state.get("repair_concept_key", "") or "")
runtime["legacy_repair_concept_key"] = str(answer_state.get("legacy_repair_concept_key", "") or "")
runtime["prediction_id"] = str(answer_state.get("prediction_id", "") or "")
runtime["prediction_snapshot"] = dict(answer_state.get("prediction_snapshot") or {})
return runtime
def reset_runtime_question_state(question: RuntimeQuestionMapping) -> QuestionRuntimeState:
runtime = as_runtime_question(question)
runtime["selected"] = []
runtime["pending"] = []
runtime["answered"] = False
runtime["flagged"] = bool(runtime.get("flagged", False))
runtime["suspended"] = bool(runtime.get("suspended", False))
runtime["last_confidence"] = str(runtime.get("last_confidence", "") or "")
runtime["last_miss_reason"] = str(runtime.get("last_miss_reason", "") or "")
runtime["last_recall_failure"] = str(runtime.get("last_recall_failure", "") or "")
runtime["answer_event_id"] = str(runtime.get("answer_event_id", "") or "")
runtime["recall_ready"] = bool(runtime.get("recall_ready", False))
runtime["session_tag"] = str(runtime.get("session_tag", "") or "")
runtime["smart_primary_role"] = str(runtime.get("smart_primary_role", "") or "")
runtime["smart_selection_reasons"] = [str(value) for value in runtime.get("smart_selection_reasons", [])]
runtime["smart_utility"] = float(runtime.get("smart_utility", 0.0) or 0.0)
runtime["smart_utility_breakdown"] = dict(runtime.get("smart_utility_breakdown") or {})
runtime["smart_policy_version"] = str(runtime.get("smart_policy_version", "") or "")
runtime["smart_policy_id"] = str(runtime.get("smart_policy_id", "") or "")
runtime["smart_concept_key"] = str(runtime.get("smart_concept_key", "") or "")
runtime["smart_root_cause"] = str(runtime.get("smart_root_cause", "") or "")
runtime["smart_root_cause_confidence"] = float(runtime.get("smart_root_cause_confidence", 0.0) or 0.0)
runtime["smart_supporting_concepts"] = [str(value) for value in runtime.get("smart_supporting_concepts", [])]
runtime["smart_graph_version"] = str(runtime.get("smart_graph_version", "") or "")
runtime["smart_information_value"] = float(runtime.get("smart_information_value", 0.0) or 0.0)
runtime["smart_information_breakdown"] = dict(runtime.get("smart_information_breakdown") or {})
runtime["smart_question_quality_status"] = str(runtime.get("smart_question_quality_status", "") or "")
runtime["smart_question_quality_confidence"] = float(runtime.get("smart_question_quality_confidence", 0.0) or 0.0)
runtime["smart_graph_bottleneck"] = float(runtime.get("smart_graph_bottleneck", 0.0) or 0.0)
runtime["repair_stage"] = str(runtime.get("repair_stage", "") or "")
runtime["repair_concept_key"] = str(runtime.get("repair_concept_key", "") or "")
runtime["legacy_repair_concept_key"] = str(runtime.get("legacy_repair_concept_key", "") or "")
runtime["prediction_id"] = str(runtime.get("prediction_id", "") or "")
runtime["prediction_snapshot"] = dict(runtime.get("prediction_snapshot") or {})
return runtime
def clear_runtime_answer_state(
question: RuntimeQuestionMapping, *, clear_flagged: bool = False
) -> QuestionRuntimeState:
runtime = as_runtime_question(question)
runtime["selected"] = []
runtime["pending"] = []
runtime["answered"] = False
runtime["last_confidence"] = ""
runtime["last_miss_reason"] = ""
runtime["last_recall_failure"] = ""
runtime["answer_event_id"] = ""
runtime["recall_ready"] = False
if clear_flagged:
runtime["flagged"] = False
return runtime