-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathquizes.py
127 lines (102 loc) · 4.14 KB
/
quizes.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
from collections import namedtuple
Question = namedtuple('Question', ['question', 'answers'])
class BaseQuiz:
def __init__(self, id, questions, lang, question_number=0, answers=None, created_at=None):
self.id = id
self.questions = questions
self.lang = lang
self.question_number = question_number
self.answers = [] if answers is None else answers
self.created_at = created_at
def get_question(self):
raise NotImplementedError
def save_answer(self, answer):
self.answers.append(answer)
self.question_number += 1
def get_result(self):
raise NotImplementedError
@property
def result(self):
return sum(self.answers)
@property
def is_completed(self):
return self.question_number == self.questions_count
@property
def questions_count(self):
raise NotImplementedError
class HARSQuiz(BaseQuiz):
RESULTS = {
'en': [
'mild anxiety severity 👍',
'mild to moderate anxiety severity 😐',
'moderate to severe anxiety severity 😦'
],
'it': [
'ansia lieve 👍',
'ansia da lieve a moderata 😐',
'ansia da moderata a grave 😦'
],
'pt': [
'ansiedade leve 👍',
'ansiedade leve a moderada 😐',
'ansiedade moderada a severa 😦'
],
'ru': [
'отсутствие тревоги 👍',
'средняя выраженность тревожного расстройства 😐',
'тяжелая тревога 😦'
]
}
type_ = 'hars'
def get_question(self):
return Question(
"\u2753({}/{}) {}".format(
(self.question_number + 1), self.questions_count,
self.questions[self.lang]['questions'][self.question_number]),
self.questions[self.lang]['answers'])
def get_result(self):
if not self.is_completed:
raise ValueError("Can't calculate result for incomplete test")
if self.result <= 17:
description = self.RESULTS[self.lang][0]
elif self.result <= 24:
description = self.RESULTS[self.lang][1]
else:
description = self.RESULTS[self.lang][2]
return '{}:\n{}/{}\n{}'.format(
'Результат' if self.lang == 'ru' else 'Result',
self.result, self.questions_count * 4, description)
@property
def questions_count(self):
return len(self.questions[self.lang]['questions'])
class MADRSQuiz(BaseQuiz):
RESULTS = {
'en': ['normal 👍', 'mild depression 😐', 'moderate depression 😔', 'severe depression 😨'],
'it': ['normale 👍', 'depressione lieve 😐', 'depressione moderata 😔', 'depressione grave 😨'],
'pt': ['normal 👍', 'depressão leve 😐', 'depressão moderada 😔', 'depressão severa 😨'],
'ru': ['норма 👍', 'слабая депрессия 😐', 'умеренная депрессия 😔', 'тяжелая депрессия 😨']
}
type_ = 'madrs'
def get_question(self):
return Question(
"\u2753({}/{}) {}".format(
(self.question_number + 1), self.questions_count,
self.questions[self.lang][self.question_number]['question']),
self.questions[self.lang][self.question_number]['answers'])
def get_result(self):
if not self.is_completed:
raise ValueError("Can't calculate result for incomplete test")
if self.result <= 6:
description = self.RESULTS[self.lang][0]
elif self.result <= 19:
description = self.RESULTS[self.lang][1]
elif self.result <= 34:
description = self.RESULTS[self.lang][2]
else:
description = self.RESULTS[self.lang][3]
return '{}:\n{}/{}\n{}'.format(
'Результат' if self.lang == 'ru' else 'Result',
self.result, self.questions_count * 6, description)
@property
def questions_count(self):
return len(self.questions[self.lang])