tradingSystem/research/chip_accumulation_20261030/finalize.py

29 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""记录运行依赖、源缓存和交付物摘要;不含凭证或原始数据正文。"""
import datetime as dt
import importlib.metadata
import platform
from common import ROOT,read,dump,digest,install_offline
def main():
install_offline()
packages={k:importlib.metadata.version(k) for k in ['numpy','pandas','scipy','matplotlib']}
(ROOT/'requirements.txt').write_text('\n'.join(k+'=='+v for k,v in packages.items())+'\n')
sources={}
for path in sorted((ROOT/'raw').glob('*.json.gz')):
sources[str(path.relative_to(ROOT))]={'sha256':digest(path),'bytes':path.stat().st_size}
parent_sources=read(ROOT/'price_coverage.json')['source_sha256']
artifacts={}
for path in sorted(ROOT.rglob('*')):
if not path.is_file() or path.name=='manifest.json':continue
relative=path.relative_to(ROOT)
if any(x in relative.parts for x in ['raw','cache','__pycache__']):continue
artifacts[str(relative)]={'sha256':digest(path),'bytes':path.stat().st_size}
dump(ROOT/'manifest.json',{'recorded_at':dt.datetime.now(dt.timezone(dt.timedelta(hours=8))).isoformat(),
'python':platform.python_version(),'packages':packages,'raw_sources':sources,
'price_sources_relative_to_research':parent_sources,'artifacts':artifacts,
'exclusions':'原始数据和中间缓存留在开发机;manifest不递归计算自身摘要。',
'environment':'开发机离线分析。155独立只读容器导出,无业务目录挂载及交易凭证。'})
print('交付清单已记录',len(sources),'份源快照,',len(artifacts),'份交付文件')
if __name__=='__main__':main()