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

update utils module

Browse files
Files changed (1) hide show
  1. scripts/quiz/utils.py +37 -8
scripts/quiz/utils.py CHANGED
@@ -1,13 +1,42 @@
 
 
 
1
  from typing import Literal
2
 
3
- def get_next_level(cur_level, levep_up: Literal[True, False] = True):
4
- if levep_up:
5
- if cur_level == "easy":
6
- return "medium"
7
  else:
8
- return "hard"
9
  else:
10
- if cur_level == "medium":
11
- return "easy"
12
  else:
13
- return "medium"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas
2
+ import random
3
+ from scipy.interpolate import interp1d
4
  from typing import Literal
5
 
6
+ def get_next_difficulty(difficulty, do_increase: Literal[True, False] = True):
7
+ if do_increase:
8
+ if difficulty >= 0.95:
9
+ next_difficulty = round(random.uniform(0.95, 0.99), 2)
10
  else:
11
+ next_difficulty = round(random.uniform(difficulty + 0.01, difficulty + 0.05), 2)
12
  else:
13
+ if difficulty <= 0.05:
14
+ next_difficulty = round(random.uniform(0.01, 0.05), 2)
15
  else:
16
+ next_difficulty = round(random.uniform(difficulty - 0.05, difficulty - 0.01), 2)
17
+
18
+ return next_difficulty
19
+
20
+
21
+ def generate_start_step(difficulty: float, path_to_csv_file: str = "data.csv"):
22
+ """generate start and step values interpolating results to function built from data from file"""
23
+ df = pandas.read_csv(path_to_csv_file, delimiter=',', header=0, names=['difficulty', 'start'])
24
+ all_rows = df.loc[:]
25
+
26
+ difficulties = [row_data['difficulty'] for _, row_data in all_rows.iterrows()]
27
+ starts = [row_data['start'] for _, row_data in all_rows.iterrows()]
28
+
29
+ interp_start_func = interp1d(difficulties, starts)
30
+ generated_start = round(float(interp_start_func(difficulty)))
31
+ if difficulty <= 0.3:
32
+ step = 1
33
+ elif difficulty > 0.6:
34
+ step = 10
35
+ else:
36
+ step = 5
37
+ return (generated_start, step)
38
+
39
+
40
+ def convert_sequence_to_string(start, step, sep=", "):
41
+ stop = start + 3 * step
42
+ return sep.join([str(num) for num in range(start, stop, step)])