修改抽签算法,降低随机性

This commit is contained in:
ZaneYork 2024-09-12 10:33:37 +08:00
parent 46393fa443
commit 818008fc74
3 changed files with 4 additions and 4 deletions

View File

@ -178,8 +178,6 @@ def fetch_roll_result_list(interval: int = 0, limit: int = 3) -> Generator[str,
row = cursor.fetchone() row = cursor.fetchone()
while row is not None: while row is not None:
yield row[0] yield row[0]
if interval != 0:
return
row = cursor.fetchone() row = cursor.fetchone()
finally: finally:
cursor.close() cursor.close()

View File

@ -74,7 +74,7 @@ def vote_reduce(summary: dict[str, float], limit: int = 2) -> tuple[dict[str, fl
# 昨日中签项降低权重 # 昨日中签项降低权重
for i, last_result in enumerate(last_results): for i, last_result in enumerate(last_results):
if last_result in summary: if last_result in summary:
summary[last_result] = summary[last_result] * (9 - i) / 10 summary[last_result] = summary[last_result] * (8 - i) / 10
total_vote = sum(value for value in summary.values()) total_vote = sum(value for value in summary.values())
return summary, total_vote, last_results return summary, total_vote, last_results
@ -163,6 +163,8 @@ def dinner():
summary_keys = list(filter(lambda x: x in summary.keys(), map(lambda y: y['name'], all_choice))) summary_keys = list(filter(lambda x: x in summary.keys(), map(lambda y: y['name'], all_choice)))
if not result: if not result:
predict_result = roll_logic(check=True) predict_result = roll_logic(check=True)
else:
predict_result = None
return render_template('dinner.html', return render_template('dinner.html',
all_choice=all_choice, all_choice=all_choice,
menu=menu, menu=menu,

View File

@ -9,7 +9,7 @@
<p>每天8:00-17:30间开放匿名投票更新17:30以后允许发起抽签抽签结果确定后不可更改</p> <p>每天8:00-17:30间开放匿名投票更新17:30以后允许发起抽签抽签结果确定后不可更改</p>
<p>第一名与第二名得票数相差不超过10%时随机抽签,按其得票数决定中签概率,否则选择第一名</p> <p>第一名与第二名得票数相差不超过10%时随机抽签,按其得票数决定中签概率,否则选择第一名</p>
{% for last_result in last_results %} {% for last_result in last_results %}
<p>今日{{ last_result }}最终得票数降低{{ 1 + loop.index0 }}0%</p> <p>今日{{ last_result }}最终得票数降低{{ 2 + loop.index0 }}0%</p>
{% endfor %} {% endfor %}
<form id="inputForm" class="form-inline"> <form id="inputForm" class="form-inline">
<div class="form-group"> <div class="form-group">