feat: add order status filtering

This commit is contained in:
王源
2026-10-14 17:44:01 +08:00
parent 034ace13b5
commit 1d0b1c54b4
3 changed files with 2457 additions and 10 deletions
+8
View File
@@ -139,6 +139,7 @@ def parse_workbook(source: Path) -> tuple[list[dict[str, str]], dict[str, int]]:
def aggregate(records: list[dict[str, str]], counters: dict[str, int], source: Path) -> dict[str, Any]:
status_priority = {"投放中": 0, "暂停": 1, "未标注": 2, "其他/不可投": 3}
groups: dict[tuple[str, str], dict[str, Any]] = {}
for row in records:
key = (row["pkg"].casefold(), row["country"])
@@ -149,6 +150,7 @@ def aggregate(records: list[dict[str, str]], counters: dict[str, int], source: P
"country": row["country"],
"products": set(),
"adpingids": set(),
"order_statuses": Counter(),
"platforms": defaultdict(
lambda: {"statuses": Counter(), "adpingids": set(), "order_count": 0}
),
@@ -156,6 +158,7 @@ def aggregate(records: list[dict[str, str]], counters: dict[str, int], source: P
},
)
group["products"].add(row["product"])
group["order_statuses"][row["status"]] += 1
if row["adpingid"]:
group["adpingids"].add(row["adpingid"])
detail = group["platforms"][row["platform"]]
@@ -170,6 +173,9 @@ def aggregate(records: list[dict[str, str]], counters: dict[str, int], source: P
platform_names = sorted(group["platforms"], key=lambda name: (name == TARGET_PLATFORM, name.casefold()))
target_present = TARGET_PLATFORM in group["platforms"]
other_platforms = [name for name in platform_names if name != TARGET_PLATFORM]
order_statuses = sorted(
group["order_statuses"], key=lambda status: (status_priority.get(status, 99), status)
)
platform_details = []
for name in platform_names:
detail = group["platforms"][name]
@@ -187,6 +193,8 @@ def aggregate(records: list[dict[str, str]], counters: dict[str, int], source: P
"product": " / ".join(sorted(group["products"])),
"pkg": group["pkg"],
"country": group["country"],
"order_statuses": order_statuses,
"order_status_counts": {status: group["order_statuses"][status] for status in order_statuses},
"platforms": platform_names,
"other_platforms": other_platforms,
"platform_details": platform_details,