I’m writing values to an Influx database with
def write_to_influx(dataPointID, value):
df = pd.DataFrame(data=[value],index=pd.date_range(start=datetime.utcnow(), periods=1, freq='S'), columns=['value'])
client.write_points(df, dataPointID, database="mydb")
I stole this method from another script, when actually I have problems grasping this. In the docs it says
write_points(points, time_precision=None, database=None, retention_policy=None, tags=None, batch_size=None, protocol=u'json', consistency=None)
Parameters:
points (list of dictionaries, each dictionary represents a point) – the list of points to be written in the database
But with write_to_influx(value_1, dataPointID_1)
, there is not just a dictionary, but an datapoint ID passed.
Analog to the method already applied and the docu description… If I would like to write multiple values to multiple datapoint IDs, should I pass a list of dictionaries AND a list of datapointIDs ? Because that does not seem to work:
def write_values_to_influx(Obj,dataPointID_list, value_list):
indexes=pd.date_range(start=datetime.utcnow().replace(tzinfo=pytz.UTC), periods=1, freq='S')
dict_list=[]
for value in value_list:
df_new= pd.DataFrame(data=[value],index=indexes)
dict_list.append(df_new)
client.write_points(dict_list, dataPointID_list, database="mydb")
Returns the error:
File "/vdp/base_functions.py", line 249, in write_values_to_influx
xyz@crVB | client.write_points(dict_list, dataPointID_list, database="mydb")
xyz@crVB | File "/usr/lib/python3.6/site-packages/influxdb/_dataframe_client.py", line 123, in write_points
xyz@crVB | numeric_precision=numeric_precision)
xyz@crVB | File "/usr/lib/python3.6/site-packages/influxdb/_dataframe_client.py", line 282, in _convert_dataframe_to_lines
xyz@crVB | dataframe = dataframe.dropna(how='all').copy()