/
main.py
198 lines (153 loc) · 5.58 KB
/
main.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
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
# This is a sample Python script.
# Press Maiusc+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
import sys
import word
import controller
import random
import array
class statistic():
t=""
proposed=0
wrong=0
correct=0
revised_section=""
def __init__(self,time,proposed,wrong,revised_section):
self.t = time
self.proposed = proposed
self.wrong = wrong
self.correct = proposed-wrong
self.revised_section = revised_section
return
def print_stat_after_recap(self):
print("Vocaboli proposti in totale: ",self.proposed)
print ("Corretti (al primo tentativo): {} ({})".format(self.correct,self.perc_right()))
print ("Sbagliati (almeno una volta): {} ({})".format(self.wrong,self.perc_wrong()))
#self.print_all_stats()
def perc_right (self):
corr_perc = (self.proposed-self.wrong) * 100 / self.proposed
return corr_perc
def perc_wrong (self):
wrong_perc = self.wrong * 100 / self.proposed
return wrong_perc
def stat_for_file(self):
stringa = str(self.t) + ";"+str(self.proposed)+";"+str(self.wrong)+";"+str(self.revised_section)
return stringa
def print_all_stats (self):
prepareString = "{} - Ripassati: {}, Corretti: {}, ({}%), Sbagliati: {} ({}%), Sezioni ripassate: {}"\
.format(self.t,self.proposed,self.correct,round(self.perc_right(),2),self.wrong, round(self.perc_wrong(),2),self.revised_section)
print(prepareString)
def print_hi(name):
# Use a breakpoint in the code line below to debug your script.
print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
def menu():
print ("Benvenuta/o! Menu principale:")
choice = input("""
R: Ripassa tutto
RS: Ripassa una sezione
S: Stampa sezioni
STAT: Visualizza le tue statistiche
Q: Esci dal programma
Please enter your choice: """)
choice = choice.lower()
if choice == "R" or choice == "r":
print ("vuoi ripassare tutto")
ripasso_totale()
menu()
elif choice == "RS" or choice == "rs":
print ("vuoi ripassare una sezione")
ripassa_sezione()
menu()
elif choice == "S" or choice == "s":
print ("vuoi stampare le sezioni")
stampa_sezioni()
menu()
elif choice == "Q" or choice == "q":
print ("Alla prossima!")
exit()
elif choice == "stat":
stampa_statistiche()
menu()
else:
print ("scegli tra R, RS, S o Q")
print ("Per favore riprova")
menu()
def stampa_sezioni():
for x in categorie:
print ("Sezione {}: {}".format(x,categorie[x]))
def stampa_statistiche():
if len(stats) == 0:
print ("Non ci sono ancora statistiche")
return menu()
print ("Corretti: al primo tentativo, Sbagliati: almeno una volta")
for x in stats:
x.print_all_stats()
menu()
def ripassa_tutto():
test2 = termini;
randomValue = random.randint(0,len(test2));
underAnalysis = termini[randomValue]
underAnalysis.printTerm()
typeOfterm = categorie.get(underAnalysis.group)
underAnalysis.giveChoice(typeOfterm)
def ripasso_totale():
terms_to_recap = []
for x in termini:
terms_to_recap.append(x)
categories_to_recap=""
for x in categorie.values():
categories_to_recap+=x+","
categories_to_recap=categories_to_recap.removesuffix(",")
controllerEx.gestisci_ripasso_sezione(terms_to_recap, categorie,categories_to_recap,stats)
def ripassa_sezione():
stampa_sezioni()
selezione= input("""Quale sezione/i vuoi ripassare? per ripassare più sezioni usa 1,2,3 etc.: """)
# print(selezione)
#print(categorie)
chosen_section= selezione.split(",")
for sect in chosen_section:
if sect not in categorie:
print ("Selezione non valida, ritorno al menu principale")
return
#if we are here all section were ok
terms_to_recap = []
chosen_cat_for_stat=""
for sect in chosen_section:
#print("sect", sect)
sezione = categorie.get(sect)
chosen_cat_for_stat+=sezione+","
for x in termini:
#print (x.group, "", sezione)
if (x.group == sezione):
# print("Adding term to recap")
#print(x.right_answer)
terms_to_recap.append(x)
sez =categorie.get(sezione)
# print (len(termini), "" ,len(terms_to_recap))
chosen_cat_for_stat = chosen_cat_for_stat.removesuffix(",")
#print (chosen_cat_for_stat)
#print(terms_to_recaprs)
controllerEx.gestisci_ripasso_sezione(terms_to_recap, categorie,chosen_cat_for_stat,stats)
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
filename="vocabolario.txt"
termini = []
categorie = {}
stats = []
controllerEx = controller.controller();
controllerEx.welcome_message()
controllerEx.loadFile(termini,categorie,filename);
termini_counter=len(termini)
if termini_counter == 0:
print ("Nessun termine presente in ",filename," il programma sarà chiuso")
exit(0)
else:
print("Caricati: ",termini_counter,"termini\n\n")
stats=controllerEx.loadStats(stats)
#menu()
#ripassa_tutto()
#ripassa_sezione("1")
#ripasso_totale()
#stampa_sezioni()
menu()
# See PyCharm help at https://www.jetbrains.com/help/pycharm/