diff --git a/src/dinner.py b/src/dinner.py index 6736f80..bb18c4e 100644 --- a/src/dinner.py +++ b/src/dinner.py @@ -51,10 +51,13 @@ def check_roll() -> int: 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 dislikes: 不吃的项 :param limit: 降低最近N次点餐结果概率 :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(): 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 is not None: if summary.get(new_name) is None: @@ -131,8 +135,8 @@ def dinner_roll(): def roll_logic(check=False): - menus, _, _ = fetch_user_menu_summary() - summary, _, _ = vote_reduce(menus) + menus, _, dislikes = fetch_user_menu_summary() + summary, _, _ = vote_reduce(menus, dislikes) sorted_items = sorted(summary.items(), key=lambda item: item[1], reverse=True) items = [item for item in sorted_items[:2]] if len(items) > 1 and (items[0][1] * 0.9) <= items[1][1]: @@ -156,7 +160,7 @@ def dinner(): """ user_menu = get_user_menu() 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() can_roll = (check_roll() == 1) all_choice = list(fetch_all_menu()) diff --git a/templates/dinner.html b/templates/dinner.html index bbe0351..3e0946a 100644 --- a/templates/dinner.html +++ b/templates/dinner.html @@ -17,7 +17,7 @@
-