|
@@ -125,20 +125,38 @@ class InfluxdbHandler:
|
|
return self.query_to_dataframe(query)
|
|
return self.query_to_dataframe(query)
|
|
|
|
|
|
def insert_dataframe(self, dataframe: pd.DataFrame,
|
|
def insert_dataframe(self, dataframe: pd.DataFrame,
|
|
|
|
+ tag_columns: list[str] = None,
|
|
batch_size: int = 10000,
|
|
batch_size: int = 10000,
|
|
time_precision: str = 'u'):
|
|
time_precision: str = 'u'):
|
|
"""
|
|
"""
|
|
- :param dataframe: DESCRIPTION
|
|
|
|
|
|
+ Writes each column of the dataframe which is not
|
|
|
|
+ in tag_columns as a separate measurement to the database.
|
|
|
|
+
|
|
|
|
+ Tag columns are put as tags to each measurement.
|
|
|
|
+
|
|
|
|
+ The dataframe has to have a datatime index!
|
|
|
|
+
|
|
|
|
+ :param dataframe: dataframe to write to the database
|
|
:type dataframe: pd.DataFrame
|
|
:type dataframe: pd.DataFrame
|
|
- :return: DESCRIPTION
|
|
|
|
- :rtype: TYPE
|
|
|
|
-
|
|
|
|
|
|
+ :param tag_columns: column names to be used as tags
|
|
|
|
+ :type tag_columns: list
|
|
|
|
+ :param betch_size:
|
|
|
|
+ :type batch_size: int
|
|
|
|
+ :param time_precision:
|
|
|
|
+ :type tiime_precision: str
|
|
"""
|
|
"""
|
|
- for column in dataframe.columns:
|
|
|
|
|
|
+
|
|
|
|
+ tags = {col: dataframe[col] for col in tag_columns}
|
|
|
|
+
|
|
|
|
+ measurement_columns = [c for c in dataframe.columns
|
|
|
|
+ if c not in tag_columns]
|
|
|
|
+
|
|
|
|
+ for column in measurement_columns:
|
|
try:
|
|
try:
|
|
self.client.write_points(
|
|
self.client.write_points(
|
|
dataframe=dataframe[column].to_frame(),
|
|
dataframe=dataframe[column].to_frame(),
|
|
measurement=column,
|
|
measurement=column,
|
|
|
|
+ tags=tags,
|
|
protocol='line',
|
|
protocol='line',
|
|
batch_size=batch_size,
|
|
batch_size=batch_size,
|
|
time_precision=time_precision)
|
|
time_precision=time_precision)
|