|
|
@@ -1,5 +1,8 @@
|
|
|
+import uuid, json
|
|
|
+from backend_refactor.service.video.Video3DAnalyzer import Video3DAnalyzer
|
|
|
+from db import db
|
|
|
from flask import request
|
|
|
-
|
|
|
+from db.task import Task
|
|
|
from worker.thread_pool import pool
|
|
|
from route.util import make_response
|
|
|
from flask import Blueprint
|
|
|
@@ -8,14 +11,42 @@ from service.photo import StandingPhotoAnalyzer
|
|
|
|
|
|
bp = Blueprint("analyze", __name__, url_prefix='/')
|
|
|
|
|
|
+def callback_generator(task_uuid):
|
|
|
+ def callback(status, **args):
|
|
|
+ task = Task.query.get(task_uuid)
|
|
|
+ task.status = status
|
|
|
+ if status == 'FINISHED':
|
|
|
+ task.result = json.dumps(args['result'])
|
|
|
+
|
|
|
+ db.session.add(task)
|
|
|
+ db.session.commit()
|
|
|
+
|
|
|
+ return callback
|
|
|
+
|
|
|
|
|
|
-@bp.route("analysis", methods={"POST"})
|
|
|
-def start_analysis():
|
|
|
|
|
|
+@bp.route("photos/analysis", methods=['POST'])
|
|
|
+def photo_analysis():
|
|
|
req = request.get_json()
|
|
|
+
|
|
|
+ ana = StandingPhotoAnalyzer(req['front'], req['right'])
|
|
|
|
|
|
- ana = StandingPhotoAnalyzer()
|
|
|
+ task_uuid = str(uuid.uuid4)
|
|
|
+ new_task = Task(task_uuid, 'PHOTO_STANDINGPOSE')
|
|
|
+ db.session.add(new_task)
|
|
|
+ db.session.commit()
|
|
|
|
|
|
- pool.submit(ana.analyze, (req['front'], req['right']))
|
|
|
+ pool.submit(ana.analyze, (callback_generator(task_uuid), ))
|
|
|
+
|
|
|
+ return make_response(201, "success", {'task_uuid' : task_uuid})
|
|
|
+
|
|
|
+@bp.route("videos/analysis", methods=['POST'])
|
|
|
+def video_analysis():
|
|
|
+ req = request.get_json()
|
|
|
+
|
|
|
+ ana_3d = Video3DAnalyzer()
|
|
|
|
|
|
- return make_response(201, "success", {})
|
|
|
+ task_uuid = str(uuid.uuid4)
|
|
|
+ new_task = Task(task_uuid, req['type'])
|
|
|
+ db.session.add(new_task)
|
|
|
+ db.session.commit()
|