-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlearn.py
369 lines (356 loc) · 9.94 KB
/
learn.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
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
360
361
362
363
364
365
366
367
368
369
#!/usr/bin/env python3
import time
import random
def main():
global last5list, nottested, type0list, type1list, type2list, type3list
klevel=0
try:
speed=int(input("What speed do you want to learn? (0) Slow (1) Fast:"))
except ValueError:
print("bad input, default speed is slow")
try:
klevel=int(input("How much do you know about this study set? (0) almost none (1) some (2) almost all (3) test me:"))
except ValueError:
print("bad input, default knowledge is 0")
if klevel >= 3:
print("testing")
full_test(tolearn)
else:
slist="studylist.mem"
matchsplchar="!!!!!"
linesplchar="###"
tolearn, progress_list=matchinglist(slist, matchsplchar, linesplchar, speed+klevel)
result=learn(speed, klevel)
rounds=1
startlist=range(0,255)
if result == 1:
success, question_num=question1mcq(startlist, tolearn, True)
difficulty=3
elif result ==2:
success, question_num, difficulty=question2write(startlist, tolearn, True)
progress_list=listconfig(success, question_num, result, progress_list)
last5list=[]
nottested=[]
type0list=[]
type1list=[]
type2list=[]
type3list=[]
done=False
while done == False:
test_list, done, result=knowledgecalc(question_num, progress_list, rounds)
if result == 1:
success, question_num=question1mcq(test_list, tolearn, True)
difficulty=3
elif result ==2:
success, question_num, difficulty=question2write(test_list, tolearn, True)
progress_list=listconfig(success, question_num, result, progress_list)
rounds+=1
def learn(speed, klevel):
coef=klevel+speed
if coef >= 2:
return 2
else:
return 1
def listconfig(success, question_num, qtype, testlist):
if success==True:
if qtype==3:
level=3
elif qtype==2:
level=3
elif qtype==1:
level=1
elif qtype==0:
level=1
else:
if qtype==3:
level=-1
elif qtype==2:
level=-1
elif qtype==1:
level=-2
elif qtype==0:
level=-2
prev_quests=testlist[question_num][2].append(qtype)
if testlist[question_num][3]:
testlist[question_num][3]=testlist[question_num][3]+level
else:
testlist[question_num][3]=level
return testlist
def knowledgecalc(question_num, progress_list, rounds):
print(question_num, progress_list, rounds)
global last5list, nottested, type0list, type1list, type2list, type3list
last5list.append(question_num)
if len(last5list)>5:
last5list.pop(0)
mastered=6
for i in range(len(progress_list)):
try:
if progress_list[i][3] > mastered:
nottested.append(i)
elif progress_list[i][3] >= 4:
type3list.append(i)
elif progress_list[i][3] >= 1:
type2list.append(i)
elif progress_list[i][3] >= -1:
type1list.append(i)
else:
type0list.append(i)
except:
print(i)
nottested=list(set(nottested))
type0list=list(set(type0list))
type1list=list(set(type1list))
type2list=list(set(type2list))
type3list=list(set(type3list))
c1=-1 #type0list
c2=-0.05 #type1list
c3=3 #type2or3 probably need to split apart these coefficients
c4=-1 #not tested
qtype=(len(type0list)*c1+len(type1list)*c2+(len(type2list)+len(type3list))*c3)/rounds+(c4*len(nottested))/len(progress_list)
print("QTYPE:", qtype )
if qtype < -2:
qtype=0
testlist=type0list
elif qtype < 1:
qtype=1
testlist=type1list
elif qtype < 4:
qtype=2
testlist=type2list
else:
qtype=3
testlist=type3list
all_mastered=True
for i in range(len(progress_list)):
try:
if progress_list[i][3] < 5:
all_mastered=False
break
except:
print(i)
if all_mastered:
total_score=0
for i in range(len(progress_list)):
try:
total_score+=progress_list[i][3]
except:
print(i)
if total_score>6.5*len(progress_list):
finished = True
else:
finished=False
else:
finished=False
return testlist, finished, qtype
def question1mcq(testlist, matchlist, withrandom):
y=len(testlist)
rand_q=random.randint(0,y-1)
question=matchlist[testlist[rand_q]][0]
rand_a=random.randint(0,3)
random_answer1=testlist[rand_q]
rand_ans=matchlist[testlist[rand_q]][1]
random_answer1=rand_ans
while random_answer1==rand_ans:
random_answer1=matchlist[ random.randint(0,len(matchlist)-1)][1]
random_answer2=rand_ans
while random_answer2==rand_ans or random_answer2==random_answer1:
random_answer2=matchlist[random.randint(0,len(matchlist)-1)][1]
random_answer3=rand_ans
while random_answer3==rand_ans or random_answer3==random_answer1 or random_answer3==random_answer2:
random_answer3=matchlist[random.randint(0,len(matchlist)-1)][1]
print(question)
# random_answer1=matchlist(random_answer1[1])
# random_answer2=matchlist(random_answer2[1])
# random_answer2=matchlist(random_answer3[1])
if rand_a==0:
print("(a)", rand_ans)
print("(b)", random_answer1)
print("(c)", random_answer2)
print("(d)", random_answer3)
elif rand_a==1:
print("(a)", random_answer1)
print("(b)", rand_ans)
print("(c)", random_answer2)
print("(d)", random_answer3)
elif rand_a==2:
print("(a)", random_answer1)
print("(b)", random_answer2)
print("(c)", rand_ans)
print("(d)", random_answer3)
elif rand_a==3:
print("(a)", random_answer1)
print("(b)", random_answer2)
print("(c)", random_answer3)
print("(d)", rand_ans)
user_answer=input("Answer:")
print("Your answer:", user_answer)
if user_answer=="a":
user_answer=0
if user_answer=="b":
user_answer=1
if user_answer=="c":
user_answer=2
if user_answer=="d":
user_answer=3
if user_answer==rand_a:
print("Correct!")
print(rand_ans)
return True, rand_q
else:
print("INCORRECT :(")
print(rand_ans)
return False, rand_q
def question2write(testlist, matchlist, withrandom):
y=len(testlist)
rand_q=random.randint(0,y-1)
question=matchlist[testlist[rand_q]][0]
rand_ans=matchlist[testlist[rand_q]][1]
print(question)
user_answer=input("Answer:")
print("Your answer:", user_answer)
if user_answer==rand_ans:
print("Correct!")
print(rand_ans)
user_level=input("How hard was that to recall, (1, easy-5, very hard), or actually I was INCORRECT(n):")
if user_level.isdigit():
user_level=int(user_level)
if user_level>0 and user_level<=5:
return True, testlist[rand_q], user_level
else:
return True, testlist[rand_q], 5
elif isinstance(user_level, str):
if user_level=="n":
print("INCORRECT ")
return False, testlist[rand_q], 0
else:
return True, testlist[rand_q], 5
else:
print("INCORRECT ")
print(rand_ans)
user_level=input("Overide I was correct, rate how easy it was to recall(1, easy-5, very hard), else just enter:")
if user_level.isdigit():
user_level=int(user_level)
if user_level>0 and user_level<=5:
print("Correct!")
return True, testlist[rand_q], user_level
else:
return False, testlist[rand_q], 0
else:
return False, testlist[rand_q] , 0
def question3NOTNOW(knowlist, testlist, matchlist, withrandom):
x=len(testlist)
y=len(unknownlist)
rand_q=random.randint(0,y-1)
question=unknownlist(rand_q[0])
rand_a=random.randint(0,3)
random_answer1=rand_q
while random_answer1==rand_q:
rand_answer1=random.randint(0,x+y-2)
while random_answer2==rand_q or random_answer2==random_answer1:
rand_answer2=random.randint(0,x+y-2)
while random_answer3==rand_q or random_answer3==random_answer1 or random_answer3==random_answer2:
rand_answer3=random.randint(0,x+y-2)
print(question)
rand_a=unknownlist(rand_q)
random_answer1=matchlist(random_answer1[1])
random_answer2=matchlist(random_answer2[1])
random_answer2=matchlist(random_answer3[1])
if rand_a==0:
print("(a)", rand_a)
print("(b)", random_answer1)
print("(c)", random_answer2)
print("(d)", random_answer3)
elif rand_a==1:
print("(a)", random_answer1)
print("(b)", rand_a)
print("(c)", random_answer2)
print("(d)", random_answer3)
elif rand_a==2:
print("(a)", random_answer1)
print("(b)", rand_a)
print("(c)", random_answer2)
print("(d)", random_answer3)
elif rand_a==3:
print("(a)", random_answer1)
print("(b)", rand_a)
print("(c)", random_answer2)
print("(d)", random_answer3)
user_answer=input("Answer:")
if user_answer=="a":
user_answer=1
if user_answer=="b":
user_answer=2
if user_answer=="c":
user_answer=3
if user_answer=="d":
user_answer=4
if user_answer==rand_a:
print("Correct!")
return True, rand_q
else:
print("__INCORRECT__ :(")
return False, rand_q
def question(qtype):
if qtype==0:
print(tolearn[random.randint(len(tolearn))])
input=int(print("?"))
elif qtype==1:
print("test1")
elif qtype==2:
print("test2")
elif qtype==3:
print("test3")
def matchinglist(slist, matchsplitchar, linesplitchar, defaultlevel):
newlines=[]
# with open(f'{slist}') as file:
# lines = [line.rstrip() for line in file]
with open(f'{slist}', 'r') as file:
data = file.read()
lines=data.split(linesplitchar)
print(lines)
for stuff in lines:
things=stuff.split(matchsplitchar)
newlines.append(things)
progresslist=newlines
for i in range(len(progresslist)):
progresslist[i].append([])
progresslist[i].append(defaultlevel)
print(newlines)
#print(progresslist)
return newlines, progresslist
def full_test(testlist):
question_list=testlist
tested=[]
correct_incorrect=[]
correct=0
for i in range(len(testlist)):
test_q=random.randint(0, len(testlist)-1)
print(testlist[test_q][0])
#print(testlist[test_q[0]])
user_input=input("Answer:")
if user_input==testlist[test_q][1]:
print("Correct")
print(testlist[test_q][1])
correction=input("overide I was incorrect?")
if correction == "Y" or correction == "y":
print("Incorrect")
correct_incorrect.append("0")
else:
correct_incorrect.append("1")
correct+=1
else:
print("Incorrect")
print(testlist[test_q][1])
correction=input("overide I was correct?")
if correction == "Y" or correction == "y":
print("Correct")
correct_incorrect.append("1")
correct+=1
else:
correct_incorrect.append("0")
tested.append(testlist[test_q])
testlist.pop(test_q)
print("You got", correct, "correct out of ", len(question_list))
print("wrong question check coming soon...., end test anytime stuff coming soon, and replaces test questions thing coming soon")
if __name__ == "__main__":
main()