def test_from_proto_creates_rawpoint(self): """ Assert from_proto creates a new instance of RawPoint """ proto = RawPointProto(time=1, value=10) point = RawPoint.from_proto(proto) assert isinstance(point, RawPoint)
def test_from_proto(self): """ Assert from_proto creates a correct object """ proto = RawPointProto(time=1, value=10) point = RawPoint.from_proto(proto) assert point.time == proto.time assert point.value == proto.value
def values(self, start, end, version=0): """ Read raw values from BTrDB between time [a, b) in nanoseconds. RawValues queries BTrDB for the raw time series data points between `start` and `end` time, both in nanoseconds since the Epoch for the specified stream `version`. Parameters ---------- start : int or datetime like object The start time in nanoseconds for the range to be queried. (see :func:`btrdb.utils.timez.to_nanoseconds` for valid input types) end : int or datetime like object The end time in nanoseconds for the range to be queried. (see :func:`btrdb.utils.timez.to_nanoseconds` for valid input types) version: int The version of the stream to be queried Returns ------ list Returns a list of tuples containing a RawPoint and the stream version (list(tuple(RawPoint,int))). Notes ----- Note that the raw data points are the original values at the sensor's native sampling rate (assuming the time series represents measurements from a sensor). This is the lowest level of data with the finest time granularity. In the tree data structure of BTrDB, this data is stored in the vector nodes. """ materialized = [] start = to_nanoseconds(start) end = to_nanoseconds(end) point_windows = self._btrdb.ep.rawValues(self._uuid, start, end, version) for point_list, version in point_windows: for point in point_list: materialized.append((RawPoint.from_proto(point), version)) return materialized
def nearest(self, time, version, backward=False): """ Finds the closest point in the stream to a specified time. Return the point nearest to the specified `time` in nanoseconds since Epoch in the stream with `version` while specifying whether to search forward or backward in time. If `backward` is false, the returned point will be >= `time`. If backward is true, the returned point will be < `time`. The version of the stream used to satisfy the query is returned. Parameters ---------- time : int or datetime like object The time (in nanoseconds since Epoch) to search near (see :func:`btrdb.utils.timez.to_nanoseconds` for valid input types) version : int Version of the stream to use in search backward : boolean True to search backwards from time, else false for forward Returns ------- tuple The closest data point in the stream and the version of the stream the value was retrieved at (tuple(RawPoint, int)). """ try: rp, version = self._btrdb.ep.nearest(self._uuid, to_nanoseconds(time), version, backward) except BTrDBError as exc: if exc.code != 401: raise return None return RawPoint.from_proto(rp), version