sviddo commited on
Commit
03fc001
1 Parent(s): 3740281

update questions module

Browse files
Files changed (1) hide show
  1. scripts/quiz/questions.py +20 -166
scripts/quiz/questions.py CHANGED
@@ -1,175 +1,29 @@
1
- import random
2
- from typing import Literal
3
 
4
 
5
- def generate_question_data(level: Literal["easy", "medium", "hard"] = "easy", increment=1):
6
- """generate question, its numbers and proper answer"""
7
-
8
- nums = generate_numbers_by_level(level)
9
- cur_num = nums['current_number'] # current number
10
- ord_num = nums['ordinal_number'] # ordinal number
11
- num_seq = generate_number_sequence(cur_num, ord_num, times=increment) # sequence with ord_num = 1, times = 1
12
-
13
- count_up_by_one_questions = [
14
- {
15
- "question": f"Let's practice counting. After {cur_num}, what number is next?\n{num_seq}",
16
- "current_number": cur_num,
17
- "ordinal_number": 1,
18
- "times": 1,
19
- "answer": cur_num + 1
20
- }
21
- ]
22
- seq_up_by_ord = generate_number_sequence(cur_num, ord_num, times=1) # sequence with times = 1
23
- count_up_by_ord_questions = [
24
- {
25
- "question": f"What number comes {ord_num} number after {cur_num}?\n{seq_up_by_ord}",
26
- "current_number": cur_num,
27
- "ordinal_number": ord_num,
28
- "times": 1,
29
- "answer": cur_num + ord_num
30
- },
31
- {
32
- "question": f"If we count up {ord_num} from {cur_num}, what number is next?\n{seq_up_by_ord}",
33
- "current_number": cur_num,
34
- "ordinal_number": ord_num,
35
- "times": 1,
36
- "answer": cur_num + ord_num
37
- }
38
- ]
39
- times = 1 if level == "easy" else nums['times']
40
- times_ord_seq = generate_number_sequence(cur_num, ord_num, times)
41
- times_ord_questions = [
42
- {
43
- "question": f"We're counting up by {times}s. What number is {ord_num} after {cur_num}?\n{times_ord_seq}",
44
- "current_number": cur_num,
45
- "ordinal_number": ord_num,
46
- "times": times,
47
- "answer": cur_num + ord_num * times
48
- }
49
- ]
50
- times_only_seq = generate_number_sequence(cur_num, 1, times) # sequence with ordinal number = 1
51
- times_only_questions = [
52
- {
53
- "question": f"Let's count up by {times}s. What number is next if we start from {cur_num}?\n{times_only_seq}",
54
- "current_number": cur_num,
55
- "ordinal_number": 1,
56
- "times": times,
57
- "answer": cur_num + times
58
- }
59
- ]
60
- print(f"Let's practice counting {'... '.join([str(num) for num in range(8, 11)])}... After 10, what is the next number you will count?")
61
- # Let's practice counting 8... 9... 10... After 10, what is the next number you will count?
62
- 8, 9, 10
63
- questions = [*count_up_by_one_questions, *count_up_by_ord_questions, *times_only_questions, *times_ord_questions]
64
- random_choice = random.choice(questions)
65
- return random_choice
66
-
67
-
68
- def generate_question(start, step=None, seq=None, question_num=1):
69
  """returns question by provided number with filled parameters
70
 
71
  parameters
72
  ----------
73
- :num: question number
74
  :start: current number
75
  :step: interval between current and next numbers
76
- :seq: sequence of numbers"""
77
- convert_sequence_to_string(start, step, )
78
- questions = {
79
- 1: f"Let's practice counting {seq} After {start}, what is the next number you will count?",
80
- 2: f"What number comes {step} number after {start}?",
81
- 3: f"We're counting by {step}s. What number is 1 after {start}?",
82
- 4: f"What is {step} number up from {start}?",
83
- 5: f"If we could up {step} from {start}, what number is next?",
84
- }
85
- if step > 1:
86
- questions.update({
87
- 6: f"Now we're counting up by {step} 😄 From {start - 2 * step}, I count {step} numbers to get to {start - step}. Then from {start - step} I count {step} numbers to get to {start}. What is {step} numbers after {start}?",
88
- 7: f"What is {step} numbers after {start}? Let's count one number ... {start + 1}... now what is the next number?"
 
 
 
 
89
  })
