data_tools.query.InfluxDBClient#
- class data_tools.query.InfluxDBClient(influxdb_org=None, influxdb_token=None, url=None, timeout=10, temporal_localization: ~typing.Type[<data_tools.localization.temporal_localization.TemporalLocalization object at 0x754fe0479070>] | None = None, language_localization: ~typing.Type[<data_tools.localization.language_localization.LanguageLocalization object at 0x754fe83c0710>] | None = None)#
Bases:
objectThis class encapsulates a connection to an InfluxDB database.
- __init__(influxdb_org=None, influxdb_token=None, url=None, timeout=10, temporal_localization: ~typing.Type[<data_tools.localization.temporal_localization.TemporalLocalization object at 0x754fe0479070>] | None = None, language_localization: ~typing.Type[<data_tools.localization.language_localization.LanguageLocalization object at 0x754fe83c0710>] | None = 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”
timeout – The request timeout in seconds, default is 10 seconds.
temporal_localization – The type of temporal localization to use, default is TemporalLocalization.
language_localization – The type of language localization to use, default is LanguageLocalization.
Methods
__init__([influxdb_org, influxdb_token, ...])Create a connection to the InfluxDB database.
close()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.
- close()#
- 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 | CanonicalName, 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