def load_list(self, data): """load list of tuples - each tuple must be of the form: (timestamp, value) - timestamps may be: - unix seconds since epoch - unix milliseconds since epoch - strings of the form YYYY-MM-DD HH:MM:SS - values may be: - anything that can be coerced to python float - anything else will be ignored Note on timezones: - a tz_utc_offset (hours) should be provided - timestamps are stored as seconds since the unix epoch (seconds utc) - the tz_utc_offset (hours) will be applied when parsing integer timestamps and when converting integer timestamp strings """ series = [] for entry in data: time = utils.read_timestamp(entry[0], self.timezone) try: value = float(entry[1]) except: value = float("nan") if math.isnan(value) != True: series.append((time, value)) return series
def load_list(self, data): """load list of tuples - each tuple must be of the form: (timestamp, value) - timestamps may be: - unix seconds since epoch - unix milliseconds since epoch - strings of the form YYYY-MM-DD HH:MM:SS - values may be: - anything that can be coerced to python float - anything else will be ignored Note on timezones: - a tz_utc_offset (hours) should be provided - timestamps are stored as seconds since the unix epoch (seconds utc) - the tz_utc_offset (hours) will be applied when parsing integer timestamps and when converting integer timestamp strings """ series = [] for entry in data: time = utils.read_timestamp(entry[0], self.timezone) try: value = float(entry[1]) except: value = float('nan') if math.isnan(value) != True: series.append((time, value)) return series
def add_named_exclusion(self, exclusion_name): # try: named_exclusion = getattr(exclusions, exclusion_name) # except: # raise Exception("unknown named exclusion") for exclusion_start in named_exclusion.values(): exclusion_start = utils.read_timestamp(exclusion_start, self.timezone) exclusion_end = exclusion_start + (3600 * 24) self.add_exclusion(exclusion_start, exclusion_end) return True
def data(self, start_at=None, end_at=None, step_size=None, exclude=True): """raw data accessors, returns a list of tuples - a section of the series can be returned by supplying start_at/end_at - if no start_at or end_at is supplied, the whole series, except for exclusion periods is returned - if a step_size argument is present, data will be interpolated first """ data = self.series # capture start_at / end_at if (start_at != None) & (end_at != None): slice_data = True start_at = utils.read_timestamp(start_at, self.timezone) end_at = utils.read_timestamp(end_at, self.timezone) else: slice_data = False start_at = data[0][0] end_at = data[-1][0] # if step_size is specified, interpolate if step_size != None: output_values = numpy.arange(start_at, (end_at + 1), step_size) x_values, y_values = zip(*data) interp_vals = numpy.interp(output_values, x_values, y_values) data = zip(output_values, interp_vals) data = [(e[0], round(e[1], 2)) for e in data] # if start_at / end_at were specified, slice data if slice_data == True: data = self._slice(list(data), start_at, end_at) # add in exclusions if exclude: for exclusion in self.exclusions: data = self._exclude(list(data), exclusion) return data
def _build_output_time_series(self, start_at=None, end_at=None, step_size=900, step_count=None): """assemble prediction series: - this is the series of timestamps for which baseline values will be calculated - the prediction series is stored in a Series object to take advantage of some of the Series features - default start_at/end is training_load_series.start_at/end_at - default prediction step is 900s - step_count will trump step_size """ if start_at == None: start_at = self.training_load_series.start_at() if end_at == None: end_at = self.training_load_series.end_at() start_at = utils.read_timestamp(start_at, self.timezone) end_at = utils.read_timestamp(end_at, self.timezone) if step_count != None: duration = end_at - start_at step_size = int(float(duration) / step_count) p_data = range(start_at, end_at+1, step_size) p_data = [(v, 0) for v in p_data] return Series(p_data, self.timezone)
def add_exclusion(self, exclusion_start, exclusion_end): exclusion_start = utils.read_timestamp(exclusion_start, self.timezone) exclusion_end = utils.read_timestamp(exclusion_end, self.timezone) self.exclusions.append( (exclusion_start, exclusion_end) ) return True
def add_dr_period(self, start_at, end_at): period_start = utils.read_timestamp(start_at, self.timezone) period_end = utils.read_timestamp(end_at, self.timezone) self.dr_periods.append( (period_start, period_end) ) return True
def add_exclusion(self, exclusion_start, exclusion_end): exclusion_start = utils.read_timestamp(exclusion_start, self.timezone) exclusion_end = utils.read_timestamp(exclusion_end, self.timezone) self.exclusions.append((exclusion_start, exclusion_end)) return True