35 lines
3.3 KiB
Python
35 lines
3.3 KiB
Python
"""核验分组加总、报告引用与交付摘要,不改研究计算口径。"""
|
|
import datetime as dt,sys,re,ast
|
|
from pathlib import Path
|
|
import numpy as np
|
|
import pandas as pd
|
|
import matplotlib
|
|
from common import *
|
|
def main():
|
|
sys.addaudithook(offline);p,panel,f,cov=load();g=pd.read_csv(ROOT/'grid.csv.gz');keys=['config','hold','period']
|
|
whole=g[g.phase_index=='all'].set_index(keys).sort_index();partition=[]
|
|
for index in ['csi300','csi500','csi1000','csi2000']:
|
|
z=g[g.phase_index==index].copy();z['weighted_gross']=z.mean_gross.fillna(0)*z.active_days
|
|
aggregate=z.groupby(keys)[['phase_days','active_days','selected','filled','completed','unresolved','delayed','weighted_gross']].sum().sort_index()
|
|
for field in ['phase_days','active_days','selected','filled','completed','unresolved','delayed']:assert np.array_equal(aggregate[field],whole[field])
|
|
weighted=divide(aggregate.weighted_gross.to_numpy(),aggregate.active_days.to_numpy());assert np.allclose(weighted,whole.mean_gross.to_numpy(),atol=1e-12,equal_nan=True)
|
|
partition.append(index)
|
|
assert len(g)==201240
|
|
assert np.all(g.mean_net60.dropna()<=g.mean_net30.dropna()+1e-14)
|
|
assert np.all(g.mean_net30.dropna()<=g.mean_gross.dropna()+1e-14)
|
|
assert not g[g.completed==0].mean_gross.notna().any()
|
|
for name,sha in cov['source_sha256'].items():assert digest(ROOT.parent/name)==sha
|
|
assert digest(ROOT/'cache/features.npz')==cov['features_sha256']
|
|
dashboard=read(ROOT/'dashboard_manifest.json');assert digest(ROOT/'反复活跃矩阵浏览器.html')==dashboard['html_sha256'];assert digest(ROOT/'grid.csv.gz')==dashboard['data_source_sha256']
|
|
links=0
|
|
docs=[ROOT/'反复活跃与持有期矩阵研究.md',ROOT.parents[1]/'docs/反复活跃矩阵研究接续_2026-10-29.md',ROOT.parents[1]/'docs/开发入口.md',ROOT/'vendor/README.md']
|
|
for path in docs:
|
|
for dest in re.findall(r'!?\[[^\]]*\]\(([^)]+)\)',path.read_text()):
|
|
if '://' not in dest and not dest.startswith('#'):assert (path.parent/dest.split('#')[0]).exists(),(path,dest);links+=1
|
|
for path in ROOT.glob('*.py'):ast.parse(path.read_text())
|
|
browser=read(ROOT/'browser_checks.json');assert not browser['external_requests'] and not browser['page_errors']
|
|
files=[path for path in ROOT.rglob('*') if path.is_file() and not any(x in path.parts for x in ['cache','__pycache__']) and path.name!='manifest.json']
|
|
result={'created_at_beijing':dt.datetime.now(dt.timezone(dt.timedelta(hours=8))).isoformat(),'protocol_sha256':digest(ROOT/'protocol.json'),'files_sha256':{str(path.relative_to(ROOT)):digest(path) for path in sorted(files)},'runtime':{'python':sys.version.split()[0],'numpy':np.__version__,'pandas':pd.__version__,'matplotlib':matplotlib.__version__},'grid_rows':len(g),'parameter_combinations':5160,'accounts':42,'phase_partitions_checked':partition,'cash_and_event_audit':'audit.json和calculation_checks.json','local_links_checked':links,'figures_checked':6,'browser_checks':len(browser['checks']),'new_database_access':False,'live_strategy_changes':False}
|
|
dump(ROOT/'manifest.json',result);print({'files':len(files),'local_links':links,'phase_partitions':partition,'grid_rows':len(g),'figures':6,'browser_checks':len(browser['checks'])})
|
|
if __name__=='__main__':main()
|