From 07389cb0d9387d27b8cac3ac8da72168ff98b691 Mon Sep 17 00:00:00 2001 From: sparky8512 <76499194+sparky8512@users.noreply.github.com> Date: Tue, 16 Mar 2021 13:19:06 -0700 Subject: [PATCH] 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. --- starlink_grpc.py | 12 +++--------- starlink_json.py | 12 +++--------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/starlink_grpc.py b/starlink_grpc.py index b7c02f2..38b0298 100644 --- a/starlink_grpc.py +++ b/starlink_grpc.py @@ -1044,14 +1044,8 @@ def history_stats(parse_samples, start=None, verbose=False, context=None, histor rtt_all.sort(key=lambda x: x[0]) wmean_all, wdeciles_all = weighted_mean_and_quantiles(rtt_all, 10) - if len(rtt_full) > 1: - deciles_full = [min(rtt_full)] - 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 + rtt_full.sort() + mean_full, deciles_full = weighted_mean_and_quantiles(tuple((x, 1.0) for x in rtt_full), 10) return { "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, "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, "stdev_full_ping_latency": statistics.pstdev(rtt_full) if rtt_full else None, }, { diff --git a/starlink_json.py b/starlink_json.py index e740c7d..a67713c 100644 --- a/starlink_json.py +++ b/starlink_json.py @@ -378,14 +378,8 @@ def history_stats(filename, parse_samples, verbose=False): rtt_all.sort(key=lambda x: x[0]) wmean_all, wdeciles_all = weighted_mean_and_quantiles(rtt_all, 10) - if len(rtt_full) > 1: - deciles_full = [min(rtt_full)] - 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 + rtt_full.sort() + mean_full, deciles_full = weighted_mean_and_quantiles(tuple((x, 1.0) for x in rtt_full), 10) return { "samples": parsed_samples, @@ -407,7 +401,7 @@ def history_stats(filename, parse_samples, verbose=False): }, { "mean_all_ping_latency": wmean_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, "stdev_full_ping_latency": statistics.pstdev(rtt_full) if rtt_full else None, }, {