From e10c9dbb7f4e5d48b7954c867a9a7ed96f541412 Mon Sep 17 00:00:00 2001 From: sparky8512 <76499194+sparky8512@users.noreply.github.com> Date: Sun, 21 Feb 2021 13:57:48 -0800 Subject: [PATCH] Mostly cosmetic changes A few things I noticed while porting this code to the JSON script. The only real change here is fixing the bulk history output to print UTC time instead of local time. --- dish_common.py | 4 ++-- dish_grpc_text.py | 8 ++++---- starlink_grpc.py | 12 ++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/dish_common.py b/dish_common.py index 562aa0a..1f6e17e 100644 --- a/dish_common.py +++ b/dish_common.py @@ -74,8 +74,8 @@ def create_arg_parser(output_description, bulk_history=True): metavar="N") if bulk_history: sample_help = ("Number of data samples to parse; normally applies to first loop " - "iteration only, default: -1 in bulk mode, loop interval if loop interval " - "set, else " + str(SAMPLES_DEFAULT)) + "iteration only, default: all in bulk mode, loop interval if loop " + "interval set, else " + str(SAMPLES_DEFAULT)) no_counter_help = ("Don't track sample counter across loop iterations in non-bulk " "modes; keep using samples option value instead") else: diff --git a/dish_grpc_text.py b/dish_grpc_text.py index 849114d..77f6923 100644 --- a/dish_grpc_text.py +++ b/dish_grpc_text.py @@ -65,7 +65,7 @@ def parse_args(): opts = dish_common.run_arg_parser(parser, no_stdout_errors=True) - if len(opts.mode) > 1 and "bulk_history" in opts.mode: + if (opts.history_stats_mode or opts.satus_mode) and opts.bulk_mode: parser.error("bulk_history cannot be combined with other modes for CSV output") return opts @@ -148,8 +148,8 @@ def loop_body(opts, gstate): def cb_add_bulk(bulk, count, timestamp, counter): if opts.verbose: print("Time range (UTC): {0} -> {1}".format( - datetime.fromtimestamp(timestamp).isoformat(), - datetime.fromtimestamp(timestamp + count).isoformat())) + datetime.utcfromtimestamp(timestamp).isoformat(), + datetime.utcfromtimestamp(timestamp + count).isoformat())) for key, val in bulk.items(): print("{0:22} {1}".format(key + ":", ", ".join(str(subval) for subval in val))) if opts.loop_interval > 0.0: @@ -157,7 +157,7 @@ def loop_body(opts, gstate): else: for i in range(count): timestamp += 1 - fields = [datetime.fromtimestamp(timestamp).isoformat()] + fields = [datetime.utcfromtimestamp(timestamp).isoformat()] fields.extend(["" if val[i] is None else str(val[i]) for val in bulk.values()]) print(",".join(fields)) diff --git a/starlink_grpc.py b/starlink_grpc.py index c0b906f..921c2f8 100644 --- a/starlink_grpc.py +++ b/starlink_grpc.py @@ -883,7 +883,7 @@ def history_ping_stats(parse_samples, verbose=False, context=None): def history_stats(parse_samples, start=None, verbose=False, context=None, history=None): - """Fetch, parse, and compute the packet loss stats. + """Fetch, parse, and compute ping and usage stats. Note: See module level docs regarding brackets in field names. @@ -918,10 +918,10 @@ def history_stats(parse_samples, start=None, verbose=False, context=None, histor except grpc.RpcError as e: raise GrpcError(e) - sample_range, parse_samples, current = _compute_sample_range(history, - parse_samples, - start=start, - verbose=verbose) + sample_range, parsed_samples, current = _compute_sample_range(history, + parse_samples, + start=start, + verbose=verbose) tot = 0.0 count_full_drop = 0 @@ -1051,7 +1051,7 @@ def history_stats(parse_samples, start=None, verbose=False, context=None, histor deciles_full = [None] * 11 return { - "samples": parse_samples, + "samples": parsed_samples, "end_counter": current, }, { "total_ping_drop": tot,