添加计票显示

This commit is contained in:
ZaneYork 2024-09-10 11:31:03 +08:00
parent 7c35b0f46a
commit 9ba075559c
2 changed files with 15 additions and 5 deletions

View File

@ -101,14 +101,21 @@ def dinner():
else: else:
menu = {} menu = {}
summary = fetch_menu_summary() summary = fetch_menu_summary()
result = fetch_roll_result()
last_result = fetch_roll_result(-1) last_result = fetch_roll_result(-1)
for x in summary:
if x == last_result:
summary[x] = summary[x] * 7 / 10
total_vote = sum(value for value in summary.values())
if total_vote == 0:
total_vote = 1
result = fetch_roll_result()
can_roll = (check_roll() == 1) can_roll = (check_roll() == 1)
all_choice = list(map(lambda x: {'name': x[0], 'label': x[1]}, fetch_all_menu())) all_choice = list(map(lambda x: {'name': x[0], 'label': x[1]}, fetch_all_menu()))
return render_template('dinner.html', return render_template('dinner.html',
all_choice=all_choice, all_choice=all_choice,
menu=menu, menu=menu,
summary=summary, summary=summary,
total_vote=total_vote,
result=result, result=result,
can_roll=can_roll, can_roll=can_roll,
last_result=last_result) last_result=last_result)

View File

@ -9,7 +9,7 @@
<p>每天8:00-17:30间开放匿名投票更新17:30以后允许发起抽签抽签结果确定后不可更改</p> <p>每天8:00-17:30间开放匿名投票更新17:30以后允许发起抽签抽签结果确定后不可更改</p>
<p>随机抽签,按得票数决定中签概率</p> <p>随机抽签,按得票数决定中签概率</p>
{% if last_result %} {% if last_result %}
<p>今日{{ last_result }}中签概率降低30%</p> <p>今日{{ last_result }}最终得票数降低30%</p>
{% endif %} {% endif %}
<form id="inputForm" class="form-inline"> <form id="inputForm" class="form-inline">
<div class="form-group"> <div class="form-group">
@ -33,19 +33,22 @@
onclick="roll()">开始抽签 onclick="roll()">开始抽签
</button> </button>
<div style="padding-top: 40px"> <div style="padding-top: 40px">
<label>大家的选择</label> <label>大家的选择 - 总票数:{{ '{:.2f}'.format(total_vote | round(2)) }}</label>
<ul style="padding-top: 20px; margin-bottom: 80px" class="list-group"> <ul style="padding-top: 20px; margin-bottom: 80px" class="list-group">
{% for key in summary %} {% for key in summary %}
<li class="list-group-item {{ "active" if result == key else "" }}"> <li class="list-group-item {{ "active" if result == key else "" }}">
<div class="row justify-content-between"> <div class="row justify-content-between">
<span class="col-8">{{ key }}</span> <span class="col-5">{{ key }}</span>
<span class="col-3">{{ '{:.2f}'.format(summary[key] | round(2)) }}票</span> <span class="col-3">{{ '{:.2f}'.format(summary[key] | round(2)) }}票</span>
<span class="col-3">{{ '{:.2f}'.format(summary[key] / total_vote * 100 | round(2)) }}%</span>
</div> </div>
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
</div> </div>
<div class="fixed-bottom"><a class="link-secondary" style="text-decoration: none; font-size: 0.8rem" href="https://git.zaneyork.cn:8443/ZaneYork/dinner_vote">本项目抽签完全公开透明,源码开放欢迎随时审查</a></div> <div class="fixed-bottom"><a class="link-secondary" style="text-decoration: none; font-size: 0.8rem"
href="https://git.zaneyork.cn:8443/ZaneYork/dinner_vote">本项目抽签完全公开透明,源码开放欢迎随时审查</a>
</div>
</div> </div>
<script src="./static/jquery-3.2.1.min.js"></script> <script src="./static/jquery-3.2.1.min.js"></script>