-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
388 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,51 @@ | ||
import Lilly | ||
import lilly | ||
|
||
lilly = Lilly.Lilly() | ||
#lilly = Lilly.Lilly() | ||
|
||
print(lilly.get_schedule()) | ||
#print(lilly.get_schedule()) | ||
|
||
from group_queue import queue | ||
queue = queue.Queue() | ||
|
||
queue.new_queue() | ||
|
||
array = queue.get_queue() | ||
for i in range(len(array)): | ||
print(f"{i+1}. {array[i].get_name()} ({array[i].get_id()})") | ||
|
||
queue.delete_person("13") | ||
print("\nqueue.delete_position('13')") | ||
|
||
print("=================================================") | ||
array = queue.get_queue() | ||
for i in range(len(array)): | ||
print(f"{i+1}. {array[i].get_name()} ({array[i].get_id()})") | ||
|
||
queue.add_person("13", 4) | ||
print("\nqueue.add_person('13', 4)") | ||
|
||
print("=================================================") | ||
array = queue.get_queue() | ||
for i in range(len(array)): | ||
print(f"{i+1}. {array[i].get_name()} ({array[i].get_id()})") | ||
|
||
queue.swap('5', '7') | ||
print("\nqueue.swap('5', '7')") | ||
|
||
print("=================================================") | ||
array = queue.get_queue() | ||
for i in range(len(array)): | ||
print(f"{i+1}. {array[i].get_name()} ({array[i].get_id()})") | ||
|
||
queue.swap('12','5') | ||
print("\nqueue.swap('12','5')") | ||
|
||
print("=================================================") | ||
array = queue.get_queue() | ||
for i in range(len(array)): | ||
print(f"{i+1}. {array[i].get_name()} ({array[i].get_id()})") | ||
|
||
print("\n=====HISTORY=====\n") | ||
array = queue.get_queue() | ||
for i in range(len(array)): | ||
print(f"{i+1}. {array[i].get_name()} ({array[i].get_id()})") |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
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 Шаяхметов Ислам Робертович |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
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 ��������� ����� ���������� |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
|
||
class History: | ||
|
||
def __init__(self, filename: str="history"): | ||
|
||
self.filename = filename | ||
self.history_file = open(filename, "w", encoding="UTF-8") | ||
|
||
def _re_open_file(self): | ||
self.history_file = open(self.filename, "a", encoding="UTF-8") | ||
|
||
def write(self, history: any): | ||
self.history_file.write(str(history)) | ||
self.history_file.write("\n") | ||
self.history_file.close() | ||
|
||
self._re_open_file() | ||
|
||
def clean(self): | ||
self.history_file = open(self.filename, "w", encoding="UTF-8") | ||
|
||
def change_file(self, new_filename: str): | ||
self.filename = new_filename | ||
self.history_file = open(new_filename, "w") | ||
|
||
def get_history(self) -> list: | ||
self.history_file.close() | ||
history = open(self.filename, "r", encoding="UTF-8") | ||
history = history.read().split("\n") | ||
self._re_open_file() | ||
return history |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class Person: | ||
|
||
def __init__(self, person_id: str, name: str): | ||
self._person_id = person_id | ||
self._name = name | ||
# Прошел очередь | ||
self.passed = False | ||
|
||
def set_passed(self, passed: bool): | ||
self.passed = passed | ||
|
||
def get_id(self): | ||
return self._person_id | ||
|
||
def get_name(self): | ||
return self._name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
import os | ||
import random | ||
from parse.date import Date | ||
from group_queue.person import Person | ||
from group_queue.history import History | ||
|
||
|
||
class Queue: | ||
|
||
def __init__(self): | ||
self._queue_list = self._set_group_list() | ||
self._GROUP_LIST = self._queue_list | ||
|
||
# Номер текущей очереди | ||
self._queue_value = 0 | ||
|
||
# Работа с историей | ||
self.history = History() | ||
|
||
# Для работы со временем | ||
self.date = Date() | ||
|
||
@staticmethod | ||
def _set_group_list(): | ||
""" | ||
Получает список группы из файла groupList.txt или groupListWindow.txt в зависимости от кодировки | ||
:return: сгенерированный список группы с элементами Person | ||
""" | ||
# TODO: do with encoding on UTF-8 | ||
if os.name == "nt": | ||
filename = "group_queue/groupListWindows.txt" | ||
else: | ||
filename = "group_queue/groupList.txt" | ||
|
||
file = open(filename, "r") | ||
group_list = [] | ||
while True: | ||
|
||
f = file.readline().split() | ||
if not f: | ||
break | ||
|
||
group_list.append(Person(f[0], f"{f[1]} {f[2]}")) | ||
|
||
return group_list | ||
|
||
def new_queue(self, group_list: list=None) -> None: | ||
""" | ||
Создание новой очереди, начиная с рандомно выбранного человека | ||
:param group_list: список группы с классами Person | ||
:return: None | ||
""" | ||
if group_list is None: | ||
group_list = self._queue_list | ||
self._queue_list = self._create_queue(random.randint(0, 27), group_list) | ||
|
||
self.history.write("Создана новая очередь") | ||
|
||
@staticmethod | ||
def _create_queue(start_person_id: int, group_list: list) -> list: | ||
""" | ||
Создает очередь с человека заданного по индексу | ||
:param start_person_id: индекс человека с которого начинается очередь | ||
:param group_list: список людей занимающих очередь | ||
:return: массив с очередью | ||
""" | ||
queue = [] | ||
for i in range(len(group_list)): | ||
index = i + start_person_id - 1 | ||
|
||
# При переполнении | ||
if index >= len(group_list): | ||
index -= len(group_list) | ||
|
||
queue.append(group_list[index]) | ||
|
||
return queue | ||
|
||
def person_passed(self) -> None: | ||
""" | ||
Вызывается когда кто-то прошел очередь. Инициализирует сдвиг очереди | ||
:return: None | ||
""" | ||
self._queue_value += 1 | ||
|
||
# При переполнении | ||
if self._queue_value == len(self._queue_list): | ||
self._queue_value -= len(self._queue_list) | ||
|
||
self.history.write(f"{self._queue_list[self._queue_value].get_id()}" | ||
f" {self._queue_list[self._queue_value].get_name()}" | ||
f" прошел очередь в {self.date.get_time()}") | ||
|
||
def get_last_person_in_queue(self) -> Person: | ||
""" | ||
:return: Предыдущий в очереди | ||
""" | ||
# TODO: Rewrite for the queue with re-turn (Add new boolean variable) | ||
if self._queue_value == 0: | ||
return Person("0", "None") | ||
else: | ||
return self._queue_list[self._queue_value - 1] | ||
|
||
def get_current_person_in_queue(self) -> Person: | ||
""" | ||
:return: Текущий в очереди | ||
""" | ||
return self._queue_list[self._queue_value] | ||
|
||
def get_next_person_in_queue(self) -> Person: | ||
""" | ||
:return: Следующий в очереди | ||
""" | ||
if self._queue_value == len(self._queue_list) - 1: | ||
return self._queue_list[0].get_name() | ||
else: | ||
return self._queue_list[self._queue_value + 1] | ||
|
||
def get_queue(self) -> list: | ||
""" | ||
Получение списка очереди | ||
:return: список очереди, элементы которой типа Person | ||
""" | ||
return self._queue_list | ||
|
||
def get_person_queue_position(self, person_id: str) -> int: | ||
""" | ||
Возвращает текущую позицию в очереди по номеру в списке | ||
:param person_id: номер в списке | ||
:return: номер в очереди. 0 - если не найден в очереди | ||
""" | ||
for i in range(len(self._queue_list)): | ||
if self._queue_list[i].get_id() == person_id: | ||
return i + 1 | ||
return 0 | ||
|
||
def delete_person(self, person_id: str): | ||
person_position = self.get_person_queue_position(person_id) - 1 | ||
del self._queue_list[person_position] | ||
self.history.write(f"{self._queue_list[person_position].get_name()} удален из очереди в {self.date.get_time()}") | ||
|
||
def add_person(self, person_id: str, position: int=-1): | ||
|
||
new_queue_list = [] | ||
|
||
if position == -1: | ||
for person in self._GROUP_LIST: | ||
if person.get_id() == person_id: | ||
self._queue_list.append(person) | ||
|
||
self.history.write(f"В конец очереди добавлен {person.get_name()} в {self.date.get_time()}") | ||
|
||
elif position == len(self._queue_list) + 1: | ||
for person in self._GROUP_LIST: | ||
if person.get_id() == person_id: | ||
self._queue_list.append(person) | ||
self.history.write(f"В позицию {position}" | ||
f" добавлен {person.get_name()} в" | ||
f" {self.date.get_time()}") | ||
|
||
else: | ||
for i in range(len(self._queue_list)): | ||
if i + 1 == position: | ||
for person in self._GROUP_LIST: | ||
if person.get_id() == person_id: | ||
new_queue_list.append(person) | ||
self.history.write(f"В позицию {position}" | ||
f" добавлен {person.get_name()} в" | ||
f" {self.date.get_time()}") | ||
|
||
new_queue_list.append(self._queue_list[i]) | ||
|
||
self._queue_list = new_queue_list | ||
|
||
def swap(self, person1_id: str, person2_id: str): | ||
""" | ||
Меняет местами двух людей | ||
:param person1_id: номер ИСУ первого | ||
:param person2_id: номер ИСУ второго | ||
:return: None | ||
""" | ||
for index1 in range(len(self._queue_list)): | ||
if self._queue_list[index1].get_id() == person1_id: | ||
|
||
for index2 in range(len(self._queue_list)): | ||
if self._queue_list[index2].get_id() == person2_id: | ||
temp = self._queue_list[index1] | ||
self._queue_list[index1] = self._queue_list[index2] | ||
self._queue_list[index2] = temp | ||
|
||
self.history.write(f"Поменялись местами: " | ||
f"{self._queue_list[index1].get_name()} <-> " | ||
f"{self._queue_list[index2].get_name()}" | ||
f" в {self.date.get_time()}") | ||
|
||
return | ||
|
||
def test(self): | ||
self.new_queue() | ||
return self.get_queue() |
Oops, something went wrong.