@@ -59,7 +59,6 @@ def get(self, name):
5959 if fields :
6060 fields = fields .split (';' )
6161 original_fields = fields
62- fields = '"' + '", "' .join (fields ) + '"'
6362 else :
6463 fields = '*'
6564
@@ -75,20 +74,26 @@ def get(self, name):
7574 fields = ',' .join (allowed_fields )
7675 name = r .get ('parent:{}' .format (name ))
7776
77+ if not fields :
78+ return jsonify (responses .no_allowed_fields )
79+
7880 if resolution :
79- if fields == '*' :
80- return jsonify ('TODO: Fields are not supported with resolution' )
8181 try :
82- query = 'select mean(*) from "' + name + '" where (time>\' ' + timestamp_to_time_string (
82+ if fields is not '*' and fields :
83+ fields = '/(' + '|' .join (fields .split (',' )) + ')-*/'
84+ query = 'select mean(' + fields + ') from "' + name + '" where (time>\' ' + timestamp_to_time_string (
8385 float (start_time )) \
8486 + '\' and time<\' ' + timestamp_to_time_string (
8587 float (end_time )) + '\' )' + " GROUP BY time(" + resolution + ")"
88+ # print('\n\n' + '{s:{c}^{n}}'.format(s=' InfluxDB Query ', n=100, c='#'))
89+ # print(query)
90+ # print('#' * 100 + '\n\n')
8691 data = influx .query (query )
8792 except influxdb .exceptions .InfluxDBClientError :
8893 return jsonify (responses .resolution_high )
8994 else :
90- if fields is not '*' :
91- fields = '" ' + '", " ' .join (fields .split (',' )) + '" '
95+ if fields is not '*' and fields :
96+ fields = '/( ' + '| ' .join (fields .split (',' )) + ')-*/ '
9297 query = 'select ' + fields + ' from "' + name + '" where time>\' ' + timestamp_to_time_string (float (start_time )) \
9398 + '\' and time<\' ' + timestamp_to_time_string (float (end_time )) + '\' '
9499
@@ -104,6 +109,7 @@ def get(self, name):
104109 # print (data.raw)
105110 # print ('#' * 100 + '\n\n')
106111 response .update ({'data' : data .raw })
112+ del response ["data" ]["statement_id" ]
107113
108114 return jsonify (response )
109115
@@ -164,7 +170,10 @@ def post(self):
164170 if type (sample [key ]) is list :
165171 length = len (sample [key ])
166172 for i in range (length ):
167- sample .update ({"%s-%d" % (key , i ): sample [key ][i ]})
173+ if isinstance (sample [key ][i ], basestring ):
174+ sample .update ({"%s-%d" % (key , i ): sample [key ][i ]})
175+ else :
176+ sample .update ({"%s-%d" % (key , i ): float (sample [key ][i ])})
168177 del sample [key ]
169178 dic = {
170179 'measurement' : sensor ['sensor_id' ],
@@ -184,7 +193,9 @@ def post(self):
184193 if view_fields :
185194 fields = [field .strip () for field in view_fields .split (',' )]
186195 view_dic = dict (dic )
187- view_fields = {k : v for k , v in dic ['fields' ].items () if k in fields }
196+ # view_fields = {k: v for k, v in dic['fields'].items() if k in fields }
197+ view_fields = {k : v for k , v in dic ['fields' ].items () if k .rsplit ('-' ,1 )[0 ] in fields }
198+
188199 view_dic .update ({'fields' : view_fields })
189200 if apps [view ]:
190201 if not pubsub :
0 commit comments