-
Notifications
You must be signed in to change notification settings - Fork 2
/
Properties.py
260 lines (215 loc) · 12 KB
/
Properties.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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
import os
import pickle
import time
from PyQt5 import QtWidgets
import GraphModel
from checker import find_t_p, find_t_n
from encrypt_module import decrypt_file
def join(*args):
return os.path.join(*args).replace(os.path.sep, "/")
basedir = os.path.dirname(__file__) # путь до данного файла
class statusTask():
def __init__(self):
self.verification_passed_tasks = {1: False, 2: False, 3: False, 4: False, 5: False} # массив пройденных заданий
def get_verification_passed_tasks(self, current):
return self.verification_passed_tasks[current]
# функция получения подтверждения пройденых заданий
def get_verification_passed_pretasks(self, current):
if (self.verification_passed_tasks[current - 1] == False):
return False
else:
return True
# функция присваивания подтверждения заданию
def set__verification_passed_task(self, number):
self.verification_passed_tasks[number] = True
def set__verification_passed_task_all(self, arg):
if (arg):
self.verification_passed_tasks = {1: True, 2: True, 3: True, 4: True, 5: True}
else:
self.verification_passed_tasks = {1: False, 2: False, 3: False, 4: False, 5: False}
class Properties():
def __init__(self, MainWindow):
self.start_time = time.time_ns() # время начала работы программы в наносекундах
self.end_time = None # время завершения последнего задания в наносекундах
self.elapsed_time = None # время прошедшее с начала работы программы до завершения последнего задания в наносекундах
# свойства, использующиеся в разных заданиях
self.variant = MainWindow.numINGroup
self.teacherMode = False
self.verification_passed_tasks = {1: False, 2: False, 3: False, 4: False, 5: False} # массив пройденных заданий
self.key_path = "" # путь до ключа преподавателя
self.enter_teacher_mode = [False, False, False, False, False, False]
# свойства первого окна
self.MainWindow = MainWindow
self.radius_points = 30 # радиус вершин по всем заданиям (кроме второго)
self.step_grid = 100 # шаг сетки по X
self.step_gridY = 75 # шаг сетки по Y
self.correct_w = self.MainWindow.getCorrectWeights()
self.n = len(self.correct_w)
self.tp = find_t_p(self.correct_w, self.n)
self.tn = find_t_n(self.correct_w, self.tp, self.n)
self.max_possible_time = self.tp[self.n-1] # максимальное время (для сетки)
#свойства второго окна
self.scaler = 3 # параметр увеличения радиуса для второго задания
self.radius_points_task_2 = self.radius_points * self.scaler # радиус во втором задании
#свойства третьего окна
self.state_of_graph_3 = None
#свойства четвертого окна
self.state_of_graph_4 = None
#свойства пятого окна
self.state_of_graph_5 = None
self.number_of_squads = self.get_number_of_squads() # количество отделений
self.max_sequences_amount = self.GetMaxSequencesAmount(self.number_of_squads) # максимальное число последовательностей по отделениям
self.graph_for_task_3_4 = self.get_graph_from_radius() # граф для 3-4 задания
self.graphs_for_task_5 = self.get_graphs_for_task_5() # графы для 5 задания
def GetMaxSequencesAmount(self, number_of_squads):
max_sequences_amount = 0
for squad in range(1, number_of_squads+1):
current_squad_max = 0
for row in range(self.MainWindow.ui.tableVar.rowCount()):
try:
current_squad = int(self.MainWindow.ui.tableVar.item(row, 1).text())
except:
current_squad = -1
if (current_squad == squad):
current_squad_max += 1
if (current_squad_max > max_sequences_amount):
max_sequences_amount = current_squad_max
return max_sequences_amount
# функция подсчета количесва отделений
def get_number_of_squads(self):
number_of_squads = 1
for row in range(self.MainWindow.ui.tableVar.rowCount()):
if self.MainWindow.ui.tableVar.item(row, 1).text() >= '1' and self.MainWindow.ui.tableVar.item(row, 1).text() <= '9' :
i = int(self.MainWindow.ui.tableVar.item(row, 1).text())
if number_of_squads < i:
number_of_squads = i
return number_of_squads
# функция получения общего графа
def get_graph_from_radius(self):
return GraphModel.Graph(self.radius_points)
# функция получения общего графа
def get_graph_from_graph(self, graph):
new_graph = graph.copy()
return new_graph
# функция получения списка графов для 5 задания
def get_graphs_for_task_5(self):
graphs = []
for i in range(self.number_of_squads):
graphs.append(self.get_graph_from_radius)
return graphs
def get_verification_passed_tasks(self, current):
return self.verification_passed_tasks[current]
# функция получения подтверждения пройденых заданий
def get_verification_passed_pretasks(self, current):
if (self.verification_passed_tasks[current - 1] == False):
return False
else:
return True
# функция присваивания подтверждения заданию
def set__verification_passed_task(self, number):
self.verification_passed_tasks[number] = True
def set__verification_passed_task_all(self, arg):
if (arg):
self.verification_passed_tasks = {1: True, 2: True, 3: True, 4: True, 5: True}
else:
self.verification_passed_tasks = {1: False, 2: False, 3: False, 4: False, 5: False}
# ФУНКЦИИ ДЛЯ РАБОТЫ С ШИФРОВАНИЕМ
def check_key(self, key_path) -> bool:
try:
with open(key_path, "rb") as file:
secret_key = file.read()
tmp_path = join(basedir, "encrypted_key")
print("TMP_PATH ", tmp_path)
teacher_token = decrypt_file(tmp_path, "teacher_token.txt") ####### ОШИБКА
print("teacher_token", teacher_token, "\t", "secret_key ", secret_key)
if teacher_token == b"ERROR_DECRYPT":
print("key_path not exist1: ERROR_DECRYPT")
return False
if secret_key == teacher_token:
print("key_path is exist")
return True
except Exception:
print("key_path not exist2 LOSE")
return False
def enter_key(self):
file_name = QtWidgets.QFileDialog.getOpenFileName()[0]
print(file_name)
if file_name == "":
print("key_path not exist1")
return False
if self.check_key(file_name):
self.key_path = file_name
print("key_path is exist")
return True
else:
print("key_path not exist2")
return False
def get_num_squad(self):
self.tableNumSquad = []
for row in range(self.MainWindow.ui.tableVar.rowCount()):
if self.MainWindow.ui.tableVar.item(row, self.MainWindow.ui.tableVar.columnCount() - 1) and self.MainWindow.ui.tableVar.item(row, self.MainWindow.ui.tableVar.columnCount() - 1) != ' ':
self.tableNumSquad.append([])
tmpItem = self.MainWindow.ui.tableVar.item(row, self.MainWindow.ui.tableVar.columnCount() - 1).text()
self.tableNumSquad[-1].append(tmpItem)
else:
break
#self.tableNumSquad[-1].appclear_answerend(tmpItem)
#print("item", row, self.MainWindow.ui.tableVar.columnCount() - 1, " ", self.tableNumSquad[-1][-1])
print(" ")
for i in self.tableNumSquad:
print(i)
####################____ФУНКЦИИ_ДЛЯ_РАБОТЫ_С_СОХРАНЕНИЕМ_ОБЪЕКТА_ДЛЯ_ПРЕПОДА__####################################################
def save_graph_for_teacher(self, graph, i, subtask = 0):
if subtask == 0:
with open(f'answer/states_of_graphs_{i}/state_{self.variant}.pickle', 'wb') as file:
pickle.dump(graph, file)
else:
with open(f'answer/states_of_graphs_{i}/state_{self.variant}_task_{subtask}.pickle', 'wb') as file:
pickle.dump(graph, file)
def get_graph_for_teacher(self, i, subtask = 0):
if subtask == 0:
with open(f'answer/states_of_graphs_{i}/state_{self.variant}.pickle', 'rb') as file:
graph = pickle.load(file)
else:
with open(f'answer/states_of_graphs_{i}/state_{self.variant}_task_{subtask}.pickle', 'rb') as file:
graph = pickle.load(file)
return graph
def get_gft(self, i, subtask = 0):
if subtask == 0:
with open(f'answer/states_of_graphs_{i}/state_1.pickle', 'rb') as file:
graph = pickle.load(file)
else:
with open(f'answer/states_of_graphs_{i}/state_1_task_{subtask}.pickle', 'rb') as file:
graph = pickle.load(file)
return graph
#######################################################################################################################
####################____ФУНКЦИИ_ДЛЯ_РАБОТЫ_С_СОХРАНЕНИЕМ_ОБЪЕКТА_ДЛЯ_ СТУДЕНТА__####################################################
def save_graph_for_student(self, graph, i, subtask = 0):
if subtask == 0:
with open(f'answer_of_student/states_of_graphs_{i}/state_{self.variant}.pickle', 'wb') as file:
pickle.dump(graph, file)
else:
with open(f'answer_of_student/states_of_graphs_{i}/state_{self.variant}_task_{subtask}.pickle', 'wb') as file:
pickle.dump(graph, file)
def get_graph_for_student(self, i, subtask = 0):
if subtask == 0:
with open(f'answer_of_student/states_of_graphs_{i}/state_{self.variant}.pickle', 'rb') as file:
graph = pickle.load(file)
else:
with open(f'answer_of_student/states_of_graphs_{i}/state_{self.variant}_task_{subtask}.pickle', 'rb') as file:
graph = pickle.load(file)
return graph
#######################################################################################################################
####################____ФУНКЦИИ_ДЛЯ_ОЧИСТКИ_СОХРАНЕНИЯ__####################################################
def clear_answer(self, task, subtask = 0):
if subtask == 0:
try:
os.remove(f'answer_of_student/states_of_graphs_{task}/state_{self.variant}.pickle')
except:
print(f'answer_of_student/states_of_graphs_{task}/state_{self.variant}.pickle' + 'not found!')
else:
try:
os.remove(f'answer_of_student/states_of_graphs_{task}/state_{self.variant}_task_{subtask}.pickle')
except:
print(f'answer_of_student/states_of_graphs_{task}/state_{self.variant}_task_{subtask}.pickle' + 'not found!')
#######################################################################################################################