class CamerasList(Resource): model = getModel("CameraList", api) @api.response(200, "Success", model) def get(self): """ Получить список камер """ cameraPath = os.path.join(cfg.UPLOAD_FOLDER) cameraList = cameraManager.listCameras(request.args) def addLocationToCameras(): index = next((i for i, camera in enumerate(cameraList) if camera['name'] == str(cameraPath)), None) if index is not None: cameraList[index]['coordinates'] = cameras[cameraName][ 'coordinates'] cameraList[index]['view'] = cameras[cameraName]['view'] for cameraName in cameras: addLocationToCameras() for cameraPath in cameras: # actual = getTrapeziumPoints(cameraPath) # exprected = cameras[cameraPath]['view'] # print(np.array(actual) - np.array(exprected)) cameraList.append({ 'id': str(cameraPath), 'name': str(cameraPath), 'view': getTrapeziumPoints(cameraPath), 'coordinates': cameras[cameraPath]['coordinates'] # **cameras[cameraPath] }) return make_response({'items': cameraList}, 200)
class ImageInformation(Resource): def get(self, filename): imageInfo = imageManager.getImageByFilename(filename) if imageInfo is None: return make_response({"error": "Image not found"}, 400) objectInfo = objectManager.getObjectOnImage(imageInfo['id']) imageInfo.update({"objects": objectInfo}) return jsonify(imageInfo) model = getModel("ImageInfo", api) @api.expect(model) def post(self, filename): currentImage = imageManager.getImageByFilename(filename) if currentImage == None: return make_response( {"error": f"Image with {filename} filename not found"}, 400) imageId = currentImage['id'] if objectManager.getObjectOnImage(imageId) != []: return make_response( {"error": "Information about this image exists already"}, 400) objects = request.json['objects'] countOfObjectsIndbAPI = objectManager.getRowsCount( ) + 1 # т.к. мы только сейчас инсертим координаты for i, detected in enumerate(objects): coordinates = Coordinates(detected['coordinates']) Object = Objects_(scores=detected['scores'], type=detected['type'], imageId=imageId, coordinatesId=i + countOfObjectsIndbAPI) if detected['type'] == 'car': car = Cars(carNumber=detected['vehiclePlate'], objectId=i + countOfObjectsIndbAPI) db.session.add(car) elif detected['type'] == 'person': person = Persons(objectId=i + countOfObjectsIndbAPI) db.session.add(person) else: make_response({"error": "Undefined object"}, 400) db.session.add(coordinates) db.session.add(Object) db.session.commit() db.session.flush() socketio.emit('infoUpdated', {'data': 42}) make_response({"success": "Info updated"}, 200)
class Camera(Resource): cameraModel = getModel("Camera", api, directory="DTO", fullOutputName="CameraDto") @api.expect(cameraModel) def post(self, cameraId): """ Добавить новую камеру """ cameraDTO = request.json cameraManager.postCamera(**cameraDTO) return make_response({'operation': 'success'}, 200) model = getModel("Camera", api) @api.response(200, "Success", model) def get(self, cameraId): """ Получить информацию о камере """ cameraPath = os.path.join(cfg.UPLOAD_FOLDER, cameraId) if not os.path.exists(cameraPath): return make_response({"images": [], 'id': cameraId}, 200) lastImageDate = os.listdir(cameraPath)[-1] imgList = recursiveSearch(cameraPath) indexedImgList = [{ 'id': i, 'src': src } for i, src in enumerate(imgList)] return make_response( { 'images': indexedImgList, 'onlineDate': lastImageDate, 'id': cameraId }, 200)
class EventsLogger(Resource): eventsManager = DatabaseEvents() cameraModel = getModel("Logs", api, directory="DTO", fullOutputName='DTOLogs') @api.expect(cameraModel) def post(self): req = request.get_json() for title in req['titles']: self.eventsManager.postEvent(timestamp=req['timestamp'], title=title, cameraId=req['cameraId']) return make_response({"success": "Log created"}, 200)
class EventLogger(Resource): eventsManager = DatabaseEvents() cameraModel = getModel("Log", api, directory="DTO", fullOutputName='DTOLog') @api.expect(cameraModel) def post(self): req = request.get_json() self.eventsManager.postEvent(timestamp=req['timestamp'], title=req['title'], cameraId=req['cameraId']) return make_response({"success": "Log created"}, 200) @api.response(200, "Success", cameraModel) def get(self): stringRes = self.eventsManager.listEvents(request.args) return make_response({"data": stringRes}, 200)
class ObjectInformation(Resource): model = getModel("ObjectInfo", api) @api.response(200, "Success", model) def get(self): pass
class LatLon(Resource): model = getModel("LatLon", api) @api.response(200, "Success", model) def get(self): pass
class ImageList(Resource): model = getModel("ImageList", api) @api.response(200, "Success", model) def get(self): return make_response({'items': recursiveSearch(cfg.UPLOAD_FOLDER)}, 200)