Added /export route

This commit is contained in:
l_samenv
2024-08-26 13:25:41 +02:00
parent c706b78d07
commit f469208c0d
2 changed files with 48 additions and 0 deletions

View File

@ -3,6 +3,7 @@ import time
import logging
from colors import assign_colors_to_curves
import json
import io
class InfluxGraph:
"""
@ -162,6 +163,27 @@ class InfluxGraph:
self.livemode = self.LIVE
return dict(type='accept-graph', live=True)
def w_export(self, variables, time, interval):
"""
Returns the bytes of a dataframe with the curves given by variables in the time range "time"
Called when the route /export is reached.
Parameters :
variables (str) : a comma separataed value string of variable names (influx names) to retrieve
time (str) : a commma separated value string (range) of seconds.
interval (str) : the interval (resolution) of the values to get (string in seconds)
Returns :
io.BytesIO : an BytesIO object containing the dataframe to retrieve
"""
df = self.influx_data_getter.get_curves_data_frame(variables, time, interval)
mem = io.BytesIO()
mem.write(bytes(df.to_csv(sep="\t", index=False), "utf-8"))
mem.seek(0)
return mem
def graphpoll(self):
"""
Polls the last known values for all the available variables, and returns only those whose polled value is more recent than the nost recent displayed one.