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
This commit is contained in:
parent
a0366b4526
commit
afab7553e3
2 changed files with 28 additions and 15 deletions
|
@ -276,8 +276,18 @@ def get_history_stats(opts, gstate, add_item, add_sequence):
|
||||||
# was a dish reboot.
|
# was a dish reboot.
|
||||||
if gstate.accum_history:
|
if gstate.accum_history:
|
||||||
if history is not None:
|
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,
|
gstate.accum_history = starlink_grpc.concatenate_history(gstate.accum_history,
|
||||||
history,
|
history,
|
||||||
|
start=start,
|
||||||
verbose=opts.verbose)
|
verbose=opts.verbose)
|
||||||
else:
|
else:
|
||||||
gstate.accum_history = history
|
gstate.accum_history = history
|
||||||
|
@ -293,8 +303,8 @@ def get_history_stats(opts, gstate, add_item, add_sequence):
|
||||||
|
|
||||||
gstate.poll_count = 0
|
gstate.poll_count = 0
|
||||||
|
|
||||||
start = gstate.counter_stats
|
start = gstate.counter_stats if gstate.counter_stats else None
|
||||||
parse_samples = opts.samples if start is None else -1
|
parse_samples = opts.samples if gstate.counter_stats is None else -1
|
||||||
groups = starlink_grpc.history_stats(parse_samples,
|
groups = starlink_grpc.history_stats(parse_samples,
|
||||||
start=start,
|
start=start,
|
||||||
verbose=opts.verbose,
|
verbose=opts.verbose,
|
||||||
|
|
|
@ -807,7 +807,8 @@ def _compute_sample_range(history, parse_samples, start=None, verbose=False):
|
||||||
print("current counter: " + str(current))
|
print("current counter: " + str(current))
|
||||||
print("All samples: " + str(samples))
|
print("All samples: " + str(samples))
|
||||||
|
|
||||||
samples = min(samples, current)
|
if not hasattr(history, "unwrapped"):
|
||||||
|
samples = min(samples, current)
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
print("Valid samples: " + str(samples))
|
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
|
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.
|
""" Append the sample-dependent fields of one history object to another.
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
|
@ -855,9 +856,13 @@ def concatenate_history(history1, history2, verbose=False):
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
history1: The grpc history object, such as one returned by a prior
|
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
|
history2: The grpc history object, such as one returned by a prior
|
||||||
call to `get_history`, from which to append.
|
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.
|
verbose (bool): Optionally produce verbose output.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
@ -881,18 +886,13 @@ def concatenate_history(history1, history2, verbose=False):
|
||||||
unwrapped = UnwrappedHistory()
|
unwrapped = UnwrappedHistory()
|
||||||
for field in HISTORY_FIELDS:
|
for field in HISTORY_FIELDS:
|
||||||
setattr(unwrapped, field, [])
|
setattr(unwrapped, field, [])
|
||||||
|
unwrapped.unwrapped = True
|
||||||
|
|
||||||
if hasattr(history1, "unwrapped"):
|
sample_range, ignore1, ignore2 = _compute_sample_range( # pylint: disable=unused-variable
|
||||||
# Make a copy so the input object is not modified.
|
history1, len(history1.pop_ping_drop_rate), start=start)
|
||||||
|
for i in sample_range:
|
||||||
for field in HISTORY_FIELDS:
|
for field in HISTORY_FIELDS:
|
||||||
getattr(unwrapped, field).extend(getattr(history1, field))
|
getattr(unwrapped, field).append(getattr(history1, field)[i])
|
||||||
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
|
|
||||||
|
|
||||||
sample_range, ignore1, ignore2 = _compute_sample_range(history2, new_samples) # pylint: disable=unused-variable
|
sample_range, ignore1, ignore2 = _compute_sample_range(history2, new_samples) # pylint: disable=unused-variable
|
||||||
for i in sample_range:
|
for i in sample_range:
|
||||||
|
@ -997,6 +997,9 @@ def history_stats(parse_samples, start=None, verbose=False, context=None, histor
|
||||||
Args:
|
Args:
|
||||||
parse_samples (int): Number of samples to process, or -1 to parse all
|
parse_samples (int): Number of samples to process, or -1 to parse all
|
||||||
available samples.
|
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.
|
verbose (bool): Optionally produce verbose output.
|
||||||
context (ChannelContext): Optionally provide a channel for reuse
|
context (ChannelContext): Optionally provide a channel for reuse
|
||||||
across repeated calls.
|
across repeated calls.
|
||||||
|
|
Loading…
Reference in a new issue