From 841847dbbab3c6fd532dcb747ca290ba6a9e12d0 Mon Sep 17 00:00:00 2001
From: xyc <jc_xiong@hotmail.com>
Date: 星期三, 11 十一月 2026 20:07:50 +0800
Subject: [PATCH] feat(企业台账): 完善抽查报告和车辆核查工具
---
tools/build_ledger_vehicle_shortlist.py | 490 ++++++++++++++
tools/enterprise_track_point_inspection.py | 97 +-
tools/build_ledger_inspection_issue_workbook.py | 385 +++++++++++
tools/build_enterprise_track_report.py | 27
tools/build_ledger_inspection_report.py | 710 ++++++++++++-------
tools/monitor_ledger_vehicle_downloads.py | 300 ++++++++
6 files changed, 1,685 insertions(+), 324 deletions(-)
diff --git a/tools/build_enterprise_track_report.py b/tools/build_enterprise_track_report.py
index e811e57..9d4c8e7 100644
--- a/tools/build_enterprise_track_report.py
+++ b/tools/build_enterprise_track_report.py
@@ -16,21 +16,26 @@
SELECTED_PLATES = {
- "\u9102L1N523",
+ "\u9102L1N275",
"\u9102L1J689",
- "\u9102J20052D",
"\u9102LH832D",
- "\u9102L53508",
- "\u9102J50898",
- "\u9102J0C916",
+ "\u9102L53789",
+ "\u9102J20052D",
+ "\u9102J0E858",
+ "\u9102J59918",
"\u9102J21646D",
- "\u9102E19507",
- "\u9102E69878",
- "\u9102E68056",
- "\u9102E36292",
+ "\u9102E32721",
+ "\u9102E56628",
+ "\u9102E59371",
+ "\u9102E99730",
}
-EXISTING_PLATES = {"\u9102L1N523", "\u9102L1J689"}
-PREVIOUS_SAMPLE_PLATES = {"\u9102J28801", "\u9102L1K202", "\u9102L5A039"}
+EXISTING_PLATES = {
+ "\u9102L1J689",
+ "\u9102LH832D",
+ "\u9102J20052D",
+ "\u9102J21646D",
+}
+PREVIOUS_SAMPLE_PLATES = set()
CN_DELIMITER = "\u3001"
diff --git a/tools/build_ledger_inspection_issue_workbook.py b/tools/build_ledger_inspection_issue_workbook.py
new file mode 100644
index 0000000..e2109c6
--- /dev/null
+++ b/tools/build_ledger_inspection_issue_workbook.py
@@ -0,0 +1,385 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""Build the reader-facing issue summary workbook for ledger inspection."""
+
+from __future__ import annotations
+
+import argparse
+import json
+import math
+from pathlib import Path
+from typing import Any, Dict, List, Sequence, Tuple
+
+from openpyxl import Workbook
+from openpyxl.styles import Alignment, Border, Font, PatternFill, Side
+from openpyxl.utils import get_column_letter
+from openpyxl.worksheet.page import PageMargins
+from openpyxl.worksheet.pagebreak import Break
+from openpyxl.worksheet.properties import PageSetupProperties
+
+from build_ledger_inspection_report import (
+ KAIXIANGDA_TOTAL_CORRECT,
+ KAIXIANGDA_TOTAL_OVER,
+ KAIXIANGDA_TOTAL_RATE,
+ KAIXIANGDA_TOTAL_REPORT,
+ city_sort_key,
+ fmt_int,
+ fmt_num,
+ fmt_pct,
+ fmt_wan_ton_km,
+ ledger_route_text,
+ main_region,
+ read_enterprises,
+ short_city_name,
+ strict_missing_endpoints,
+)
+
+FANGSONG = "\u4eff\u5b8b_GB2312"
+HEITI = "\u9ed1\u4f53"
+BORDER_COLOR = "D9D9D9"
+EMPTY = "\u2014"
+TITLE_FONT = Font(name=HEITI, size=18, bold=True, color="000000")
+HEADER_FONT = Font(name=FANGSONG, size=14, bold=True, color="000000")
+BODY_FONT = Font(name=FANGSONG, size=12, color="000000")
+THIN = Side(style="thin", color=BORDER_COLOR)
+BORDER = Border(left=THIN, right=THIN, top=THIN, bottom=THIN)
+
+HEADERS = [
+ "\u5e8f\u53f7",
+ "\u5e02\u5dde",
+ "\u4f01\u4e1a",
+ "\u95ee\u9898\u7c7b\u522b",
+ "\u5177\u4f53\u95ee\u9898",
+ "\u6d89\u53ca\u8f66\u8f86",
+ "\u53f0\u8d26\u60c5\u51b5",
+ "\u6708\u62a5\u53ca\u5e73\u53f0\u76d1\u6d4b\u60c5\u51b5",
+ "\u6838\u67e5\u7ed3\u8bba",
+ "\u6838\u67e5\u4f9d\u636e",
+]
+COLUMN_WIDTHS = [5.5, 7.5, 20.0, 14.0, 24.0, 13.0, 28.0, 40.0, 26.0, 26.0]
+DATA_ALIGNMENTS = [
+ "center", "center", "center", "center", "left", "center",
+ "left", "left", "left", "left",
+]
+
+
+def plate_summary(item: Dict[str, Any]) -> str:
+ plates = [str(value) for value in item.get("no_track_plates", []) if value]
+ return "\u3001".join(plates)
+
+
+def make_issue(
+ item: Dict[str, Any],
+ category: str,
+ problem: str,
+ scope: str,
+ ledger_situation: str,
+ monitoring_situation: str,
+ conclusion: str,
+ evidence: str,
+) -> Dict[str, Any]:
+ return {
+ "city": short_city_name(item["city"]),
+ "enterprise": str(item["enterprise"]),
+ "category": category,
+ "problem": problem,
+ "scope": scope,
+ "ledger": ledger_situation,
+ "monitoring": monitoring_situation,
+ "conclusion": conclusion,
+ "evidence": evidence,
+ }
+
+
+def build_issue_records(
+ enterprises: Sequence[Dict[str, Any]],
+ vehicles: Sequence[Dict[str, Any]],
+) -> List[Dict[str, Any]]:
+ vehicles_by_enterprise = {str(item["enterprise"]): item for item in vehicles}
+ ordered = sorted(
+ enterprises,
+ key=lambda item: (city_sort_key(item["city"]), str(item["enterprise"])),
+ )
+ records: List[Dict[str, Any]] = []
+
+ for item in ordered:
+ enterprise = str(item["enterprise"])
+ vehicle = vehicles_by_enterprise.get(enterprise)
+ if vehicle is None:
+ raise RuntimeError("missing sample vehicle for %s" % enterprise)
+
+ if "\u51ef\u7965\u8fbe" in enterprise:
+ records.append(make_issue(
+ item=item,
+ category="\u5468\u8f6c\u91cf\u6c47\u603b",
+ problem="2026\u5e741\u20149\u6708\u5468\u8f6c\u91cf\u6c47\u603b\u516c\u5f0f\u9519\u8bef",
+ scope="\u4f01\u4e1a\u6574\u4f53",
+ ledger_situation="\u53f0\u8d26\u9010\u884c\u6b63\u786e\u5408\u8ba1%s\u4e07\u5428\u516c\u91cc" % fmt_wan_ton_km(KAIXIANGDA_TOTAL_CORRECT),
+ monitoring_situation="\u6708\u62a5%s\u4e07\u5428\u516c\u91cc" % fmt_wan_ton_km(KAIXIANGDA_TOTAL_REPORT),
+ conclusion="\u6c47\u603b\u516c\u5f0f\u9519\u8bef\uff0c1\u20149\u6708\u7d2f\u8ba1\u591a\u62a5%s\u4e07\u5428\u516c\u91cc\uff0c\u591a\u62a5%s" % (
+ fmt_wan_ton_km(KAIXIANGDA_TOTAL_OVER),
+ fmt_pct(KAIXIANGDA_TOTAL_RATE, False),
+ ),
+ evidence="\u63091\u20149\u6708\u6708\u62a5\u4e0e\u53f0\u8d26\u660e\u7ec6\u9010\u6708\u91cd\u7b97\u6bd4\u5bf9\u3002",
+ ))
+
+ mileage_diff = float(item["mileage_diff"] or 0)
+ if abs(mileage_diff) > 0.30:
+ direction = "\u9ad8\u4e8e" if mileage_diff > 0 else "\u4f4e\u4e8e"
+ records.append(make_issue(
+ item=item,
+ category="\u53f0\u8d26\u4e0e\u5e73\u53f0\u91cc\u7a0b",
+ problem="\u53f0\u8d26\u91cc\u7a0b\u660e\u663e%s\u5e73\u53f0\u76d1\u6d4b\u91cc\u7a0b" % direction,
+ scope="\u4f01\u4e1a\u6574\u4f53",
+ ledger_situation="\u53f0\u8d26\u8f66\u8f86%s\u8f86\uff1b\u53f0\u8d26\u91cc\u7a0b%s\u516c\u91cc" % (
+ fmt_int(item["ledger_vehicles"]),
+ fmt_num(item["ledger_mileage"], 0),
+ ),
+ monitoring_situation="\u5e73\u53f0\u76d1\u6d4b\u91cc\u7a0b%s\u516c\u91cc" % fmt_num(item["platform_mileage"], 0),
+ conclusion="\u53f0\u8d26\u4e0e\u5e73\u53f0\u5dee\u5f02\u7387%s\uff0c\u8d85\u51fa\u6b63\u8d1f30%%\u6b63\u5e38\u8303\u56f4" % fmt_pct(mileage_diff),
+ evidence="\u6309\u4f01\u4e1a\u53f0\u8d26\u8f66\u8f86\u4e0e\u5e73\u53f0\u6708\u5ea6\u65e5\u91cc\u7a0b\u9010\u8f66\u6c47\u603b\u6bd4\u5bf9\u3002",
+ ))
+
+ no_track = int(item["no_track"] or 0)
+ ledger_vehicles = int(item["ledger_vehicles"] or 0)
+ if no_track > 0:
+ plate_text = plate_summary(item)
+ plate_clause = "\uff08%s\uff09" % plate_text if plate_text else ""
+ records.append(make_issue(
+ item=item,
+ category="\u52a8\u6001\u76d1\u6d4b\u8986\u76d6",
+ problem="\u90e8\u5206\u53f0\u8d26\u8f66\u8f86\u65e0\u5e73\u53f0\u6708\u91cc\u7a0b\u8bb0\u5f55",
+ scope="\u4f01\u4e1a\u6574\u4f53",
+ ledger_situation="\u53f0\u8d26\u8f66\u8f86%s\u8f86" % fmt_int(ledger_vehicles),
+ monitoring_situation="\u65e0\u5e73\u53f0\u6708\u91cc\u7a0b\u8bb0\u5f55\u8f66\u8f86%s\u8f86%s" % (fmt_int(no_track), plate_clause),
+ conclusion="\u65e0\u5e73\u53f0\u6708\u91cc\u7a0b\u8f66\u8f86\u5360\u6bd4%s" % fmt_pct(no_track / ledger_vehicles if ledger_vehicles else 0, False),
+ evidence="\u6309\u53f0\u8d26\u8f66\u724c\u4e0e\u5e73\u53f0\u65e5\u91cc\u7a0b\u8bb0\u5f55\u9010\u8f66\u5339\u914d\u3002",
+ ))
+
+ positive_days = int(vehicle["platform"].get("positive_mileage_days") or 0)
+ daily_days = int(vehicle["platform"].get("daily_record_days") or vehicle["platform"].get("days") or 0)
+ if positive_days < 30:
+ records.append(make_issue(
+ item=item,
+ category="\u52a8\u6001\u76d1\u6d4b\u8986\u76d6",
+ problem="\u91cd\u70b9\u8f66\u8f86\u5e73\u53f0\u603b\u91cc\u7a0b\u5927\u4e8e0\u7684\u5929\u6570\u4e0d\u8db330\u5929",
+ scope=str(vehicle["plate"]),
+ ledger_situation="\u53f0\u8d26%s\u8d9f\uff0c%s\u516c\u91cc" % (
+ fmt_num(vehicle["ledger"]["trips"], 0),
+ fmt_num(vehicle["ledger"]["mileage"], 2),
+ ),
+ monitoring_situation="\u5e73\u53f0\u65e5\u8bb0\u5f55%s\u5929\uff0c\u603b\u91cc\u7a0b\u5927\u4e8e0\u7684%s\u5929" % (
+ fmt_int(daily_days),
+ fmt_int(positive_days),
+ ),
+ conclusion="\u5e73\u53f0\u603b\u91cc\u7a0b\u5927\u4e8e0\u4ec5%s\u5929\uff0c\u5c11\u4e8e30\u5929" % fmt_int(positive_days),
+ evidence="\u5e73\u53f0\u65e5\u91cc\u7a0b\u8bb0\u5f55\u4e2d\u5b58\u5728\u603b\u91cc\u7a0b\u4e3a0\u7684\u65e5\u671f\u3002",
+ ))
+
+ missing = strict_missing_endpoints(vehicle)
+ route_text = ledger_route_text(vehicle)
+ total_mileage = fmt_num(vehicle["platform"]["total_mileage"], 2)
+ point_count = fmt_int(vehicle["points"]["valid_point_count"])
+ region = main_region(vehicle)
+ support_rate = float(vehicle["comparison"].get("trip_support_rate") or 0)
+ if missing:
+ missing_text = "\u3001".join(missing)
+ monitoring = (
+ "\u5e73\u53f0%s\u516c\u91cc\uff1b\u8f68\u8ff9\u70b9%s\u4e2a\uff1b"
+ "\u4e3b\u8981\u6d3b\u52a8\u533a\u57df%s\uff1b\u5e73\u53f0\u8f68\u8ff9\u672a\u76d1\u6d4b\u5230%s"
+ ) % (total_mileage, point_count, region, missing_text)
+ category = "\u91cd\u70b9\u8f66\u8f86\u7ebf\u8def"
+ problem = "\u7533\u62a5\u7ebf\u8def\u672a\u83b7\u8f68\u8ff9\u652f\u6301"
+ conclusion = "\u7533\u62a5\u7ebf\u8def\u672a\u83b7\u8f68\u8ff9\u652f\u6301"
+ evidence = "\u8f68\u8ff9\u6d3b\u52a8\u533a\u57df\u4e0e\u7533\u62a5\u7ebf\u8def\u7aef\u70b9\u4e0d\u4e00\u81f4\u3002"
+ else:
+ monitoring = (
+ "\u5e73\u53f0%s\u516c\u91cc\uff1b\u8f68\u8ff9\u70b9%s\u4e2a\uff1b"
+ "\u4e3b\u8981\u6d3b\u52a8\u533a\u57df%s\uff1b\u8f68\u8ff9\u53ef\u652f\u6301\u8d9f\u6b21\u6bd4\u4f8b%s"
+ ) % (total_mileage, point_count, region, fmt_pct(support_rate, False))
+ category = "\u91cd\u70b9\u8f66\u8f86\u8d9f\u6b21"
+ problem = "\u7ebf\u8def\u65b9\u5411\u6709\u652f\u6301\uff0c\u4f46\u53ef\u652f\u6301\u8d9f\u6b21\u4e0d\u8db3"
+ conclusion = "\u8d9f\u6b21\u4e0d\u8db3\uff0c\u8f68\u8ff9\u53ef\u652f\u6301\u6bd4\u4f8b%s" % fmt_pct(support_rate, False)
+ evidence = "\u8f68\u8ff9\u8986\u76d6\u7533\u62a5\u7ebf\u8def\u65b9\u5411\uff0c\u4f46\u62b5\u8fbe\u7ebf\u8def\u7aef\u70b9\u7684\u9891\u6b21\u4e0d\u8db3\u3002"
+
+ records.append(make_issue(
+ item=item,
+ category=category,
+ problem=problem,
+ scope=str(vehicle["plate"]),
+ ledger_situation="\u53f0\u8d26\u7ebf\u8def%s\uff1b\u53f0\u8d26%s\u8d9f\uff0c%s\u516c\u91cc" % (
+ route_text,
+ fmt_num(vehicle["ledger"]["trips"], 0),
+ fmt_num(vehicle["ledger"]["mileage"], 2),
+ ),
+ monitoring_situation=monitoring,
+ conclusion=conclusion,
+ evidence=evidence,
+ ))
+
+ return records
+
+
+def display_units(value: Any) -> int:
+ text = str(value or "")
+ return sum(2 if ord(char) > 127 else 1 for char in text)
+
+
+def estimated_row_height(values: Sequence[Any], widths: Sequence[float]) -> float:
+ lines = 1
+ for value, width in zip(values, widths):
+ capacity = max(6, int(width * 0.86))
+ value_lines = 0
+ for part in str(value or "").split("\n"):
+ value_lines += max(1, math.ceil(display_units(part) / capacity))
+ lines = max(lines, value_lines)
+ return max(44.0, min(170.0, 16.0 * lines + 12.0))
+
+
+def style_cell(cell: Any, value: Any, font: Font, alignment: str) -> None:
+ cell.value = value
+ cell.font = font
+ cell.border = BORDER
+ cell.fill = PatternFill(fill_type=None)
+ cell.alignment = Alignment(horizontal=alignment, vertical="center", wrap_text=True)
+
+
+def write_workbook(records: Sequence[Dict[str, Any]], output_path: Path) -> None:
+ workbook = Workbook()
+ sheet = workbook.active
+ sheet.title = "\u95ee\u9898\u6c47\u603b"
+ sheet.sheet_view.showGridLines = False
+
+ column_count = len(HEADERS)
+ sheet.merge_cells(start_row=1, start_column=1, end_row=1, end_column=column_count)
+ title_cell = sheet.cell(1, 1, "2026\u5e749\u6708\u4f01\u4e1a\u53f0\u8d26\u62bd\u67e5\u6838\u67e5\u95ee\u9898\u6c47\u603b\u8868")
+ title_cell.font = TITLE_FONT
+ title_cell.alignment = Alignment(horizontal="center", vertical="center")
+ title_cell.border = Border(bottom=THIN)
+ sheet.row_dimensions[1].height = 36
+
+ for column, header in enumerate(HEADERS, start=1):
+ style_cell(sheet.cell(2, column), header, HEADER_FONT, "center")
+ sheet.row_dimensions[2].height = 47
+
+ group_starts: List[Tuple[int, int]] = []
+ current_enterprise = None
+ group_start = 3
+ for index, record in enumerate(records, start=1):
+ row = index + 2
+ if record["enterprise"] != current_enterprise:
+ if current_enterprise is not None:
+ group_starts.append((group_start, row - 1))
+ current_enterprise = record["enterprise"]
+ group_start = row
+ values = [
+ index,
+ record["city"],
+ record["enterprise"],
+ record["category"],
+ record["problem"],
+ record["scope"],
+ record["ledger"],
+ record["monitoring"],
+ record["conclusion"],
+ record["evidence"],
+ ]
+ for column, value in enumerate(values, start=1):
+ style_cell(sheet.cell(row, column), value, BODY_FONT, DATA_ALIGNMENTS[column - 1])
+ sheet.row_dimensions[row].height = estimated_row_height(values, COLUMN_WIDTHS)
+ if current_enterprise is not None:
+ group_starts.append((group_start, len(records) + 2))
+
+ for start_row, end_row in group_starts:
+ if end_row > start_row:
+ for column in (2, 3):
+ sheet.merge_cells(start_row=start_row, start_column=column, end_row=end_row, end_column=column)
+ cell = sheet.cell(start_row, column)
+ cell.alignment = Alignment(horizontal="center", vertical="center", wrap_text=True)
+ for row in range(start_row, end_row + 1):
+ sheet.cell(row, column).border = BORDER
+
+ for column, width in enumerate(COLUMN_WIDTHS, start=1):
+ sheet.column_dimensions[get_column_letter(column)].width = width
+
+ page_capacity = 790.0
+ header_height = float(sheet.row_dimensions[2].height or 0)
+ used_height = sum(float(sheet.row_dimensions[row].height or 0) for row in (1, 2))
+ for start_row, end_row in group_starts:
+ group_height = sum(float(sheet.row_dimensions[row].height or 0) for row in range(start_row, end_row + 1))
+ if used_height > 0 and used_height + group_height > page_capacity and start_row > 3:
+ sheet.row_breaks.append(Break(id=start_row - 1))
+ used_height = header_height
+ used_height += group_height
+
+ last_row = len(records) + 2
+ sheet.print_area = "A1:J%d" % last_row
+ sheet.print_title_rows = "2:2"
+ sheet.freeze_panes = "A3"
+ sheet.sheet_properties.pageSetUpPr = PageSetupProperties(fitToPage=True)
+ sheet.page_setup.orientation = "landscape"
+ sheet.page_setup.paperSize = sheet.PAPERSIZE_A3
+ sheet.page_setup.fitToWidth = 1
+ sheet.page_setup.fitToHeight = 0
+ sheet.print_options.horizontalCentered = True
+ sheet.print_options.verticalCentered = False
+ # Keep at least a two-centimetre binding allowance on both sides.
+ sheet.page_margins = PageMargins(left=0.8, right=0.8, top=0.35, bottom=0.35, header=0.2, footer=0.2)
+ sheet.oddFooter.center.text = "\u7b2c &P \u9875\uff0c\u5171 &N \u9875"
+ sheet.oddFooter.center.font = FANGSONG
+ sheet.oddFooter.center.size = 9
+
+ output_path.parent.mkdir(parents=True, exist_ok=True)
+ workbook.save(output_path)
+
+
+def validate_records(records: Sequence[Dict[str, Any]]) -> None:
+ if len(records) != 40:
+ raise RuntimeError("expected 40 issue records, got %d" % len(records))
+ enterprise_names = {record["enterprise"] for record in records}
+ city_names = {record["city"] for record in records}
+ if len(enterprise_names) != 12 or city_names != {"\u5b9c\u660c", "\u9ec4\u5188", "\u54b8\u5b81"}:
+ raise RuntimeError("enterprise or city grouping mismatch")
+ counts: Dict[str, int] = {}
+ for record in records:
+ counts[record["category"]] = counts.get(record["category"], 0) + 1
+ expected = {
+ "\u5468\u8f6c\u91cf\u6c47\u603b": 1,
+ "\u53f0\u8d26\u4e0e\u5e73\u53f0\u91cc\u7a0b": 11,
+ "\u52a8\u6001\u76d1\u6d4b\u8986\u76d6": 16,
+ "\u91cd\u70b9\u8f66\u8f86\u7ebf\u8def": 7,
+ "\u91cd\u70b9\u8f66\u8f86\u8d9f\u6b21": 5,
+ }
+ if counts != expected:
+ raise RuntimeError("category counts mismatch: %s" % counts)
+
+
+def main() -> int:
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument("--workbook", required=True)
+ parser.add_argument("--diagnostics", required=True)
+ parser.add_argument("--output", required=True)
+ args = parser.parse_args()
+
+ workbook_path = Path(args.workbook)
+ diagnostics_path = Path(args.diagnostics)
+ output_path = Path(args.output)
+ if not workbook_path.is_file():
+ raise SystemExit("workbook not found: %s" % workbook_path)
+ if not diagnostics_path.is_file():
+ raise SystemExit("diagnostics not found: %s" % diagnostics_path)
+
+ enterprises = read_enterprises(workbook_path)
+ diagnostics = json.loads(diagnostics_path.read_text(encoding="utf-8"))
+ vehicles = diagnostics["vehicles"]
+ if len(enterprises) != 12 or len(vehicles) != 12:
+ raise RuntimeError("expected 12 enterprises and 12 sample vehicles")
+ records = build_issue_records(enterprises, vehicles)
+ validate_records(records)
+ write_workbook(records, output_path)
+ print(str(output_path))
+ return 0
+
+
+if __name__ == "__main__":
+ raise SystemExit(main())
diff --git a/tools/build_ledger_inspection_report.py b/tools/build_ledger_inspection_report.py
index 68c8158..dfa54dc 100644
--- a/tools/build_ledger_inspection_report.py
+++ b/tools/build_ledger_inspection_report.py
@@ -5,6 +5,7 @@
from __future__ import annotations
import argparse
+import json
from collections import Counter
from pathlib import Path
from typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple
@@ -263,6 +264,24 @@
element.set(qn("w:color"), BORDER_COLOR)
+def set_table_borders_gray(table: Any) -> None:
+ tbl_pr = table._tbl.tblPr
+ tbl_borders = tbl_pr.first_child_found_in("w:tblBorders")
+ if tbl_borders is None:
+ tbl_borders = OxmlElement("w:tblBorders")
+ tbl_pr.append(tbl_borders)
+ for edge in ("top", "left", "bottom", "right", "insideH", "insideV"):
+ tag = "w:" + edge
+ element = tbl_borders.find(qn(tag))
+ if element is None:
+ element = OxmlElement(tag)
+ tbl_borders.append(element)
+ element.set(qn("w:val"), "single")
+ element.set(qn("w:sz"), "4")
+ element.set(qn("w:space"), "0")
+ element.set(qn("w:color"), BORDER_COLOR)
+
+
def set_cell_margins(cell: Any, top: int = 90, start: int = 100, bottom: int = 90, end: int = 100) -> None:
tc = cell._tc
tcpr = tc.get_or_add_tcPr()
@@ -294,16 +313,31 @@
def set_table_widths(table: Any, widths_cm: Sequence[float]) -> None:
table.autofit = False
- for row in table.rows:
- for index, width in enumerate(widths_cm):
- row.cells[index].width = Cm(width)
+ dxa_widths = [int(width * 567) for width in widths_cm]
tbl_pr = table._tbl.tblPr
+
+ tbl_layout = tbl_pr.first_child_found_in("w:tblLayout")
+ if tbl_layout is None:
+ tbl_layout = OxmlElement("w:tblLayout")
+ tbl_pr.append(tbl_layout)
+ tbl_layout.set(qn("w:type"), "fixed")
+
tbl_w = tbl_pr.first_child_found_in("w:tblW")
if tbl_w is None:
tbl_w = OxmlElement("w:tblW")
tbl_pr.append(tbl_w)
tbl_w.set(qn("w:type"), "dxa")
- tbl_w.set(qn("w:w"), str(int(sum(widths_cm) * 567)))
+ tbl_w.set(qn("w:w"), str(sum(dxa_widths)))
+
+ grid_cols = table._tbl.tblGrid.findall(qn("w:gridCol"))
+ if len(grid_cols) != len(widths_cm):
+ raise ValueError("table grid column count mismatch")
+ for grid_col, width in zip(grid_cols, dxa_widths):
+ grid_col.set(qn("w:w"), str(width))
+
+ for row in table.rows:
+ for index, width in enumerate(widths_cm):
+ row.cells[index].width = Cm(width)
def set_cell_text(cell: Any, text: str, font_size: float, bold: bool, alignment: str) -> None:
@@ -339,6 +373,7 @@
table.alignment = WD_TABLE_ALIGNMENT.CENTER
table.style = "Table Grid"
table.autofit = False
+ set_table_borders_gray(table)
set_table_widths(table, widths_cm)
header = table.rows[0]
set_repeat_table_header(header)
@@ -371,6 +406,61 @@
paragraph.paragraph_format.line_spacing = Pt(12)
+CITY_ORDER = {
+ "\u6b66\u6c49\u5e02": 0,
+ "\u9ec4\u77f3\u5e02": 1,
+ "\u5341\u5830\u5e02": 2,
+ "\u5b9c\u660c\u5e02": 3,
+ "\u8944\u9633\u5e02": 4,
+ "\u9102\u5dde\u5e02": 5,
+ "\u8346\u95e8\u5e02": 6,
+ "\u5b5d\u611f\u5e02": 7,
+ "\u8346\u5dde\u5e02": 8,
+ "\u9ec4\u5188\u5e02": 9,
+ "\u54b8\u5b81\u5e02": 10,
+ "\u968f\u5dde\u5e02": 11,
+ "\u6069\u65bd\u5dde": 12,
+ "\u4ed9\u6843\u5e02": 13,
+ "\u6f5c\u6c5f\u5e02": 14,
+ "\u5929\u95e8\u5e02": 15,
+ "\u6797\u533a": 16,
+}
+CITY_FULL_NAMES = {
+ "\u6b66\u6c49": "\u6b66\u6c49\u5e02",
+ "\u9ec4\u77f3": "\u9ec4\u77f3\u5e02",
+ "\u5341\u5830": "\u5341\u5830\u5e02",
+ "\u5b9c\u660c": "\u5b9c\u660c\u5e02",
+ "\u8944\u9633": "\u8944\u9633\u5e02",
+ "\u9102\u5dde": "\u9102\u5dde\u5e02",
+ "\u8346\u95e8": "\u8346\u95e8\u5e02",
+ "\u5b5d\u611f": "\u5b5d\u611f\u5e02",
+ "\u8346\u5dde": "\u8346\u5dde\u5e02",
+ "\u9ec4\u5188": "\u9ec4\u5188\u5e02",
+ "\u54b8\u5b81": "\u54b8\u5b81\u5e02",
+ "\u968f\u5dde": "\u968f\u5dde\u5e02",
+ "\u6069\u65bd\u5dde": "\u6069\u65bd\u5dde",
+ "\u4ed9\u6843": "\u4ed9\u6843\u5e02",
+ "\u6f5c\u6c5f": "\u6f5c\u6c5f\u5e02",
+ "\u5929\u95e8": "\u5929\u95e8\u5e02",
+ "\u6797\u533a": "\u6797\u533a",
+}
+
+
+def full_city_name(value: Any) -> str:
+ text = str(value or "").strip()
+ return CITY_FULL_NAMES.get(text, text)
+
+
+def short_city_name(value: Any) -> str:
+ text = full_city_name(value)
+ return text[:-1] if text.endswith("\u5e02") else text
+
+
+def city_sort_key(value: Any) -> Tuple[int, str]:
+ city = full_city_name(value)
+ return CITY_ORDER.get(city, 99), city
+
+
def fmt_int(value: Any) -> str:
return f"{int(round(float(value or 0))):,}"
@@ -388,100 +478,200 @@
return (f"{rate:+.2f}%" if signed else f"{rate:.2f}%")
-def fmt_days(value: Any) -> str:
- days = int(value or 0)
- return str(days) if days != 0 else "-"
-
-
-def read_workbook(path: Path) -> Tuple[List[Dict[str, Any]], List[Dict[str, Any]], Counter, Counter]:
+def read_enterprises(path: Path) -> List[Dict[str, Any]]:
wb = load_workbook(path, data_only=True)
- overall = wb["鎬讳綋鎯呭喌"]
enterprises: List[Dict[str, Any]] = []
- for row in range(4, overall.max_row + 1):
- if not overall.cell(row, 2).value:
- continue
- enterprises.append({
- "city": overall.cell(row, 1).value or "",
- "enterprise": overall.cell(row, 2).value or "",
- "ledger_vehicles": overall.cell(row, 7).value or 0,
- "month_turnover": overall.cell(row, 6).value or 0,
- "ledger_turnover": overall.cell(row, 9).value or 0,
- "report_vs_ledger": overall.cell(row, 11).value or 0,
- "ledger_mileage": overall.cell(row, 13).value or 0,
- "platform_mileage": overall.cell(row, 14).value or 0,
- "mileage_diff": overall.cell(row, 15).value or 0,
- "no_track": overall.cell(row, 16).value or 0,
- })
- samples_sheet = wb["鎶芥煡杞﹁締杞ㄨ抗鎯呭喌"]
- samples: List[Dict[str, Any]] = []
- for row in range(4, samples_sheet.max_row + 1):
- if not samples_sheet.cell(row, 3).value:
- continue
- conclusion = str(samples_sheet.cell(row, 19).value or "")
- if "涓庣敵鎶ヨ矾绾夸笉绗�" in conclusion:
- judgment = "璺嚎涓嶇"
- elif "杩滀綆浜庣敵鎶ヨ稛娆�" in conclusion:
- judgment = "绔偣棰戞涓嶈冻"
- elif "涓嶇煕鐩�" in conclusion and "鏃犳硶" in conclusion:
- judgment = "灞�閮ㄧ鐐规棤娉曞畾浣�"
- elif "鐢虫姤绔偣涓鸿鏂芥垨閬撹矾鍚嶇О" in conclusion:
- judgment = "绔偣鍚嶇О鏃犳硶鏍搁獙"
- else:
- judgment = "闇�杩涗竴姝ユ牳鏌�"
- samples.append({
- "city": samples_sheet.cell(row, 1).value or "",
- "enterprise": samples_sheet.cell(row, 2).value or "",
- "plate": samples_sheet.cell(row, 3).value or "",
- "ledger_mileage": samples_sheet.cell(row, 7).value or 0,
- "platform_mileage": samples_sheet.cell(row, 8).value or 0,
- "mileage_diff": samples_sheet.cell(row, 9).value or 0,
- "points": samples_sheet.cell(row, 10).value or 0,
- "days": samples_sheet.cell(row, 11).value or 0,
- "support_ratio": samples_sheet.cell(row, 16).value or 0,
- "judgment": judgment,
- "risk": samples_sheet.cell(row, 20).value or "",
- })
- issue_sheet = wb["闂鏄庣粏"]
- issue_types: Counter = Counter()
- issue_severity: Counter = Counter()
- issue_header_row = next(
- (
- row for row in range(1, issue_sheet.max_row + 1)
- if issue_sheet.cell(row, 4).value == "闂绫诲瀷"
- ),
- 3,
- )
- for row in range(issue_header_row + 1, issue_sheet.max_row + 1):
- issue_type = issue_sheet.cell(row, 4).value
- severity = issue_sheet.cell(row, 5).value
- if issue_type:
- issue_types[str(issue_type)] += 1
- if severity:
- issue_severity[str(severity)] += 1
+ if "\u603b\u4f53\u60c5\u51b5" in wb.sheetnames:
+ sheet = wb["\u603b\u4f53\u60c5\u51b5"]
+ for row in range(4, sheet.max_row + 1):
+ if not sheet.cell(row, 2).value:
+ continue
+ enterprises.append({
+ "city": sheet.cell(row, 1).value or "",
+ "enterprise": sheet.cell(row, 2).value or "",
+ "ledger_vehicles": sheet.cell(row, 7).value or 0,
+ "month_turnover": sheet.cell(row, 6).value or 0,
+ "ledger_turnover": sheet.cell(row, 9).value or 0,
+ "report_vs_ledger": sheet.cell(row, 11).value or 0,
+ "ledger_mileage": sheet.cell(row, 13).value or 0,
+ "platform_mileage": sheet.cell(row, 14).value or 0,
+ "mileage_diff": sheet.cell(row, 15).value or 0,
+ "no_track": sheet.cell(row, 16).value or 0,
+ })
+ elif "\u4f01\u4e1a\u6838\u67e5\u7ed3\u679c" in wb.sheetnames:
+ sheet = wb["\u4f01\u4e1a\u6838\u67e5\u7ed3\u679c"]
+ for row in range(5, sheet.max_row + 1):
+ enterprise = sheet.cell(row, 2).value
+ if not enterprise:
+ continue
+ turnover_pair = str(sheet.cell(row, 4).value or "").split("/")
+ mileage_pair = str(sheet.cell(row, 6).value or "").split("/")
+ if len(turnover_pair) != 2 or len(mileage_pair) != 2:
+ continue
+ enterprises.append({
+ "city": sheet.cell(row, 1).value or "",
+ "enterprise": enterprise,
+ "ledger_vehicles": sheet.cell(row, 3).value or 0,
+ "month_turnover": float(turnover_pair[0].replace(",", "").strip()) * 10000,
+ "ledger_turnover": float(turnover_pair[1].replace(",", "").strip()) * 10000,
+ "report_vs_ledger": sheet.cell(row, 5).value or 0,
+ "ledger_mileage": float(mileage_pair[0].replace(",", "").strip()),
+ "platform_mileage": float(mileage_pair[1].replace(",", "").strip()),
+ "mileage_diff": sheet.cell(row, 7).value or 0,
+ "no_track": sheet.cell(row, 8).value or 0,
+ })
+ no_track_by_enterprise: Dict[str, List[str]] = {}
+ if "\u8f66\u8f86\u91cc\u7a0b\u5dee\u5f02\u60c5\u51b5" in wb.sheetnames:
+ vehicle_sheet = wb["\u8f66\u8f86\u91cc\u7a0b\u5dee\u5f02\u60c5\u51b5"]
+ for values in vehicle_sheet.iter_rows(min_row=4, max_col=12, values_only=True):
+ enterprise = values[1]
+ plate = values[2]
+ status = values[11]
+ if enterprise and plate and status == "\u5e73\u53f0\u660e\u7ec6\u65e0\u5339\u914d":
+ no_track_by_enterprise.setdefault(str(enterprise), []).append(str(plate))
+ for item in enterprises:
+ item["no_track_plates"] = no_track_by_enterprise.get(str(item["enterprise"]), [])
wb.close()
- return enterprises, samples, issue_types, issue_severity
+ return enterprises
-def enterprise_judgment(item: Dict[str, Any]) -> str:
- parts: List[str] = []
- if abs(float(item["report_vs_ledger"])) > 0.01:
- if "鍑ゥ杈�" in str(item["enterprise"]):
- parts.append("鍛ㄨ浆閲忔眹鎬诲叕寮忛敊璇�")
- else:
- parts.append("鏈堟姤鍙拌处宸紓澶�")
- if abs(float(item["mileage_diff"])) > 0.30:
- parts.append("閲岀▼宸紓瓒呰寖鍥�")
+def turnover_judgment(item: Dict[str, Any]) -> str:
+ difference = float(item["report_vs_ledger"])
+ if abs(difference) <= 0.01:
+ return "\u6570\u503c\u57fa\u672c\u4e00\u81f4"
+ if "\u51ef\u7965\u8fbe" in str(item["enterprise"]):
+ return "\u5468\u8f6c\u91cf\u6c47\u603b\u516c\u5f0f\u9519\u8bef"
+ return "\u6708\u62a5\u53f0\u8d26\u5dee\u5f02\u8f83\u5927"
+
+
+def mileage_judgment(item: Dict[str, Any]) -> str:
+ difference = float(item["mileage_diff"])
+ if difference > 0.30:
+ parts = ["\u53f0\u8d26\u91cc\u7a0b\u660e\u663e\u9ad8\u4e8e\u5e73\u53f0"]
+ elif difference < -0.30:
+ parts = ["\u53f0\u8d26\u91cc\u7a0b\u660e\u663e\u4f4e\u4e8e\u5e73\u53f0"]
else:
- parts.append("閲岀▼宸紓姝e父")
+ parts = ["\u53f0\u8d26\u91cc\u7a0b\u5728\u6b63\u5e38\u533a\u95f4"]
if int(item["no_track"] or 0) > 0:
- parts.append("瀛樺湪鏃犺建杩硅溅杈�")
- return "锛�".join(parts)
+ parts.append("\u5b58\u5728\u65e0\u5e73\u53f0\u6708\u91cc\u7a0b\u8f66\u8f86")
+ return "\uff1b".join(parts)
-def build_report(workbook_path: Path, output_path: Path, attachment_name: str) -> None:
- enterprises, samples, issue_types, issue_severity = read_workbook(workbook_path)
- if len(enterprises) != 12 or len(samples) != 12:
+def add_two_level_table(
+ doc: Document,
+ groups: Sequence[Tuple[str, Sequence[str]]],
+ rows: Sequence[Sequence[str]],
+ widths_cm: Sequence[float],
+ body_alignments: Sequence[str],
+ header_size: float = 9.0,
+ body_size: float = 8.5,
+) -> Any:
+ column_count = sum(max(1, len(children)) for _, children in groups)
+ if len(widths_cm) != column_count or len(body_alignments) != column_count:
+ raise ValueError("two-level table width or alignment count mismatch")
+ table = doc.add_table(rows=2, cols=column_count)
+ table.alignment = WD_TABLE_ALIGNMENT.CENTER
+ table.style = "Table Grid"
+ table.autofit = False
+ set_table_borders_gray(table)
+ set_table_widths(table, widths_cm)
+
+ top_row = table.rows[0]
+ second_row = table.rows[1]
+ set_repeat_table_header(top_row)
+ set_repeat_table_header(second_row)
+ prevent_row_split(top_row)
+ prevent_row_split(second_row)
+ column = 0
+ for label, children in groups:
+ span = max(1, len(children))
+ if children:
+ top_cell = top_row.cells[column]
+ if span > 1:
+ top_cell = top_cell.merge(top_row.cells[column + span - 1])
+ set_cell_text(top_cell, label, header_size, True, ALIGN_CENTER)
+ for offset, child in enumerate(children):
+ set_cell_text(second_row.cells[column + offset], child, header_size, True, ALIGN_CENTER)
+ else:
+ merged = top_row.cells[column].merge(second_row.cells[column])
+ set_cell_text(merged, label, header_size, True, ALIGN_CENTER)
+ column += span
+
+ for values in rows:
+ row = table.add_row()
+ prevent_row_split(row)
+ for index, value in enumerate(values):
+ set_cell_text(row.cells[index], value, body_size, False, body_alignments[index])
+ set_table_widths(table, widths_cm)
+ for row_index in (0, 1):
+ for cell in table.rows[row_index].cells:
+ set_cell_margins(cell, top=35, start=45, bottom=35, end=45)
+ for paragraph in cell.paragraphs:
+ paragraph.paragraph_format.line_spacing = Pt(12)
+ for row in table.rows[2:]:
+ for cell in row.cells:
+ set_cell_margins(cell, top=35, start=55, bottom=35, end=55)
+ for paragraph in cell.paragraphs:
+ paragraph.paragraph_format.line_spacing = Pt(12)
+
+ spacer = doc.add_paragraph()
+ spacer.paragraph_format.first_line_indent = Pt(0)
+ spacer.paragraph_format.space_before = Pt(0)
+ spacer.paragraph_format.space_after = Pt(0)
+ spacer.paragraph_format.line_spacing = Pt(6)
+ return table
+
+
+def strict_missing_endpoints(vehicle: Dict[str, Any]) -> List[str]:
+ return [
+ endpoint["label"] for endpoint in vehicle["points"].get("endpoints", [])
+ if endpoint.get("strict", True) and endpoint["day_count"] == 0
+ ]
+
+
+def main_region(vehicle: Dict[str, Any]) -> str:
+ regions: List[str] = []
+ for name, points, days in vehicle["points"].get("top_counties", [])[:2]:
+ parts = [part for part in str(name).split("|") if part]
+ label = (parts[-2] + parts[-1]) if len(parts) >= 3 else (parts[-1] if parts else str(name))
+ regions.append(label)
+ return "\u3001".join(regions) if regions else "\u65e0\u6709\u6548\u6d3b\u52a8\u533a\u57df"
+
+
+def sample_judgment(vehicle: Dict[str, Any]) -> str:
+ if strict_missing_endpoints(vehicle):
+ return "\u7533\u62a5\u7ebf\u8def\u672a\u83b7\u8f68\u8ff9\u652f\u6301"
+ return "\u7ebf\u8def\u65b9\u5411\u6709\u652f\u6301\u4f46\u8d9f\u6b21\u4e0d\u8db3"
+
+
+def sample_support(vehicle: Dict[str, Any]) -> float:
+ return float(vehicle["comparison"].get("trip_support_rate") or 0)
+
+
+def ledger_route_text(vehicle: Dict[str, Any]) -> str:
+ groups = list(vehicle["ledger"].get("route_groups", []))
+ groups.sort(key=lambda group: float(group.get("trips") or 0), reverse=True)
+ parts: List[str] = []
+ for group in groups:
+ route = str(group.get("route") or "").strip()
+ if len(route) > 28:
+ route = route[:27] + "\u2026"
+ trips = float(group.get("trips") or 0)
+ parts.append(f"{route}\uff08{trips:g}\u8d9f\uff09")
+ return "\u3001".join(parts) if parts else "\u672a\u8bc6\u522b"
+
+
+def build_report(workbook_path: Path, diagnostics_path: Path, output_path: Path) -> None:
+ enterprises = read_enterprises(workbook_path)
+ enterprises.sort(key=lambda item: (city_sort_key(item["city"]), str(item["enterprise"])))
+ diagnostics_data = json.loads(diagnostics_path.read_text(encoding="utf-8"))
+ vehicles = diagnostics_data["vehicles"]
+ if len(enterprises) != 12 or len(vehicles) != 12:
raise RuntimeError("Expected 12 enterprise rows and 12 sample vehicles")
+ vehicles_by_enterprise = {str(item["enterprise"]): item for item in vehicles}
+ if any(str(item["enterprise"]) not in vehicles_by_enterprise for item in enterprises):
+ raise RuntimeError("Enterprise and sample vehicle data do not match")
+
total_ledger_mileage = sum(float(item["ledger_mileage"]) for item in enterprises)
total_platform_mileage = sum(float(item["platform_mileage"]) for item in enterprises)
total_vehicles = sum(int(item["ledger_vehicles"]) for item in enterprises)
@@ -490,100 +680,118 @@
layer2_normal = sum(abs(float(item["mileage_diff"])) <= 0.30 for item in enterprises)
total_mileage_diff = total_ledger_mileage / total_platform_mileage - 1 if total_platform_mileage else 0
no_track_ratio = total_no_track / total_vehicles if total_vehicles else 0
- total_points = sum(int(item["points"]) for item in samples)
- below_half = sum(float(item["support_ratio"]) < 0.5 for item in samples)
- support_min = min(float(item["support_ratio"]) for item in samples)
- support_max = max(float(item["support_ratio"]) for item in samples)
- route_mismatch = sum(item["judgment"] == "璺嚎涓嶇" for item in samples)
- frequency_short = sum(item["judgment"] == "绔偣棰戞涓嶈冻" for item in samples)
- endpoint_uncheckable = len(samples) - route_mismatch - frequency_short
- issue_total = sum(issue_types.values())
- high_issues = int(issue_severity.get("楂�", 0))
- medium_issues = int(issue_severity.get("涓�", 0))
- kxd_formula_issue_extra = 0 if issue_types.get("鍛ㄨ浆閲忔眹鎬诲叕寮忛敊璇�", 0) else 1
- issue_total += kxd_formula_issue_extra
- high_issues += kxd_formula_issue_extra
- kxd = next((item for item in enterprises if "鍑ゥ杈�" in item["enterprise"]), None)
- datong = next((item for item in enterprises if "澶ч��" in item["enterprise"]), None)
+ raw_points = sum(int(item["points"]["valid_point_count"] or 0) for item in vehicles)
+ point_files = sum(int(item["points"]["file_count"] or 0) for item in vehicles)
+ point_days_30 = sum(int(item["points"]["day_count"] or 0) == 30 for item in vehicles)
+ point_days_29 = len(vehicles) - point_days_30
+ positive_days_30 = sum(int(item["platform"].get("positive_mileage_days") or 0) == 30 for item in vehicles)
+ positive_days_29 = sum(int(item["platform"].get("positive_mileage_days") or 0) == 29 for item in vehicles)
+ positive_days_short = len(vehicles) - positive_days_30 - positive_days_29
+ route_mismatch = sum(bool(strict_missing_endpoints(item)) for item in vehicles)
+ supported_vehicles = [item for item in vehicles if not strict_missing_endpoints(item)]
+ support_below_half_supported = sum(sample_support(item) < 0.5 for item in supported_vehicles)
+ supported_support_min = min(sample_support(item) for item in supported_vehicles)
+ supported_support_max = max(sample_support(item) for item in supported_vehicles)
+ kxd = next((item for item in enterprises if "\u51ef\u7965\u8fbe" in str(item["enterprise"])), None)
+ datong = next((item for item in enterprises if "\u5927\u901a" in str(item["enterprise"])), None)
doc = Document()
configure_document(doc)
- doc.core_properties.title = "2026骞�9鏈堜紒涓氬彴璐︽娊鏌ユ牳鏌ユ姤鍛�"
- doc.core_properties.subject = "浼佷笟鍙拌处銆侀噸杞藉钩鍙伴噷绋嬪拰閲嶇偣杞﹁締杞ㄨ抗鐐规牳鏌�"
- add_title(doc, "2026骞�9鏈堜紒涓氬彴璐︽娊鏌ユ牳鏌ユ姤鍛�")
+ doc.core_properties.title = "2026\u5e749\u6708\u4f01\u4e1a\u53f0\u8d26\u62bd\u67e5\u6838\u67e5\u62a5\u544a"
+ doc.core_properties.subject = "\u4f01\u4e1a\u53f0\u8d26\u3001\u91cd\u8f7d\u5e73\u53f0\u91cc\u7a0b\u548c\u91cd\u70b9\u8f66\u8f86\u8f68\u8ff9\u70b9\u6838\u67e5"
+ add_title(doc, "2026\u5e749\u6708\u4f01\u4e1a\u53f0\u8d26\u62bd\u67e5\u6838\u67e5\u62a5\u544a")
add_body(
doc,
- "鎸夌収宸ヤ綔瀹夋帓锛屽鍜稿畞銆侀粍鍐堛�佸疁鏄�3涓競宸�12瀹朵紒涓�2026骞�9鏈堝彴璐﹀強鍏惰溅杈嗚建杩规暟鎹紑灞曟娊鏌ユ牳鏌ワ紝绱鎶曞叆绾�1鍛ㄣ�傜幇灏嗘牳鏌ユ儏鍐垫姤鍛婂涓嬨��",
+ "\u6309\u7167\u5de5\u4f5c\u5b89\u6392\uff0c\u5bf9\u5b9c\u660c\u5e02\u3001\u9ec4\u5188\u5e02\u3001\u54b8\u5b81\u5e023\u4e2a\u5e02\u5dde12\u5bb6\u4f01\u4e1a2026\u5e749\u6708\u53f0\u8d26\u53ca\u5176\u8f66\u8f86\u8f68\u8ff9\u6570\u636e\u5f00\u5c55\u62bd\u67e5\u6838\u67e5\u3002\u73b0\u5c06\u6838\u67e5\u60c5\u51b5\u62a5\u544a\u5982\u4e0b\u3002",
)
- add_heading(doc, "涓�銆佹牳鏌ヨ寖鍥翠笌宸ヤ綔閲�")
+ add_heading(doc, "\u4e00\u3001\u6838\u67e5\u8303\u56f4\u4e0e\u6570\u636e\u60c5\u51b5")
add_body(
doc,
- "鏈鏍告煡浠ヤ紒涓氫笂鎶ユ湀鎶ャ�佷紒涓氳繍杈撳彴璐︺�侀噸杞藉钩鍙拌溅杈嗘湀搴﹂噷绋嬪拰杞﹁締杞ㄨ抗鐐逛负鍩虹锛岄�愭埛鏍稿鏈堟姤涓庡彴璐︽暟鎹紝閫愯溅姣斿鍙拌处閲岀▼涓庡钩鍙扮洃娴嬮噷绋嬶紝骞舵寜鐓ф瘡鎴蜂紒涓�1杈嗛噸鐐硅溅杈嗙殑鏂瑰紡寮�灞曟暣鏈堣建杩圭偣绮炬煡銆傛牳鏌ヨ鐩栬寖鍥村拰宸ヤ綔閲忓涓嬨��",
+ "\u672c\u6b21\u6838\u67e5\u4ee5\u4f01\u4e1a\u4e0a\u62a5\u6708\u62a5\u3001\u4f01\u4e1a\u8fd0\u8f93\u53f0\u8d26\u3001\u91cd\u8f7d\u5e73\u53f0\u8f66\u8f86\u6708\u5ea6\u91cc\u7a0b\u548c\u8f66\u8f86\u8f68\u8ff9\u70b9\u4e3a\u57fa\u7840\uff0c\u4f9d\u6b21\u6838\u5bf9\u6708\u62a5\u4e0e\u53f0\u8d26\u3001\u53f0\u8d26\u91cc\u7a0b\u4e0e\u5e73\u53f0\u76d1\u6d4b\u91cc\u7a0b\uff0c\u5e76\u5bf9\u6bcf\u6237\u4f01\u4e1a1\u8f86\u91cd\u70b9\u8f66\u8f86\u5f00\u5c55\u6574\u6708\u8f68\u8ff9\u70b9\u7cbe\u67e5\u3002\u6838\u67e5\u6570\u636e\u60c5\u51b5\u5982\u4e0b\u3002",
)
- add_caption(doc, "琛�1 鏍告煡鑼冨洿涓庡伐浣滈噺")
+ add_caption(doc, "\u88681 \u6838\u67e5\u8303\u56f4\u4e0e\u6570\u636e\u60c5\u51b5")
workload_rows = [
- ("鏍告煡鑼冨洿", "3涓競宸炪��12瀹朵紒涓�"),
- ("浼佷笟鍙拌处", "12浠斤紝瑙f瀽杞﹁締鈥旇矾绾库�旇稛娆¤褰�3,003鏉�"),
- ("鍙拌处杞﹁締", "579杈�"),
- ("骞冲彴鏈堝害閲岀▼", "12浠斤紝杞﹁締鏃ラ噷绋嬭褰�12,921鏉�"),
- ("杞ㄨ抗鐐硅祫鏂�", "119涓建杩圭偣鏂囦欢锛屽師濮嬭建杩圭偣286,438鏉★紝鍘婚噸鍚�286,436鏉�"),
- ("閲嶇偣杞﹁締绮炬煡", "12杈嗭紝姣忔埛浼佷笟1杈�"),
- ("姣斿缁撴灉", "浼佷笟绾х粨鏋�12缁勶紝杞﹁締绾х粨鏋�579缁勶紝杞ㄨ抗绾胯矾缁撴灉12缁�"),
- ("闂璇嗗埆", f"闂{issue_total}椤癸紝鍏朵腑楂橀闄﹞high_issues}椤广�佷腑椋庨櫓{medium_issues}椤�"),
- ("鏍告煡鎶曞叆", "绾�1鍛�"),
+ ("\u6838\u67e5\u8303\u56f4", "3\u4e2a\u5e02\u5dde\u300112\u5bb6\u4f01\u4e1a"),
+ ("\u4f01\u4e1a\u53f0\u8d26", "12\u4efd\uff0c\u8f66\u8f86\u2014\u8def\u7ebf\u2014\u8d9f\u6b21\u2014\u8d27\u8fd0\u91cf\u2014\u5468\u8f6c\u91cf\u8bb0\u5f553,003\u6761"),
+ ("\u53f0\u8d26\u8f66\u8f86", f"{fmt_int(total_vehicles)}\u8f86"),
+ ("\u5e73\u53f0\u6708\u5ea6\u91cc\u7a0b", "12\u4efd\uff0c\u4ece\u91cd\u8f7d\u5e73\u53f0\u4e0b\u8f7d\uff0c\u8f66\u8f86\u65e5\u91cc\u7a0b\u8bb0\u5f5512,921\u6761"),
+ ("\u91cd\u70b9\u8f66\u8f86\u7cbe\u67e5", f"\u4ece\u8f66\u8f86\u65e5\u91cc\u7a0b\u8bb0\u5f55\u7b5b\u9009\u8f68\u8ff9\u5c3d\u91cf\u8986\u76d6\u5168\u6708\u7684\u8f66\u8f86\uff0c\u517112\u8f86\uff0c\u6bcf\u6237\u4f01\u4e1a1\u8f86\uff1b{point_days_30}\u8f8630\u5929\u6709\u8f68\u8ff9\u70b9\uff0c{point_days_29}\u8f8629\u5929\u6709\u8f68\u8ff9\u70b9"),
+ ("\u8f68\u8ff9\u70b9\u8d44\u6599", f"{point_files}\u4e2a\u6587\u4ef6\uff0c\u4ece\u91cd\u8f7d\u5e73\u53f0\u4e0b\u8f7d\uff0c\u8f68\u8ff9\u70b9{fmt_int(raw_points)}\u4e2a"),
+ ("\u95ee\u9898\u6c47\u603b", "\u53e6\u9644\u95ee\u9898\u6c47\u603b\u8868Excel\uff0c\u517140\u6761\u95ee\u9898\u8bb0\u5f55"),
]
add_table(
doc,
- ["鏍告煡缁村害", "鏁伴噺鍙婂唴瀹�"],
+ ["\u6838\u67e5\u7ef4\u5ea6", "\u6570\u91cf\u53ca\u5185\u5bb9"],
workload_rows,
- [3.7, 10.9],
+ [3.5, 11.1],
[ALIGN_CENTER, ALIGN_LEFT],
+ header_size=12,
+ body_size=12,
)
- add_heading(doc, "浜屻�佹牳鏌ュ唴瀹逛笌鏂规硶")
- add_heading(doc, "锛堜竴锛夋湀鎶ヤ笌鍙拌处涓�鑷存�ф牳鏌�", 2)
+ add_heading(doc, "\u4e8c\u3001\u6838\u67e5\u5185\u5bb9\u4e0e\u65b9\u6cd5")
+ add_heading(doc, "\uff08\u4e00\uff09\u5206\u5c42\u6838\u67e5", 2)
add_body(
doc,
- "灏嗕紒涓氫笂鎶ョ殑鏈堟姤璐ц繍閲忋�佸懆杞噺涓庡彴璐﹂�愮瑪姹囨�荤粨鏋滆繘琛屾瘮瀵癸紝骞跺悓姝ユ鏌ュ彴璐︽眹鎬诲崟鍏冩牸鐨勮绠楀叕寮忋�傚樊寮傜巼缁濆鍊间笉瓒呰繃1%鐨勶紝鍒ゅ畾涓烘暟鍊煎熀鏈竴鑷达紱瓒呰繃1%鐨勶紝鍒椾负宸紓浜嬮」銆傚鍙拌处姹囨�诲叕寮忎笉閲囩敤閫愮瑪鍛ㄨ浆閲忔眰鍜岀殑锛岃繘涓�姝ュ绠�1鈥�9鏈堝悇鏈堟湀鎶ュ�间笌姝g‘鏄庣粏鍚堣锛岄槻姝㈡湀鎶ュ拰鍙拌处娌跨敤鍚屼竴閿欒鍏紡鑰屽舰鎴愯〃闈竴鑷淬��",
+ "\u7b2c\u4e00\u5c42\u6838\u5bf9\u6708\u62a5\u4e0e\u53f0\u8d26\u5468\u8f6c\u91cf\uff0c\u5dee\u5f02\u7387\u7edd\u5bf9\u503c\u4e0d\u8d85\u8fc71%\u7684\u5224\u5b9a\u4e3a\u6570\u503c\u57fa\u672c\u4e00\u81f4\uff0c\u8d85\u8fc71%\u7684\u5217\u4e3a\u5dee\u5f02\u4e8b\u9879\uff1b\u7b2c\u4e8c\u5c42\u9010\u8f66\u6bd4\u5bf9\u53f0\u8d26\u91cc\u7a0b\u4e0e\u5e73\u53f0\u6708\u5ea6\u76d1\u6d4b\u91cc\u7a0b\uff0c\u5dee\u5f02\u7387\u5728\u6b63\u8d1f30%\u4ee5\u5185\u7684\u5224\u5b9a\u4e3a\u6b63\u5e38\uff1b\u7b2c\u4e09\u5c42\u5bf9\u91cd\u70b9\u8f66\u8f86\u6574\u6708\u8f68\u8ff9\u70b9\u6838\u67e5\u6d3b\u52a8\u533a\u57df\u3001\u7ebf\u8def\u7aef\u70b9\u3001\u91cc\u7a0b\u89c4\u6a21\u548c\u53ef\u652f\u6301\u8d9f\u6b21\u3002",
)
- add_heading(doc, "锛堜簩锛夊彴璐﹂噷绋嬩笌骞冲彴鐩戞祴閲岀▼鏍告煡", 2)
+ add_heading(doc, "\uff08\u4e8c\uff09\u91cd\u70b9\u8f66\u8f86\u9009\u53d6", 2)
add_body(
doc,
- "浠ラ噸杞藉钩鍙拌溅杈嗘棩閲岀▼姹囨�诲舰鎴愪紒涓氭湀搴︾洃娴嬮噷绋嬶紝鍐嶄笌浼佷笟鍙拌处杞﹁締鎬婚噷绋嬮�愯溅銆侀�愪紒涓氭瘮瀵广�傚彴璐︿笌骞冲彴閲岀▼宸紓鐜囧湪姝h礋30%浠ュ唴鐨勶紝鍒ゅ畾涓烘甯革紱瓒呭嚭璇ヨ寖鍥寸殑锛屽垪涓洪噸鐐瑰樊寮傘�傚鏃犲钩鍙扮洃娴嬭褰曠殑杞﹁締鍗曠嫭缁熻锛屼笉鎸夐浂鍏噷澶勭悊銆�",
+ "\u91cd\u70b9\u8f66\u8f86\u4f18\u5148\u9009\u53d6\u5e73\u53f0\u65e5\u91cc\u7a0b30\u5929\u5747\u6709\u8bb0\u5f55\u4e14\u6bcf\u65e5\u603b\u91cc\u7a0b\u5927\u4e8e0\u3001\u53f0\u8d26\u4e0e\u5e73\u53f0\u91cc\u7a0b\u5dee\u5f02\u8d85\u8fc730%\u3001\u7ebf\u8def\u53ef\u4e0e\u53f0\u8d26\u5bf9\u5e94\u3001\u8f68\u8ff9\u70b9\u8fde\u7eed\u6027\u8f83\u597d\u7684\u8f66\u8f86\u3002\u4e2a\u522b\u4f01\u4e1a\u4e0d\u5b58\u5728\u540c\u65f6\u6ee1\u8db3\u4e0a\u8ff0\u6761\u4ef6\u7684\u8f66\u8f86\u65f6\uff0c\u9009\u53d6\u5f53\u6708\u8986\u76d629\u5929\u4ee5\u4e0a\u3001\u5df2\u8986\u76d6\u65e5\u671f\u603b\u91cc\u7a0b\u5747\u5927\u4e8e0\u4e14\u5dee\u5f02\u7387\u8f83\u5927\u7684\u8f66\u8f86\uff0c\u5e76\u5c06\u8986\u76d6\u4e0d\u8db3\u4f5c\u4e3a\u4f01\u4e1a\u52a8\u6001\u76d1\u63a7\u7ef4\u62a4\u95ee\u9898\u5355\u72ec\u6838\u67e5\u3002",
)
- add_heading(doc, "锛堜笁锛夐噸鐐硅溅杈嗚建杩圭偣绮炬煡", 2)
+ add_heading(doc, "\uff08\u4e09\uff09\u8bc1\u636e\u4f7f\u7528\u8fb9\u754c", 2)
add_body(
doc,
- "閲嶇偣杞﹁締閫夊彇浠ラ噸杞藉钩鍙拌溅杈嗘湀搴﹂噷绋嬫暟鎹负鍩虹锛屼紭鍏堥�夋嫨杞ㄨ抗瑕嗙洊澶╂暟杈冨銆佸彴璐︿笌骞冲彴鏈堝害閲岀▼宸紓杈冨ぇ锛屼笖鑳藉瀵瑰簲鍙拌处涓昏杩愯緭绾胯矾鐨勮溅杈嗭紱姣忔埛浼佷笟閫夊彇1杈嗐��",
- )
- add_body(
- doc,
- "瀵归�変腑杞﹁締2026骞�9鏈堟暣鏈堣建杩圭偣寮�灞曟牳楠岋紝閲嶇偣鏍告煡杞﹁締娲诲姩鍖哄煙銆佺嚎璺鐐广�佽建杩硅鐩栧ぉ鏁般�佽建杩圭偣璺緞閲岀▼浠ュ強鎸夊彴璐﹀钩鍧囧崟瓒熼噷绋嬫姌绠楃殑鍙敮鎸佽稛娆°�傝建杩圭偣鑳藉璇佹槑杞﹁締娲诲姩鍖哄煙鍜岄噷绋嬭妯★紝浣嗕笉鑳藉崟鐙瘉鏄庢瘡瓒熻揣鐗╃殑瀹為檯閲嶉噺鍙婅鍗歌揣浜嬪疄銆�",
+ "\u8f68\u8ff9\u6570\u636e\u7528\u4e8e\u5224\u65ad\u8f66\u8f86\u6d3b\u52a8\u533a\u57df\u3001\u7ebf\u8def\u65b9\u5411\u3001\u91cc\u7a0b\u89c4\u6a21\u548c\u8d9f\u6b21\u6570\u91cf\u7ea7\u3002\u8f68\u8ff9\u8986\u76d6\u5929\u6570\u7528\u4e8e\u5224\u65ad\u4f01\u4e1a\u52a8\u6001\u76d1\u63a7\u7ef4\u62a4\u60c5\u51b5\uff0c\u4e0d\u636e\u6b64\u5355\u72ec\u8ba4\u5b9a\u53f0\u8d26\u865a\u5047\uff1b\u8f68\u8ff9\u4e5f\u4e0d\u80fd\u76f4\u63a5\u8bc1\u660e\u6bcf\u8d9f\u8d27\u7269\u5b9e\u9645\u91cd\u91cf\u548c\u88c5\u5378\u8d27\u4e8b\u5b9e\uff0c\u76f8\u5173\u4e8b\u9879\u4ecd\u9700\u7ed3\u5408\u8fd0\u5355\u3001\u8fc7\u78c5\u5355\u3001\u88c5\u5378\u8d27\u8bb0\u5f55\u7b49\u539f\u59cb\u51ed\u636e\u6838\u5b9e\u3002",
)
- add_heading(doc, "涓夈�佹牳鏌ョ粨鏋�")
- add_heading(doc, "锛堜竴锛�1瀹朵紒涓氬凡鏌ユ槑鏈堟姤鍛ㄨ浆閲忓洜鍙拌处姹囨�诲叕寮忛敊璇鎶�", 2)
+ add_section(doc, landscape=False)
+ add_heading(doc, "\u4e09\u3001\u6838\u67e5\u7ed3\u679c")
+ add_heading(doc, "\uff08\u4e00\uff09\u6708\u62a5\u4e0e\u53f0\u8d26\u5468\u8f6c\u91cf", 2)
+ add_body(
+ doc,
+ f"12\u5bb6\u4f01\u4e1a\u4e2d\uff0c{layer1_consistent}\u5bb6\u6708\u62a5\u4e0e\u53f0\u8d26\u5468\u8f6c\u91cf\u5dee\u5f02\u7387\u7edd\u5bf9\u503c\u4e0d\u8d85\u8fc71%\uff0c1\u5bb6\u8d85\u8fc750%\u3002\u5404\u4f01\u4e1a\u6bd4\u8f83\u60c5\u51b5\u89c1\u88682\u3002",
+ )
+ add_caption(doc, "\u88682 \u4f01\u4e1a\u6708\u62a5\u4e0e\u53f0\u8d26\u5468\u8f6c\u91cf\u6838\u67e5\u7ed3\u679c")
+ turnover_groups = [
+ ("\u5e8f\u53f7", ()),
+ ("\u5e02\u5dde", ()),
+ ("\u4f01\u4e1a", ()),
+ ("\u5468\u8f6c\u91cf\uff08\u4e07\u5428\u516c\u91cc\uff09", ("\u6708\u62a5", "\u53f0\u8d26", "\u5dee\u5f02\u7387")),
+ ("\u6838\u67e5\u5224\u65ad", ()),
+ ]
+ turnover_rows: List[Sequence[str]] = []
+ for index, item in enumerate(enterprises, start=1):
+ turnover_rows.append((
+ str(index), short_city_name(item["city"]), str(item["enterprise"]),
+ fmt_wan_ton_km(item["month_turnover"]), fmt_wan_ton_km(item["ledger_turnover"]),
+ fmt_pct(item["report_vs_ledger"]), turnover_judgment(item),
+ ))
+ add_two_level_table(
+ doc,
+ turnover_groups,
+ turnover_rows,
+ [0.8, 1.1, 4.0, 2.1, 2.1, 1.5, 3.0],
+ [ALIGN_CENTER, ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_RIGHT, ALIGN_RIGHT, ALIGN_LEFT],
+ header_size=12,
+ body_size=10.5,
+ )
+
if kxd:
add_body(
doc,
- f"12瀹朵紒涓氫腑锛寋layer1_consistent}瀹舵湀鎶ヤ笌鍙拌处鍛ㄨ浆閲忓樊寮傜巼缁濆鍊间笉瓒呰繃1%锛�1瀹惰秴杩�50%銆傚樊寮傝緝澶х殑涓哄疁鏄屽嚡绁ヨ揪鐗╂祦鏈夐檺鍏徃锛�9鏈堟湀鎶ュ懆杞噺{fmt_wan_ton_km(kxd['month_turnover'])}涓囧惃鍏噷銆佸彴璐﹂�愯姝g‘鍚堣{fmt_wan_ton_km(kxd['ledger_turnover'])}涓囧惃鍏噷锛屾湀鎶ュ鎶fmt_pct(kxd['report_vs_ledger'])}銆傜粡閫愭湀鏍稿锛岃浼佷笟1鈥�9鏈堝彴璐﹀潎浣跨敤鈥滆揣杩愰噺鍚堣脳骞冲潎閲岀▼鈥濊绠楀懆杞噺锛屾湭鎸夋槑缁嗛�愮瑪姹囨�伙紝宸叉煡鏄庝负鍙拌处姹囨�诲叕寮忛敊璇��",
+ f"\u5b9c\u660c\u51ef\u7965\u8fbe\u7269\u6d41\u6709\u9650\u516c\u53f89\u6708\u6708\u62a5\u5468\u8f6c\u91cf{fmt_wan_ton_km(kxd['month_turnover'])}\u4e07\u5428\u516c\u91cc\uff0c\u53f0\u8d26\u9010\u884c\u6b63\u786e\u5408\u8ba1{fmt_wan_ton_km(kxd['ledger_turnover'])}\u4e07\u5428\u516c\u91cc\uff0c\u6708\u62a5\u591a\u62a5{fmt_pct(kxd['report_vs_ledger'])}\u3002\u8be5\u4f01\u4e1a1\u20149\u6708\u5747\u4f7f\u7528\u201c\u8d27\u8fd0\u91cf\u5408\u8ba1\u00d7\u5e73\u5747\u91cc\u7a0b\u201d\u8ba1\u7b97\u5468\u8f6c\u91cf\uff0c\u5df2\u67e5\u660e\u4e3a\u516c\u5f0f\u9519\u8bef\u30021\u20149\u6708\u6708\u62a5\u5468\u8f6c\u91cf\u5408\u8ba1{fmt_wan_ton_km(KAIXIANGDA_TOTAL_REPORT)}\u4e07\u5428\u516c\u91cc\uff0c\u53f0\u8d26\u9010\u884c\u6b63\u786e\u5408\u8ba1{fmt_wan_ton_km(KAIXIANGDA_TOTAL_CORRECT)}\u4e07\u5428\u516c\u91cc\uff0c\u7d2f\u8ba1\u591a\u62a5{fmt_wan_ton_km(KAIXIANGDA_TOTAL_OVER)}\u4e07\u5428\u516c\u91cc\uff0c\u591a\u62a5\u7387{fmt_pct(KAIXIANGDA_TOTAL_RATE, False)}\u3002",
)
- else:
- add_body(doc, f"12瀹朵紒涓氫腑锛寋layer1_consistent}瀹舵湀鎶ヤ笌鍙拌处鍛ㄨ浆閲忓樊寮傜巼缁濆鍊间笉瓒呰繃1%锛屽叾浣欎紒涓氬瓨鍦ㄨ緝澶у樊寮傘��")
-
- add_body(
- doc,
- f"1鈥�9鏈堟湀鎶ュ懆杞噺鍚堣{fmt_wan_ton_km(KAIXIANGDA_TOTAL_REPORT)}涓囧惃鍏噷锛屽彴璐﹂�愯姝g‘鍚堣{fmt_wan_ton_km(KAIXIANGDA_TOTAL_CORRECT)}涓囧惃鍏噷锛岀疮璁″鎶fmt_wan_ton_km(KAIXIANGDA_TOTAL_OVER)}涓囧惃鍏噷锛屽鎶ョ巼{fmt_pct(KAIXIANGDA_TOTAL_RATE, False)}銆�",
- )
- add_caption(doc, "琛�2 瀹滄槍鍑ゥ杈�1鈥�9鏈堝懆杞噺姹囨�绘牳鏌ョ粨鏋�")
+ add_caption(doc, "\u88683 \u5b9c\u660c\u51ef\u7965\u8fbe1\u20149\u6708\u5468\u8f6c\u91cf\u6c47\u603b\u6838\u67e5\u7ed3\u679c")
kxd_rows = [
(month, fmt_wan_ton_km(report), fmt_wan_ton_km(correct), fmt_wan_ton_km(over), fmt_pct(rate, False))
for month, report, correct, over, rate in KAIXIANGDA_MONTHLY
]
kxd_rows.append((
- "鍚堣",
+ "\u5408\u8ba1",
fmt_wan_ton_km(KAIXIANGDA_TOTAL_REPORT),
fmt_wan_ton_km(KAIXIANGDA_TOTAL_CORRECT),
fmt_wan_ton_km(KAIXIANGDA_TOTAL_OVER),
@@ -591,173 +799,140 @@
))
kxd_table = add_table(
doc,
- ["鏈堜唤", "鏈堟姤鍛ㄨ浆閲忥紙涓囧惃鍏噷锛�", "鍙拌处閫愯姝g‘鍚堣锛堜竾鍚ㄥ叕閲岋級", "鏈堟姤澶氭姤锛堜竾鍚ㄥ叕閲岋級", "澶氭姤鐜�"],
+ ["\u6708\u4efd", "\u6708\u62a5\u5468\u8f6c\u91cf\uff08\u4e07\u5428\u516c\u91cc\uff09", "\u53f0\u8d26\u6b63\u786e\u5408\u8ba1\uff08\u4e07\u5428\u516c\u91cc\uff09", "\u7d2f\u8ba1\u591a\u62a5\uff08\u4e07\u5428\u516c\u91cc\uff09", "\u591a\u62a5\u7387"],
kxd_rows,
- [1.4, 3.5, 4.0, 3.3, 2.4],
+ [1.3, 3.2, 3.6, 3.3, 2.2],
[ALIGN_CENTER, ALIGN_RIGHT, ALIGN_RIGHT, ALIGN_RIGHT, ALIGN_RIGHT],
- header_size=10,
- body_size=9,
+ header_size=12,
+ body_size=12,
)
compact_table(kxd_table)
add_body(
doc,
- "鏁板涓婏紝鈥滆揣杩愰噺鍚堣脳骞冲潎閲岀▼鈥濆彧鏈夊湪鍚勮稛閲岀▼鎴栧悇瓒熻揣杩愰噺瀹屽叏涓�鑷存椂鎵嶇瓑浜庨�愯鍚堣锛屼竴鑸儏鍐典笅鏃㈠彲鑳藉鎶ワ紝涔熷彲鑳藉皯鎶ワ紝鏂瑰悜鍙栧喅浜庤揣杩愰噺涓庤繍璺濈殑鐩稿叧鎬с�傚嚡绁ヨ揪1鈥�9鏈堝洜鐭�旇浇閲嶈緝澶с�侀暱閫旇浇閲嶈緝灏忥紝閿欒鍏紡缁撴灉鍚勬湀鍧囧亸澶с��",
+ "\u8be5\u9519\u8bef\u516c\u5f0f\u53ea\u6709\u5728\u5404\u8d9f\u91cc\u7a0b\u6216\u5404\u8d9f\u8d27\u8fd0\u91cf\u5b8c\u5168\u4e00\u81f4\u65f6\u624d\u7b49\u4e8e\u9010\u884c\u5408\u8ba1\uff0c\u4e00\u822c\u60c5\u51b5\u4e0b\u53ef\u80fd\u591a\u62a5\u6216\u5c11\u62a5\u3002\u51ef\u7965\u8fbe1\u20149\u6708\u5404\u6708\u5747\u8868\u73b0\u4e3a\u591a\u62a5\uff0c\u9700\u6309\u660e\u7ec6\u9010\u884c\u91cd\u7b97\u5e76\u8c03\u51cf\u3002",
)
- add_heading(doc, "锛堜簩锛夊彴璐﹂噷绋嬩笌骞冲彴鐩戞祴閲岀▼宸紓鏅亶杈冨ぇ", 2)
+ add_heading(doc, "\uff08\u4e8c\uff09\u4f01\u4e1a\u53f0\u8d26\u91cc\u7a0b\u4e0e\u5e73\u53f0\u76d1\u6d4b\u91cc\u7a0b", 2)
add_body(
doc,
- f"12瀹朵紒涓氬彴璐﹁溅杈嗗叡{fmt_int(total_vehicles)}杈嗭紝鍏朵腑鏃犲钩鍙拌建杩硅溅杈唟fmt_int(total_no_track)}杈嗭紝鍗爗fmt_pct(no_track_ratio, False)}銆傚彴璐﹂噷绋嬪悎璁fmt_num(total_ledger_mileage, 2)}鍏噷锛屽钩鍙扮洃娴嬮噷绋嬪悎璁fmt_num(total_platform_mileage, 2)}鍏噷锛屽彴璐﹁緝骞冲彴楂榹fmt_pct(total_mileage_diff)}銆傛寜宸紓鐜囨璐�30%鐨勬甯稿尯闂村垽鏂紝浠厈layer2_normal}瀹朵紒涓氬浜庢甯歌寖鍥达紝{len(enterprises) - layer2_normal}瀹朵紒涓氳秴鍑烘甯歌寖鍥淬��",
+ f"12\u5bb6\u4f01\u4e1a\u53f0\u8d26\u8f66\u8f86\u5171{fmt_int(total_vehicles)}\u8f86\uff0c\u5176\u4e2d\u65e0\u5e73\u53f0\u6708\u91cc\u7a0b\u8bb0\u5f55\u8f66\u8f86{fmt_int(total_no_track)}\u8f86\uff0c\u5360{fmt_pct(no_track_ratio, False)}\u3002\u53f0\u8d26\u91cc\u7a0b\u5408\u8ba1{fmt_num(total_ledger_mileage, 0)}\u516c\u91cc\uff0c\u5e73\u53f0\u76d1\u6d4b\u91cc\u7a0b\u5408\u8ba1{fmt_num(total_platform_mileage, 0)}\u516c\u91cc\uff0c\u53f0\u8d26\u8f83\u5e73\u53f0\u9ad8{fmt_pct(total_mileage_diff)}\u3002\u6309\u6b63\u8d1f30%\u7684\u6b63\u5e38\u533a\u95f4\u5224\u65ad\uff0c{layer2_normal}\u5bb6\u4f01\u4e1a\u5904\u4e8e\u6b63\u5e38\u8303\u56f4\uff0c{len(enterprises) - layer2_normal}\u5bb6\u4f01\u4e1a\u8d85\u51fa\u6b63\u5e38\u8303\u56f4\u3002",
)
+ if datong:
+ add_body(
+ doc,
+ f"\u6e56\u5317\u5927\u901a\u4e34\u7a7a\u7269\u6d41\u6709\u9650\u516c\u53f8\u4f01\u4e1a\u53f0\u8d26\u4e0e\u5e73\u53f0\u91cc\u7a0b\u5dee\u5f02\u7387\u4e3a{fmt_pct(datong['mileage_diff'])}\uff0c\u5904\u4e8e\u6b63\u5e38\u8303\u56f4\uff1b\u5176\u4f5911\u5bb6\u4f01\u4e1a\u5747\u8d85\u51fa\u6b63\u5e38\u8303\u56f4\u3002",
+ )
+
add_section(doc, landscape=True)
- add_caption(doc, "琛�3 浼佷笟鏈堟姤銆佸彴璐︿笌骞冲彴鐩戞祴鏍告煡缁撴灉")
- enterprise_rows: List[Sequence[str]] = []
+ add_caption(doc, "\u88684 \u4f01\u4e1a\u53f0\u8d26\u91cc\u7a0b\u4e0e\u5e73\u53f0\u76d1\u6d4b\u91cc\u7a0b\u6838\u67e5\u7ed3\u679c")
+ mileage_groups = [
+ ("\u5e8f\u53f7", ()),
+ ("\u5e02\u5dde", ()),
+ ("\u4f01\u4e1a", ()),
+ ("\u53f0\u8d26\u8f66\u8f86\u6570", ()),
+ ("\u91cc\u7a0b\uff08\u516c\u91cc\uff09", ("\u53f0\u8d26", "\u5e73\u53f0", "\u5dee\u5f02\u7387")),
+ ("\u65e0\u8f68\u8ff9\u8f66\u8f86", ("\u6570\u91cf", "\u5360\u6bd4")),
+ ("\u6838\u67e5\u5224\u65ad", ()),
+ ]
+ mileage_rows: List[Sequence[str]] = []
for index, item in enumerate(enterprises, start=1):
ledger_vehicles = int(item["ledger_vehicles"] or 0)
no_track_vehicles = int(item["no_track"] or 0)
no_track_ratio_item = no_track_vehicles / ledger_vehicles if ledger_vehicles else 0
- enterprise_rows.append((
- str(index),
- str(item["city"]),
- str(item["enterprise"]),
- fmt_int(ledger_vehicles),
- f"{fmt_wan_ton_km(item['month_turnover'])} / {fmt_wan_ton_km(item['ledger_turnover'])}",
- fmt_pct(item["report_vs_ledger"]),
- f"{fmt_num(item['ledger_mileage'], 0)} / {fmt_num(item['platform_mileage'], 0)}",
- fmt_pct(item["mileage_diff"]),
- fmt_int(no_track_vehicles),
- fmt_pct(no_track_ratio_item, False),
- enterprise_judgment(item),
+ mileage_rows.append((
+ str(index), short_city_name(item["city"]), str(item["enterprise"]), fmt_int(ledger_vehicles),
+ fmt_num(item["ledger_mileage"], 0), fmt_num(item["platform_mileage"], 0), fmt_pct(item["mileage_diff"]),
+ fmt_int(no_track_vehicles), fmt_pct(no_track_ratio_item, False), mileage_judgment(item),
))
- table2 = add_table(
+ add_two_level_table(
doc,
- ["搴忓彿", "甯傚窞", "浼佷笟", "鍙拌处杞﹁締鏁�", "鏈堟姤/鍙拌处鍛ㄨ浆閲忥紙涓囧惃鍏噷锛�", "鏈堟姤/鍙拌处鍛ㄨ浆閲忓樊寮傜巼", "鍙拌处/骞冲彴閲岀▼锛堝叕閲岋級", "鍙拌处/骞冲彴閲岀▼宸紓鐜�", "鏃犺建杩硅溅杈嗘暟", "鏃犺建杩硅溅杈嗗崰姣�", "鏍告煡鍒ゆ柇"],
- enterprise_rows,
- [0.9, 1.2, 4.5, 1.4, 3.3, 1.6, 4.0, 1.6, 1.4, 1.7, 4.0],
- [ALIGN_CENTER, ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_RIGHT, ALIGN_RIGHT, ALIGN_RIGHT, ALIGN_RIGHT, ALIGN_RIGHT, ALIGN_RIGHT, ALIGN_LEFT],
- header_size=8.5,
- body_size=8.5,
+ mileage_groups,
+ mileage_rows,
+ [0.8, 1.1, 4.8, 1.4, 2.0, 2.0, 1.6, 1.4, 1.6, 9.0],
+ [ALIGN_CENTER, ALIGN_CENTER, ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT, ALIGN_RIGHT,
+ ALIGN_RIGHT, ALIGN_RIGHT, ALIGN_RIGHT, ALIGN_LEFT],
+ header_size=12,
+ body_size=10.5,
)
- compact_table(table2)
+
add_section(doc, landscape=False)
- if datong:
- add_body(
- doc,
- f"鍦�12瀹朵紒涓氫腑锛屾箹鍖楀ぇ閫氫复绌虹墿娴佹湁闄愬叕鍙稿彴璐︿笌骞冲彴閲岀▼宸紓鐜囦负{fmt_pct(datong['mileage_diff'])}锛屽浜庢甯稿尯闂达紱鍏朵綑浼佷笟鍧囪秴杩囨璐�30%銆傚彴璐﹂噷绋嬮珮浜庡钩鍙扮洃娴嬮噷绋嬬殑鐗瑰緛杈冧负闆嗕腑銆�",
- )
-
- enterprise_formula_note = doc.add_paragraph()
- enterprise_formula_note.alignment = WD_ALIGN_PARAGRAPH.LEFT
- enterprise_formula_note.paragraph_format.first_line_indent = Pt(0)
- enterprise_formula_note.paragraph_format.space_before = Pt(2)
- enterprise_formula_note.paragraph_format.space_after = Pt(2)
- enterprise_formula_note.paragraph_format.line_spacing = Pt(16)
- enterprise_formula_run = enterprise_formula_note.add_run(
- "娉細鍑ゥ杈�9鏈堝樊寮傚凡鏌ユ槑涓哄彴璐﹀懆杞噺姹囨�诲叕寮忛敊璇紝1鈥�9鏈堢疮璁″鎶�39.00%锛涜瑙佸墠琛ㄥ強闂鏄庣粏銆�"
- )
- set_run_font(enterprise_formula_run, BODY_FONT, 10.5, False)
-
- add_heading(doc, "锛堜笁锛夐噸鐐硅溅杈嗚建杩圭簿鏌ュ潎鍙戠幇楂橀闄╅棶棰�", 2)
+ add_heading(doc, "\uff08\u4e09\uff09\u91cd\u70b9\u8f66\u8f86\u8f68\u8ff9\u70b9\u7cbe\u67e5", 2)
add_body(
doc,
- f"12杈嗛噸鐐硅溅杈嗗叡鏍搁獙杞ㄨ抗鐐箋fmt_int(total_points)}涓�傝建杩规牳鏌ユ樉绀猴紝{route_mismatch}杈嗗瓨鍦ㄦ槑纭矾绾夸笉绗︼紝{frequency_short}杈嗗瓨鍦ㄧ嚎璺鐐瑰嚭鐜伴娆℃槑鏄句笉瓒筹紝{endpoint_uncheckable}杈嗗洜绔偣鍚嶇О銆佽鏂藉悕绉版垨閬撹矾鍚嶇О鏃犳硶鐩存帴瀹氫綅鑰屼笉鑳藉畬鎴愬畬鏁寸嚎璺牳楠屻��10杈嗚溅杞ㄨ抗鍙敮鎸佽稛娆℃瘮渚嬩綆浜�50%锛�12杈嗚溅鍧囨湭杈惧埌鍙拌处鐢虫姤瓒熸锛涘彲鏀寔瓒熸姣斾緥鏈�浣庝负{fmt_pct(support_min, False)}锛屾渶楂樹负{fmt_pct(support_max, False)}銆�",
+ f"12\u8f86\u91cd\u70b9\u8f66\u8f86\u5171\u6838\u9a8c\u8f68\u8ff9\u70b9{fmt_int(raw_points)}\u4e2a\u3002{route_mismatch}\u8f86\u7533\u62a5\u7ebf\u8def\u672a\u83b7\u8f68\u8ff9\u652f\u6301\uff1b\u5176\u4f59{len(vehicles) - route_mismatch}\u8f86\u7ebf\u8def\u65b9\u5411\u867d\u6709\u8f68\u8ff9\u652f\u6301\uff0c\u4f46\u53ef\u652f\u6301\u8d9f\u6b21\u6bd4\u4f8b\u5747\u672a\u8fbe\u5230100%\uff0c\u8303\u56f4{fmt_pct(supported_support_min, False)}\u2014{fmt_pct(supported_support_max, False)}\uff0c\u5176\u4e2d{support_below_half_supported}\u8f86\u4f4e\u4e8e50%\u3002{positive_days_30}\u8f86\u5e73\u53f0\u65e5\u91cc\u7a0b30\u5929\u603b\u91cc\u7a0b\u5747\u5927\u4e8e0\uff0c{positive_days_29}\u8f86\u4e3a29\u5929\uff0c\u53e6\u6709{positive_days_short}\u8f86\u4ec523\u5929\u603b\u91cc\u7a0b\u5927\u4e8e0\uff0c\u52a8\u6001\u76d1\u6d4b\u7ef4\u62a4\u5b58\u5728\u7f3a\u53e3\u3002\u8f68\u8ff9\u53ef\u652f\u6301\u8d9f\u6b21\u6bd4\u4f8b\u4ec5\u5bf9\u7ebf\u8def\u65b9\u5411\u83b7\u5f97\u8f68\u8ff9\u652f\u6301\u7684{len(vehicles) - route_mismatch}\u8f86\u8f66\u8ba1\u7b97\u3002",
)
add_section(doc, landscape=True)
- add_caption(doc, "琛�4 閲嶇偣杞﹁締杞ㄨ抗鏍告煡缁撴灉")
+ add_caption(doc, "\u88685 \u91cd\u70b9\u8f66\u8f86\u8f68\u8ff9\u6838\u67e5\u7ed3\u679c")
+ sample_groups = [
+ ("\u5e8f\u53f7", ()),
+ ("\u5e02\u5dde", ()),
+ ("\u4f01\u4e1a", ()),
+ ("\u8f66\u724c\u53f7", ()),
+ ("\u53f0\u8d26", ("\u8d9f\u6b21", "\u91cc\u7a0b\uff08\u516c\u91cc\uff09")),
+ ("\u5e73\u53f0\u76d1\u6d4b", ("\u91cc\u7a0b\uff08\u516c\u91cc\uff09", "\u8f68\u8ff9\u70b9\u6570", "\u91cc\u7a0b\u5927\u4e8e0\u5929\u6570")),
+ ("\u53f0\u8d26\u8f83\u5e73\u53f0\u91cc\u7a0b\u5dee\u5f02\u7387", ()),
+ ("\u8f68\u8ff9\u53ef\u652f\u6301\u8d9f\u6b21\u6bd4\u4f8b", ()),
+ ("\u6838\u67e5\u5224\u65ad", ()),
+ ]
sample_rows: List[Sequence[str]] = []
- for index, item in enumerate(samples, start=1):
+ for index, item in enumerate(enterprises, start=1):
+ vehicle = vehicles_by_enterprise[str(item["enterprise"])]
sample_rows.append((
- str(index),
- str(item["city"]),
- str(item["enterprise"]),
- str(item["plate"]),
- f"{fmt_num(item['ledger_mileage'], 2)} / {fmt_num(item['platform_mileage'], 2)}",
- fmt_pct(item["mileage_diff"]),
- fmt_int(item["points"]),
- fmt_pct(item["support_ratio"], False),
- item["judgment"],
+ str(index), short_city_name(item["city"]), str(item["enterprise"]), str(vehicle["plate"]),
+ fmt_num(vehicle["ledger"]["trips"], 0), fmt_num(vehicle["ledger"]["mileage"], 2),
+ fmt_num(vehicle["platform"]["total_mileage"], 2), fmt_int(vehicle["points"]["valid_point_count"]),
+ str(int(vehicle["platform"].get("positive_mileage_days") or 0)),
+ fmt_pct(vehicle["comparison"].get("ledger_vs_platform_rate")), ("\u2014" if strict_missing_endpoints(vehicle) else fmt_pct(sample_support(vehicle), False)),
+ sample_judgment(vehicle),
))
- table3 = add_table(
+ add_two_level_table(
doc,
- ["搴忓彿", "甯傚窞", "浼佷笟", "杞︾墝鍙�", "鍙拌处/骞冲彴閲岀▼锛堝叕閲岋級", "閲岀▼宸紓鐜�", "杞ㄨ抗鐐规暟", "鍙敮鎸佽稛娆℃瘮渚�", "鏍告煡鍒ゆ柇"],
+ sample_groups,
sample_rows,
- [1.2, 1.3, 5.4, 2.2, 4.0, 2.6, 2.2, 2.8, 3.8],
- [ALIGN_CENTER, ALIGN_CENTER, ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT, ALIGN_RIGHT, ALIGN_RIGHT, ALIGN_RIGHT, ALIGN_CENTER],
+ [0.8, 1.1, 4.2, 1.8, 1.2, 1.7, 1.7, 1.8, 1.5, 2.0, 2.2, 5.7],
+ [ALIGN_CENTER, ALIGN_CENTER, ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT, ALIGN_RIGHT,
+ ALIGN_RIGHT, ALIGN_RIGHT, ALIGN_CENTER, ALIGN_CENTER, ALIGN_CENTER, ALIGN_LEFT],
+ header_size=12,
+ body_size=10.5,
)
- compact_table(table3)
add_section(doc, landscape=False)
- add_heading(doc, "鍥涖�佷富瑕侀棶棰�")
+ add_heading(doc, "\u56db\u3001\u4f01\u4e1a\u95ee\u9898\u6c47\u603b")
add_body(
doc,
- "浼佷笟鍛ㄨ浆閲忔湀搴︽眹鎬诲叕寮忛敊璇紝閫犳垚1鈥�9鏈堢疮璁″鎶ャ�傚疁鏄屽嚡绁ヨ揪鐗╂祦鏈夐檺鍏徃1鈥�9鏈堝彴璐﹀潎浠モ�滆揣杩愰噺鍚堣脳骞冲潎閲岀▼鈥濅唬鏇块�愯鈥滆揣杩愰噺脳璇ヨ稛閲岀▼鈥濈殑鍚堣锛屾湀鎶ュ懆杞噺鍚堣16,765.20涓囧惃鍏噷锛屽彴璐﹂�愯姝g‘鍚堣12,061.67涓囧惃鍏噷锛岀疮璁″鎶�4,703.53涓囧惃鍏噷锛屽鎶�39.00%銆傛湰娆′粎鎶芥煡12瀹朵紒涓氾紝鑰屽叏鐪�2026骞磋涓婅揣杩愪紒涓氬叡636瀹讹紝鍏朵粬浼佷笟瀛樺湪鍚岀被鍏紡閿欒鐨勫彲鑳斤紝闇�缁勭粐寮�灞曞叏闈㈢瓫鏌ャ��",
- "锛堜竴锛�",
- )
- add_body(
- doc,
- "鍙拌处閲岀▼鐢虫姤鏅亶楂樹簬骞冲彴鐩戞祴閲岀▼銆傞櫎婀栧寳澶ч�氫复绌虹墿娴佹湁闄愬叕鍙稿锛屽叾浣�11瀹朵紒涓氬彴璐︿笌骞冲彴閲岀▼宸紓鐜囧潎瓒呭嚭姝h礋30%锛屽彴璐﹀悎璁¢噷绋嬭緝骞冲彴楂�134.89%锛岃鏄庡樊寮備笉鏄釜鍒溅杈嗛�犳垚锛岃�屾槸浼佷笟鍙拌处灞傞潰瀛樺湪鏅亶鎬с��",
- "锛堜簩锛�",
- )
- add_body(
- doc,
- "閮ㄥ垎浼佷笟鐢虫姤绾胯矾涓庤溅杈嗗疄闄呮椿鍔ㄥ尯鍩熸槑鏄句笉绗︺�備互鎶芥煡杞﹁締涓轰緥锛屾箹鍖楀畨娆g墿娴佹湁闄愯矗浠诲叕鍙搁剛L1N523鏈洃娴嬪埌澶╂触銆佸磭闃筹紱婀栧寳澶ч�氫复绌虹墿娴佹湁闄愬叕鍙搁剛J20052D鏈洃娴嬪埌娴犳按锛屼富瑕佹椿鍔ㄥ尯鍩熶负瀹夊窘姹犲窞銆侀摐闄碉紱瀹滄槍鍑ゥ杈剧墿娴佹湁闄愬叕鍙搁剛E68056鏈洃娴嬪埌鍖楁捣銆佹禉姹燂紝涓昏娲诲姩鍖哄煙闆嗕腑鍦ㄥ疁鏄屽競銆傜浉鍏宠建杩逛笉鑳芥敮鎸佸彴璐︾敵鎶ョ殑杩愯緭绾胯矾銆�",
- "锛堜笁锛�",
- )
- add_body(
- doc,
- "鍙拌处鐢虫姤瓒熸涓庤建杩瑰彲鏀寔瓒熸瀛樺湪鏄庢樉宸窛銆�12杈嗛噸鐐硅溅杈嗘寜鍙拌处骞冲潎鍗曡稛閲岀▼鎶樼畻锛屽钩鍙拌建杩瑰彲鏀寔瓒熸姣斾緥鍧囦綆浜�100%锛屽叾涓�10杈嗕綆浜�50%銆傞儴鍒嗚溅杈嗗彴璐︾敵鎶ヨ稛娆¤緝楂橈紝浣嗚溅杈嗘暣鏈堟椿鍔ㄨ寖鍥存湁闄愶紝闇�杩涗竴姝ユ牳瀵硅繍杈撲换鍔℃簮銆佽繍鍗曘�佽揣杩愬崟鍜岃鍗歌揣璁板綍銆�",
- "锛堝洓锛�",
- )
- add_body(
- doc,
- "鏃犲钩鍙拌建杩硅溅杈嗗崰姣旇緝楂樸��579杈嗗彴璐﹁溅杈嗕腑鏈�64杈嗘病鏈夊钩鍙扮洃娴嬭建杩癸紝鍗�11.05%銆傚涓婅堪杞﹁締锛屽簲鍖哄垎鏈帴鍏ュ钩鍙般�佽溅鐗屼俊鎭笉涓�鑷淬�佸仠杩愬拰婕忔姤绛変笉鍚屾儏褰紝涓嶈兘鐩存帴璁ゅ畾涓烘湭杩愯緭锛屼篃涓嶈兘鍦ㄧ己灏戜緷鎹殑鎯呭喌涓嬬户缁鍏ュ彴璐﹂噷绋嬨��",
- "锛堜簲锛�",
+ "\u4f01\u4e1a\u9010\u9879\u6838\u67e5\u95ee\u9898\u3001\u6d89\u53ca\u8f66\u8f86\u3001\u53f0\u8d26\u60c5\u51b5\u3001\u6708\u62a5\u53ca\u5e73\u53f0\u76d1\u6d4b\u60c5\u51b5\u3001\u6838\u67e5\u7ed3\u8bba\u548c\u6838\u67e5\u4f9d\u636e\uff0c\u8be6\u89c1\u9644\u4ef6\u300a2026\u5e749\u6708\u4f01\u4e1a\u53f0\u8d26\u62bd\u67e5\u6838\u67e5\u95ee\u9898\u6c47\u603b\u8868.xlsx\u300b\u3002",
)
- add_heading(doc, "浜斻�佹牳鏌ョ粨璁�")
+ add_heading(doc, "\u4e94\u3001\u5904\u7406\u5efa\u8bae")
add_body(
doc,
- "瀹滄槍鍑ゥ杈剧墿娴佹湁闄愬叕鍙�1鈥�9鏈堝懆杞噺姹囨�诲叕寮忛敊璇凡缁忔煡瀹烇細鏈堟姤鍚堣16,765.20涓囧惃鍏噷锛屽彴璐﹂�愯姝g‘鍚堣12,061.67涓囧惃鍏噷锛岀疮璁″鎶�4,703.53涓囧惃鍏噷锛屽鎶�39.00%銆傝闂璇存槑锛屾湀鎶ヤ笌鍙拌处鏁板�间竴鑷翠笉鑳芥浛浠e璁$畻杩囩▼鍜屽師濮嬫槑缁嗙殑鏍告煡銆傛湰娆′粎鎶芥煡12瀹朵紒涓氾紝鑰�2026骞村叏鐪佽涓婅揣杩愪紒涓氬叡636瀹讹紝鍚岀被妯℃澘鎴栧悓绫诲叕寮忛敊璇彲鑳藉湪鍏朵粬浼佷笟瀛樺湪锛岄渶灏嗗懆杞噺姹囨�诲叕寮忕撼鍏ュ叏鐪佽涓婁紒涓氫笓椤圭瓫鏌ャ��",
+ "\u8981\u6c42\u5b9c\u660c\u51ef\u7965\u8fbe\u7269\u6d41\u6709\u9650\u516c\u53f8\u7acb\u5373\u5c06\u5468\u8f6c\u91cf\u6c47\u603b\u516c\u5f0f\u6539\u4e3a\u9010\u884c\u201c\u8d27\u8fd0\u91cf\u00d7\u8be5\u8d9f\u91cc\u7a0b\u201d\u6c42\u548c\uff0c\u5e76\u5bf91\u20149\u6708\u591a\u62a5\u7684\u6570\u636e\u62ff\u51fa\u8c03\u51cf\u65b9\u6848\u3002",
+ "\uff08\u4e00\uff09",
)
add_body(
doc,
- "闄や笂杩板叕寮忛棶棰樺锛屽彴璐﹂噷绋嬬敵鎶ヤ笌骞冲彴鐩戞祴宸紓浠嶇劧绐佸嚭銆傚彴璐﹂噷绋嬪悎璁¤緝骞冲彴鐩戞祴閲岀▼楂�134.89%锛�11瀹朵紒涓氳秴鍑烘璐�30%鐨勬甯歌寖鍥达紱12杈嗛噸鐐硅溅杈嗚建杩瑰潎瀛樺湪楂橀闄╅棶棰橈紝鍏朵腑7杈嗘槑纭〃鐜颁负鐢虫姤绾胯矾涓庤溅杈嗗疄闄呮椿鍔ㄥ尯鍩熶笉绗︺��",
+ "\u5bf92026\u5e74636\u5bb6\u89c4\u4e0a\u8d27\u8fd0\u4f01\u4e1a\u7ec4\u7ec7\u5f00\u5c55\u5468\u8f6c\u91cf\u6c47\u603b\u516c\u5f0f\u4e13\u9879\u7b5b\u67e5\uff0c\u9010\u6237\u4ee5\u660e\u7ec6\u884c\u91cd\u7b971\u20149\u6708\u53ca\u7d2f\u8ba1\u5468\u8f6c\u91cf\uff0c\u65e2\u8bc6\u522b\u591a\u62a5\uff0c\u4e5f\u8bc6\u522b\u5c11\u62a5\u3002",
+ "\uff08\u4e8c\uff09",
)
add_body(
doc,
- "鏈缁撹閽堝鎶芥煡鐨�3涓競宸炪��12瀹朵紒涓氥��12杈嗛噸鐐硅溅杈嗗拰鍑ゥ杈�1鈥�9鏈堝懆杞噺鍏紡澶嶆牳缁撴灉锛屼笉鐩存帴璁ゅ畾鍏朵粬浼佷笟瀛樺湪鍚岀被闂銆傜幇鏈夎建杩硅瘉鎹兘澶熸敮鎸佸杞﹁締娲诲姩鍖哄煙銆侀噷绋嬭妯″拰绾胯矾鏂瑰悜鐨勫垽鏂紝浣嗚揣杞﹀疄闄呰浇閲嶃�佹瘡瓒熻鍗歌揣浜嬪疄鍜岃繍杈撳悎鍚屽饱琛屾儏鍐碉紝浠嶉渶缁撳悎浼佷笟鍘熷鍑嵁杩涗竴姝ユ牳瀹炪��",
- )
-
- add_heading(doc, "鍏�佸鐞嗗缓璁�")
- add_body(
- doc,
- "瑕佹眰瀹滄槍鍑ゥ杈剧墿娴佹湁闄愬叕鍙哥珛鍗冲皢鍛ㄨ浆閲忔眹鎬诲叕寮忔敼涓洪�愯鈥滆揣杩愰噺脳璇ヨ稛閲岀▼鈥濇眰鍜岋紝骞跺1鈥�9鏈堝鎶ョ殑鏁版嵁鎷垮嚭璋冨噺鏂规銆�",
- "锛堜竴锛�",
+ "\u5bf9\u53f0\u8d26\u91cc\u7a0b\u4e0e\u5e73\u53f0\u91cc\u7a0b\u5dee\u5f02\u8d85\u8fc730%\u768411\u5bb6\u4f01\u4e1a\uff0c\u8981\u6c42\u9010\u8f66\u8bf4\u660e\u539f\u56e0\uff0c\u5e76\u63d0\u4f9b\u8fd0\u8f93\u4efb\u52a1\u6e90\u3001\u8fd0\u5355\u3001\u8fc7\u78c5\u5355\u3001\u88c5\u5378\u8d27\u8bb0\u5f55\u548c\u8fd0\u8f93\u5408\u540c\u7b49\u539f\u59cb\u8d44\u6599\u3002",
+ "\uff08\u4e09\uff09",
)
add_body(
doc,
- "瀵�2026骞�636瀹惰涓婅揣杩愪紒涓氱粍缁囧紑灞曞懆杞噺姹囨�诲叕寮忎笓椤圭瓫鏌ワ紝閲嶇偣妫�鏌ュ彴璐︽槸鍚︿娇鐢ㄢ�滆揣杩愰噺鍚堣脳骞冲潎閲岀▼鈥濈瓑閿欒绠楁硶銆傞�愭埛浠ユ槑缁嗚鈥滆揣杩愰噺脳璇ヨ稛閲岀▼鈥濋噸绠�1鈥�9鏈堝強绱鍛ㄨ浆閲忥紝鏃㈣瘑鍒鎶ワ紝涔熻瘑鍒皯鎶ワ紝涓嶉璁炬柟鍚戙��",
- "锛堜簩锛�",
+ "\u5bf964\u8f86\u65e0\u5e73\u53f0\u6708\u91cc\u7a0b\u8bb0\u5f55\u8f66\u8f86\u5f00\u5c55\u4e13\u9879\u6e05\u7406\uff0c\u9010\u8f66\u6838\u5b9e\u63a5\u5165\u72b6\u6001\u3001\u8f66\u724c\u4fe1\u606f\u3001\u8fd0\u8425\u72b6\u6001\u548c\u53f0\u8d26\u586b\u62a5\u60c5\u51b5\uff1b\u5bf9\u5e73\u53f0\u603b\u91cc\u7a0b\u5927\u4e8e0\u5929\u6570\u4e0d\u8db330\u5929\u7684\u91cd\u70b9\u8f66\u8f86\uff0c\u6838\u5b9e\u8f66\u8f7d\u7ec8\u7aef\u5728\u7ebf\u548c\u8fd0\u884c\u72b6\u6001\u3002",
+ "\uff08\u56db\uff09",
)
add_body(
doc,
- "鍦ㄤ笓椤圭瓫鏌ュ熀纭�涓婏紝涓句竴鍙嶄笁妫�鏌ュ叾浠栨湀搴︽眹鎬绘寚鏍囧強骞村害绱鍏紡锛岄噸鐐规牳瀵规湀搴﹀悎璁℃槸鍚︾瓑浜庢槑缁嗚姹傚拰銆佸勾搴︾疮璁℃槸鍚︾瓑浜庡悇鏈堟牎姝e�间箣鍜岋紝骞跺浣跨敤骞冲潎鏁板拰姣斾緥娲剧敓鎸囨爣鐨勬儏褰㈤�愰」楠岃瘉缁熻鍙e緞銆�",
- "锛堜笁锛�",
+ "\u5bf9\u7533\u62a5\u7ebf\u8def\u672a\u83b7\u8f68\u8ff9\u652f\u6301\u3001\u7ebf\u8def\u7aef\u70b9\u51fa\u73b0\u9891\u6b21\u4e0d\u8db3\u7684\u8f66\u8f86\uff0c\u7ed3\u5408\u8c03\u5ea6\u8bb0\u5f55\u3001\u88c5\u5378\u8d27\u5730\u70b9\u3001\u9ad8\u901f\u516c\u8def\u901a\u884c\u8bb0\u5f55\u7b49\u5f00\u5c55\u590d\u6838\u3002",
+ "\uff08\u4e94\uff09",
)
add_body(
doc,
- "瀵�11瀹跺彴璐︿笌骞冲彴閲岀▼宸紓瓒呰繃30%鐨勪紒涓氾紝瑕佹眰閫愯溅璇存槑鍘熷洜锛屽苟鎻愪緵杩愯緭浠诲姟婧愩�佽繍鍗曘�佽揣杩愬崟銆佽繃纾呭崟銆佽鍗歌揣璁板綍鍜岃繍杈撳悎鍚岀瓑鍘熷璧勬枡銆傚鍙拌处閲岀▼鏄庢樉鍋忛珮涓旀棤娉曟彁渚涙湁鏁堣繍杈撳嚟鎹殑锛屾寜绋嬪簭杩涗竴姝ユ牳瀹炪��",
- "锛堝洓锛�",
- )
- add_body(
- doc,
- "瀵�64杈嗘棤骞冲彴杞ㄨ抗杞﹁締寮�灞曚笓椤规竻鐞嗭紝閫愯溅鏍稿疄鎺ュ叆鐘舵�併�佽溅鐗屼俊鎭�佽繍钀ョ姸鎬佸拰鍙拌处濉姤鎯呭喌锛涘杞ㄨ抗鏄剧ず绾胯矾涓嶇銆佺鐐归娆′笉瓒虫垨鏃犳硶瀹氫綅鐨勮溅杈嗭紝缁撳悎璋冨害璁板綍銆佽鍗歌揣鍦扮偣鍜岄珮閫熷叕璺�氳璁板綍寮�灞曞鏍搞��",
- "锛堜簲锛�",
- )
- add_body(
- doc,
- "鐫d績浼佷笟瑙勮寖寤虹珛鏈堝害杩愯緭鍙拌处锛屽仛鍒拌溅杈嗐�佹棩鏈熴�佺嚎璺�佽稛娆°�侀噷绋嬨�佽揣杩愰噺鍜屽懆杞噺鐩镐簰瀵瑰簲锛屽苟淇濈暀鍙牳楠岀殑鍘熷杩愯緭鍑嵁銆�",
- "锛堝叚锛�",
+ "\u7763\u4fc3\u4f01\u4e1a\u89c4\u8303\u5efa\u7acb\u6708\u5ea6\u8fd0\u8f93\u53f0\u8d26\uff0c\u505a\u5230\u8f66\u8f86\u3001\u65e5\u671f\u3001\u7ebf\u8def\u3001\u8d9f\u6b21\u3001\u91cc\u7a0b\u3001\u8d27\u8fd0\u91cf\u548c\u5468\u8f6c\u91cf\u76f8\u4e92\u5bf9\u5e94\uff1b\u540c\u6b65\u843d\u5b9e\u8f66\u8f86\u52a8\u6001\u76d1\u63a7\u8bbe\u5907\u7ef4\u62a4\u548c\u5f02\u5e38\u6570\u636e\u5904\u7f6e\u8d23\u4efb\u3002",
+ "\uff08\u516d\uff09",
)
signature = doc.add_paragraph()
@@ -766,17 +941,8 @@
signature.paragraph_format.space_before = Pt(18)
signature.paragraph_format.space_after = Pt(0)
signature.paragraph_format.line_spacing = Pt(30)
- signature_run = signature.add_run("2026骞�10鏈�28鏃�")
+ signature_run = signature.add_run("2026\u5e7410\u670829\u65e5")
set_run_font(signature_run, BODY_FONT, 16, False)
-
- attachment = doc.add_paragraph()
- attachment.alignment = WD_ALIGN_PARAGRAPH.LEFT
- attachment.paragraph_format.first_line_indent = Pt(0)
- attachment.paragraph_format.space_before = Pt(14)
- attachment.paragraph_format.space_after = Pt(0)
- attachment.paragraph_format.line_spacing = Pt(24)
- attachment_run = attachment.add_run("闄勪欢锛�" + attachment_name)
- set_run_font(attachment_run, BODY_FONT, 14, False)
output_path.parent.mkdir(parents=True, exist_ok=True)
doc.save(output_path)
@@ -785,15 +951,17 @@
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--workbook", required=True)
+ parser.add_argument("--diagnostics", required=True)
parser.add_argument("--output", required=True)
- parser.add_argument("--attachment", default="")
args = parser.parse_args()
workbook = Path(args.workbook)
+ diagnostics = Path(args.diagnostics)
output = Path(args.output)
if not workbook.is_file():
raise SystemExit("workbook not found: %s" % workbook)
- attachment_name = args.attachment or workbook.name
- build_report(workbook, output, attachment_name)
+ if not diagnostics.is_file():
+ raise SystemExit("diagnostics not found: %s" % diagnostics)
+ build_report(workbook, diagnostics, output)
print(str(output))
return 0
diff --git a/tools/build_ledger_vehicle_shortlist.py b/tools/build_ledger_vehicle_shortlist.py
new file mode 100644
index 0000000..d9f7ff3
--- /dev/null
+++ b/tools/build_ledger_vehicle_shortlist.py
@@ -0,0 +1,490 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""Build a vehicle shortlist for the enterprise-ledger track-point review."""
+
+from __future__ import annotations
+
+import argparse
+import json
+from collections import defaultdict
+from pathlib import Path
+from textwrap import dedent
+from typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple
+
+import pymysql
+from openpyxl import Workbook
+from openpyxl.styles import Alignment, Border, Font, Side
+from openpyxl.utils import get_column_letter
+
+
+CITY_ORDER = {
+ "\u54b8\u5b81": 0,
+ "\u9ec4\u5188": 1,
+ "\u5b9c\u660c": 2,
+}
+
+HEADER_FONT = Font(name="\u4eff\u5b8b_GB2312", size=11, bold=True)
+BODY_FONT = Font(name="\u4eff\u5b8b_GB2312", size=10)
+TITLE_FONT = Font(name="\u9ed1\u4f53", size=16, bold=True)
+THIN = Side(style="thin", color="000000")
+BORDER = Border(left=THIN, right=THIN, top=THIN, bottom=THIN)
+
+
+def city_sort(city: str) -> int:
+ return CITY_ORDER.get(city, 99)
+
+
+def ordered_rows(rows: Iterable[Dict[str, Any]]) -> List[Dict[str, Any]]:
+ return sorted(
+ rows,
+ key=lambda row: (
+ city_sort(str(row["city_name"])),
+ str(row["enterprise_name"]),
+ -int(row["daily_record_days"]),
+ -int(row["positive_mileage_days"]),
+ -abs(float(row["mileage_diff_rate"] or 0)),
+ -float(row["ledger_mileage"] or 0),
+ ),
+ )
+
+
+def select_vehicle(
+ rows: Sequence[Dict[str, Any]],
+ current_plate: str,
+) -> Tuple[Dict[str, Any], str, str]:
+ by_plate = {str(row["plate_no"]): row for row in rows}
+ current = by_plate.get(current_plate)
+ current_is_basically_complete = bool(
+ current
+ and int(current["daily_record_days"]) >= 29
+ and int(current["positive_mileage_days"]) == int(current["daily_record_days"])
+ )
+ if current_is_basically_complete:
+ return (
+ current,
+ "\u4fdd\u7559",
+ (
+ "\u5f53\u524d\u8f66\u8f86\u5df2\u8fbe\u523029\u5929\u4ee5\u4e0a\u8fde\u7eed\u8986\u76d6\uff0c\u4e14\u5b58\u5728\u8bb0\u5f55\u7684\u65e5\u671f\u5747\u6709\u91cc\u7a0b\uff1b"
+ "\u7ee7\u7eed\u4f7f\u7528\u65e2\u6709\u8f68\u8ff9\u70b9\uff0c\u907f\u514d\u4e3a\u8865\u9f501\u5929\u800c\u66f4\u6362\u4e3a\u8bc1\u660e\u529b\u66f4\u5f31\u7684\u8f66\u8f86\u3002"
+ ),
+ )
+
+ full_rows = [
+ row for row in rows
+ if int(row["daily_record_days"]) == 30
+ and int(row["positive_mileage_days"]) == 30
+ ]
+ high_full_rows = [
+ row for row in full_rows
+ if abs(float(row["mileage_diff_rate"] or 0)) > 0.30
+ ]
+ if high_full_rows:
+ selected = max(
+ high_full_rows,
+ key=lambda row: (
+ abs(float(row["mileage_diff_rate"] or 0)),
+ float(row["ledger_mileage"] or 0),
+ int(row["daily_point_count"] or 0),
+ ),
+ )
+ return (
+ selected,
+ "\u66f4\u6362",
+ (
+ "\u4f18\u5148\u9009\u62e930\u5929\u5747\u6709\u5e73\u53f0\u65e5\u8bb0\u5f55\u3001\u6bcf\u65e5\u5747\u6709\u91cc\u7a0b\u3001"
+ "\u4e14\u53f0\u8d26\u4e0e\u5e73\u53f0\u91cc\u7a0b\u5dee\u5f02\u8d85\u8fc730%\u7684\u8f66\u8f86\uff0c\u5e76\u9009\u62e9\u5dee\u5f02\u6700\u5927\u7684\u8f66\u8f86\u3002"
+ ),
+ )
+
+ max_positive_days = max(int(row["positive_mileage_days"]) for row in rows)
+ high_continuous_rows = [
+ row for row in rows
+ if int(row["positive_mileage_days"]) == int(row["daily_record_days"])
+ and int(row["positive_mileage_days"]) >= 29
+ and abs(float(row["mileage_diff_rate"] or 0)) > 0.30
+ ]
+ if high_continuous_rows:
+ selected = max(
+ high_continuous_rows,
+ key=lambda row: (
+ int(row["positive_mileage_days"]),
+ abs(float(row["mileage_diff_rate"] or 0)),
+ float(row["ledger_mileage"] or 0),
+ int(row["daily_point_count"] or 0),
+ ),
+ )
+ return (
+ selected,
+ "\u66f4\u6362",
+ (
+ "\u8be5\u4f01\u4e1a\u5f53\u6708\u65e0\u657430\u5929\u5747\u6709\u91cc\u7a0b\u4e14\u5dee\u5f02\u8d85\u8fc730%\u7684\u8f66\u8f86\uff1b"
+ "\u5df2\u9009\u62e9\u672c\u6708\u8fde\u7eed\u8986\u76d629\u5929\u4ee5\u4e0a\u3001\u5b58\u5728\u8bb0\u5f55\u65e5\u671f\u5747\u6709\u91cc\u7a0b\u7684\u8f66\u8f86\u3002"
+ ),
+ )
+
+ if full_rows:
+ selected = max(
+ full_rows,
+ key=lambda row: (
+ abs(float(row["mileage_diff_rate"] or 0)),
+ float(row["ledger_mileage"] or 0),
+ int(row["daily_point_count"] or 0),
+ ),
+ )
+ return (
+ selected,
+ "\u66f4\u6362",
+ (
+ "\u5df2\u9009\u62e930\u5929\u5747\u6709\u5e73\u53f0\u65e5\u8bb0\u5f55\u3001\u6bcf\u65e5\u5747\u6709\u91cc\u7a0b\u7684\u8f66\u8f86\uff0c"
+ "\u4f5c\u4e3a\u8be5\u4f01\u4e1a\u8f68\u8ff9\u6838\u67e5\u7684\u57fa\u51c6\u8f66\u8f86\u3002"
+ ),
+ )
+
+ continuous_rows = [
+ row for row in rows
+ if int(row["positive_mileage_days"]) == max_positive_days
+ and int(row["positive_mileage_days"]) == int(row["daily_record_days"])
+ ]
+ selected = max(
+ continuous_rows,
+ key=lambda row: (
+ int(row["positive_mileage_days"]),
+ abs(float(row["mileage_diff_rate"] or 0)),
+ float(row["ledger_mileage"] or 0),
+ int(row["daily_point_count"] or 0),
+ ),
+ )
+ return (
+ selected,
+ "\u66f4\u6362",
+ (
+ f"\u8be5\u4f01\u4e1a\u6700\u5927\u8fde\u7eed\u8986\u76d6\u4e3a{max_positive_days}\u5929\uff1b"
+ "\u5df2\u9009\u62e9\u672c\u6708\u5b58\u5728\u8bb0\u5f55\u65e5\u671f\u5747\u6709\u91cc\u7a0b\u7684\u8f66\u8f86\u3002"
+ ),
+ )
+
+
+def query_rows(
+ conn: pymysql.connections.Connection,
+ task_code: str,
+) -> Tuple[List[Dict[str, Any]], Dict[str, str], Dict[str, float]]:
+ enterprise_sql = dedent(
+ """
+ SELECT city_name, enterprise_name, mileage_diff_rate
+ FROM ledger_inspection_enterprise
+ WHERE task_id=(SELECT id FROM ledger_inspection_task WHERE task_code=%s)
+ """
+ )
+ vehicle_sql = dedent(
+ """
+ SELECT v.city_name, v.enterprise_name, v.plate_no,
+ CAST(v.ledger_mileage AS DECIMAL(24,2)) AS ledger_mileage,
+ CAST(v.track_total_mileage AS DECIMAL(24,2)) AS track_mileage,
+ CAST(v.ledger_trips AS DECIMAL(20,2)) AS ledger_trips,
+ v.mileage_diff_rate,
+ v.track_days,
+ COUNT(DISTINCT d.track_date) AS daily_record_days,
+ COUNT(DISTINCT CASE WHEN d.total_mileage > 0 THEN d.track_date END) AS positive_mileage_days,
+ COALESCE(SUM(d.point_count), 0) AS daily_point_count
+ FROM ledger_inspection_vehicle v
+ JOIN vehicle_track_daily d
+ ON d.freight_enterprise_name=v.enterprise_name
+ AND d.plate_no=v.plate_no
+ AND d.report_period='2026-09'
+ WHERE v.task_id=(SELECT id FROM ledger_inspection_task WHERE task_code=%s)
+ GROUP BY v.id, v.city_name, v.enterprise_name, v.plate_no,
+ v.ledger_mileage, v.track_total_mileage, v.ledger_trips,
+ v.mileage_diff_rate, v.track_days
+ """
+ )
+ sample_sql = dedent(
+ """
+ SELECT enterprise_name, plate_no
+ FROM ledger_inspection_sample_vehicle
+ WHERE task_id=(SELECT id FROM ledger_inspection_task WHERE task_code=%s)
+ """
+ )
+ with conn.cursor() as cur:
+ cur.execute(enterprise_sql, (task_code,))
+ enterprise_rows = cur.fetchall()
+ cur.execute(vehicle_sql, (task_code,))
+ vehicle_rows = cur.fetchall()
+ cur.execute(sample_sql, (task_code,))
+ sample_rows = cur.fetchall()
+ city_by_enterprise = {
+ str(row["enterprise_name"]): str(row["city_name"])
+ for row in enterprise_rows
+ }
+ enterprise_diff = {
+ str(row["enterprise_name"]): float(row["mileage_diff_rate"] or 0)
+ for row in enterprise_rows
+ }
+ current_by_enterprise = {
+ str(row["enterprise_name"]): str(row["plate_no"])
+ for row in sample_rows
+ }
+ for row in vehicle_rows:
+ row["city_name"] = city_by_enterprise.get(str(row["enterprise_name"]), row["city_name"])
+ return vehicle_rows, current_by_enterprise, enterprise_diff
+
+
+def set_cell(cell: Any, value: Any, font: Font, horizontal: str = "center") -> None:
+ cell.value = value
+ cell.font = font
+ cell.border = BORDER
+ cell.alignment = Alignment(horizontal=horizontal, vertical="center", wrap_text=True)
+
+
+def style_sheet(sheet: Any, title: str, headers: Sequence[str]) -> None:
+ sheet.merge_cells(start_row=1, start_column=1, end_row=1, end_column=len(headers))
+ set_cell(sheet.cell(1, 1), title, TITLE_FONT)
+ sheet.row_dimensions[1].height = 32
+ for index, header in enumerate(headers, start=1):
+ set_cell(sheet.cell(3, index), header, HEADER_FONT)
+ sheet.row_dimensions[3].height = 42
+ sheet.freeze_panes = "A4"
+ sheet.sheet_view.showGridLines = False
+
+
+def set_widths(sheet: Any, widths: Sequence[float]) -> None:
+ for index, width in enumerate(widths, start=1):
+ sheet.column_dimensions[get_column_letter(index)].width = width
+
+
+def pct(value: Any) -> float:
+ return float(value or 0)
+
+
+def build_workbook(
+ rows: Sequence[Dict[str, Any]],
+ current_by_enterprise: Dict[str, str],
+ enterprise_diff: Dict[str, float],
+ output_path: Path,
+) -> List[Dict[str, Any]]:
+ grouped: Dict[Tuple[str, str], List[Dict[str, Any]]] = defaultdict(list)
+ for row in rows:
+ grouped[(str(row["city_name"]), str(row["enterprise_name"]))].append(row)
+
+ selected_rows: List[Dict[str, Any]] = []
+ for (city, enterprise), enterprise_rows in sorted(
+ grouped.items(),
+ key=lambda item: (city_sort(item[0][0]), item[0][1]),
+ ):
+ current_plate = current_by_enterprise.get(enterprise, "")
+ ordered = ordered_rows(enterprise_rows)
+ selected, action, reason = select_vehicle(ordered, current_plate)
+ current = next(
+ (row for row in ordered if str(row["plate_no"]) == current_plate),
+ None,
+ )
+ selected_rows.append({
+ "city": city,
+ "enterprise": enterprise,
+ "enterprise_diff": enterprise_diff.get(enterprise, 0.0),
+ "current": current,
+ "selected": selected,
+ "action": action,
+ "reason": reason,
+ "candidates": ordered,
+ })
+
+ wb = Workbook()
+ sheet = wb.active
+ sheet.title = "\u5f85\u4e0b\u8f7d\u8f66\u8f86"
+ headers = [
+ "\u5e8f\u53f7",
+ "\u5e02\u5dde",
+ "\u4f01\u4e1a",
+ "\u4f01\u4e1a\u53f0\u8d26/\u5e73\u53f0\u5dee\u5f02\u7387",
+ "\u73b0\u62bd\u67e5\u8f66\u8f86",
+ "\u73b0\u8bb0\u5f55/\u6709\u91cc\u7a0b\u5929",
+ "\u5efa\u8bae\u8f66\u8f86",
+ "\u5efa\u8bae\u8bb0\u5f55/\u6709\u91cc\u7a0b\u5929",
+ "\u53f0\u8d26\u91cc\u7a0b",
+ "\u5e73\u53f0\u91cc\u7a0b",
+ "\u53f0\u8d26/\u5e73\u53f0\u5dee\u5f02\u7387",
+ "\u53f0\u8d26\u8d9f\u6b21",
+ "\u65e5\u8bb0\u5f55\u8f68\u8ff9\u70b9",
+ "\u5904\u7406",
+ "\u9009\u53d6\u8bf4\u660e",
+ ]
+ style_sheet(sheet, "2026\u5e749\u6708\u4f01\u4e1a\u53f0\u8d26\u62bd\u67e5\u5f85\u4e0b\u8f7d\u8f66\u8f86\u6e05\u5355", headers)
+ for row_no, item in enumerate(selected_rows, start=1):
+ current = item["current"] or {}
+ selected = item["selected"]
+ values = [
+ row_no,
+ item["city"],
+ item["enterprise"],
+ pct(item["enterprise_diff"]),
+ current.get("plate_no", ""),
+ (
+ f"{int(current.get('daily_record_days', 0))}/"
+ f"{int(current.get('positive_mileage_days', 0))}"
+ ) if current else "",
+ selected["plate_no"],
+ f"{int(selected['daily_record_days'])}/{int(selected['positive_mileage_days'])}",
+ float(selected["ledger_mileage"] or 0),
+ float(selected["track_mileage"] or 0),
+ pct(selected["mileage_diff_rate"]),
+ float(selected["ledger_trips"] or 0),
+ int(selected["daily_point_count"] or 0),
+ item["action"],
+ item["reason"],
+ ]
+ for col, value in enumerate(values, start=1):
+ set_cell(sheet.cell(row_no + 3, col), value, BODY_FONT)
+ for col in (4, 11):
+ sheet.cell(row_no + 3, col).number_format = "0.00%"
+ for col in (9, 10):
+ sheet.cell(row_no + 3, col).number_format = "#,##0.00"
+ sheet.row_dimensions[row_no + 3].height = 54
+ set_widths(sheet, [6, 9, 29, 15, 13, 13, 13, 13, 13, 13, 15, 10, 14, 9, 72])
+ sheet.auto_filter.ref = f"A3:O{3 + len(selected_rows)}"
+ sheet.print_area = f"A1:O{3 + len(selected_rows)}"
+ sheet.page_setup.orientation = "landscape"
+ sheet.page_setup.fitToWidth = 1
+ sheet.page_setup.fitToHeight = 0
+ sheet.sheet_properties.pageSetUpPr.fitToPage = True
+
+ detail = wb.create_sheet("\u4f01\u4e1a\u5185\u5019\u9009")
+ detail_headers = [
+ "\u5e02\u5dde",
+ "\u4f01\u4e1a",
+ "\u8f66\u724c\u53f7",
+ "\u8bb0\u5f55/\u6709\u91cc\u7a0b\u5929",
+ "\u53f0\u8d26\u91cc\u7a0b",
+ "\u5e73\u53f0\u91cc\u7a0b",
+ "\u53f0\u8d26/\u5e73\u53f0\u5dee\u5f02\u7387",
+ "\u53f0\u8d26\u8d9f\u6b21",
+ "\u65e5\u8bb0\u5f55\u8f68\u8ff9\u70b9",
+ "\u662f\u5426\u5f53\u524d\u62bd\u67e5",
+ ]
+ style_sheet(detail, "\u5404\u4f01\u4e1a\u8986\u76d6\u7387\u4e0e\u5dee\u5f02\u7387\u5019\u9009", detail_headers)
+ detail_row = 4
+ for item in selected_rows:
+ for candidate in item["candidates"][:10]:
+ values = [
+ item["city"],
+ item["enterprise"],
+ candidate["plate_no"],
+ f"{int(candidate['daily_record_days'])}/{int(candidate['positive_mileage_days'])}",
+ float(candidate["ledger_mileage"] or 0),
+ float(candidate["track_mileage"] or 0),
+ pct(candidate["mileage_diff_rate"]),
+ float(candidate["ledger_trips"] or 0),
+ int(candidate["daily_point_count"] or 0),
+ "\u662f" if str(candidate["plate_no"]) == current_by_enterprise.get(item["enterprise"], "") else "",
+ ]
+ for col, value in enumerate(values, start=1):
+ set_cell(detail.cell(detail_row, col), value, BODY_FONT, "left" if col in (2,) else "center")
+ for col in (5, 6):
+ detail.cell(detail_row, col).number_format = "#,##0.00"
+ detail.cell(detail_row, 7).number_format = "0.00%"
+ detail_row += 1
+ set_widths(detail, [9, 31, 13, 14, 14, 14, 15, 10, 14, 12])
+ detail.auto_filter.ref = f"A3:J{detail_row - 1}"
+ detail.page_setup.orientation = "landscape"
+ detail.page_setup.fitToWidth = 1
+ detail.page_setup.fitToHeight = 0
+ detail.sheet_properties.pageSetUpPr.fitToPage = True
+
+ notes = wb.create_sheet("\u9009\u8f66\u53e3\u5f84")
+ notes.merge_cells("A1:F1")
+ set_cell(notes.cell(1, 1), "\u9009\u8f66\u53e3\u5f84", TITLE_FONT)
+ note_rows = [
+ ("1", "\u5e73\u53f0\u8f68\u8ff9\u91cc\u7a0b\u4f5c\u4e3a\u76d1\u6d4b\u57fa\u51c6\uff0c\u4e0d\u4ee5\u5e73\u53f0\u5f02\u5e38\u8f68\u8ff9\u5360\u6bd4\u4f5c\u4e3a\u9009\u8f66\u6216\u8bc4\u4ef7\u6761\u4ef6\u3002"),
+ ("2", "\u4f18\u5148\u9009\u62e9\u5f53\u670830\u5929\u5747\u6709\u5e73\u53f0\u65e5\u8bb0\u5f55\u3001\u4e1430\u5929\u65e5\u91cc\u7a0b\u5747\u5927\u4e8e0\u7684\u8f66\u8f86\u3002"),
+ ("3", "\u82e5\u4f01\u4e1a\u65e0\u6ee1\u8db330\u5929\u7684\u8f66\u8f86\uff0c\u5219\u9009\u62e9\u672c\u6708\u6700\u5927\u8fde\u7eed\u8986\u76d6\u5929\u6570\u3001\u4e14\u5b58\u5728\u8bb0\u5f55\u7684\u65e5\u671f\u5747\u6709\u91cc\u7a0b\u7684\u8f66\u8f86\u3002"),
+ ("4", "\u5728\u540c\u7b49\u8986\u76d6\u6761\u4ef6\u4e0b\uff0c\u4f18\u5148\u9009\u62e9\u53f0\u8d26\u4e0e\u5e73\u53f0\u91cc\u7a0b\u5dee\u5f02\u660e\u663e\u3001\u53f0\u8d26\u91cc\u7a0b\u548c\u8d9f\u6b21\u5177\u6709\u4ee3\u8868\u6027\u7684\u8f66\u8f86\u3002"),
+ ("5", "\u5f53\u524d\u62bd\u67e5\u8f66\u8f86\u5df2\u8fbe\u523029\u5929\u4ee5\u4e0a\u8fde\u7eed\u8986\u76d6\u4e14\u5b58\u5728\u8bb0\u5f55\u65e5\u671f\u5747\u6709\u91cc\u7a0b\u7684\uff0c\u4fdd\u7559\u539f\u8f66\u8f86\uff0c\u907f\u514d\u4e3a\u8865\u9f501\u5929\u800c\u66f4\u6362\u4e3a\u8bc1\u660e\u529b\u66f4\u5f31\u7684\u8f66\u8f86\u3002"),
+ ("7", "\u8f68\u8ff9\u8986\u76d6\u4e0d\u5b8c\u6574\u4e0d\u76f4\u63a5\u8bc1\u660e\u53f0\u8d26\u91cc\u7a0b\u865a\u5047\uff0c\u4f46\u5c5e\u4e8e\u4f01\u4e1a\u8f66\u8f86\u52a8\u6001\u76d1\u63a7\u4fdd\u969c\u4e0d\u5230\u4f4d\uff0c\u5e94\u4f5c\u4e3a\u72ec\u7acb\u95ee\u9898\u8981\u6c42\u4f01\u4e1a\u8bf4\u660e\u5e76\u6574\u6539\u3002"),
+ ("8", "\u5e73\u53f0\u6709\u65e5\u8bb0\u5f55\u4f46\u5f53\u65e5\u91cc\u7a0b\u4e3a0\uff0c\u53ef\u80fd\u662f\u8f66\u8f86\u672a\u8fd0\u884c\uff0c\u5e94\u533a\u5206\u4e8e\u65e0\u5e73\u53f0\u65e5\u8bb0\u5f55\uff0c\u4e0d\u80fd\u4ec5\u636e\u6b64\u76f4\u63a5\u8ba4\u5b9a\u8bbe\u5907\u6545\u969c\u3002"),
+ ("6", "\u8f68\u8ff9\u70b9\u4e0b\u8f7d\u540e\uff0c\u518d\u6838\u9a8c\u6d3b\u52a8\u533a\u57df\u3001\u8def\u7ebf\u7aef\u70b9\u3001\u53ef\u652f\u6301\u8d9f\u6b21\u4e0e\u53f0\u8d26\u7533\u62a5\u662f\u5426\u5339\u914d\u3002"),
+ ]
+ for row_no, (number, text) in enumerate(note_rows, start=3):
+ set_cell(notes.cell(row_no, 1), number, BODY_FONT)
+ notes.merge_cells(start_row=row_no, start_column=2, end_row=row_no, end_column=6)
+ set_cell(notes.cell(row_no, 2), text, BODY_FONT, "left")
+ notes.row_dimensions[row_no].height = 42
+ set_widths(notes, [6, 24, 24, 24, 24, 24])
+ notes.sheet_view.showGridLines = False
+
+ output_path.parent.mkdir(parents=True, exist_ok=True)
+ wb.save(output_path)
+ return selected_rows
+
+
+def selection_summary(selected_rows: Sequence[Dict[str, Any]]) -> List[Dict[str, Any]]:
+ result = []
+ for item in selected_rows:
+ selected = item["selected"]
+ current = item["current"] or {}
+ result.append({
+ "city": item["city"],
+ "enterprise": item["enterprise"],
+ "enterprise_diff_rate": item["enterprise_diff"],
+ "current_plate": current.get("plate_no"),
+ "current_record_days": current.get("daily_record_days"),
+ "current_positive_days": current.get("positive_mileage_days"),
+ "selected_plate": selected.get("plate_no"),
+ "selected_record_days": selected.get("daily_record_days"),
+ "selected_positive_days": selected.get("positive_mileage_days"),
+ "selected_ledger_mileage": float(selected.get("ledger_mileage") or 0),
+ "selected_track_mileage": float(selected.get("track_mileage") or 0),
+ "selected_diff_rate": float(selected.get("mileage_diff_rate") or 0),
+ "selected_ledger_trips": float(selected.get("ledger_trips") or 0),
+ "selected_daily_points": int(selected.get("daily_point_count") or 0),
+ "action": item["action"],
+ "reason": item["reason"],
+ })
+ return result
+
+
+def main(argv: Optional[Sequence[str]] = None) -> int:
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument("--db-host", default="127.0.0.1")
+ parser.add_argument("--db-port", type=int, default=3305)
+ parser.add_argument("--db-user", default="root")
+ parser.add_argument("--db-password", default="root")
+ parser.add_argument("--db-name", default="traffic_audit")
+ parser.add_argument("--task-code", default="LEDGER_SPOT_202609_R1")
+ parser.add_argument("--output", required=True)
+ parser.add_argument("--summary-json")
+ args = parser.parse_args(argv)
+
+ conn = pymysql.connect(
+ host=args.db_host,
+ port=args.db_port,
+ user=args.db_user,
+ password=args.db_password,
+ database=args.db_name,
+ charset="utf8mb4",
+ cursorclass=pymysql.cursors.DictCursor,
+ )
+ try:
+ rows, current_by_enterprise, enterprise_diff = query_rows(conn, args.task_code)
+ finally:
+ conn.close()
+
+ output_path = Path(args.output)
+ selected_rows = build_workbook(
+ rows,
+ current_by_enterprise,
+ enterprise_diff,
+ output_path,
+ )
+ summary = selection_summary(selected_rows)
+ if args.summary_json:
+ summary_path = Path(args.summary_json)
+ summary_path.parent.mkdir(parents=True, exist_ok=True)
+ summary_path.write_text(
+ json.dumps(summary, ensure_ascii=False, indent=2),
+ encoding="utf-8",
+ )
+ print(json.dumps(summary, ensure_ascii=False, indent=2))
+ return 0
+
+
+if __name__ == "__main__":
+ raise SystemExit(main())
diff --git a/tools/enterprise_track_point_inspection.py b/tools/enterprise_track_point_inspection.py
index 7654e93..9237eba 100644
--- a/tools/enterprise_track_point_inspection.py
+++ b/tools/enterprise_track_point_inspection.py
@@ -53,12 +53,12 @@
SELECTED_VEHICLES: Tuple[VehicleSpec, ...] = (
VehicleSpec(
"anxin",
- "\u9102L1N523",
+ "\u9102L1N275",
"\u54b8\u5b81/\u5b89\u6b23",
(
Endpoint("\u54b8\u5b81", ("\u54b8\u5b81",)),
+ Endpoint("\u8d64\u58c1", ("\u8d64\u58c1",)),
Endpoint("\u5929\u6d25", ("\u5929\u6d25",)),
- Endpoint("\u5d07\u9633", ("\u5d07\u9633",)),
),
),
VehicleSpec(
@@ -72,12 +72,6 @@
),
),
VehicleSpec(
- "datong",
- "\u9102J20052D",
- "\u9ec4\u5188/\u5927\u901a",
- (Endpoint("\u6d60\u6c34", ("\u6d60\u6c34",)),),
- ),
- VehicleSpec(
"huinong",
"\u9102LH832D",
"\u54b8\u5b81/\u60e0\u4fac",
@@ -88,27 +82,34 @@
),
VehicleSpec(
"luchang",
- "\u9102L53508",
+ "\u9102L53789",
"\u54b8\u5b81/\u8def\u7545\u901a",
(
Endpoint("\u901a\u57ce", ("\u901a\u57ce",)),
- Endpoint("\u9ec4\u9f99", ("\u9ec4\u9f99",), False),
+ Endpoint("\u5d07\u9633", ("\u5d07\u9633",)),
),
),
VehicleSpec(
+ "datong",
+ "\u9102J20052D",
+ "\u9ec4\u5188/\u5927\u901a",
+ (Endpoint("\u6d60\u6c34", ("\u6d60\u6c34",)),),
+ ),
+ VehicleSpec(
+ "kaiying",
+ "\u9102J0E858",
+ "\u9ec4\u5188/\u51ef\u8d62",
+ (Endpoint("\u77f3\u9996", ("\u77f3\u9996",)),),
+ ("\u5b89\u9053\u9ea6", "\u6e56\u5317\u777f\u52e4", "\u6e56\u5317\u5229\u62d3"),
+ ),
+ VehicleSpec(
"guangfa",
- "\u9102J50898",
+ "\u9102J59918",
"\u9ec4\u5188/\u5e7f\u53d1",
(
Endpoint("\u9ec4\u6885", ("\u9ec4\u6885",)),
Endpoint("\u4e49\u4e4c", ("\u4e49\u4e4c",)),
),
- ),
- VehicleSpec(
- "kaiying",
- "\u9102J0C916",
- "\u9ec4\u5188/\u51ef\u8d62",
- unresolved_route_terms=("\u5b89\u9053\u9ea6", "\u946b\u745e\u666f"),
),
VehicleSpec(
"xindafei",
@@ -120,40 +121,47 @@
),
),
VehicleSpec(
- "shengda",
- "\u9102E19507",
- "\u5b9c\u660c/\u665f\u8fbe",
- (
- Endpoint("\u5408\u80a5", ("\u5408\u80a5",)),
- Endpoint("\u6b66\u6c49", ("\u6b66\u6c49",)),
- Endpoint("\u5b9c\u660c", ("\u5b9c\u660c",)),
- ),
- ("\u5174\u798f\u7535\u5b50", "\u8054\u4ed5(\u6e56\u5317)\u65b0\u6750\u6599"),
- ),
- VehicleSpec(
- "heyun",
- "\u9102E69878",
- "\u5b9c\u660c/\u8a38\u8fd0",
- (
- Endpoint("\u679d\u6c5f", ("\u679d\u6c5f",)),
- Endpoint("\u5949\u8282", ("\u5949\u8282",)),
- ),
- ),
- VehicleSpec(
"kaixiangda",
- "\u9102E68056",
+ "\u9102E32721",
"\u5b9c\u660c/\u51ef\u7965\u8fbe",
(
+ Endpoint("\u679d\u6c5f", ("\u679d\u6c5f",)),
Endpoint("\u7307\u4ead", ("\u7307\u4ead",)),
- Endpoint("\u5317\u6d77", ("\u5317\u6d77",)),
- Endpoint("\u6d59\u6c5f", ("\u6d59\u6c5f", "\u5609\u5174")),
+ Endpoint("\u5b9c\u90fd", ("\u5b9c\u90fd",)),
+ Endpoint("\u4e0a\u6d77", ("\u4e0a\u6d77",)),
+ Endpoint("\u957f\u9633", ("\u957f\u9633",)),
+ Endpoint("\u677e\u6ecb", ("\u677e\u6ecb",)),
+ ),
+ ),
+ VehicleSpec(
+ "shengda",
+ "\u9102E56628",
+ "\u5b9c\u660c/\u665f\u8fbe",
+ (
+ Endpoint("\u6b66\u6c49", ("\u6b66\u6c49",)),
+ Endpoint("\u5b9c\u660c", ("\u5b9c\u660c",)),
),
),
VehicleSpec(
"minkun",
- "\u9102E36292",
+ "\u9102E59371",
"\u5b9c\u660c/\u6c11\u5764",
- unresolved_route_terms=("\u5408\u76ca\u8def", "\u5927\u6811\u6e7e"),
+ (Endpoint("\u5b9c\u660c", ("\u5b9c\u660c",)),),
+ ("\u845b\u6d32\u575d", "\u5357\u7ad9\u8def"),
+ ),
+ VehicleSpec(
+ "heyun",
+ "\u9102E99730",
+ "\u5b9c\u660c/\u8a38\u8fd0",
+ (
+ Endpoint("\u679d\u6c5f", ("\u679d\u6c5f",)),
+ Endpoint("\u7307\u4ead", ("\u7307\u4ead",)),
+ Endpoint("\u5b9c\u90fd", ("\u5b9c\u90fd",)),
+ Endpoint("\u5e38\u5fb7", ("\u5e38\u5fb7",)),
+ Endpoint("\u8944\u9633", ("\u8944\u9633",)),
+ Endpoint("\u5546\u6d1b", ("\u5546\u6d1b",)),
+ Endpoint("\u9547\u5b89", ("\u9547\u5b89",)),
+ ),
),
)
@@ -649,6 +657,11 @@
"abnormal_mileage": selected_track["abnormal_mileage"],
"anomaly_rate": selected_track["anomaly_rate"],
"days": len(selected_track["days"]),
+ "daily_record_days": len(selected_track["days"]),
+ "positive_mileage_days": len({
+ row.track_date for row in selected_track["daily_rows"]
+ if row.track_date and row.total_mileage > 0
+ }),
},
"points": {
"file_count": len(files),
diff --git a/tools/monitor_ledger_vehicle_downloads.py b/tools/monitor_ledger_vehicle_downloads.py
new file mode 100644
index 0000000..290a861
--- /dev/null
+++ b/tools/monitor_ledger_vehicle_downloads.py
@@ -0,0 +1,300 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""Detect completed vehicle point downloads and inspect each vehicle independently."""
+
+from __future__ import annotations
+
+import argparse
+import json
+import time
+from dataclasses import dataclass
+from datetime import datetime
+from pathlib import Path
+from typing import Any, Dict, List, Optional, Sequence, Tuple
+
+from tools.enterprise_track_point_inspection import (
+ Endpoint,
+ VehicleSpec,
+ expected_segments,
+ inspect_vehicle,
+ json_default,
+ missing_segments,
+ parse_segment_dates,
+ read_cells,
+)
+
+
+@dataclass(frozen=True)
+class DownloadTarget:
+ spec: VehicleSpec
+
+
+TARGETS: Tuple[DownloadTarget, ...] = (
+ DownloadTarget(VehicleSpec(
+ "anxin",
+ "\u9102L1N275",
+ "\u54b8\u5b81/\u5b89\u6b23",
+ (
+ Endpoint("\u54b8\u5b81", ("\u54b8\u5b81",)),
+ Endpoint("\u8d64\u58c1", ("\u8d64\u58c1",)),
+ Endpoint("\u5929\u6d25", ("\u5929\u6d25",)),
+ ),
+ )),
+ DownloadTarget(VehicleSpec(
+ "luchang",
+ "\u9102L53789",
+ "\u54b8\u5b81/\u8def\u7545\u901a",
+ (
+ Endpoint("\u901a\u57ce", ("\u901a\u57ce",)),
+ Endpoint("\u5d07\u9633", ("\u5d07\u9633",)),
+ ),
+ )),
+ DownloadTarget(VehicleSpec(
+ "kaiying",
+ "\u9102J0E858",
+ "\u9ec4\u5188/\u51ef\u8d62",
+ (Endpoint("\u77f3\u9996", ("\u77f3\u9996",)),),
+ ("\u5b89\u9053\u9ea6", "\u6e56\u5317\u777f\u52e4", "\u6e56\u5317\u5229\u62d3"),
+ )),
+ DownloadTarget(VehicleSpec(
+ "guangfa",
+ "\u9102J59918",
+ "\u9ec4\u5188/\u5e7f\u53d1",
+ (
+ Endpoint("\u9ec4\u6885", ("\u9ec4\u6885",)),
+ Endpoint("\u4e49\u4e4c", ("\u4e49\u4e4c",)),
+ ),
+ )),
+ DownloadTarget(VehicleSpec(
+ "kaixiangda",
+ "\u9102E32721",
+ "\u5b9c\u660c/\u51ef\u7965\u8fbe",
+ (
+ Endpoint("\u679d\u6c5f", ("\u679d\u6c5f",)),
+ Endpoint("\u7307\u4ead", ("\u7307\u4ead",)),
+ Endpoint("\u5b9c\u90fd", ("\u5b9c\u90fd",)),
+ Endpoint("\u4e0a\u6d77", ("\u4e0a\u6d77",)),
+ Endpoint("\u957f\u9633", ("\u957f\u9633",)),
+ Endpoint("\u677e\u6ecb", ("\u677e\u6ecb",)),
+ ),
+ )),
+ DownloadTarget(VehicleSpec(
+ "shengda",
+ "\u9102E56628",
+ "\u5b9c\u660c/\u665f\u8fbe",
+ (
+ Endpoint("\u6b66\u6c49", ("\u6b66\u6c49",)),
+ Endpoint("\u5b9c\u660c", ("\u5b9c\u660c",)),
+ ),
+ )),
+ DownloadTarget(VehicleSpec(
+ "minkun",
+ "\u9102E57519",
+ "\u5b9c\u660c/\u6c11\u5764",
+ (Endpoint("\u5b9c\u660c", ("\u5b9c\u660c",)),),
+ ("\u845b\u6d32\u575d", "\u5357\u7ad9\u8def"),
+ )),
+ DownloadTarget(VehicleSpec(
+ "minkun",
+ "\u9102E59371",
+ "\u5b9c\u660c/\u6c11\u5764",
+ (Endpoint("\u5b9c\u660c", ("\u5b9c\u660c",)),),
+ ("\u845b\u6d32\u575d", "\u5357\u7ad9\u8def"),
+ )),
+ DownloadTarget(VehicleSpec(
+ "heyun",
+ "\u9102E99730",
+ "\u5b9c\u660c/\u8a38\u8fd0",
+ (
+ Endpoint("\u679d\u6c5f", ("\u679d\u6c5f",)),
+ Endpoint("\u7307\u4ead", ("\u7307\u4ead",)),
+ Endpoint("\u5b9c\u90fd", ("\u5b9c\u90fd",)),
+ Endpoint("\u5e38\u5fb7", ("\u5e38\u5fb7",)),
+ Endpoint("\u8944\u9633", ("\u8944\u9633",)),
+ Endpoint("\u5546\u6d1b", ("\u5546\u6d1b",)),
+ Endpoint("\u9547\u5b89", ("\u9547\u5b89",)),
+ ),
+ )),
+)
+
+
+def target_files(target: DownloadTarget, work_root: Path) -> List[Path]:
+ directory = work_root / target.spec.directory
+ if not directory.exists():
+ return []
+ return sorted(
+ directory.glob("*%s*.xls" % target.spec.plate),
+ key=lambda item: (parse_segment_dates(item, "2026-09"), item.name),
+ )
+
+
+def stable_readable(paths: Sequence[Path], stable_seconds: int) -> Tuple[bool, List[str]]:
+ errors: List[str] = []
+ now = time.time()
+ for path in paths:
+ try:
+ if now - path.stat().st_mtime < stable_seconds:
+ errors.append("%s is still being written" % path.name)
+ continue
+ with path.open("rb") as handle:
+ handle.read(16)
+ cells = read_cells(path)
+ if not cells:
+ errors.append("%s contains no readable cells" % path.name)
+ except Exception as exc:
+ errors.append("%s: %s" % (path.name, exc))
+ return not errors, errors
+
+
+def classify_target(
+ target: DownloadTarget,
+ work_root: Path,
+ period: str,
+ stable_seconds: int,
+) -> Dict[str, Any]:
+ paths = target_files(target, work_root)
+ missing = missing_segments(paths, period)
+ expected_count = len(expected_segments(period))
+ stable, errors = stable_readable(paths, stable_seconds) if paths else (False, [])
+ complete = (
+ len(paths) == expected_count
+ and not missing
+ and stable
+ and not errors
+ )
+ return {
+ "plate": target.spec.plate,
+ "city": target.spec.profile_key,
+ "enterprise_key": target.spec.profile_key,
+ "directory": str(work_root / target.spec.directory),
+ "file_count": len(paths),
+ "expected_file_count": expected_count,
+ "missing_segments": missing,
+ "stable": stable,
+ "errors": errors,
+ "complete": complete,
+ "files": [str(path) for path in paths],
+ }
+
+
+def load_json(path: Path) -> Optional[Dict[str, Any]]:
+ try:
+ return json.loads(path.read_text(encoding="utf-8"))
+ except (OSError, ValueError):
+ return None
+
+
+def concise_result(result: Dict[str, Any]) -> Dict[str, Any]:
+ points = result["points"]
+ comparison = result["comparison"]
+ platform = result["platform"]
+ ledger = result["ledger"]
+ return {
+ "city": result["city"],
+ "enterprise": result["enterprise"],
+ "plate": result["plate"],
+ "ledger_routes": result["ledger"]["route_groups"],
+ "ledger_trips": ledger["trips"],
+ "ledger_mileage": ledger["mileage"],
+ "platform_mileage": platform["total_mileage"],
+ "ledger_vs_platform_rate": comparison["ledger_vs_platform_rate"],
+ "point_day_count": points["day_count"],
+ "unique_point_count": points["unique_point_count"],
+ "top_provinces": points["top_provinces"],
+ "top_prefectures": points["top_prefectures"],
+ "top_counties": points["top_counties"],
+ "endpoints": points["endpoints"],
+ "missing_days": points["missing_days"],
+ "raw_point_distance": points["raw_distance"],
+ "point_vs_ledger_rate": comparison["point_vs_ledger_rate"],
+ "platform_supported_trips": comparison["platform_supported_trips"],
+ "trip_support_rate": comparison["trip_support_rate"],
+ }
+
+
+def write_json(path: Path, payload: Any) -> None:
+ path.parent.mkdir(parents=True, exist_ok=True)
+ path.write_text(
+ json.dumps(payload, ensure_ascii=False, indent=2, default=json_default),
+ encoding="utf-8",
+ )
+
+
+def main(argv: Optional[Sequence[str]] = None) -> int:
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument("--period", default="2026-09")
+ parser.add_argument("--source-root", required=True)
+ parser.add_argument("--work-root", required=True)
+ parser.add_argument("--output-dir", required=True)
+ parser.add_argument("--stable-seconds", type=int, default=90)
+ parser.add_argument("--force", action="store_true")
+ args = parser.parse_args(argv)
+
+ source_root = Path(args.source_root)
+ work_root = Path(args.work_root)
+ output_dir = Path(args.output_dir)
+ output_dir.mkdir(parents=True, exist_ok=True)
+
+ status: Dict[str, Any] = {
+ "checked_at": datetime.now().isoformat(sep=" "),
+ "targets": [],
+ }
+ newly_completed: List[Dict[str, Any]] = []
+ failed: List[Dict[str, Any]] = []
+
+ for target in TARGETS:
+ item = classify_target(target, work_root, args.period, args.stable_seconds)
+ result_path = output_dir / ("%s.json" % target.spec.plate)
+ existing = load_json(result_path)
+ if existing and not args.force:
+ item["status"] = "DONE"
+ item["result_file"] = str(result_path)
+ status["targets"].append(item)
+ continue
+ if item["complete"]:
+ try:
+ result = inspect_vehicle(
+ target.spec,
+ source_root,
+ work_root,
+ args.period,
+ )
+ write_json(result_path, result)
+ item["status"] = "DONE"
+ item["result_file"] = str(result_path)
+ item["summary"] = concise_result(result)
+ newly_completed.append(item["summary"])
+ except Exception as exc:
+ item["status"] = "ERROR"
+ item["error"] = str(exc)
+ failed.append({"plate": target.spec.plate, "error": str(exc)})
+ elif item["errors"]:
+ item["status"] = "ERROR"
+ failed.append({
+ "plate": target.spec.plate,
+ "errors": item["errors"],
+ })
+ else:
+ item["status"] = "WAITING"
+ status["targets"].append(item)
+
+ write_json(output_dir / "monitor_status.json", status)
+ print(json.dumps({
+ "checked_at": status["checked_at"],
+ "newly_completed": newly_completed,
+ "failed": failed,
+ "statuses": [
+ {
+ "plate": item["plate"],
+ "status": item["status"],
+ "file_count": item["file_count"],
+ "missing_segments": item["missing_segments"],
+ }
+ for item in status["targets"]
+ ],
+ }, ensure_ascii=False, indent=2, default=json_default))
+ return 0
+
+
+if __name__ == "__main__":
+ raise SystemExit(main())
--
Gitblit v1.9.1