def get(self, wifi_name): response = self.geo_repository.get_info_from_wifi(wifi_name) print(response) if response: return Response.success(response) return Response.error(GENERIC)
def post(self): args = business_rule_parser.parse_args() # Get BusinessRule arguments if BusinessRuleValidator.is_name_valid(args["name"]): name = args["name"] response = self.repository.get_business_rule(name) if response: return Response.error(EXISTS_ID) else: return Response.error(FIELD_NOT_VALID) if BusinessRuleValidator.is_query_valid(args["query"]): query = args["query"] else: return Response.error(FIELD_NOT_VALID) if BusinessRuleValidator.is_executing_valid(args["executing"]): executing = args["executing"] else: executing = True business_rule = BusinessRule(name=name, query=query, executing=executing) result = self.repository.add_business_rule(business_rule) if result: return Response.success({"name": result}) return Response.error(GENERIC)
def get(self, ip): response = self.geo_repository.get_info_from_ip(ip) print(response) if response: return Response.success(response.json()) return Response.error(GENERIC)
def post(self): args = location_parser.parse_args() # Get Location arguments if LocationValidator.is_name_valid(args["name"]): name = args["name"] response = self.repository.get_location(name) if response: return Response.error(EXISTS_ID) else: return Response.error(FIELD_NOT_VALID) if LocationValidator.is_latlng_valid(args["latlng"]): latlng = args["latlng"] else: latlng = None location = Location(name=name, latlng=latlng) result = self.repository.add_location(location) if result: return Response.success({"name": result}) return Response.error(GENERIC)
def get(self): response = self.repository.get_all_business_rules() return Response.success([ translator.business_rule_translator(business_rule) for business_rule in response ])
def post(self): raw_gnss_args = location_parser.parse_args() user_file = raw_gnss_args["user_file"] user_location_from_file = self.geo_repository.get_locations_from_gnss(user_file) return Response.success(user_location_from_file)
def get(self, location_name): response = self.repository.get_location(location_name) if response: return Response.success( translator.location_translator(response)) return Response.error(NOT_EXISTS_ID)
def get(self, data_type_name): response = self.repository.get_data_type(data_type_name) if response: return Response.success(response) return Response.error(NOT_EXISTS_ID)
def put(self, device_name): args = device_parser.parse_args() response = self.repository.get_device(device_name) if response is None: return Response.error(NOT_EXISTS_ID) # Get Device arguments if DeviceValidator.is_name_valid(args["name"]): name = args["name"] else: return Response.error(FIELD_NOT_VALID) if DeviceValidator.is_category_valid(args["category"]): category = args["category"] else: return Response.error(FIELD_NOT_VALID) if DeviceValidator.is_location_valid(args["location"]): location = args["location"] else: return Response.error(FIELD_NOT_VALID) device = {"name": name, "category": category, "location": location} response = self.repository.update_device(device_name, device) if response: return Response.success({"name": response}) return Response.error(GENERIC)
def put(self, location_name): args = location_parser.parse_args() # Get Location arguments if LocationValidator.is_name_valid(args["name"]): name = args["name"] response = self.repository.get_location(name) if response is None: return Response.error(NOT_EXISTS_ID) else: return Response.error(FIELD_NOT_VALID) if LocationValidator.is_latlng_valid(args["latlng"]): latlng = args["latlng"] else: latlng = None location = { "name": name, "latlng": latlng, } response = self.repository.update_location(location_name, location) if response: return Response.success({"name": response}) return Response.error(GENERIC)
def post(self): args = device_category_parser.parse_args() # Get DeviceCategory arguments if DeviceCategoryValidator.is_name_valid(args["name"]): name = args["name"] response = self.repository.get_device_category(name) if response: return Response.error(EXISTS_ID) else: return Response.error(FIELD_NOT_VALID) if DeviceCategoryValidator.is_data_type_valid(args["data_type"]): data_type = args["data_type"] else: return Response.error(FIELD_NOT_VALID) device_category = DeviceCategory(name=name, data_type=data_type) result = self.repository.add_device_category(device_category) if result: return Response.success({"name": result}) return Response.error(GENERIC)
def get(self): response = self.repository.get_all_device_categories() return Response.success([ translator.device_category_translator(device_category) for device_category in response ])
def put(self, device_category_name): args = device_category_parser.parse_args() response = self.repository.get_device_category( device_category_name) if response is None: return Response.error(NOT_EXISTS_ID) # Get DeviceCategory arguments if DeviceCategoryValidator.is_name_valid(args["name"]): name = args["name"] else: return Response.error(FIELD_NOT_VALID) if DeviceCategoryValidator.is_data_type_valid(args["data_type"]): data_type = args["data_type"] else: return Response.error(FIELD_NOT_VALID) device = {"name": name, "data_type": data_type} response = self.repository.update_device_category( device_category_name, device) if response: return Response.success({"name": response}) return Response.error(GENERIC)
def put(self, entry_id=None): args = entry_parser.parse_args() response = self.api_repository.get_entry(entry_id) if not response: return Response.error(NOT_EXISTS_ID) # Get Entry arguments if validator.is_value_valid(args["value"]): value = args["value"] else: return Response.error(FIELD_NOT_VALID) if validator.is_date_valid(args["date"]): date = args["date"] else: return Response.error(FIELD_NOT_VALID) entry = { "value": value, "date": date } response = self.api_repository.update_entry(entry_id, entry) if response: return Response.success({"internal_id": response}) return Response.error(GENERIC)
def get(self): response = self.repository.get_all_locations() return Response.success([ translator.location_translator(location) for location in response ])
def get(self, business_rule_name): response = self.repository.get_business_rule(business_rule_name) if response: return Response.success( translator.business_rule_translator(response)) return Response.error(NOT_EXISTS_ID)
def delete(self, entry_id=None): response = self.api_repository.get_entry(entry_id) if response: result = self.api_repository.delete_entry(entry_id) if result: return Response.success({"internal_id": result}) return Response.error(NOT_EXISTS_ID)
def post(self): args = object_parser.parse_args() try: self.repository.execute_response(args["data"]) return Response.success(args["data"]) except (AttributeError, ValueError) as err: logger.error(err) return Response.error()
def get(self, device_category_name): response = self.repository.get_device_category( device_category_name) if response: return Response.success( translator.device_category_translator(response)) return Response.error(NOT_EXISTS_ID)
def get(self, device_name): response = self.repository.get_device(device_name) if response is None: return Response.error(NOT_EXISTS_ID) response = self.repository.get_events_for_device(device_name) return Response.success( [translator.event_translator(event) for event in response])
def delete(self, location_name): response = self.repository.get_location(location_name) if response is None: return Response.error(NOT_EXISTS_ID) result = self.repository.delete_location(location_name) if result: return Response.success({"name": result}) return Response.error(GENERIC)
def delete(self, business_rule_name): response = self.repository.get_business_rule(business_rule_name) if response is None: return Response.error(NOT_EXISTS_ID) result = self.repository.delete_business_rule(business_rule_name) if result: return Response.success({"name": result}) return Response.error(GENERIC)
def post(self): args = event_parser.parse_args() # Get Event arguments if EventValidator.is_device_name_valid(args["device_name"]): device_name = args["device_name"] device = self.repository.get_device(device_name) if not device: return Response.error(NOT_EXISTS_DEVICE) else: return Response.error(FIELD_NOT_VALID) if EventValidator.is_value_valid(args["value"]): value = args["value"] else: return Response.error(FIELD_NOT_VALID) if EventValidator.is_date_valid(args["datetime"]): datetime = args["datetime"] else: return Response.error(FIELD_NOT_VALID) device_category_name = device.category if device_category_name is None: return Response.error(NOT_DEVICE_CATEGORY) device_category = self.repository.get_device_category( device_category_name) if device_category is None: return Response.error(NOT_DEVICE_CATEGORY) device_category_data_type = device_category.data_type if device_category_data_type is None: return Response.error(NOT_DEVICE_CATEGORY) event = None if device_category_data_type == DataTypeEnum.EventA: event = EventA(device_name=device_name, value=value, datetime=datetime) elif device_category_data_type == DataTypeEnum.EventB: event = EventB(device_name=device_name, value=value, datetime=datetime) if event is None: return Response.error(GENERIC) result = self.repository.add_event(event) if result: return Response.success({"id": result}) return Response.error(GENERIC)
def delete(self, event_id): response = self.repository.get_event(event_id) if response is None: return Response.error(NOT_EXISTS_ID) result = self.repository.delete_event(event_id) if result: return Response.success({"id": result}) return Response.error(GENERIC)
def delete(self, device_category_name): response = self.repository.get_device_category( device_category_name) if response is None: return Response.error(NOT_EXISTS_ID) response = self.repository.get_devices_with_device_category( device_category_name) if response: return Response.error(DEVICE_CATEGORY_HAS_DEVICE) result = self.repository.delete_device_category( device_category_name) if result: return Response.success({"name": result}) return Response.error(GENERIC)
def post(self): args = location_parser.parse_args() gps_latlon = args["gps_latlon"] ip_address = args["ip_address"] wifi_ssid = args["wifi_ssid"] user_file = args["user_file"] print("Obtaining IP Locations") ip_locations = self.geo_repository.get_locations_from_ip(ip_address) print(f"IP Locations: {ip_locations}") print("Obtaining WiFi SSID locations") wifi_locations = self.geo_repository.get_locations_from_wifi(wifi_ssid) print(f"WiFi SSID Locations: {wifi_locations}") print("Obtaining GNSS location") gnss_location = self.geo_repository.get_locations_from_gnss(user_file) print(f"GNSS Location: {gnss_location}") score_ip = self.geo_repository.get_ip_scores(ip_locations, gps_latlon) score_wifi = self.geo_repository.get_wifi_scores(wifi_locations, gps_latlon) score_gnss = self.geo_repository.get_gnss_score(gnss_location, gps_latlon) return Response.success({ "info": { "info": f"Score obtained for location {gps_latlon}", "help": "Score between 0 and 1 (max). From correlating the different inputs " "given by the user", "available_inputs": ["gps, gnss, ip, wifi"] }, "gnss": { "locations": [gnss_location], "score": score_gnss }, "ip": { "locations": ip_locations, "score": score_ip }, "wifi": { "locations": wifi_locations, "score": score_wifi } })
def post(self): args = entry_parser.parse_args() # Get Entry arguments if validator.is_value_valid(args["value"]): value = args["value"] else: return Response.error(FIELD_NOT_VALID) if validator.is_date_valid(args["date"]): date = args["date"] else: return Response.error(FIELD_NOT_VALID) entry = Entry(value=value, date=date) result = self.api_repository.add_entry(entry) if result: return Response.success({"internal_id": result}) return Response.error(GENERIC)
def put(self, business_rule_name): args = business_rule_parser.parse_args() response = self.repository.get_business_rule(business_rule_name) if response is None: return Response.error(NOT_EXISTS_ID) # Get BusinessRule arguments if BusinessRuleValidator.is_name_valid(args["name"]): name = args["name"] response = self.repository.get_business_rule(name) if response is None: return Response.error(EXISTS_ID) else: return Response.error(FIELD_NOT_VALID) if BusinessRuleValidator.is_query_valid(args["query"]): query = args["query"] else: return Response.error(FIELD_NOT_VALID) if BusinessRuleValidator.is_executing_valid(args["executing"]): executing = args["executing"] else: executing = True business_rule = { "name": name, "query": query, "executing": executing } response = self.repository.update_business_rule( business_rule_name, business_rule) if response: return Response.success({"name": response}) return Response.error(GENERIC)
def post(self): args = device_parser.parse_args() # Get Device arguments if DeviceValidator.is_name_valid(args["name"]): name = args["name"] response = self.repository.get_device(name) if response: return Response.error(EXISTS_ID) else: return Response.error(FIELD_NOT_VALID) if DeviceValidator.is_category_valid(args["category"]): category = args["category"] response = self.repository.get_device_category(category) if response is None: return Response.error(NOT_DEVICE_CATEGORY) else: return Response.error(FIELD_NOT_VALID) if DeviceValidator.is_location_valid(args["location"]): location = args["location"] response = self.repository.get_location(location) if response is None: return Response.error(NOT_EXISTS_LOCATION) else: location = None device = Device(name=name, category=category, location=location) result = self.repository.add_device(device) if result: return Response.success({"name": result}) return Response.error(GENERIC)
def get(self): response = self.repository.get_all_data_types() return Response.success(response)