兼容单科和总分
This commit is contained in:
@@ -36,6 +36,16 @@ def _safe_title(text: str) -> str:
|
||||
return text.replace(":", "-").replace("/", "-").replace("\\", "-").replace("?", "-")[:31]
|
||||
|
||||
|
||||
def _score_kind(result_or_group: dict) -> str:
|
||||
return (result_or_group.get("score_kind") or "总分").strip() or "总分"
|
||||
|
||||
|
||||
def _line_title(group: dict, line_name: str) -> str:
|
||||
kind = _score_kind(group)
|
||||
prefix = "" if kind == "总分" else f"{kind}——"
|
||||
return f"{prefix}{group['group']}方向{line_name}指标分配"
|
||||
|
||||
|
||||
def _raw_sheet(wb: Workbook, group: dict, students: list[dict]):
|
||||
title = _safe_title(f"{group['group']}方向人员")
|
||||
ws = wb.create_sheet(title)
|
||||
@@ -149,7 +159,7 @@ def _metric_sheet(wb: Workbook, group: dict):
|
||||
ws = wb.create_sheet(title)
|
||||
r = 1
|
||||
for line in group["targets"]:
|
||||
ws.cell(r, 1, f"{group['group']}方向{line['name']}指标分配")
|
||||
ws.cell(r, 1, _line_title(group, line["name"]))
|
||||
r += 1
|
||||
headers = ["班级"] + [f"{i+1}层人数" for i in range(group["n_layers"])] + ["加权计算", "摊派指标"]
|
||||
ws.cell(r, 1, headers[0])
|
||||
@@ -182,7 +192,11 @@ def _metric_sheet(wb: Workbook, group: dict):
|
||||
ws.cell(r, len(headers) - 1, line["sum_expected"])
|
||||
ws.cell(r, len(headers), line["sum_assigned"])
|
||||
r += 1
|
||||
ws.cell(r, 1, "注:加权计算=Σ(各层人数×拟合概率);摊派指标=加权计算四舍五入。")
|
||||
last_exam = (group.get("_exams") or [None])[-1]
|
||||
note = "注:加权计算=Σ(各层人数×拟合概率);摊派指标=加权计算四舍五入。"
|
||||
if last_exam:
|
||||
note = f"注:数据源以最后一次考试「{last_exam}」为准。" + note[2:]
|
||||
ws.cell(r, 1, note)
|
||||
r += 3
|
||||
ws.column_dimensions["A"].width = 14
|
||||
for c in range(2, ws.max_column + 1):
|
||||
@@ -197,9 +211,11 @@ def build_export(result: dict) -> bytes:
|
||||
wb.remove(wb.active)
|
||||
# Keep the same familiar order as basedata.xlsx: 物理 raw/prob/metric, then 历史.
|
||||
groups = sorted(result["groups"], key=lambda g: _group_order(g["group"]))
|
||||
score_kind = _score_kind(result)
|
||||
for i, group in enumerate(groups):
|
||||
students = [s for s in result["students"] if s["group"] == group["group"]]
|
||||
group["_exams"] = result["exams"]
|
||||
group["score_kind"] = score_kind
|
||||
_raw_sheet(wb, group, students)
|
||||
for group in groups:
|
||||
_probability_sheet(wb, group)
|
||||
|
||||
Reference in New Issue
Block a user