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()
Пример #2
0
 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)
Пример #4
0
 def to_point(v):
   t = energykit.Time.from_ms(v[0])
   return energykit.DataPoint(t, self.stream._to_value(v[1], t))
Пример #5
0
 def get_datapoint(self):
     return energykit.DataPoint(self._time, self._value)