-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdifficulty.py
65 lines (59 loc) · 1.47 KB
/
difficulty.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
from db.models import Score
from db.models import Category
EASY = 1
MEDIUM = 2
HARD = 3
BEGINNER = 1
INTERMEDIATE = 2
EXPERT = 3
def difficulty(user_id):
data = []
sum = 0
question_data = Score.find_all(user_id = user_id)
for i in question_data:
category_data = Category.find(category_id = i.category_id)
data.append((category_data.name, str(((i.num_correct / i.num_answered) * 100 )) + "%"))
return data
"""
for person, correct in people_answers:
if correct:
if person == BEGINNER:
sum += EASY
elif person == INTERMEDIATE:
sum += MEDIUM
elif person == EXPERT:
sum += HARD
else:
if person == BEGINNER:
sum += MEDIUM
elif person == INTERMEDIATE:
sum += HARD
elif person == EXPERT:
sum += HARD
average = sum/len(people_answers)
if 0 <= average < 2:
return "Easy"
elif 2 <= average < 3:
return "Medium"
elif 3 < average:
return "Hard"
"""
def skill_level(questions_answers):
''' This is findind the skill level of a user.
questions_answers is a list of the questions the user has answered and if they got it right or wrong. '''
total = 0
for question, correct in questions_answers:
if correct:
if question == EASY:
total += 1
elif question == MEDIUM:
total += 2
elif question == HARD:
total += 3
final = total/len(questions_answers)
if final < 1.25:
return 'Beginner'
elif 1.25 <= final < 2.25:
return 'Intermediate'
elif 2.25 <= final:
return 'Expert'