-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
76 lines (55 loc) · 1.98 KB
/
main.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
import random
from Questions import Questions
from PaperFormat import PaperFormat
from utils import *
def paper(questions, format):
res_easy = find_questions(questions, format.easy, EASY)
res_medium = find_questions(questions, format.medium, MEDIUM)
res_hard = find_questions(questions, format.hard, HARD)
# Printing the results
print_questions(res_easy)
print_total_marks(res_easy)
print_questions(res_medium)
print_total_marks(res_medium)
print_questions(res_hard)
print_total_marks(res_hard)
def find_questions(questions, percentage, difficulty):
from random import shuffle
filtered_questions = list(filter(lambda q: q.difficulty == difficulty, questions))
shuffle(filtered_questions)
res = next_delta(filtered_questions, percentage, [], [])
return res
def next_delta(questions, remaining, res, removed):
for i in range(0, len(questions)):
if not questions[i]:
return []
left = remaining - questions[i].marks
if left >= 0:
if left == 0:
res.append(questions[i])
return res
elif left > 0:
removed.append(questions[i])
res.append(questions[i])
del questions[i]
return next_delta(questions, left, res, removed)
else:
del questions[i]
return next_delta(questions, remaining, res, removed)
else:
return []
def generate_questions():
import json
questions = []
with open('MOCK_DATA.json') as f:
raq_questions = json.load(f)
for q in raq_questions:
questions.append(Questions(q['text'], q['subject'], q['topic'], q['difficulty'], q['marks']))
return questions
def main():
questions = generate_questions()
paper_format = PaperFormat(20, 10, 5, 5)
# Func paper will print all the required meta. Func paper is not a pure func
paper(questions, paper_format)
if __name__ == '__main__':
main()