def update_garbage_can_contents(): """route: /garbage/update POST: Update existing garbage bin details params: company_id, req_id, latitude, longitude, percentage_filled, predict_full, volume """ company_id = str(request.data.get('company_id', '')) req_id = str(request.data.get('req_id', '')) percentage_filled = str(request.data.get('percentage_filled', '0.0')) latitude = str(request.data.get('latitude', '')) longitude = str(request.data.get('longitude', '')) volume = str(request.data.get('volume', '')) predict_full = str(request.data.get('predict_full', '0')) print("check: "+str(Company.check_if_exists(company_id))) print("check: "+company_id) print(request.data) if company_id and req_id and percentage_filled and latitude and longitude and volume and Company.check_if_exists(company_id): grbg_status = GarbageStatus() grbg_status.company_id = company_id grbg_status.garbage_can_id = req_id grbg_status.volume = volume grbg_status.completion = float(percentage_filled) if grbg_status.completion >= 0.8: grbg_status.is_full = True grbg_status.location = [float(latitude), float(longitude)] if predict_full == '1' and grbg_status.completion < 0.8: grbg_status.predict_full = True else: grbg_status.predict_full = False grbg_status.save() return common.to_json({}, "Can update successfully submitted", 200) else: return common.to_json({}, "Can update is bad. Check your parameters.", 400)
async def render_put(self, request): company_id = str(request.data.get('company_id', '')) req_id = str(request.data.get('req_id', '')) percentage_filled = str(request.data.get('percentage_filled', '0.0')) latitude = str(request.data.get('latitude', '')) longitude = str(request.data.get('longitude', '')) volume = str(request.data.get('volume', '')) predict_full = str(request.data.get('predict_full', '0')) print("check: " + str(Company.check_if_exists(company_id))) print("check: " + company_id) print(request.data) if company_id and req_id and percentage_filled and latitude and longitude and volume and Company.check_if_exists( company_id): grbg_status = GarbageStatus() grbg_status.company_id = company_id grbg_status.garbage_can_id = req_id grbg_status.volume = volume grbg_status.completion = float(percentage_filled) if grbg_status.completion >= 0.8: grbg_status.is_full = True grbg_status.location = [float(latitude), float(longitude)] if predict_full == '1' and grbg_status.completion < 0.8: grbg_status.predict_full = True else: grbg_status.predict_full = False grbg_status.save() return aiocoap.Message(code=aiocoap.CHANGED, payload=self.content)
def register_garbage_can(): """route: /garbage/register POST: Register a company garbage bin params: id: company_id, req_id, latitude, longitude, volume """ company_id = str(request.data.get('company_id', '')) req_id = str(request.data.get('req_id', '')) volume = str(request.data.get('volume', '')) latitude = (request.data.get('latitude', '')) longitude = str(request.data.get('longitude', '')) if len(company_id) > 0 and Company.check_if_exists(company_id): can = GarbageCanRequest.objects(req_id=req_id).first() if can: can.delete() Company.add_garbage_can(company_id, req_id, volume, latitude, longitude) return common.to_json({}, "Can successfully added", 200) else: return common.to_json({}, "No such can addition request", 400) else: return common.to_json({}, "No such company", 400)
async def render_put(self, request): print('PUT payload: %s' % request.payload) company_id = str(request.data.get('company_id', '')) req_id = str(request.data.get('req_id', '')) volume = str(request.data.get('volume', '')) latitude = (request.data.get('latitude', '')) longitude = str(request.data.get('longitude', '')) if len(company_id) > 0 and Company.check_if_exists(company_id): can = GarbageCanRequest.objects(req_id=req_id).first() if can: can.delete() Company.add_garbage_can(company_id, req_id, volume, latitude, longitude) self.set_content(request.payload) return aiocoap.Message(code=aiocoap.CHANGED, payload=self.content)