def moving_window(x): msec = datetime.timedelta(milliseconds=1) zero = datetime.timedelta(seconds=0) half_span = datetime.timedelta(seconds=window / 2) start = utils.normalize_time(data.index[0]) stop = utils.normalize_time(data.index[-1] + datetime.timedelta(seconds=min_grain)) # min_grain addition necessary since each bin of rolled-up data # is indexed by leftmost timestamp of bin. left = half_span if center else zero right = 2 * half_span - left - msec # msec subtraction is so we don't include right endpoint in slice. x = utils.normalize_time(x) if x - left >= start and x + right <= stop: dslice = data[x - left:x + right] if center and dslice.size % 2 == 0: return func([ func(data[x - msec - left:x - msec + right]), func(data[x + msec - left:x + msec + right]) ]) # (NOTE) atmalagon: the msec shift here is so that we have two # consecutive windows; one centered at time x - msec, # and one centered at time x + msec. We then average the # aggregates from the two windows; this result is centered # at time x. Doing this double average is a way to return a # centered average indexed by a timestamp that existed in # the input data (which wouldn't be the case for an even number # of points if we did only one centered average). else: return numpy.nan if dslice.size < min_size: return numpy.nan return func(dslice)
def process_result_value(self, value, dialect): if dialect.name == 'mysql': value = self._decimal_to_dt(value) if value is not None: return utils.normalize_time(value).replace( tzinfo=iso8601.iso8601.UTC)
def process_bind_param(self, value, dialect): if value is not None: value = utils.normalize_time(value) if dialect.name == 'mysql': return self._dt_to_decimal(value) return value
def process_bind_param(self, value, dialect): if value is not None: return utils.normalize_time(value)
def process_result_value(self, value, dialect): if dialect.name == 'mysql': value = self._decimal_to_dt(value) if value is not None: return utils.normalize_time(value).replace( tzinfo=iso8601.iso8601.UTC)
def process_bind_param(self, value, dialect): if value is not None: value = utils.normalize_time(value) if dialect.name == 'mysql': return self._dt_to_decimal(value) return value
def process_bind_param(self, value, dialect): if value is not None: return utils.normalize_time(value)