90
- return questions[question_num]
91
-
92
-
93
- def generate_start_by_score(score):
94
- """generate number by scrore
95
-
96
- to calculate the starting point """
97
- if score <= 0.3:
98
- range_size = 27 - 1 # total range size
99
- range_offset = score # offset from the lower end of the range
100
- proportion = range_offset / 0.3 # proportion of the total range
101
- number_range = int(proportion * range_size) # size of the range based on the argument
102
- return random.randint(1, 1 + number_range)
103
- elif score >= 0.6:
104
- range_size = 495 - 97 # total range size
105
- range_offset = score - 0.6 # offset from the lower end of the range
106
- proportion = range_offset / (1 - 0.6) # proportion of the total range
107
- number_range = int(proportion * range_size) # size of the range based on the argument
108
- return random.randint(98, 98 + number_range)
109
- else:
110
- range_size = 97 - 28 # total range size
111
- range_offset = score - 0.3 # offset from the lower end of the range
112
- proportion = range_offset / (0.6 - 0.3) # proportion of the total range
113
- number_range = int(proportion * range_size) # size of the range based on the argument
114
- return random.randint(28, 28 + number_range)
115
-
116
-
117
- def convert_sequence_to_string(start, step):
118
- func_vars = {}
119
- exec("seq = ', '.join([str(num) for num in range({start}, {stop}, {step})][::-1])".format(start=start, stop=start-3*step, step=step * (-1)), func_vars)
120
- return func_vars['seq']
121
-
122
-
123
-
124
- def generate_numbers_by_level(level: Literal["easy", "medium", "hard"] = "easy"):
125
- """generate current number, ordinal number and times parameter
126
-
127
- returns
128
- dict with params:
129
- :param current_number: current number
130
- :param ordinal numebr: the number we count up by
131
- :param times: the number of times we count up by ordinal number"""
132
-
133
- if level == "easy":
134
- cur_num = random.randint(5, 15)
135
- ord_num = random.randint(1, 2)
136
- times = 1
137
- elif level == "medium":
138
- cur_num = random.randint(1, 94)
139
- ord_num = random.randint(1, 3)
140
- times = random.randint(1, 2)
141
- elif level == "hard":
142
- cur_num = random.randint(1, 488)
143
- ord_num = random.randint(1, 4)
144
- times = random.randint(1, 2)
145
-
146
- return {
147
- "current_number": cur_num,
148
- "ordinal_number": ord_num,
149
- "times": times
150
- }
151
-
152
-
153
- def generate_number_sequence(cur_num, ord_num, times=1):
154
- """generate one of 2 sequences. For example we want 55 to be a right answer, then sequences can be:
155
- 52 53 54 ...
156
- ... 56 57 58
157
-
158
- parameters
159
- :cur_num: current number
160
- :ord_num: ordinal number
161
- :times: times"""
162
- max_num = cur_num + times * ord_num
163
-
164
- seq_before = [str(num) for num in range(max_num - times, 0, -times)][:3][::-1]
165
- seq_after = [str(num) for num in range(max_num + times, max_num + 4 * times, times)]
166
- seq_before.append("...")
167
- seq_after.insert(0, "...")
168
-
169
- seqs = []
170
- if len(seq_before) == 4:
171
- seqs.append(seq_before)
172
- if len(seq_after) == 4:
173
- seqs.append(seq_after)
174
- rand_seq = " ".join(random.choice(seqs))
175
- return rand_seq
 
1
+ from .utils import convert_sequence_to_string
 
2
 
3
 
4
+ def generate_question_data(start, step, question_num=1):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  """returns question by provided number with filled parameters
6
 
7
  parameters
8
  ----------
 
9
  :start: current number
10
  :step: interval between current and next numbers
11
+ :question_num: question number"""
12
+ seq = convert_sequence_to_string(start, step)
13
+ start_from_num = start + 2 * step
14
+ questions = [
15
+ f"Let's practice counting {convert_sequence_to_string(start, step, sep='... ')} After {start_from_num}, what is the next number you will count?\n{seq}",
16
+ f"What number comes {step} number after {start_from_num}?\n{seq}",
17
+ f"We're counting by {step}s. What number is 1 after {start_from_num}?\n{seq}",
18
+ f"What is {step} number up from {start_from_num}?\n{seq}",
19
+ f"If we count up {step} from {start_from_num}, what number is next?\n{seq}",
20
+ ]
21
+ questions_data = []
22
+ for quest in questions:
23
+ questions_data.append({
24
+ "question": quest,
25
+ "answer": start_from_num + step,
26
+ "start": start_from_num,
27
+ "step": step
28
  })
29
+ return questions_data[question_num]