data_tools.query.DBClient#

class data_tools.query.DBClient(influxdb_org=None, influxdb_token=None, url=None)#

Bases: object

This class encapsulates a connection to an InfluxDB database.

__init__(influxdb_org=None, influxdb_token=None, url=None)#

Create a connection to the InfluxDB database.

Parameters:
  • influxdb_org – The name of the InfluxDB organization.

  • influxdb_token – The API Token to the InfluxDB database.

  • url – The URL to the InfluxDB database, default is “http://influxdb.telemetry.ubcsolar.com

Methods

__init__([influxdb_org, influxdb_token, url])

Create a connection to the InfluxDB database.

get_buckets()

Obtain the available buckets.

get_cars_in_measurement(bucket, measurement)

Obtain the different cars within a measurement and bucket.

get_fields_in_measurement(bucket, measurement)

Obtain the possible fields within a measurement and bucket.

get_measurements_in_bucket(bucket)

Obtain a list of the possible measurements within a bucket.

query_dataframe(query)

Submit a Flux query, and return the result as a DataFrame.

query_series(start, stop, field[, bucket, ...])

Query the database for a specific field, over a certain time range.

query_time_series(start, stop, field[, ...])

Query the database for a specific field, over a certain time range.

get_buckets() list[str]#

Obtain the available buckets. :return: list of available buckets

get_cars_in_measurement(bucket: str, measurement: str) list[str]#

Obtain the different cars within a measurement and bucket. :param bucket: the bucket that will be queried. Must exist. :param measurement: the measurement that will be queried. Must exist. :return:

get_fields_in_measurement(bucket: str, measurement: str) list[str]#

Obtain the possible fields within a measurement and bucket. :param bucket: the bucket that will be queried. Must exist. :param measurement: the measurement that will be queried. Must exist. :return:

get_measurements_in_bucket(bucket: str) list[str]#

Obtain a list of the possible measurements within a bucket.

Parameters:

bucket – the bucket that will be queried. Must exist.

Returns:

a list of available measurements in bucket.

query_dataframe(query: FluxQuery) DataFrame#

Submit a Flux query, and return the result as a DataFrame.

Parameters:

query (FluxQuery) – the query which will be submitted

Returns:

the resulting data as a DataFrame

query_series(start: datetime, stop: datetime, field: str, bucket: str = 'CAN_log', car: str = 'Brightside', measurement: str = None)#

Query the database for a specific field, over a certain time range. The data will be returned as a DataFrame.

Parameters:
  • start – the start time of the query as an ISO 8601-compliant string, such as “2024-06-30T23:00:00Z”.

  • stop – the end time of the query as an ISO 8601-compliant string, such as “2024-06-30T23:00:00Z”.

  • field – the field which is to be queried.

  • bucket (str) – the bucket which will be queried

  • car – the car which data is being queried for, default is “Brightside”.

Returns:

a TimeSeries of the resulting time-series data

query_time_series(start: datetime, stop: datetime, field: str, bucket: str = 'CAN_log', car: str = 'Brightside', granularity: float = 0.1, units: str = '', measurement: str = None) TimeSeries#

Query the database for a specific field, over a certain time range. The data will be processed into a TimeSeries, which has homogenous and evenly-spaced (temporally) elements. Data will be re-interpolated to have temporal granularity of granularity.

Parameters:
  • start – the start time of the query as an ISO 8601-compliant string, such as “2024-06-30T23:00:00Z”.

  • stop – the end time of the query as an ISO 8601-compliant string, such as “2024-06-30T23:00:00Z”.

  • field – the field which is to be queried.

  • bucket (str) – the bucket which will be queried

  • car – the car which data is being queried for, default is “Brightside”.

  • granularity – the temporal granularity of the resulting TimeSeries in seconds, default is 0.1s.

  • units – the units of the returned data, optional.

Returns:

a TimeSeries of the resulting time-series data