forked from sidhantagar/AI-Proctoring-Mate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shuffler.py
74 lines (65 loc) · 2.53 KB
/
shuffler.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
import random
randomizer_questions = None
randomizer_options = None
def shuffle_question_num(question_num, active_section):
if randomizer_questions is not None:
return randomizer_questions[active_section-1][question_num-1]
else:
return question_num
def response_transform (number, question_num, active_section):
if randomizer_options is None:
return number
response = 0
shuffling_pattern = randomizer_options[active_section-1][question_num-1]
arr = [1,2,4,8]
for i in range(4):
vals = number % 2
number = number//2
response += vals*arr[shuffling_pattern[i]-1]
return response
def response_inverse_transform (number, question_num, active_section):
if randomizer_options is None:
return number
shuffling_pattern = randomizer_options[active_section-1][question_num-1]
inverse_shuffling_pattern = [0, 0, 0, 0]
response = 0
for i in range(4):
inverse_shuffling_pattern[shuffling_pattern[i]-1]= i+1
arr = [1,2,4,8]
for i in range(4):
vals = number % 2
number = number//2
response += vals*arr[shuffling_pattern[i]-1]
return response
def shuffle_option (this_question, question_num, active_section):
#print(this_question)
if randomizer_options is None:
return this_question
shuffling_pattern = randomizer_options[active_section-1][question_num-1]
shuffled_options = this_question.copy()
for i in range(1,5):
shuffled_options.at[0, 'Option_'+ str(i)] = this_question.at[0, 'Option_'+ str(shuffling_pattern[i-1])]
#print(shuffled_options)
#print(shuffling_pattern)
return shuffled_options
def define_initializations(DF_CONFIGURATION, NUM_QUESTIONS):
global randomizer_questions, randomizer_options
if (DF_CONFIGURATION.at['Randomize_questions','Value'] == 'True'):
randomizer_questions = []
for i in NUM_QUESTIONS:
arr = [j for j in range(1,i+1)]
random.shuffle(arr)
randomizer_questions.append(arr)
if (DF_CONFIGURATION.at['Randomize_options','Value'] == 'True'):
randomizer_options = []
for i in NUM_QUESTIONS:
temp = []
for j in range(i):
arr = [k for k in range(1,5)]
random.shuffle(arr)
temp.append(arr)
randomizer_options.append(temp)
#print(randomizer_options)
#print(randomizer_questions)
def initialze_shuffler(DF_CONFIGURATION, NUM_QUESTIONS):
define_initializations(DF_CONFIGURATION, NUM_QUESTIONS)