-
Notifications
You must be signed in to change notification settings - Fork 0
/
duo-mem-mcc.py
121 lines (80 loc) · 2.6 KB
/
duo-mem-mcc.py
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
import pandas as pd
import numpy as np
from tkinter import *
from tkinter import messagebox as mb
import sys
class Quiz:
def __init__(self, n):
self.gui = Tk()
self.gui.geometry("300x400")
self.gui.title("Duo+Memrise Quiz")
self.q_no = 0
self.total_q = n
self.correct=0
self.wrong_list=[]
self.display_question()
self.opt_selected=IntVar()
self.opts=self.radio_buttons()
self.display_options()
self.buttons()
def display_result(self):
score = int(self.correct / self.total_q * 100)
result = f"Score: {score}%"
wrong_words = question[self.wrong_list]
mb.showinfo("Result", f"{result}\nWrong words:\n{wrong_words}")
def check_ans(self, q_no):
if self.opt_selected.get() == answer[q_no]+1:
return True
def next_btn(self):
if self.check_ans(self.q_no):
self.correct += 1
else:
self.wrong_list.append(self.q_no)
self.q_no += 1
if self.q_no==self.total_q:
self.display_result()
self.gui.destroy()
else:
self.display_question()
self.display_options()
def buttons(self):
quit_button = Button(self.gui, text="Quit", command=self.gui.destroy,
width=5,bg="black", fg="black",font=("ariel",16," bold"))
quit_button.place(x=100,y=320)
def display_options(self):
val=0
self.opt_selected.set(0)
for option in options[self.q_no]:
print(self.opts, val)
self.opts[val]['text']=option
val+=1
res = Label(self.gui, text=f"Score: {self.correct}/{self.q_no}")
res.place(x=100, y=280)
def display_question(self):
q_no = Label(self.gui, text=question[self.q_no], width=60,
font=( 'ariel' ,16, 'bold' ), anchor= 'w' )
q_no.place(x=70, y=70)
def radio_buttons(self):
q_list = []
y_pos = 100
while len(q_list) < options.shape[1]:
radio_btn = Radiobutton(self.gui,variable=self.opt_selected, command=self.next_btn,
value = len(q_list)+1,font = ("ariel",14))
q_list.append(radio_btn)
radio_btn.place(x = 80, y = y_pos)
y_pos += 30
return q_list
url = "https://raw.githubusercontent.com/ddundo/norsk/main/data/duomem_dict.csv"
data = pd.read_csv(url, sep=";").sample(frac=1)
question = data['engelsk'].to_numpy()
correct = data['norsk'].to_numpy()
_opts = [correct, np.random.permutation(correct), np.random.permutation(correct), np.random.permutation(correct)]
options = np.squeeze(np.dstack(_opts))
options = options.swapaxes(-1, -1)
for ndx in np.ndindex(options.shape[:-1]):
np.random.shuffle(options[ndx])
_ans2d = np.repeat(correct, 4).reshape(-1, 4)
_, answer = np.where(options == _ans2d)
n = int(sys.argv[1]) # number of questions per quiz
quiz = Quiz(n)
quiz.gui.mainloop()