Files

48 lines
2.9 KiB
Python
Raw Permalink Normal View History

"""BR-69: observed meeting feedback against frozen prescreen results, never training."""
from datetime import datetime
from services import assistant_store as store
def time(value):
try:
stamp=datetime.fromisoformat(str(value).replace('Z','+00:00'))
return stamp.timestamp() if stamp.tzinfo else None
except (ValueError,TypeError):
return None
def summarize(db,project_id):
outcomes=store.listing(db,'review_outcome',project_id)
runs=store.listing(db,'run',project_id)
views={r['id']:r for r in store.listing(db,'prescreen_run',project_id)}
replaced={o['supersedes_id'] for o in outcomes if o.get('supersedes_id')}
active=[o for o in outcomes if o['id'] not in replaced]
groups={}
for row in active:
groups.setdefault(row.get('reviewed_snapshot_id'),[]).append(row)
rows,excluded=[],[]
for outcome in outcomes:
reason=None
snapshot=outcome.get('reviewed_snapshot_id')
if outcome['id'] in replaced: reason='旧结果已被更正'
elif not snapshot or outcome.get('status')!='matched': reason='未匹配材料版本'
elif len(groups[snapshot])!=1: reason='同一材料版本存在多个当前结果,需明确更正关系'
elif outcome.get('label') not in (True,False) or outcome.get('label') is None: reason='结果未映射或不是通过/否决'
meeting=time(outcome.get('occurred_at'))
candidates=[r for r in runs if r.get('input_snapshot_id')==snapshot and r.get('status')=='completed' and r['id'] in views and meeting is not None and time(r.get('ended_at')) is not None and time(r['ended_at'])<meeting]
if not reason and not candidates: reason='没有会议之前完成的冻结预审'
if reason:
excluded.append({'outcome_id':outcome['id'],'reason':reason});continue
run=max(candidates,key=lambda r:time(r['ended_at']))
view=views[run['id']]
recommendation=view.get('recommendation')
rows.append({'outcome_id':outcome['id'],'run_id':run['id'],'snapshot_id':snapshot,
'meeting_id':outcome['meeting_id'],'recommendation':recommendation,
'approved':outcome['label'],'predicted_at':run['ended_at'],
'meeting_at':outcome['occurred_at'],'divergence':recommendation=='advance' and not outcome['label'],
'data_domain':view.get('data_domain'),'plan_ref':view.get('plan_ref')})
advance=[r for r in rows if r['recommendation']=='advance']
passed=sum(r['approved'] for r in advance)
return {'observed':len(rows),'excluded':excluded,'rows':rows,
'advance_group':{'count':len(advance),'approved':passed,'rate':passed/len(advance) if advance else None},
'probability_status':'not_calibrated',
'note':'这是已观察的会议反馈统计,不能冒充项目审批概率或证明持续学习有效;模拟域和真实域不能混合。'}