def do_teen_analysis(args):
    check_args(args)
    tgt_args = transfer_fields(args)

    image_id = args.get('image', None)
    assert image_id is not None, "receive none image_id in character analysis"
    uid = handle_image(image_id)

    assert jwt.decode().get('identity', None) is not None
    user = handle_user(tgt_args)

    # real analysis logic here
    # 1. call AI API to get objects in image
    # 2. calculate the locations and area info
    # 3. evaluation the mind scores based on the above info
    # 4. genearte the result
    log_id = create_cuid()
    login_dict[log_id] = user

    c_analysis = CA_Model(**tgt_args)
    c_analysis.log_id = log_id
    c_analysis.result = mock_obj.emit_ca_result()

    ar_args = {'request_type': 12, 'log_id': c_analysis.log_id}
    a_report = AR_Model(**ar_args)
    a_report.result = mock_obj.emit_report()

    c_analysis.result += a_report.result
    return c_analysis
def handle_user(tgt_args):
    user_info = jwt.decode()['identity']
    phone = user_info['identifier']
    # need to get user data from DB by phone,
    # if not exist, create new one with cuid.
    user = User_Model.query.filter_by(phone=phone).first()
    if not user:
        # add one
        with api.commit_or_abort(
                db.session, default_error_message="Failed to create a user"):
            user = User_Model(cuid=tgt_args['cuid'],
                              age=tgt_args['age'],
                              gender=tgt_args['gender'],
                              phone=phone,
                              region=tgt_args['address'],
                              client_id=user_info['req_source'],
                              reg_time=datetime.utcnow())

            db.session.add(user)

    else:
        print("get user info ....")
        print(user)
        # update the other field?

    return user
示例#3
0
 def get(self):
     try:
         token = jwt.decode()
         return response.ok(token, '')
     except Exception as e:
         print(e)