From bbcc1b416a605dd11b5b483a9c12088390bff74a Mon Sep 17 00:00:00 2001 From: Alexei Bezborodov Date: Fri, 28 Oct 2022 16:52:49 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D1=8C=20=D0=BE=D1=82=D0=BA=D0=BB=D1=8E=D1=87=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D1=83=D1=87=D0=B0=D1=81=D1=82=D0=BD=D0=B8?= =?UTF-8?q?=D0=BA=D0=BE=D0=B2,=20=D0=B1=D0=B5=D0=B7=20=D0=B8=D1=85=20?= =?UTF-8?q?=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20#4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- table_distributor.html | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/table_distributor.html b/table_distributor.html index 092fdce..5778a21 100755 --- a/table_distributor.html +++ b/table_distributor.html @@ -128,24 +128,29 @@ def load_input(val): cur_meet_list = cur_meet_list | {int(s)} p = Person(cur_beig_id,cur_name, cur_meet_list) persons.append(p) - persons = sorted(persons, key=lambda person: len(person.meet_set)) + +def get_present_persons(): + global persons + return list(filter(lambda p : p.beig_id > 0, persons)) def show_meet_table_data(): global persons html = "Всего участников: " + str(len(persons)) + "
" + html += "Присутсвуют участников: " + str(len(get_present_persons())) + "
" + html += "" # Первая строка html += "" html += "" for p in persons: - html += "" + str(p.beig_id) + "" + html += "" + str(abs(p.beig_id)) + "" html += "" # Остальные строки for p in persons: html += "" - html += "" + str(p.beig_id) + "" + html += "" + str(abs(p.beig_id)) + "" for ip in persons: - if p.beig_id in ip.meet_set: + if abs(p.beig_id) in ip.meet_set: html += "" else: html += "" @@ -202,20 +207,18 @@ def print_result_table(): def get_person_by_id(id): global persons for p in persons: - if p.beig_id == id: + if abs(p.beig_id) == id: return p print("Error", id) -def fill_next_table(start_person_id, persons_set, table_size_count): - global persons - +def fill_next_table(start_person_id, persons_set, table_size_count, persons): result_persons = [get_person_by_id(start_person_id)] result_set = {start_person_id} while(len(result_set) < table_size_count): search_succes = False for p in persons: - cur_id = p.beig_id + cur_id = abs(p.beig_id) if cur_id in persons_set: continue if cur_id in result_set: @@ -233,7 +236,7 @@ def fill_next_table(start_person_id, persons_set, table_size_count): if not search_succes: for p in persons: - cur_id = p.beig_id + cur_id = abs(p.beig_id) if cur_id in persons_set: continue if cur_id in result_set: @@ -244,18 +247,19 @@ def fill_next_table(start_person_id, persons_set, table_size_count): return result_set -def get_beig_id_set(): +def get_beig_id_set(persons): result = set() for p in persons: - result = result | {p.beig_id} + result = result | {abs(p.beig_id)} return result def fill_tables(): - global persons global tables tables = [] cur_table_id = 0 + sort_persons = sorted(get_present_persons(), key=lambda person: len(person.meet_set)) + all_table_size = 0 str_table_size = document["table_size"].value.replace(" ", "").split(",") table_size = [] @@ -266,16 +270,16 @@ def fill_tables(): table_size += [t] table_count = len(table_size); - beig_id_set = get_beig_id_set() + beig_id_set = get_beig_id_set(sort_persons) persons_set = set() - while len(persons_set) != len(persons): + while len(persons_set) != len(sort_persons): if len(persons_set) >= all_table_size: break new_person_id = random.sample(list(beig_id_set - persons_set), 1)[0] - cur_set = fill_next_table(new_person_id, persons_set, min(table_size[cur_table_id], len(persons) - len(persons_set))) + cur_set = fill_next_table(new_person_id, persons_set, min(table_size[cur_table_id], len(sort_persons) - len(persons_set)), sort_persons) persons_set = persons_set | cur_set tables.append(Table(cur_table_id, cur_set)) cur_table_id += 1 @@ -285,7 +289,7 @@ def fill_persons(): global tables for t in tables: for p in persons: - if p.beig_id in t.person_set: + if abs(p.beig_id) in t.person_set: p.meet_set = t.person_set | p.meet_set def load_input_table(val):