Browse Source

Добавлена возможность отключения участников, без их удаления #4

master
parent
commit
bbcc1b416a
  1. 38
      table_distributor.html

38
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)) + "<br/>"
html += "Присутсвуют участников: " + str(len(get_present_persons())) + "<br/>"
html += "<table border = 1>"
# Первая строка
html += "<tr>"
html += "<td></td>"
for p in persons:
html += "<th" + " title="+ p.name + ">" + str(p.beig_id) + "</th>"
html += "<th" + " title="+ p.name + ">" + str(abs(p.beig_id)) + "</th>"
html += "</tr>"
# Остальные строки
for p in persons:
html += "<tr>"
html += "<th" + " title="+ p.name + ">" + str(p.beig_id) + "</th>"
html += "<th" + " title="+ p.name + ">" + str(abs(p.beig_id)) + "</th>"
for ip in persons:
if p.beig_id in ip.meet_set:
if abs(p.beig_id) in ip.meet_set:
html += "<td bgcolor='red'></td>"
else:
html += "<td></td>"
@ -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):

Loading…
Cancel
Save