diff --git a/influxdb.py b/influxdb.py index 2a16e52..6166d3b 100644 --- a/influxdb.py +++ b/influxdb.py @@ -472,7 +472,7 @@ class InfluxDataGetter: variable (str) : the name (Influx) of the variable we want the values of. parameter (str) : the parameter of the variable to get the values from time ([(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 nanoseconds) + interval (int) : the interval (resolution) of the values to get (in milliseconds) Returns : [[(int), (float)]] : an array of pairs (also arrays), the first value being the Unix timestamp in second (x), the seconds being the value (y) @@ -483,7 +483,7 @@ class InfluxDataGetter: |> range(start: {time[0]}, stop: {time[1] + 1}) |> filter(fn : (r) => r._measurement == "{variable}") |> filter(fn : (r) => r._field == "{parameter+"_float"}") - {"|> aggregateWindow(every: duration(v:"+str(interval)+"), fn: last, createEmpty:false, timeDst:"+chr(34)+"binning_time"+chr(34)+")" if interval else ""} + {"|> aggregateWindow(every: duration(v:"+str(self._milliseconds_to_nanoseconds(interval))+"), fn: last, createEmpty:false, timeDst:"+chr(34)+"binning_time"+chr(34)+")" if interval else ""} |> keep(columns: ["_time","_value","expired"{", "+chr(34)+"binning_time"+chr(34) if interval else ""}]) |> yield(name: "res") """ @@ -648,4 +648,7 @@ class InfluxDataGetter: return res def _seconds_to_nanoseconds(self, seconds): - return seconds * 1000000000 \ No newline at end of file + return seconds * 1000000000 + + def _milliseconds_to_nanoseconds(self, milliseconds): + return milliseconds * 1000000 \ No newline at end of file diff --git a/influxgraph.py b/influxgraph.py index 1a5e32c..63ec4bc 100644 --- a/influxgraph.py +++ b/influxgraph.py @@ -34,15 +34,6 @@ class InfluxGraph: self.lastvalues = {} self.variables = {} # name:label - def milliseconds_to_nano(self, milliseconds): - """ - Converts milliseconds to nanoseconds - Parameters: - milliseconds (int) - Returns : - int - """ - return milliseconds*1000000 def get_abs_time(self, times): """ @@ -83,7 +74,7 @@ class InfluxGraph: 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. They are treated as relative from now if they are lesser than one year. - interval (str) : the interval (resolution) of the values to get (string in seconds) + interval (str) : the interval (resolution) of the values to get (string in milliseconds) Returns : {"type":"graph-draw", "reduced":(bool), "graph":{(str):[[(int),(float)]]}} : a dictionnary with its "graph-draw" type (so it can be processed by the client), a "reduced" value @@ -97,7 +88,7 @@ class InfluxGraph: queried_variables = variables.split(',') self.livemode = self.ACTUAL if end+10 >= now else self.HISTORICAL logging.info('LIVE %g %g %d %d', end, now, end >= now, self.livemode) - if interval : interval = self.milliseconds_to_nano(int(interval)) + if interval : interval = int(interval) result = self.influx_data_getter.get_curves_in_timerange(queried_variables, queried_time_range, interval) self.complete_to_end(result, min(end, now))