From 30bdd1f832b577cfb11332daabc3e8f6d20590fb Mon Sep 17 00:00:00 2001 From: l_samenv Date: Tue, 27 Aug 2024 10:20:48 +0200 Subject: [PATCH] Export : added API call + fixed route issues --- client/jsFiles/SEAWebClientGraphics.js | 9 ++++++++- influxdb.py | 5 ++++- influxgraph.py | 13 ++++++++++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/client/jsFiles/SEAWebClientGraphics.js b/client/jsFiles/SEAWebClientGraphics.js index e954bbe..37f372d 100644 --- a/client/jsFiles/SEAWebClientGraphics.js +++ b/client/jsFiles/SEAWebClientGraphics.js @@ -285,7 +285,14 @@ function loadExportPopup(){ } function exportCallback(selectedVariables, startDateTimeMs, endDateTimeMs, binning=null){ - console.log(selectedVariables, startDateTimeMs, endDateTimeMs, binning); + + let binningParam = "None"; + if (binning !== null) + binningParam = binning + let exportURL = "http://" + hostPort + "/export?time=" + startDateTimeMs/1000 + "," + endDateTimeMs/1000 + "&variables=" + selectedVariables + "&interval=" + binningParam + "&id=" + clientID + let a = document.createElement('a'); + a.href = exportURL + a.click() } let graphs = (function (){ diff --git a/influxdb.py b/influxdb.py index a9116ef..a0c36d4 100644 --- a/influxdb.py +++ b/influxdb.py @@ -197,7 +197,10 @@ class InfluxDataGetter: data_frame_last_known = self._db.query_data_frame(query_last_known) row_to_insert = None for index, row in data_frame_last_known.iterrows(): - if row_to_insert == None or row["timestamp"] > row_to_insert["timestamp"]: + try: #needed because row_to_insert == None is not possible + if row_to_insert.empty or row["timestamp"] > row_to_insert["timestamp"]: + row_to_insert = row + except: row_to_insert = row try: if not row_to_insert.empty : diff --git a/influxgraph.py b/influxgraph.py index 248130b..b71737d 100644 --- a/influxgraph.py +++ b/influxgraph.py @@ -176,12 +176,19 @@ class InfluxGraph: Returns : io.BytesIO : an BytesIO object containing the dataframe to retrieve """ - df = self.influx_data_getter.get_curves_data_frame(variables, time, interval) + + time = [float(t) for t in time.split(',')] + start, end = self.get_abs_time(time) + start, end = int(start), int(end) + + queried_variables = variables.split(',') + if interval != "None" : interval = self.milliseconds_to_nano(int(interval)) + + df = self.influx_data_getter.get_curves_data_frame(queried_variables, [start, end], interval) mem = io.BytesIO() - mem.write(bytes(df.to_csv(sep="\t", index=False), "utf-8")) + df.to_csv(mem, sep="\t", index=False) mem.seek(0) - return mem def graphpoll(self):