Files
ai-use-outdoor-industry-res…/scripts/validate_run.py
T

45 lines
3.1 KiB
Python
Raw Normal View History

2026-09-14 12:34:28 -06:00
import json, sys
from pathlib import Path
from datetime import datetime, date, timedelta
CATEGORIES=['Strategy','Systems/infrastructure','Product development','Finance','Production','Logistics','Supply chain','Marketing','Sales/distribution','Other operations']
def validate(folder):
folder=Path(folder); errors=[]
def check(ok,msg):
if not ok: errors.append(msg)
for name in ['standard-web.md','exa.md','comparison.md','evidence.json','search-log.json']:
check((folder/name).is_file() and (folder/name).stat().st_size>0,'Missing '+name)
if errors:return errors
d=json.loads((folder/'evidence.json').read_text(encoding='utf-8'))
log=json.loads((folder/'search-log.json').read_text(encoding='utf-8'))
start=datetime.fromisoformat(d['window_start']); end=datetime.fromisoformat(d['window_end'])
check(end-start==timedelta(days=7),'Window must be exactly seven days')
check((start.tzinfo is not None and end.tzinfo is not None),'Timezone required')
check(log['window_start']==d['window_start'] and log['window_end']==d['window_end'],'Log window mismatch')
for eng,key in [('standard-web','standard_web'),('exa','exa')]:
txt=(folder/(eng+'.md')).read_text(encoding='utf-8')
check(len(log.get(key,{}).get('queries',[]))>=6,'Missing search coverage: '+eng)
for cat in CATEGORIES:check('| '+cat+' |' in txt,'Missing coverage '+eng+' '+cat)
for h in ['Internal','Customer-facing','Both','Method and limitations']: check('## '+h in txt,'Missing group '+h)
ids=[]
for c in d['cases']:
for k in ['id','engine','organization','evidence_date','event_date','measurement_period','primary_function','secondary_functions','exposure','deployment_status','ai_mechanism','outcome','outcome_status','future_plans','source_url','source_type','source_opened','confidence','continuity','score']:
check(k in c,'Missing case field '+k)
if errors:continue
ids.append(c['id'])
check(c['engine'] in ['standard-web','exa'],'Invalid engine')
check(c['exposure'] in ['Internal','Customer-facing','Both'],'Invalid exposure')
check(c['primary_function'] in CATEGORIES and all(x in CATEGORIES for x in c['secondary_functions']),'Invalid function')
check(c['deployment_status'] in ['planned','pilot','live','scaled','withdrawn','unclear'],'Invalid status')
check(start.date()<=date.fromisoformat(c['evidence_date'])<=end.date(),'Out-of-window case')
check(c['source_url'].startswith('https://') and c['source_opened'] is True,'Missing opened citation')
if c['engine'] in ['standard-web','exa']:
txt=(folder/(c['engine']+'.md')).read_text(encoding='utf-8')
check(c['source_url'] in txt and c['id'] in txt,'Report missing case citation')
check(len(ids)==len(set(ids)),'Duplicate case ID')
return errors
if __name__=='__main__':
try: errors=validate(sys.argv[1])
except (KeyError,ValueError,OSError,IndexError) as e: errors=[str(e)]
print('\n'.join(errors) if errors else 'PASS: report structure, seven-day window, coverage and evidence fields')
sys.exit(bool(errors))