Fixed same measurement with different param for export bug
This commit is contained in:
20
influxdb.py
20
influxdb.py
@ -142,7 +142,7 @@ class InfluxDataGetter:
|
|||||||
components = self._get_device_name_components(time)
|
components = self._get_device_name_components(time)
|
||||||
return "/".join(components)
|
return "/".join(components)
|
||||||
|
|
||||||
def get_curves_data_frame(self, variables, times, interval):
|
def get_curves_data_frame(self, variables, times, interval, variables_name_label_map=None):
|
||||||
"""
|
"""
|
||||||
Gets the curves for the given variables within a timerange times, as a pandas dataframe.
|
Gets the curves for the given variables within a timerange times, as a pandas dataframe.
|
||||||
All curves are on a single common time axis.
|
All curves are on a single common time axis.
|
||||||
@ -156,7 +156,7 @@ class InfluxDataGetter:
|
|||||||
variables ([(str)]) : an array of variable names (Influx) to get the curves for.
|
variables ([(str)]) : an array of variable names (Influx) to get the curves for.
|
||||||
times ([int]) : the timerange we want the values in. It consists of two values which are Unix timestamps in seconds, first included, second excluded.
|
times ([int]) : the timerange we want the values in. It consists of two values which are Unix timestamps in seconds, first included, second excluded.
|
||||||
interval (int) : the interval (resolution) of the values to get (in seconds). Allows data binning.
|
interval (int) : the interval (resolution) of the values to get (in seconds). Allows data binning.
|
||||||
|
variables_name_label_map ({(str):(str)} | None) : a dictionnary containing curve labels, indexed by INFLUX names. The corresponding label will be used in the TSV header for each variable if found, else the influx name.
|
||||||
Returns :
|
Returns :
|
||||||
pandas.DataFrame : the curves in a single pandas DataFrame
|
pandas.DataFrame : the curves in a single pandas DataFrame
|
||||||
"""
|
"""
|
||||||
@ -213,25 +213,27 @@ class InfluxDataGetter:
|
|||||||
if data_frame.empty:
|
if data_frame.empty:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
variable_df_column_name = variables_name_label_map.get(variable, variable) if not variables_name_label_map == None else variable
|
||||||
|
data_frame.rename(columns={variable_name_for_query : variable_df_column_name}, inplace=True)
|
||||||
data_frame.drop(["result", "table"], axis=1, inplace=True)
|
data_frame.drop(["result", "table"], axis=1, inplace=True)
|
||||||
data_frame.sort_values(by=["timestamp"], inplace=True)
|
data_frame.sort_values(by=["timestamp"], inplace=True)
|
||||||
data_frame.reset_index()
|
data_frame.reset_index()
|
||||||
|
|
||||||
variables_info[variable] = {}
|
variables_info[variable_df_column_name] = {}
|
||||||
variables_info[variable]["expired_ranges"] = []
|
variables_info[variable_df_column_name]["expired_ranges"] = []
|
||||||
|
|
||||||
# Identify time windows for which the curve is expired
|
# Identify time windows for which the curve is expired
|
||||||
|
|
||||||
for index, row in data_frame.iterrows():
|
for index, row in data_frame.iterrows():
|
||||||
if row["expired"] == "True":
|
if row["expired"] == "True":
|
||||||
data_frame.loc[index, variable] = NaN
|
data_frame.loc[index, variable_df_column_name] = NaN
|
||||||
variables_info[variable]["expired_ranges"].append([row["timestamp"]])
|
variables_info[variable_df_column_name]["expired_ranges"].append([row["timestamp"]])
|
||||||
elif row["expired"] == "False":
|
elif row["expired"] == "False":
|
||||||
if len(variables_info[variable]["expired_ranges"]) > 0 and len(variables_info[variable]["expired_ranges"][-1]) == 1:
|
if len(variables_info[variable_df_column_name]["expired_ranges"]) > 0 and len(variables_info[variable_df_column_name]["expired_ranges"][-1]) == 1:
|
||||||
variables_info[variable]["expired_ranges"][-1].append(row["timestamp"])
|
variables_info[variable_df_column_name]["expired_ranges"][-1].append(row["timestamp"])
|
||||||
data_frame.reset_index()
|
data_frame.reset_index()
|
||||||
data_frame.drop(["expired"], axis=1, inplace=True)
|
data_frame.drop(["expired"], axis=1, inplace=True)
|
||||||
variables_info[variable]["df"] = data_frame
|
variables_info[variable_df_column_name]["df"] = data_frame
|
||||||
res = None
|
res = None
|
||||||
non_empty_variables = list(variables_info.keys())
|
non_empty_variables = list(variables_info.keys())
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ class InfluxGraph:
|
|||||||
self.livemode = self.HISTORICAL
|
self.livemode = self.HISTORICAL
|
||||||
self.end_query = 0
|
self.end_query = 0
|
||||||
self.lastvalues = {}
|
self.lastvalues = {}
|
||||||
self.variables = []
|
self.variables = {} # name:label
|
||||||
|
|
||||||
def milliseconds_to_nano(self, milliseconds):
|
def milliseconds_to_nano(self, milliseconds):
|
||||||
"""
|
"""
|
||||||
@ -141,7 +141,7 @@ class InfluxGraph:
|
|||||||
blocks = self.influx_data_getter.get_available_variables_at_time([start_time, end_time])
|
blocks = self.influx_data_getter.get_available_variables_at_time([start_time, end_time])
|
||||||
device_name = self.influx_data_getter.get_device_name(end_time)
|
device_name = self.influx_data_getter.get_device_name(end_time)
|
||||||
# updates the self.variables attribute to keep track of the available variables
|
# updates the self.variables attribute to keep track of the available variables
|
||||||
self.variables = [variable["name"] for block in blocks for variable in block["curves"]]
|
self.variables = {variable["name"]:variable["label"] for block in blocks for variable in block["curves"]}
|
||||||
|
|
||||||
assign_colors_to_curves(blocks)
|
assign_colors_to_curves(blocks)
|
||||||
result = dict(type='var_list')
|
result = dict(type='var_list')
|
||||||
@ -185,7 +185,7 @@ class InfluxGraph:
|
|||||||
queried_variables = variables.split(',')
|
queried_variables = variables.split(',')
|
||||||
if interval != "None" : interval = int(interval)
|
if interval != "None" : interval = int(interval)
|
||||||
|
|
||||||
df = self.influx_data_getter.get_curves_data_frame(queried_variables, [start, end], interval)
|
df = self.influx_data_getter.get_curves_data_frame(queried_variables, [start, end], interval, self.variables)
|
||||||
|
|
||||||
mem = io.BytesIO()
|
mem = io.BytesIO()
|
||||||
df.to_csv(mem, sep="\t", index=False, float_format="%.15g", na_rep=nan)
|
df.to_csv(mem, sep="\t", index=False, float_format="%.15g", na_rep=nan)
|
||||||
@ -207,7 +207,7 @@ class InfluxGraph:
|
|||||||
return None
|
return None
|
||||||
now, = self.get_abs_time([0])
|
now, = self.get_abs_time([0])
|
||||||
|
|
||||||
result = self.influx_data_getter.poll_last_values(self.variables, self.lastvalues, now)
|
result = self.influx_data_getter.poll_last_values(list(self.variables.keys()), self.lastvalues, now)
|
||||||
for variable in self.lastvalues.keys():
|
for variable in self.lastvalues.keys():
|
||||||
if variable in result.keys():
|
if variable in result.keys():
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user