feat(企业台账): 完善抽查报告和车辆核查工具
| | |
| | | |
| | | |
| | | 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" |
| | | |
| New file |
| | |
| | | #!/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()) |
| | |
| | | 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 |
| | |
| | | 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() |
| | |
| | | |
| | | 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: |
| | |
| | | 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) |
| | |
| | | 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))):,}" |
| | | |
| | |
| | | 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: |
| | | 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": 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, |
| | | "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, |
| | | }) |
| | | 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: |
| | | 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 |
| | | 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 "", |
| | | 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, |
| | | }) |
| | | 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 |
| | | 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("周转量汇总公式错误") |
| | | 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("月报台账差异大") |
| | | if abs(float(item["mileage_diff"])) > 0.30: |
| | | parts.append("里程差异超范围") |
| | | else: |
| | | parts.append("里程差异正常") |
| | | 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) |
| | |
| | | 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份,解析车辆—路线—趟次记录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月各月月报值与正确明细合计,防止月报和台账沿用同一错误公式而形成表面一致。", |
| | | "\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, |
| | | "以重载平台车辆日里程汇总形成企业月度监测里程,再与企业台账车辆总里程逐车、逐企业比对。台账与平台里程差异率在正负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'])}万吨公里、台账逐行正确合计{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)}万吨公里,台账逐行正确合计{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), |
| | |
| | | )) |
| | | kxd_table = add_table( |
| | | doc, |
| | | ["月份", "月报周转量(万吨公里)", "台账逐行正确合计(万吨公里)", "月报多报(万吨公里)", "多报率"], |
| | | ["\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_heading(doc, "\uff08\u4e09\uff09\u91cd\u70b9\u8f66\u8f86\u8f68\u8ff9\u70b9\u7cbe\u67e5", 2) |
| | | 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_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万吨公里,台账逐行正确合计12,061.67万吨公里,累计多报4,703.53万吨公里,多报39.00%。本次仅抽查12家企业,而全省2026年规上货运企业共636家,其他企业存在同类公式错误的可能,需组织开展全面筛查。", |
| | | "(一)", |
| | | ) |
| | | add_body( |
| | | doc, |
| | | "台账里程申报普遍高于平台监测里程。除湖北大通临空物流有限公司外,其余11家企业台账与平台里程差异率均超出正负30%,台账合计里程较平台高134.89%,说明差异不是个别车辆造成,而是企业台账层面存在普遍性。", |
| | | "(二)", |
| | | ) |
| | | add_body( |
| | | doc, |
| | | "部分企业申报线路与车辆实际活动区域明显不符。以抽查车辆为例,湖北安欣物流有限责任公司鄂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万吨公里,台账逐行正确合计12,061.67万吨公里,累计多报4,703.53万吨公里,多报39.00%。该问题说明,月报与台账数值一致不能替代对计算过程和原始明细的核查。本次仅抽查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, |
| | | "在专项筛查基础上,举一反三检查其他月度汇总指标及年度累计公式,重点核对月度合计是否等于明细行求和、年度累计是否等于各月校正值之和,并对使用平均数和比例派生指标的情形逐项验证统计口径。", |
| | | "(三)", |
| | | "\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, |
| | | "督促企业规范建立月度运输台账,做到车辆、日期、线路、趟次、里程、货运量和周转量相互对应,并保留可核验的原始运输凭据。", |
| | | "(六)", |
| | | "\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() |
| | |
| | | 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) |
| | |
| | | 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 |
| | | |
| New file |
| | |
| | | #!/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()) |
| | |
| | | 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( |
| | |
| | | ), |
| | | ), |
| | | VehicleSpec( |
| | | "datong", |
| | | "\u9102J20052D", |
| | | "\u9ec4\u5188/\u5927\u901a", |
| | | (Endpoint("\u6d60\u6c34", ("\u6d60\u6c34",)),), |
| | | ), |
| | | VehicleSpec( |
| | | "huinong", |
| | | "\u9102LH832D", |
| | | "\u54b8\u5b81/\u60e0\u4fac", |
| | |
| | | ), |
| | | 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", |
| | |
| | | ), |
| | | ), |
| | | 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",)), |
| | | ), |
| | | ), |
| | | ) |
| | | |
| | |
| | | "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), |
| New file |
| | |
| | | #!/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()) |