#!/usr/bin/env python3
"""单独执行 category_tree_weight 整树节点加权平均计算，并在全部写入后更新四维排名分。

用法:
    python jobs/run_category_tree_weight.py 20260714
    python jobs/run_category_tree_weight.py          # 默认当天

前置: 已执行建表 SQL，且当天 demand_popularity_stats 已就绪。
仅补跑排名分: python jobs/run_category_tree_rank_scores.py [biz_dt]
"""

from __future__ import annotations

import logging
import sys
from datetime import datetime

from supply_infra.scheduler.jobs.compute_category_tree_weight import (
    compute_category_tree_weight,
)

logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
)


def main(biz_dt: str | None = None) -> dict:
    if biz_dt is None:
        biz_dt = datetime.now().strftime("%Y%m%d")
    result = compute_category_tree_weight(biz_dt)
    print(result)
    return result


if __name__ == "__main__":
    date_arg = sys.argv[1] if len(sys.argv) > 1 else None
    main(date_arg)
