This commit is contained in:
darkclip 2026-05-31 00:48:31 +08:00
parent d7fc1edd85
commit 2431fc7735
Signed by: hl
GPG Key ID: A948B2AA5A5D3BDB

27
main.py
View File

@ -1069,7 +1069,7 @@ async def print_program_score(program_sn: str):
FROM scores WHERE judge_id = ? AND program_sn = ?""",
(judge['id'], program_sn),
).fetchone()
total = 0
total = None
has_score = False
comment = ''
if score:
@ -1079,23 +1079,29 @@ async def print_program_score(program_sn: str):
has_score = True
else:
# 计算明细分之和
sum_score = 0
if score['content_score'] is not None:
total += score['content_score']
sum_score += score['content_score']
has_score = True
if score['stage_score'] is not None:
total += score['stage_score']
sum_score += score['stage_score']
has_score = True
if score['art_score'] is not None:
total += score['art_score']
sum_score += score['art_score']
has_score = True
if score['overall_score'] is not None:
total += score['overall_score']
sum_score += score['overall_score']
has_score = True
if has_score:
total = sum_score
comment = score['comment'] or ''
# 只有已评分的评委才计入统计(包括0分)
if has_score:
all_scores.append(total)
scores_data[judge['name']] = {'total': total, 'comment': comment}
scores_data[judge['name']] = {
'total': total,
'comment': comment,
'has_score': has_score,
}
max_score = max(all_scores) if all_scores else 0
min_score = min(all_scores) if all_scores else 0
avg_score = round(sum(all_scores) / len(all_scores), 3) if all_scores else 0
@ -1183,7 +1189,12 @@ def render_print_program_template(
<table><thead><tr><th>评委姓名</th><th>总分(100分)</th><th>评委点评</th></tr></thead><tbody>"""
for judge in judges:
s = scores_data.get(judge['name'], {})
html += f"""<tr><td style="font-weight:bold;">{judge['name']}</td><td class="total">{s.get('total') if s.get('total') is not None else '-'}</td><td class="comment-cell">{s.get('comment', '')}</td></tr>"""
total_display = (
'-'
if not s.get('has_score')
else (s.get('total') if s.get('total') is not None else '-')
)
html += f"""<tr><td style="font-weight:bold;">{judge['name']}</td><td class="total">{total_display}</td><td class="comment-cell">{s.get('comment', '')}</td></tr>"""
html += f"""</tbody></table><div style="margin-top: 30px;"><p>评委组签名:____________________</p><p style="text-align: right;">日期:{datetime.now().strftime('%Y年%m月%d日')}</p></div>
<div class="no-print" style="margin-top: 30px; text-align: center;"><button onclick="window.print()">🖨️ 打印本页</button> <button onclick="window.close()">关闭</button></div></div></body></html>"""
return html