111 lines
3.4 KiB
Python
Executable file
111 lines
3.4 KiB
Python
Executable file
#!/usr/bin/env python3
|
||
|
||
import sys
|
||
from itertools import zip_longest
|
||
from numberdealers import parse_numberdealers, times, report_errors, numbers_per_user
|
||
from numberdealers.times import format_time
|
||
from mdtables import Table, Column
|
||
|
||
|
||
def main():
|
||
numberdealers_tail = sys.argv[1]
|
||
numberdealers_history = sys.argv[2]
|
||
numberdealers_ng = sys.argv[3]
|
||
|
||
with \
|
||
open(numberdealers_tail, "r") as nd_tail, \
|
||
open(numberdealers_history, "r") as nd_history, \
|
||
open(numberdealers_ng, "r") as nd_ng:
|
||
numbers_tail, errors_tail = parse_numberdealers.parse(nd_tail, parse_numberdealers.ErrorStyle.NUMBERDEALERS)
|
||
numbers_history, _errors = parse_numberdealers.parse(nd_history, parse_numberdealers.ErrorStyle.NUMBERDEALERS)
|
||
numbers_ng, errors_ng = parse_numberdealers.parse(nd_ng, parse_numberdealers.ErrorStyle.NUMBERDEALERS_NG)
|
||
|
||
assert numbers_tail
|
||
assert numbers_history
|
||
assert numbers_ng
|
||
|
||
table = Table(
|
||
Column('', alignment='right'),
|
||
Column('~numberdealers'),
|
||
Column('~numberdealers-ng')
|
||
)
|
||
|
||
table.row(
|
||
"Stats for",
|
||
f"{numbers_history[0].recognized_number} up to {numbers_history[-1].recognized_number}",
|
||
f"{numbers_ng[0].recognized_number} up to {numbers_ng[-1].recognized_number}",
|
||
)
|
||
|
||
label = "Errors"
|
||
for error_line, error_line_ng in zip(
|
||
report_errors.report_errors(errors_tail) or [f"No errors (after {numbers_tail[0].recognized_number})! 🎉"],
|
||
report_errors.report_errors(errors_ng) or ["No errors! 🎉"]
|
||
):
|
||
table.row(
|
||
label,
|
||
error_line,
|
||
error_line_ng
|
||
)
|
||
label = ""
|
||
|
||
table.row("", "", "")
|
||
|
||
a = times.analyze_times(numbers_history)
|
||
b = times.analyze_times(numbers_ng)
|
||
table.row( "μ", format_time(a.avg), format_time(b.avg))
|
||
table.row( "σ", format_time(a.stdev), format_time(b.stdev))
|
||
table.row("", "", "")
|
||
table.row( "min", format_time(a.min), format_time(b.min))
|
||
table.row( "P5", format_time(a.perc5), format_time(b.perc5))
|
||
table.row("median", format_time(a.med), format_time(b.med))
|
||
table.row( "P95", format_time(a.perc95), format_time(b.perc95))
|
||
table.row( "max", format_time(a.max), format_time(b.max))
|
||
|
||
print(table)
|
||
print()
|
||
|
||
print("```")
|
||
_stats_history = numbers_per_user.analyze_users(numbers_history)
|
||
stats_history = sorted(_stats_history.items(), key=lambda x: x[1], reverse=True)
|
||
_stats_ng = numbers_per_user.analyze_users(numbers_ng)
|
||
stats_ng = sorted(_stats_ng.items(), key=lambda x: x[1], reverse=True)
|
||
print(f"{'~numberdealers':31s} ~numberdealers-ng")
|
||
i = 0
|
||
others_count_hist = 0
|
||
others_names_hist = 0
|
||
others_count_ng = 0
|
||
others_names_ng = 0
|
||
for hist, ng in zip_longest(stats_history, stats_ng):
|
||
if hist is not None:
|
||
username_hist, count_hist = hist
|
||
else:
|
||
username_hist, count_hist = "", ""
|
||
if ng is not None:
|
||
username_ng, count_ng = ng
|
||
else:
|
||
username_ng, count_ng = "", ""
|
||
|
||
if i < 7:
|
||
print(f"{str(count_hist):>5s} {username_hist:25s} {str(count_ng):>5s} {username_ng}")
|
||
else:
|
||
if hist is not None:
|
||
others_count_hist += count_hist
|
||
others_names_hist += 1
|
||
if ng is not None:
|
||
others_count_ng += count_ng
|
||
others_names_ng += 1
|
||
i += 1
|
||
|
||
if others_names_hist > 0 or others_names_ng > 0:
|
||
if others_names_hist > 0:
|
||
others_hist = f"{others_count_hist: 5d} [{others_names_hist} others]"
|
||
if others_names_ng > 0:
|
||
others_ng = f"{others_count_ng: 5d} [{others_names_ng} others]"
|
||
print(f"{others_hist:31s} {others_ng}")
|
||
|
||
print("```")
|
||
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|