#!/usr/bin/python3 "Analyze logs from reversedigitspan.py. Not safe for untrusted input." import datetime import sys def main(): perf = {} min_ts, max_ts = None, None for line in sys.stdin: if 'reverse digit span of' not in line: continue fields = line.split() timestamp = int(fields[0]) correctness = fields[1] size = int(fields[6]) who_start = line.index(' by ') + 4 quote = line.index("'", who_start + 2) if quote == -1: who_end = len(line) else: who_end = quote + 1 who = eval(line[who_start:who_end]) if min_ts is None or timestamp < min_ts: min_ts = timestamp if max_ts is None or timestamp > max_ts: max_ts = timestamp if who not in perf: perf[who] = {} if size not in perf[who]: perf[who][size] = {'correct': 0, 'incorrect': 0} perf[who][size][correctness] += 1 min_dt = datetime.datetime.utcfromtimestamp(min_ts) max_dt = datetime.datetime.utcfromtimestamp(max_ts) print("From {} to {} UTC ({}):".format(min_dt, max_dt, max_dt - min_dt)) for who, how in perf.items(): print('\t{} did {} trials:'.format(who, sum(k for measure in how.values() for k in measure.values()))) for size, measure in sorted(how.items()): correct = measure['correct'] incorrect = measure['incorrect'] print('\t\tat {} digits, {} correct, {} incorrect ({:5.4}%, {:5.4}% smoothed)' .format(size, correct, incorrect, 100*correct/(incorrect+correct), 100*(correct+1)/(incorrect+correct+2))) if __name__ == '__main__': main()