-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClass_Creator_for_App.py
More file actions
130 lines (113 loc) · 6.13 KB
/
Class_Creator_for_App.py
File metadata and controls
130 lines (113 loc) · 6.13 KB
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
128
129
130
from Class_Gener import *
from fpdf import FPDF
class Creator:
def export_task(self, path, key):
pdf = FPDF()
pdf.add_page()
pdf.add_font('Arial', '', './Arial.ttf', uni=True)
pdf.set_font('Arial', '', 14)
res = self.function_creator(key)
pdf.multi_cell(190, 10, txt=res[0])
pdf.output(path)
return res
def export_PDF(self, path, text):
pdf = FPDF()
pdf.add_page()
pdf.add_font('Arial', '', './Arial.ttf', uni=True)
pdf.set_font('Arial', '', 14)
pdf.multi_cell(190, 10, txt=text)
pdf.output(path)
def function_creator(self, key):
que_text_result = ""
ans_text_result = ""
if key["Type"] == "СР": # Самостоятельная работа
if key["Subject"] == "Физика":
if key["Theme"] == "Кинематика":
if key["Theme_section"] == "Равномерное движение":
for i in range(int(key["N"])):
que_ans_text = TaskGenerator().uniform_motion()
ans_text_result += f'{i + 1}) Ответ: '
for j, answer in enumerate(que_ans_text[1]):
ans_text_result += f'{answer} {que_ans_text[2][j]}; '
que_text_result += f'{i+1}) {que_ans_text[0]}\n\n'
ans_text_result += '\n'
return que_text_result, ans_text_result
elif key["Theme_section"] == "Равноускоренное движение":
for i in range(int(key["N"])):
que_ans_text = TaskGenerator().equiaxed_motion()
ans_text_result += f'{i + 1}) Ответ: '
for j, answer in enumerate(que_ans_text[1]):
ans_text_result += f'{answer} {que_ans_text[2][j]}; '
que_text_result += f'{i+1}) {que_ans_text[0]}\n\n'
ans_text_result += '\n'
return que_text_result, ans_text_result
elif key["Theme"] == "Баллистика":
if key["Theme_section"] == "Свободное падение":
for i in range(int(key["N"])):
que_ans_text = TaskGenerator().ballistics_motion()
ans_text_result += f'{i + 1}) Ответ: '
for j, answer in enumerate(que_ans_text[1]):
ans_text_result += f'{answer} {que_ans_text[2][j]}; '
que_text_result += f'{i+1}) {que_ans_text[0]}\n\n'
ans_text_result += '\n'
return que_text_result, ans_text_result
elif key["Theme_section"] == "Баллистическое движение":
for i in range(int(key["N"])):
que_ans_text = TaskGenerator().ballistics_corner_motion()
ans_text_result += f'{i + 1}) Ответ: '
for j, answer in enumerate(que_ans_text[1]):
ans_text_result += f'{answer} {que_ans_text[2][j]}; '
que_text_result += f'{i+1}) {que_ans_text[0]}\n\n'
ans_text_result += '\n'
return que_text_result, ans_text_result
elif key["Type"] == "КР": # Контрольная работа
if key["Subject"] == "Физика":
if key["Theme"] == "Кинематика":
return self._generate_test(key, "kinematics")
elif key["Theme"] == "Механика":
return self._generate_test(key, "mechanics")
elif key["Theme"] == "Баллистика":
return self._generate_test(key, "ballistics")
return "Тип работы не поддерживается", ""
def _generate_test(self, key, test_type):
que_text_result = ""
ans_text_result = ""
n = int(key["N"])
# Распределение вопросов: 30% теории, 20% тестов, 50% задач
num_questions = max(1, round(0.3 * n))
num_tests = max(1, round(0.2 * n))
num_problems = max(1, n - num_questions - num_tests)
generator = TaskGenerator()
# Теоретические вопросы
for i in range(num_questions):
if test_type == "kinematics":
question = generator.questions_for_kr_kinematics()
elif test_type == "mechanics":
question = generator.questions_for_kr_mechanics()
elif test_type == "ballistics":
question = generator.questions_for_kr_ballistics()
que_text_result += f'{i+1}) {question}\n\n'
# Тестовые вопросы
for i in range(num_tests):
if test_type == "kinematics":
test = generator.tests_for_kr_kinematics()
elif test_type == "mechanics":
test = generator.tests_for_kr_mechanics()
elif test_type == "ballistics":
test = generator.tests_for_kr_ballistics()
que_text_result += f'{num_questions + i+1}) {test}\n\n'
# Практические задачи
for i in range(num_problems):
if test_type == "kinematics":
task = generator.phis_kr_kinematics()
elif test_type == "mechanics":
task = generator.phis_kr_mechanics()
elif test_type == "ballistics":
task = generator.phis_kr_ballistics()
que_text_result += f'{num_questions + num_tests + i+1}) {task[0]}\n\n'
ans_text_result += f'{num_questions + num_tests + i+1}) Ответ: {task[1][0]} {task[2][0]}\n'
return que_text_result, ans_text_result
def GetTaskText(key):
creator = Creator()
result = creator.function_creator(key)
return f"{result[0]}\n\nОтветы:\n{result[1]}"