~ knotless Search/
↑↓ move↵ open⇧↵ all results

zat.dev/zlay

atproto relay in zig · mirror of https://tangled.org/zat.dev/zlay

0
0
18 lines · 1.1 KB Raw History
"""Qualify measured collector intervals rather than connected-once flags."""
def qualify(report, expected_hosts):
    start, end = report['window_start_ns'], report['window_end_ns']
    if end <= start:
        raise ValueError('invalid evaluator window')
    observations = report['collectors']
    if sorted(row['host'] for row in observations) != sorted(expected_hosts):
        raise ValueError('unexpected evaluator sources')
    sources = []
    for row in observations:
        connected, ended = row['connected_ns'], row['ended_ns']
        overlap = 0 if connected is None or ended is None else max(0, min(end, ended) - max(start, connected))
        fraction = overlap / (end - start)
        valid = (row['stop'] == 'shutdown' and row['error_name'] is None
                 and ended is not None and ended >= end and fraction >= .99)
        sources.append(dict(row, connected_fraction=fraction, valid_window=valid))
    return {'window_seconds': (end - start) / 1e9, 'minimum_connected_fraction': .99,
            'sources': sources, 'valid_window': all(row['valid_window'] for row in sources)}