def get(self): args = self.parser.parse_args() sensor, sensor_name, sensor_attribute = None, None, None if 'sensor' in args and args['sensor'] is not None: sensor = args['sensor'] if sensor != '': if sensor == 'all': sensors = Sensor.get_all() return [a.json() for a in sensors], 200 else: return (Sensor.get_by_id(sensor)).json(), 200 if 'sensorname' in args and args['sensorname'] is not None: sensor_name = args['sensorname'] if sensor_name != '': _sensors = sensor_name.split(',') _by_name = Sensor.get_by_name_in(_sensors) return [a.json() for a in _by_name], 200 if 'sensorattribute' in args and args['sensorattribute'] is not None: sensor_attribute = args['sensorattribute'] if sensor_attribute != '': _sen_attrs_ids = sensor_attribute.split(',') _sen_attrs = SensorAttribute.get_by_id_in(_sen_attrs_ids) attrs_ids = [_id.a_id for _id in _sen_attrs] _attributes = Attributes.get_by_id_in(attrs_ids) return [a.json() for a in _attributes], 200 return { "error": "error occured while processing request" }, 400
def get(self): args = self.parser.parse_args() theme, subtheme, attribute_data, sensor, sensor_name, sensor_attribute, attributes, sensorid, n_predictions, predictions, grouped, harmonising_method, per_sensor, freq = None, None, None, None, None, None, [], None, 100, None, None, None, None, '1H' if 'theme' in args: theme = args['theme'] if 'subtheme' in args: subtheme = args['subtheme'] if 'attributedata' in args: attribute_data = args['attributedata'] if 'attribute' in args and args['attribute'] is not None: _attributes = args['attribute'] if _attributes != '': attributes = _attributes.split(',') if 'sensor' in args and args['sensor'] is not None: sensor = args['sensor'] if sensor != '': if sensor == 'all': sensors = Sensor.get_all() return [a.json() for a in sensors], 200 else: return (Sensor.get_by_id(sensor)).json(), 200 if 'sensorname' in args and args['sensorname'] is not None: sensor_name = args['sensorname'] if sensor_name != '': _sensors = sensor_name.split(',') _by_name = Sensor.get_by_name_in(_sensors) return [a.json() for a in _by_name], 200 if 'sensorattribute' in args and args['sensorattribute'] is not None: sensor_attribute = args['sensorattribute'] if sensor_attribute != '': _sen_attrs_ids = sensor_attribute.split(',') _sen_attrs = SensorAttribute.get_by_id_in(_sen_attrs_ids) attrs_ids = [_id.a_id for _id in _sen_attrs] _attributes = Attributes.get_by_id_in(attrs_ids) return [a.json() for a in _attributes], 200 if 'grouped' in args: grouped = args['grouped'] if 'harmonising_method' in args: harmonising_method = args['harmonising_method'] if 'per_sensor' in args: per_sensor = args['per_sensor'] if 'freq' in args: freq = args['freq'] if 'predictions' in args: predictions = args['predictions'] if predictions >=100: predictions = 100 if 'n_predictions' in args: n_predictions = args['n_predictions'] if 'sensorid' in args: sensorid = args['sensorid'] if theme is None and subtheme is None \ and len(attributes) == 0 and attribute_data is None \ and sensor is None and sensor_name is None and sensor_attribute is None: themes = Theme.get_all() return [a.json() for a in themes], 200 if attribute_data is not None: global LIMIT, OFFSET data = None operation = None if 'limit' in args and args['limit'] is not None: LIMIT = args['limit'] if 'offset' in args and args['offset'] is not None: OFFSET = args['offset'] if 'operation' in args and args['operation'] is not None: operation = args['operation'] if ('fromdate' in args and args['fromdate'] is not None and 'todate' in args and args['todate'] is not None): data = self.get_attribute_data(attribute_data, LIMIT, OFFSET, args['fromdate'], args['todate'], operation) if predictions: data.append(self.get_predictions(attribute_table = data[0]["Attribute_Table"], sensor_id = sensorid, n_pred = n_predictions)) else: if grouped: if harmonising_method: data = self.get_attribute_data(attribute_data, LIMIT, OFFSET, operation=operation) data = request_harmonised_data(data, harmonising_method=harmonising_method) else: data = self.get_attribute_data(attribute_data, LIMIT, OFFSET, operation=operation) data = request_grouped_data(data, per_sensor=per_sensor, freq=freq) else: data = self.get_attribute_data(attribute_data, LIMIT, OFFSET, operation=operation) if predictions: #### Ceck for data if data[0]["Total_Records"] != 0: #### Check for non numeric data if is_number(data[0]["Attribute_Values"][0]["Value"]): data.append(self.get_predictions(attribute_table = data[0]["Attribute_Table"], sensor_id = sensorid, n_pred = n_predictions)) else: print("Cannot predict non-numeric data") pass else: pass return data, 200 if attributes: _attrs = [] attr = Attributes.get_by_name_in(attributes) for a in attr: _attrs.append(a.json()) return _attrs, 200 if subtheme is not None and subtheme != '': attributes = Attributes.get_by_sub_theme_id(subtheme) return [a.json() for a in attributes], 200 if theme is not None and theme != '': subthemes = SubTheme.get_by_theme_id(theme) return [a.json() for a in subthemes], 200 return { "error": "error occured while processing request" }, 400