Files
sanguo_vnpy_v2/scripts/data_platform/index_monthly_wrapper.ps1
T
claude_dev e7465c342f feat(data): 中证1000/2000 定期更新 schtask + schtask 路径坑修复
sanguo-index 增强: index_monthly_wrapper 加 STEP0 parse_csindex_announce
(治偏差全集, 月度16号自动刷新 constituent_unified)

register_akshare_schtasks 修 PowerShell schtasks /tr 反斜杠路径丢前缀坑:
$ws 变量在双引号被原生命令解析吃掉 -> Arguments 存成 \xxx.ps1 ->
schtasks /run 返回成功但 wrapper 静默不跑从不写日志。改全路径硬编码 + --%。
ak-* 5 schtask 路径全坏已批量修(register_akshare 旧版"已部署Ready"是假成功)。

诊断: Get-ScheduledTask 中文Win报 0x80070057 无用, 改 schtasks /query /xml
看 Arguments 才发现丢前缀。

schtask 全链路验证 STEP0-3 exit=0, constituent_unified
000852=1672(was_removed=672) / 932000=2684(684) 治偏差保持。
2026-07-24 00:20:36 +08:00

40 lines
2.4 KiB
PowerShell

# index_monthly_wrapper.ps1 — sanguo-index schtask wrapper (monthly 16号 19:50 成份股刷新)
# STEP0: parse_csindex_announce (csindex 调整公告 -> announce_union, 治幸存者偏差全集, 2026-07-23 新增)
# STEP1: index_const_hist_download --parts A B (深证 A adjust_cni + 中证 B snapshot) akshare parquet 刷新
# STEP2: migrate_constituent 重建 staging (baostock _old 全集 + 深证 union + 中证 announce_union 全集)
# STEP3: merge_constituent staging -> constituent_unified (幂等 DROP+CREATE)
# 不碰 baostock online (全集已在 _old, migrate 读它); 不跑 C 新浪 (baostock 权威)
# STEP0 失败不阻塞 (csindex 网络抖动时 migrate 回退 snapshot, 治偏差降级但 pipeline 不死)
$env:http_proxy = ''
$env:https_proxy = ''
$env:all_proxy = ''
$env:PYTHONIOENCODING = 'utf-8'
$env:INDEX_HIST_OUT_DIR = 'C:\sanguo_vnpy_v2\data\index_const_hist'
$env:CSINDEX_CACHE = 'C:\sanguo_vnpy_v2\data\csindex_raw'
Set-Location C:\sanguo_vnpy_v2
$ts = Get-Date -Format 'yyyyMMdd_HHmmss'
$logDir = 'C:\sanguo_vnpy_v2\data\migration_logs'
if (-not (Test-Path $logDir)) { New-Item -ItemType Directory -Path $logDir -Force | Out-Null }
$log = Join-Path $logDir "index_monthly_$ts.txt"
$py = 'C:\Python310\python.exe'
$dir = 'C:\sanguo_vnpy_v2\scripts\data_platform'
"[$ts] STEP0 parse_csindex_announce --only both (csindex 公告 -> announce_union, 治偏差全集)" | Out-File $log -Encoding UTF8
& $py -X utf8 "$dir\parse_csindex_announce.py" --only both *>> $log
"[$ts] STEP0 done exit=$LASTEXITCODE (失败不阻塞, migrate 回退 snapshot)" | Out-File $log -Append -Encoding UTF8
"[$ts] STEP1 index_const_hist_download --parts A B (深证 adjust + 中证 snapshot)" | Out-File $log -Append -Encoding UTF8
& $py -X utf8 "$dir\index_const_hist_download.py" --parts A B *>> $log
"[$ts] STEP1 done exit=$LASTEXITCODE" | Out-File $log -Append -Encoding UTF8
"[$ts] STEP2 migrate_constituent (rebuild staging from _old + parquet + announce_union)" | Out-File $log -Append -Encoding UTF8
& $py -X utf8 "$dir\migrate_constituent.py" *>> $log
"[$ts] STEP2 done exit=$LASTEXITCODE" | Out-File $log -Append -Encoding UTF8
"[$ts] STEP3 merge_constituent (staging -> constituent_unified, idempotent)" | Out-File $log -Append -Encoding UTF8
& $py -X utf8 "$dir\merge_constituent.py" *>> $log
$final = $LASTEXITCODE
"[$ts] STEP3 done exit=$final" | Out-File $log -Append -Encoding UTF8
exit $final