Remove dependence on Python 3.8 or later

statistics.quantiles was not present in Python 3.7 or earlier, which is a problem on Windows if you want to run a binary optimized version of the protobuf package, since those are not currently being posted for Python 3.8 or later.

This change switches to use the weighted median function just with equal weights. It's a bit of overkill, but it also cuts out the mess that was working around deficiencies of the statistics.quantiles implementation.
This commit is contained in:
sparky8512 2021-03-16 13:19:06 -07:00
parent 55ba411db8
commit 07389cb0d9
2 changed files with 6 additions and 18 deletions

View file

@ -1044,14 +1044,8 @@ def history_stats(parse_samples, start=None, verbose=False, context=None, histor
rtt_all.sort(key=lambda x: x[0]) rtt_all.sort(key=lambda x: x[0])
wmean_all, wdeciles_all = weighted_mean_and_quantiles(rtt_all, 10) wmean_all, wdeciles_all = weighted_mean_and_quantiles(rtt_all, 10)
if len(rtt_full) > 1: rtt_full.sort()
deciles_full = [min(rtt_full)] mean_full, deciles_full = weighted_mean_and_quantiles(tuple((x, 1.0) for x in rtt_full), 10)
deciles_full.extend(statistics.quantiles(rtt_full, n=10, method="inclusive"))
deciles_full.append(max(rtt_full))
elif rtt_full:
deciles_full = [rtt_full[0]] * 11
else:
deciles_full = [None] * 11
return { return {
"samples": parsed_samples, "samples": parsed_samples,
@ -1073,7 +1067,7 @@ def history_stats(parse_samples, start=None, verbose=False, context=None, histor
}, { }, {
"mean_all_ping_latency": wmean_all, "mean_all_ping_latency": wmean_all,
"deciles_all_ping_latency[]": wdeciles_all, "deciles_all_ping_latency[]": wdeciles_all,
"mean_full_ping_latency": statistics.fmean(rtt_full) if rtt_full else None, "mean_full_ping_latency": mean_full,
"deciles_full_ping_latency[]": deciles_full, "deciles_full_ping_latency[]": deciles_full,
"stdev_full_ping_latency": statistics.pstdev(rtt_full) if rtt_full else None, "stdev_full_ping_latency": statistics.pstdev(rtt_full) if rtt_full else None,
}, { }, {

View file

@ -378,14 +378,8 @@ def history_stats(filename, parse_samples, verbose=False):
rtt_all.sort(key=lambda x: x[0]) rtt_all.sort(key=lambda x: x[0])
wmean_all, wdeciles_all = weighted_mean_and_quantiles(rtt_all, 10) wmean_all, wdeciles_all = weighted_mean_and_quantiles(rtt_all, 10)
if len(rtt_full) > 1: rtt_full.sort()
deciles_full = [min(rtt_full)] mean_full, deciles_full = weighted_mean_and_quantiles(tuple((x, 1.0) for x in rtt_full), 10)
deciles_full.extend(statistics.quantiles(rtt_full, n=10, method="inclusive"))
deciles_full.append(max(rtt_full))
elif rtt_full:
deciles_full = [rtt_full[0]] * 11
else:
deciles_full = [None] * 11
return { return {
"samples": parsed_samples, "samples": parsed_samples,
@ -407,7 +401,7 @@ def history_stats(filename, parse_samples, verbose=False):
}, { }, {
"mean_all_ping_latency": wmean_all, "mean_all_ping_latency": wmean_all,
"deciles_all_ping_latency[]": wdeciles_all, "deciles_all_ping_latency[]": wdeciles_all,
"mean_full_ping_latency": statistics.fmean(rtt_full) if rtt_full else None, "mean_full_ping_latency": mean_full,
"deciles_full_ping_latency[]": deciles_full, "deciles_full_ping_latency[]": deciles_full,
"stdev_full_ping_latency": statistics.pstdev(rtt_full) if rtt_full else None, "stdev_full_ping_latency": statistics.pstdev(rtt_full) if rtt_full else None,
}, { }, {