路由规则投票人数排除掉不吃的人
This commit is contained in:
parent
33589709c3
commit
5c3d0c1d3f
|
@ -51,10 +51,13 @@ def check_roll() -> int:
|
||||||
return 0 if within_time() else 1
|
return 0 if within_time() else 1
|
||||||
|
|
||||||
|
|
||||||
def vote_reduce(summary: dict[str, float], limit: int = 2) -> tuple[dict[str, float], float, list[RollResult]]:
|
def vote_reduce(summary: dict[str, float],
|
||||||
|
dislikes: list[tuple[str, list[str]]], limit: int = 2
|
||||||
|
) -> tuple[dict[str, float], float, list[RollResult]]:
|
||||||
"""
|
"""
|
||||||
按规则对投票结果进行修饰
|
按规则对投票结果进行修饰
|
||||||
:param summary: 投票汇总结果
|
:param summary: 投票汇总结果
|
||||||
|
:param dislikes: 不吃的项
|
||||||
:param limit: 降低最近N次点餐结果概率
|
:param limit: 降低最近N次点餐结果概率
|
||||||
:return: 投票汇总结果
|
:return: 投票汇总结果
|
||||||
"""
|
"""
|
||||||
|
@ -65,7 +68,8 @@ def vote_reduce(summary: dict[str, float], limit: int = 2) -> tuple[dict[str, fl
|
||||||
if menu.expression is None or menu.name not in summary.keys():
|
if menu.expression is None or menu.name not in summary.keys():
|
||||||
continue
|
continue
|
||||||
# 计算预定路由规则
|
# 计算预定路由规则
|
||||||
new_name = eval(menu.expression, {'total_vote': total_vote})
|
dislike_cnt = len(list(filter(lambda x: menu.name in x[1], dislikes)))
|
||||||
|
new_name = eval(menu.expression, {'total_vote': total_vote - dislike_cnt})
|
||||||
if new_name != menu.name:
|
if new_name != menu.name:
|
||||||
if new_name is not None:
|
if new_name is not None:
|
||||||
if summary.get(new_name) is None:
|
if summary.get(new_name) is None:
|
||||||
|
@ -131,8 +135,8 @@ def dinner_roll():
|
||||||
|
|
||||||
|
|
||||||
def roll_logic(check=False):
|
def roll_logic(check=False):
|
||||||
menus, _, _ = fetch_user_menu_summary()
|
menus, _, dislikes = fetch_user_menu_summary()
|
||||||
summary, _, _ = vote_reduce(menus)
|
summary, _, _ = vote_reduce(menus, dislikes)
|
||||||
sorted_items = sorted(summary.items(), key=lambda item: item[1], reverse=True)
|
sorted_items = sorted(summary.items(), key=lambda item: item[1], reverse=True)
|
||||||
items = [item for item in sorted_items[:2]]
|
items = [item for item in sorted_items[:2]]
|
||||||
if len(items) > 1 and (items[0][1] * 0.9) <= items[1][1]:
|
if len(items) > 1 and (items[0][1] * 0.9) <= items[1][1]:
|
||||||
|
@ -156,7 +160,7 @@ def dinner():
|
||||||
"""
|
"""
|
||||||
user_menu = get_user_menu()
|
user_menu = get_user_menu()
|
||||||
menus, users, dislikes = fetch_user_menu_summary()
|
menus, users, dislikes = fetch_user_menu_summary()
|
||||||
summary, total_vote, last_results = vote_reduce(menus)
|
summary, total_vote, last_results = vote_reduce(menus, dislikes)
|
||||||
result = fetch_roll_result()
|
result = fetch_roll_result()
|
||||||
can_roll = (check_roll() == 1)
|
can_roll = (check_roll() == 1)
|
||||||
all_choice = list(fetch_all_menu())
|
all_choice = list(fetch_all_menu())
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<label class="input-group-text" for="inputName" id="basic-addon1">姓名</label>
|
<label class="input-group-text" for="inputName" id="basic-addon1">姓名</label>
|
||||||
<input type="text" class="form-control"
|
<input type="text" class="form-control" {{ 'disabled="disabled"' if user_menu.nickname else '' | safe }}
|
||||||
id="inputName" name="nickname" value="{{ user_menu.nickname }}">
|
id="inputName" name="nickname" value="{{ user_menu.nickname }}">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue