Update data 9/25-9/27; detect data sources by content
The consumption export keeps changing filename (每日数据 -> Week39...), which broke the glob each time. build_data.py now treats any workbook containing a 平台消耗统计 sheet as a data source and orders them by the latest date they contain, so the fresher file wins on overlapping days. 2026Week39平台消耗.xlsx covers 8/31-9/27 and fully supersedes the 2609 file, which is removed; 2608 stays for the earlier August dates. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
+16
-6
@@ -8,12 +8,14 @@
|
||||
import openpyxl, collections, json, datetime, os, sys, glob
|
||||
|
||||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
# 源文件按月滚动(2608 -> 2609 -> ...)。全部读进来合并:
|
||||
# 同一天出现在多个文件时,以文件名较新的为准(源表会修订历史数据)。
|
||||
SRC_FILES = sorted(glob.glob(os.path.join(HERE, '*每日数据-武汉萌奇熊.xlsx')))
|
||||
# 花名册 投手.xlsx 单独处理,不参与消耗数据合并
|
||||
# 消耗数据源:不认文件名(每月/每周导出的命名一直在变),改为认内容——
|
||||
# 仓库里任何带「平台消耗统计」sheet 的 xlsx 都算数据源。花名册 roster.xlsx
|
||||
# 没有该 sheet,自然被排除。同一天出现在多个文件时,以数据更新的那份为准
|
||||
# (见下方按最大日期排序),因为源表会修订历史数据。
|
||||
SRC_FILES = [f for f in sorted(glob.glob(os.path.join(HERE, '*.xlsx')))
|
||||
if '平台消耗统计' in openpyxl.load_workbook(f, read_only=True).sheetnames]
|
||||
if not SRC_FILES:
|
||||
sys.exit('ERROR: 仓库里找不到 *每日数据-武汉萌奇熊.xlsx')
|
||||
sys.exit('ERROR: 仓库里没有任何含「平台消耗统计」sheet 的 xlsx')
|
||||
_cfg = json.load(open(os.path.join(HERE, 'exclude.json')))
|
||||
EXCL = set(_cfg['packages']) # 按包名剔除
|
||||
EXCL_ADP = set(_cfg.get('adpings', {})) # 按 Adpingid 剔除
|
||||
@@ -27,6 +29,14 @@ def key(v):
|
||||
|
||||
books = [(f, openpyxl.load_workbook(f, data_only=True)) for f in SRC_FILES]
|
||||
|
||||
def _max_date(wb_):
|
||||
ds = [r[1].date() for r in wb_['平台消耗统计'].iter_rows(min_row=2, values_only=True)
|
||||
if isinstance(r[1], datetime.datetime)]
|
||||
return max(ds) if ds else datetime.date.min
|
||||
|
||||
# 按数据最大日期排序:日期更靠后的文件视为更新,其数据覆盖同一天的旧值
|
||||
books.sort(key=lambda fb: (_max_date(fb[1]), fb[0]))
|
||||
|
||||
# --- 投手花名册 ---
|
||||
# 优先用独立的 投手.xlsx(月度数据文件已不再带「投手」sheet);
|
||||
# 没有它时退回到最新一个仍带该 sheet 的月度文件。
|
||||
@@ -193,7 +203,7 @@ data = {
|
||||
}
|
||||
json.dump(data, open(os.path.join(HERE, 'data.json'), 'w'), ensure_ascii=False, indent=2)
|
||||
|
||||
print('源文件:', ', '.join(os.path.basename(f) for f in SRC_FILES))
|
||||
print('源文件(按数据新旧):', ' -> '.join(os.path.basename(f) for f, _ in books))
|
||||
print('投手表取自:', os.path.basename(roster_file))
|
||||
if extra_used:
|
||||
print('roster_extra 补充生效:', ', '.join(f'{a}->{amap[a]}' for a in extra_used))
|
||||
|
||||
Reference in New Issue
Block a user