diff --git a/table_distributor.html b/table_distributor.html index ec8c983..aaa4ce7 100755 --- a/table_distributor.html +++ b/table_distributor.html @@ -28,7 +28,7 @@ Начальные данные

- +

@@ -100,39 +100,44 @@ from browser import document, html, window import random + class Table: - def __init__(self, id, person_set): - self.id = id + def __init__(self, a_id, person_set): + self.id = a_id self.person_set = person_set id = 0 person_set = set() + class Person: def __init__(self, beig_id, name, meet_set): self.beig_id = beig_id self.name = name self.meet_set = meet_set - + def __str__(self): return str(self.beig_id) + ", " + self.name + "\n" + str(self.meet_set) - + beig_id = 0 name = "" meet_set = set() -global persons -persons = [] + +global people +people = [] global tables tables = [] + def add_to_all_data(val): document["all_output_data"].value += "\n\n#Шаг " + document["step_id"].value + "\n" + val + def load_input(val): - global persons - persons = [] + global people + people = [] input_data = val for p in input_data.split("\n"): if p == "": @@ -149,34 +154,36 @@ def load_input(val): for s in str_meet_list: if len(s) != 0: cur_meet_list = cur_meet_list | {int(s)} - p = Person(cur_beig_id,cur_name, cur_meet_list) - persons.append(p) + p = Person(cur_beig_id, cur_name, cur_meet_list) + people.append(p) + + +def get_present_people(): + global people + return list(filter(lambda p: p.beig_id > 0, people)) -def get_present_persons(): - global persons - return list(filter(lambda p : p.beig_id > 0, persons)) def show_meet_table_data(): - global persons + global people - html = "Всего участников: " + str(len(persons)) + "
" - html += "Присутсвуют участников: " + str(len(get_present_persons())) + "
" + html = "Всего участников: " + str(len(people)) + "
" + html += "Присутствуют участников: " + str(len(get_present_people())) + "
" - html += "Номер расперделения: " + document["step_id"].value + "
" + html += "Номер распределения: " + document["step_id"].value + "
" - meet_count = 0; + meet_count = 0 html += "" # Первая строка html += "" html += "" - for p in persons: - html += "" + str(abs(p.beig_id)) + "" + for p in people: + html += "" + str(abs(p.beig_id)) + "" html += "" # Остальные строки - for p in persons: + for p in people: html += "" - html += "" + str(abs(p.beig_id)) + "" - for ip in persons: + html += "" + str(abs(p.beig_id)) + "" + for ip in people: if abs(p.beig_id) in ip.meet_set: html += "" meet_count += 1 @@ -185,20 +192,22 @@ def show_meet_table_data(): html += "" html += "
" - html += "
Знакомств: " + str(meet_count) + "/" + str(len(persons)**2) + "
" + html += "
Знакомств: " + str(meet_count) + "/" + str(len(people) ** 2) + "
" document["meet_table"].innerHTML = html + def get_result(): - global persons + global people result = "" - for p in persons: + for p in people: result += str(p.beig_id) + ";" + p.name + ";" if len(p.meet_set): result += str(p.meet_set) result += "\n" return result + def result_table_fill(): global tables result_txt = "" @@ -209,6 +218,7 @@ def result_table_fill(): result_txt += "\n" return result_txt + def print_result_table(): table_names = document["table_name"].value @@ -229,70 +239,74 @@ def print_result_table(): html += "" + str(table_names[t.id]) + "" if len(t.person_set): - html += "" + str(t.person_set).replace("{","").replace("}","") + "" + html += "" + str(t.person_set).replace("{", "").replace("}", "") + "" else: html += "" html += "" html += "" document["result_table"].innerHTML = html - + document["result_table_txt"].value = result_table_fill() + def get_person_by_id(id): - global persons - for p in persons: + global people + for p in people: if abs(p.beig_id) == id: return p print("Error", id) -def fill_next_table(start_person_id, persons_set, table_size_count, persons): - result_persons = [get_person_by_id(start_person_id)] + +def fill_next_table(start_person_id, people_set, table_size_count, people): + result_people = [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: + + while len(result_set) < table_size_count: + search_success = False + for p in people: cur_id = abs(p.beig_id) - if cur_id in persons_set: + if cur_id in people_set: continue if cur_id in result_set: continue pers_free = True - for ip in result_persons: + for ip in result_people: if cur_id in ip.meet_set: pers_free = False break if pers_free: result_set = result_set | {cur_id} - result_persons.append(p) - search_succes = True + result_people.append(p) + search_success = True break - - if not search_succes: - for p in persons: + + if not search_success: + for p in people: cur_id = abs(p.beig_id) - if cur_id in persons_set: + if cur_id in people_set: continue if cur_id in result_set: continue result_set = result_set | {cur_id} - result_persons.append(p) + result_people.append(p) break - + return result_set -def get_beig_id_set(persons): + +def get_beig_id_set(people): result = set() - for p in persons: + for p in people: result = result | {abs(p.beig_id)} return result + def fill_tables(): global tables tables = [] cur_table_id = 0 - sort_persons = sorted(get_present_persons(), key=lambda person: len(person.meet_set)) + sort_people = sorted(get_present_people(), key=lambda person: len(person.meet_set)) all_table_size = 0 str_table_size = document["table_size"].value.replace(" ", "").split(",") @@ -303,29 +317,31 @@ def fill_tables(): all_table_size += t table_size += [t] - table_count = len(table_size); - beig_id_set = get_beig_id_set(sort_persons) + beig_id_set = get_beig_id_set(sort_people) - persons_set = set() - while len(persons_set) != len(sort_persons): - if len(persons_set) >= all_table_size: + people_set = set() + while len(people_set) != len(sort_people): + if len(people_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(sort_persons) - len(persons_set)), sort_persons) - persons_set = persons_set | cur_set + + new_person_id = random.sample(list(beig_id_set - people_set), 1)[0] + + cur_set = fill_next_table(new_person_id, people_set, + min(table_size[cur_table_id], len(sort_people) - len(people_set)), sort_people) + people_set = people_set | cur_set tables.append(Table(cur_table_id, cur_set)) cur_table_id += 1 -def fill_persons(): - global persons + +def fill_people(): + global people global tables for t in tables: - for p in persons: + for p in people: if abs(p.beig_id) in t.person_set: p.meet_set = t.person_set | p.meet_set + def load_input_table(val): global tables tables = [] @@ -343,11 +359,13 @@ def load_input_table(val): if len(s) != 0: cur_meet_list = cur_meet_list | {int(s)} t = Table(cur_id, cur_meet_list) - tables.append(t) + tables.append(t) + def make_result(): fill_tables() - fill_persons() + fill_people() + def load_data(event): val = document["input_data"].value @@ -355,21 +373,24 @@ def load_data(event): add_to_all_data("#Таблица знакомств\n" + val) show_meet_table_data() + def table_distrib(event): load_input(document["input_data"].value) make_result() print_result_table() - document["output_data"].value = get_result() + document["output_data"].value = get_result() show_meet_table_data() + def table_distrib_load(event): load_input(document["input_data"].value) load_input_table(document["result_table_txt"].value) - fill_persons() + fill_people() print_result_table() - document["output_data"].value = get_result() + document["output_data"].value = get_result() show_meet_table_data() + def next_step(event): document["step_id"].value = str(int(document["step_id"].value) + 1) @@ -380,6 +401,7 @@ def next_step(event): add_to_all_data("#Таблица знакомств\n" + val) show_meet_table_data() + document["load_data"].bind("click", load_data) document["table_distrib"].bind("click", table_distrib) document["next_step"].bind("click", next_step)