-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquiz_engine.py
More file actions
31 lines (26 loc) · 987 Bytes
/
quiz_engine.py
File metadata and controls
31 lines (26 loc) · 987 Bytes
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
from __future__ import annotations
import datetime as dt
from dataclasses import dataclass
from typing import List
from contributions import (
ContributionsClient,
DayContribution,
generate_mcq_for_date,
pick_random_quizable_date,
)
@dataclass
class QuizQuestion:
text: str
options: List[int]
correct_index: int
date: dt.date
class QuizEngine:
def __init__(self):
self.client = ContributionsClient()
def load_user_year(self, username: str) -> List[DayContribution]:
return self.client.get_contributions(username=username, days=365)
def make_question(self, username: str) -> QuizQuestion:
contribs = self.load_user_year(username)
chosen_date = pick_random_quizable_date(contribs, lookback_days=120)
q, options, correct_idx = generate_mcq_for_date(contribs, chosen_date)
return QuizQuestion(text=q, options=options, correct_index=correct_idx, date=chosen_date)