|
|
|
@ -28,7 +28,7 @@
|
|
|
|
|
<summary>Начальные данные</summary> |
|
|
|
|
<div> |
|
|
|
|
<p> |
|
|
|
|
<label>Номер расперделения:</label> |
|
|
|
|
<label>Номер распределения:</label> |
|
|
|
|
<input id = "step_id" type="number" value="1" step="1"/> |
|
|
|
|
</p> |
|
|
|
|
|
|
|
|
@ -100,14 +100,16 @@
|
|
|
|
|
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 |
|
|
|
@ -121,18 +123,21 @@ class Person:
|
|
|
|
|
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)) + "<br/>" |
|
|
|
|
html += "Присутсвуют участников: " + str(len(get_present_persons())) + "<br/>" |
|
|
|
|
html = "Всего участников: " + str(len(people)) + "<br/>" |
|
|
|
|
html += "Присутствуют участников: " + str(len(get_present_people())) + "<br/>" |
|
|
|
|
|
|
|
|
|
html += "Номер расперделения: " + document["step_id"].value + "<br/>" |
|
|
|
|
html += "Номер распределения: " + document["step_id"].value + "<br/>" |
|
|
|
|
|
|
|
|
|
meet_count = 0; |
|
|
|
|
meet_count = 0 |
|
|
|
|
html += "<table border = 1>" |
|
|
|
|
# Первая строка |
|
|
|
|
html += "<tr>" |
|
|
|
|
html += "<td></td>" |
|
|
|
|
for p in persons: |
|
|
|
|
html += "<th" + " title='"+ p.name + "'>" + str(abs(p.beig_id)) + "</th>" |
|
|
|
|
for p in people: |
|
|
|
|
html += "<th" + " title='" + p.name + "'>" + str(abs(p.beig_id)) + "</th>" |
|
|
|
|
html += "</tr>" |
|
|
|
|
# Остальные строки |
|
|
|
|
for p in persons: |
|
|
|
|
for p in people: |
|
|
|
|
html += "<tr>" |
|
|
|
|
html += "<th" + " title='"+ p.name + "'>" + str(abs(p.beig_id)) + "</th>" |
|
|
|
|
for ip in persons: |
|
|
|
|
html += "<th" + " title='" + p.name + "'>" + str(abs(p.beig_id)) + "</th>" |
|
|
|
|
for ip in people: |
|
|
|
|
if abs(p.beig_id) in ip.meet_set: |
|
|
|
|
html += "<td bgcolor='red'></td>" |
|
|
|
|
meet_count += 1 |
|
|
|
@ -185,20 +192,22 @@ def show_meet_table_data():
|
|
|
|
|
html += "</tr>" |
|
|
|
|
html += "</table>" |
|
|
|
|
|
|
|
|
|
html += "<br/>Знакомств: " + str(meet_count) + "/" + str(len(persons)**2) + "<br/>" |
|
|
|
|
html += "<br/>Знакомств: " + str(meet_count) + "/" + str(len(people) ** 2) + "<br/>" |
|
|
|
|
|
|
|
|
|
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,7 +239,7 @@ def print_result_table():
|
|
|
|
|
html += "<td>" + str(table_names[t.id]) + "</td>" |
|
|
|
|
|
|
|
|
|
if len(t.person_set): |
|
|
|
|
html += "<td>" + str(t.person_set).replace("{","").replace("}","") + "</td>" |
|
|
|
|
html += "<td>" + str(t.person_set).replace("{", "").replace("}", "") + "</td>" |
|
|
|
|
else: |
|
|
|
|
html += "<td></td>" |
|
|
|
|
html += "</tr>" |
|
|
|
@ -238,61 +248,65 @@ def print_result_table():
|
|
|
|
|
|
|
|
|
|
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] |
|
|
|
|
new_person_id = random.sample(list(beig_id_set - people_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 |
|
|
|
|
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 = [] |
|
|
|
@ -345,9 +361,11 @@ def load_input_table(val):
|
|
|
|
|
t = Table(cur_id, cur_meet_list) |
|
|
|
|
tables.append(t) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def make_result(): |
|
|
|
|
fill_tables() |
|
|
|
|
fill_persons() |
|
|
|
|
fill_people() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def load_data(event): |
|
|
|
|
val = document["input_data"].value |
|
|
|
@ -355,6 +373,7 @@ 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() |
|
|
|
@ -362,14 +381,16 @@ def table_distrib(event):
|
|
|
|
|
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() |
|
|
|
|
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) |
|
|
|
|