"""R618:预定批次全部有去向;缺失日志不冒称未启动。""" from collections import Counter from math import isfinite PLAN = ['T' + str(i) for i in range(1, 9)] RECORDS = { 'T1': {'status': 'completed', 'artifact_ok': True, 'net': 5}, 'T2': {'status': 'completed', 'artifact_ok': True, 'net': -2}, 'T3': {'status': 'failed', 'stage': 'load', 'retryable': True}, 'T4': {'status': 'failed', 'stage': 'strategy', 'retryable': False}, 'T5': {'status': 'failed', 'stage': 'engine', 'retryable': False}, 'T6': {'status': 'completed', 'artifact_ok': False, 'net': 9}, 'T7': {'status': 'cancelled'}, 'T8': {'status': 'not_started'}, } def audit(plan, records): if len(set(plan)) != len(plan) or set(records) != set(plan): raise ValueError('duplicate, orphan or unresolved trial') counts, eligible, rerun, failures = Counter(), [], [], {} for ident in plan: row = records[ident] status = row['status'] if status == 'completed': if row['artifact_ok'] and isfinite(row['net']): eligible.append(ident) else: status = 'failed' failures[ident] = 'artifact' rerun.append(ident) elif status == 'failed': failures[ident] = row['stage'] if row['retryable']: rerun.append(ident) elif status not in {'cancelled', 'not_started'}: raise ValueError('unresolved state') counts[status] += 1 assert sum(counts.values()) == len(plan) return dict(counts), eligible, rerun, failures counts, eligible, rerun, stages = audit(PLAN, RECORDS) assert counts == {'completed': 2, 'failed': 4, 'cancelled': 1, 'not_started': 1} assert eligible == ['T1', 'T2'] and rerun == ['T3', 'T6'] assert max(eligible, key=lambda k: RECORDS[k]['net']) == 'T1' missing = dict(RECORDS); del missing['T8'] try: audit(PLAN, missing) except ValueError: pass else: raise AssertionError('missing log mislabeled not_started') print('planned=8 counts=' + str(counts) + ' completion=25.000000%') print('eligible=' + str(eligible) + ' rerun=' + str(rerun) + ' failure_stages=' + str(stages)) print('best_completed=T1 full_batch_best=unknown missing_registry=rejected')