def value_at(self, time): result = self.source.db.view('energy_data/by_source_and_time', startkey=[self._feed_name], endkey=self._key(time)) if len(result): return self._to_point(result.first()['value']) else: return energykit.DataPoint()
def callback(change): doc = change['doc'] time = energykit.Time.from_ms(doc['timestamp']) for key in self._datastreams: if key in doc: source = self.get_stream_by_key((doc['source'], key)) value = doc[key] datapoint = energykit.DataPoint(time, value) self.publish(datapoint, source)
def _to_point(self, value): time = energykit.Time.from_json(value[self.source._at_idx]) value = value[self.source._datastream_idx[self._name]] return energykit.DataPoint(time, value)
def to_point(v): t = energykit.Time.from_ms(v[0]) return energykit.DataPoint(t, self.stream._to_value(v[1], t))
def get_datapoint(self): return energykit.DataPoint(self._time, self._value)