def current(self): """ Returns the points of data in the streams closest to the current timestamp. If the current timestamp is outside of the filtered range of data, a ValueError is raised. Parameters ---------- None Returns ------- tuple The latest points of data found among all streams """ latest = [] params = self._params_from_filters() now = currently_as_ns() end = params.get("end", None) start = params.get("start", None) if (end is not None and end <= now) or (start is not None and start > now): raise ValueError( "current time is not included in filtered stream range") for s in self._streams: version = self.versions()[s.uuid] point, _ = s.nearest(now, version=version, backward=True) latest.append(point) return tuple(latest)
def test_currently_as_ns(self): """ Assert currently_as_ns returns correct value """ expected = int(datetime.datetime(2018, 1, 1, 12).timestamp() * 1e9) with freeze_time("2018-01-01 12:00:00 -0000"): assert currently_as_ns() == expected
def latest(self): """ Returns latest points of data in the streams using available filters. Note that this method will return None if no end filter is provided and point cannot be found that is less than the current date/time. Parameters ---------- None Returns ------- tuple The latest points of data found among all streams """ latest = [] params = self._params_from_filters() start = params.get("end", currently_as_ns()) for s in self._streams: version = self.versions()[s.uuid] point, _ = s.nearest(start, version=version, backward=True) latest.append(point) return tuple(latest)
def test_currently_as_ns(self): """ Assert currently_as_ns returns correct value """ expected = 1514808000000000000 with freeze_time("2018-01-01 12:00:00 -0000"): assert currently_as_ns() == expected
def latest(self, version=0): """ Returns last point of data in the stream. Note that this method will return None if no point can be found that is less than the current date/time. Parameters ---------- None Returns ------- tuple The last data point in the stream and the version of the stream the value was retrieved at (tuple(RawPoint, int)). """ start = currently_as_ns() return self.nearest(start, version=version, backward=True)
def current(self, version=0): """ Returns the point that is closest to the current timestamp, e.g. the latest point in the stream up until now. Note that no future values will be returned. Returns None if errors during lookup or there are no values before now. Parameters ---------- version : int, default: 0 Specify the version of the stream to query; if zero, queries the latest stream state rather than pinning to a version. Returns ------- tuple The last data point in the stream up until now and the version of the stream the value was retrieved at (tuple(RawPoint, int)). """ start = currently_as_ns() return self.nearest(start, version, backward=True)