def last_hour_count(self): last_min_since_epoch = utils.epoch_sec_to_minutes_since_epoch( self.counter_data["latest_time_sec"]) curr_min_since_epoch = utils.epoch_sec_to_minutes_since_epoch( self.current_epoch_sec) # If the current time is more than 1 hour aheads of the data return 0 # OR # We somehow have data ahead of the current_time (we won't try to resolve that) difference_btw_curr_and_last = curr_min_since_epoch - last_min_since_epoch if difference_btw_curr_and_last >= 60 or difference_btw_curr_and_last < 0: return 0 # Example: # curr_min_since_epoch = 620 / curr_min_since_epoch = 20 # last_min_since_epoch = 615 / last_min_of_hour_with_data = 15 # The array therefore looks something like # counter_data[14] = Data from 614 # counter_data[15] = Data from 615 (last recorded value, 0 minutes old) # counter_data[16] = Data from 556 (64 minutes old) # counter_data[20] = Data from 560 (60 minutes old) # Thus we want values starting from position 15 going backward through position 21 last_min_of_hour_with_data = last_min_since_epoch % 60 num_mins_with_data_in_last_hour = 60 - difference_btw_curr_and_last filtered_mins = self._filter_counters_data( last_min_of_hour_with_data, num_mins_with_data_in_last_hour, self.counter_data["min_counters"]) return sum(filtered_mins)
def last_hour_count(self): last_min_since_epoch = utils.epoch_sec_to_minutes_since_epoch(self.counter_data["latest_time_sec"]) curr_min_since_epoch = utils.epoch_sec_to_minutes_since_epoch(self.current_epoch_sec) # If the current time is more than 1 hour aheads of the data return 0 # OR # We somehow have data ahead of the current_time (we won't try to resolve that) difference_btw_curr_and_last = curr_min_since_epoch - last_min_since_epoch if difference_btw_curr_and_last >= 60 or difference_btw_curr_and_last < 0: return 0 # Example: # curr_min_since_epoch = 620 / curr_min_since_epoch = 20 # last_min_since_epoch = 615 / last_min_of_hour_with_data = 15 # The array therefore looks something like # counter_data[14] = Data from 614 # counter_data[15] = Data from 615 (last recorded value, 0 minutes old) # counter_data[16] = Data from 556 (64 minutes old) # counter_data[20] = Data from 560 (60 minutes old) # Thus we want values starting from position 15 going backward through position 21 last_min_of_hour_with_data = last_min_since_epoch % 60 num_mins_with_data_in_last_hour = 60 - difference_btw_curr_and_last filtered_mins = self._filter_counters_data(last_min_of_hour_with_data, num_mins_with_data_in_last_hour, self.counter_data["min_counters"]) return sum(filtered_mins)
def last_minute_count(self): # TODO: Make this the prior minute to the current one; only change when SamplerStats has # similar behavior curr_time_dt = utils.sec_since_epoch_to_datetime(self.current_epoch_sec) last_min_since_epoch = utils.epoch_sec_to_minutes_since_epoch(self.counter_data["latest_time_sec"]) curr_min_since_epoch = utils.epoch_sec_to_minutes_since_epoch(self.current_epoch_sec) # It actually wouldn't be that hard to handle the case where we have data beyond the # current_time, but let's not bother # Obviously, if the curr_min is ahead of the last_min_since_epoch, we don't have data if curr_min_since_epoch != last_min_since_epoch: return 0 curr_min_of_hour = curr_time_dt.minute return self.counter_data["min_counters"][curr_min_of_hour]
def last_minute_count(self): # TODO: Make this the prior minute to the current one; only change when SamplerStats has # similar behavior curr_time_dt = utils.sec_since_epoch_to_datetime( self.current_epoch_sec) last_min_since_epoch = utils.epoch_sec_to_minutes_since_epoch( self.counter_data["latest_time_sec"]) curr_min_since_epoch = utils.epoch_sec_to_minutes_since_epoch( self.current_epoch_sec) # It actually wouldn't be that hard to handle the case where we have data beyond the # current_time, but let's not bother # Obviously, if the curr_min is ahead of the last_min_since_epoch, we don't have data if curr_min_since_epoch != last_min_since_epoch: return 0 curr_min_of_hour = curr_time_dt.minute return self.counter_data["min_counters"][curr_min_of_hour]
def last_minute_stats(self): # TODO: Lots of changes need to happen to make this the last full clock time minute latest_min = utils.epoch_sec_to_minutes_since_epoch(self.sampler_data["latest_time_sec"]) if latest_min != self.current_min: stats = self._compute_order_statistics([]) stats["count"] = 0 else: last_minute_samples = self.sampler_data["last_minute_samples"] stats = self._compute_order_statistics(last_minute_samples["sample_values"]) stats["count"] = last_minute_samples["num_events"] return stats
def last_minute_stats(self): # TODO: Lots of changes need to happen to make this the last full clock time minute latest_min = utils.epoch_sec_to_minutes_since_epoch( self.sampler_data["latest_time_sec"]) if latest_min != self.current_min: stats = self._compute_order_statistics([]) stats["count"] = 0 else: last_minute_samples = self.sampler_data["last_minute_samples"] stats = self._compute_order_statistics( last_minute_samples["sample_values"]) stats["count"] = last_minute_samples["num_events"] return stats
def __init__(self, sampler_data, current_epoch_sec): '''Assumes that sampler_data is an SAMPLER_JSON object, per the protocol definition''' self.sampler_data = sampler_data self.current_epoch_sec = current_epoch_sec self.current_min = utils.epoch_sec_to_minutes_since_epoch( self.current_epoch_sec)
def __init__(self, sampler_data, current_epoch_sec): '''Assumes that sampler_data is an SAMPLER_JSON object, per the protocol definition''' self.sampler_data = sampler_data self.current_epoch_sec = current_epoch_sec self.current_min = utils.epoch_sec_to_minutes_since_epoch(self.current_epoch_sec)