From afab7553e3d1e53f1b0de61dd8819e3142a8f977 Mon Sep 17 00:00:00 2001 From: sparky8512 <76499194+sparky8512@users.noreply.github.com> Date: Thu, 7 Oct 2021 12:23:48 -0700 Subject: [PATCH] Fix -o option breakage from recent change This restores the ability of -o to keep polled data across a reboot. It broke due to a simple issue in concatenate_history, but I realized that counter tracking for -o accumulated data was also a bit broken, so I fixed that, too. Fix #31 --- dish_common.py | 14 ++++++++++++-- starlink_grpc.py | 29 ++++++++++++++++------------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/dish_common.py b/dish_common.py index 6e624b6..3e5ba16 100644 --- a/dish_common.py +++ b/dish_common.py @@ -276,8 +276,18 @@ def get_history_stats(opts, gstate, add_item, add_sequence): # was a dish reboot. if gstate.accum_history: if history is not None: + # This gets too complicated to handle across reboots once the data + # has been accumulated, so just have concatenate do it on the + # first pass and use a value of 0 to remember it was done (as + # opposed to None, which is used for a different purpose). + if gstate.counter_stats: + start = gstate.counter_stats + gstate.counter_stats = 0 + else: + start = None gstate.accum_history = starlink_grpc.concatenate_history(gstate.accum_history, history, + start=start, verbose=opts.verbose) else: gstate.accum_history = history @@ -293,8 +303,8 @@ def get_history_stats(opts, gstate, add_item, add_sequence): gstate.poll_count = 0 - start = gstate.counter_stats - parse_samples = opts.samples if start is None else -1 + start = gstate.counter_stats if gstate.counter_stats else None + parse_samples = opts.samples if gstate.counter_stats is None else -1 groups = starlink_grpc.history_stats(parse_samples, start=start, verbose=opts.verbose, diff --git a/starlink_grpc.py b/starlink_grpc.py index 56491d9..5cd81ee 100644 --- a/starlink_grpc.py +++ b/starlink_grpc.py @@ -807,7 +807,8 @@ def _compute_sample_range(history, parse_samples, start=None, verbose=False): print("current counter: " + str(current)) print("All samples: " + str(samples)) - samples = min(samples, current) + if not hasattr(history, "unwrapped"): + samples = min(samples, current) if verbose: print("Valid samples: " + str(samples)) @@ -845,7 +846,7 @@ def _compute_sample_range(history, parse_samples, start=None, verbose=False): return sample_range, current - start, current -def concatenate_history(history1, history2, verbose=False): +def concatenate_history(history1, history2, start=None, verbose=False): """ Append the sample-dependent fields of one history object to another. Note: @@ -855,9 +856,13 @@ def concatenate_history(history1, history2, verbose=False): Args: history1: The grpc history object, such as one returned by a prior - call to `get_history`, or equivalent dict, to which to append. + call to `get_history`, or object with similar attributes, to which + to append. history2: The grpc history object, such as one returned by a prior call to `get_history`, from which to append. + start (int): Optional starting counter value to be applied to the + history1 data. See `history_bulk_data` documentation for more + details on how this parameter is used. verbose (bool): Optionally produce verbose output. Returns: @@ -881,18 +886,13 @@ def concatenate_history(history1, history2, verbose=False): unwrapped = UnwrappedHistory() for field in HISTORY_FIELDS: setattr(unwrapped, field, []) + unwrapped.unwrapped = True - if hasattr(history1, "unwrapped"): - # Make a copy so the input object is not modified. + sample_range, ignore1, ignore2 = _compute_sample_range( # pylint: disable=unused-variable + history1, len(history1.pop_ping_drop_rate), start=start) + for i in sample_range: for field in HISTORY_FIELDS: - getattr(unwrapped, field).extend(getattr(history1, field)) - else: - sample_range, ignore1, ignore2 = _compute_sample_range( # pylint: disable=unused-variable - history1, len(history1.pop_ping_drop_rate)) - for i in sample_range: - for field in HISTORY_FIELDS: - getattr(unwrapped, field).append(getattr(history1, field)[i]) - unwrapped.unwrapped = True + getattr(unwrapped, field).append(getattr(history1, field)[i]) sample_range, ignore1, ignore2 = _compute_sample_range(history2, new_samples) # pylint: disable=unused-variable for i in sample_range: @@ -997,6 +997,9 @@ def history_stats(parse_samples, start=None, verbose=False, context=None, histor Args: parse_samples (int): Number of samples to process, or -1 to parse all available samples. + start (int): Optional starting counter value to be applied to the + history data. See `history_bulk_data` documentation for more + details on how this parameter is used. verbose (bool): Optionally produce verbose output. context (ChannelContext): Optionally provide a channel for reuse across repeated calls.