Datastores

Datastore Interface

class zircon.datastores.base.BaseDatastore[source]

Abstract base class defining the Datastore interface.

A Datastore is a connector to something that can store timeseries data. It provides an interface to add, remove, and access timeseries data efficiently. A single piece of information consists of a signal name, a timestamp in microseconds, and some associated data.

To be efficient, a Datastore should keep information sorted by timestamp and separated by signal name. The most important ingredient is that the most recent N points for a given signal can be retrieved in constant time.

What kind of data can be stored depends on the implementation. For example, a Datastore may accept integers, floats, strings, or any combination of them.

create_database(db_name)[source]

Create a database.

Returns:True if successful, False otherwise.
delete_database(db_name)[source]

Delete a database.

Returns:True if successful, False otherwise.
switch_database(db_name)[source]

Switch the current database.

Returns:True if successful, False otherwise.
list_databases()[source]

Return a list of databases.

list_signals()[source]

Return a list of signals in this database.

>>> datastore.list_signals()
['SIGNAL_A', 'SIGNAL_B', 'SIGNAL_C']
delete_signal(data)[source]

Delete this signal and all associated data.

Returns:True if successful, False otherwise.
insert(data)[source]

Insert data.

Parameters:data – Dictionary mapping signal names to timeseries.
Returns:True if successful, False otherwise.

Timeseries consist of an epoch timestamp in microseconds followed by some data.

>>> datastore.insert({
... 'SIGNAL_A': (
...                 (1409481110001000, 1.2),
...                 (1409481110002000, 1.5)
...             ),
... 'SIGNAL_B': (
...                 (1409481110001500, -2.1)
...             )
... })
True
get_last_points(signals, num)[source]

Return the last N points for the given signals.

Parameters:
  • signals – A list of signals.
  • num – The number of points to fetch.
Returns:

A dictionary mapping signals to points.

>>> signal = datastore.get_last_points(['SIGNAL_A'], 10)
{'SIGNAL_A': [[1409481110001000, 1.2], [1409481110002000, 1.5], ...]}
get_timeseries(signals, t0, t1, dt, aggregate, limit)[source]

Return a uniformly sampled time series in a given time interval. Can downsample, aggregate, and limit the result.

Aggregate functions depend on the implementation, but should at least include ‘mean’, ‘first’, ‘last’, ‘min’, and ‘max’.

Parameters:
  • signals – A list of signals.
  • t0 – Start time in microseconds.
  • t1 – End time in microseconds.
  • dt – Sample time in microseconds
  • aggregate – Aggregate function to apply.
  • limit – Maximum number of points per signal to return.
Returns:

A dictionary mapping signals to points.