Esempio n. 1
0
 def decorated_function(*args, **kwargs):
     result = auth.identify(request)
     if 0 == result['err_no'] and result['data']:
         user = User.get(result['data'])
         if not user.can(permission):
             return jsonify(err_no=RET.AUTHERR, err_desc='权限不足')
     else:
         return jsonify(result)
     return f(*args, **kwargs)
def get_index():
    """
    数据集--列表
    :return:
    """
    local_time = time.time()
    result = auth.identify(request)
    if 0 == result['err_no'] and result['data']:
        try:
            user = User.query.filter_by(id=result['data']).first()
        except Exception as e:
            current_app.logger.error(e)
            return jsonify(commons.falseReturn(RET.DBERR, '', '查询数据库错误'))

        # try:
        #     collection = redis_store.get('my_collection_%s' % user.id)
        # except Exception as e:
        #     current_app.logger.error(e)
        #     collection = None
        # if collection:
        #     return jsonify(commons.trueReturn(collection, "OK"))

        try:
            collection = user.collections
        except Exception as e:
            current_app.logger.error(e)
            return jsonify(commons.falseReturn(RET.DBERR, '', '查询数据集信息异常'))
        if not collection:
            return jsonify(commons.falseReturn(RET.NODATA, '', '无数据集信息'))
        my_list = []
        for i in collection:
            my_list.append(i.to_dict())
        my_json = json.dumps(my_list)
        # try:
        #     redis_store.setex('my_collection_%s' % user.id, 7200, my_json)
        # except Exception as e:
        #     current_app.logger.error(e)

        try:
            request_id = request.cookies.get('session')[:36]
        except TypeError:
            request_id = {}
        time_used = int((time.time() * 1000) - int(local_time * 1000))

        resp = {
            "time_used": time_used,
            "request_id": request_id,
            "collections": json.loads(my_json)
        }
        return jsonify(commons.trueReturn(resp, "OK"))
    else:
        return jsonify(result)
Esempio n. 3
0
def get():
    """
    获取用户信息
    :return: json
    """
    result = auth.identify(request)
    if 0 == result['err_no'] and result['data']:
        user = User.get(result['data'])
        returnUser = {
            'id': user.id,
            'username': user.name,
            'email': user.email,
            'login_time': user.login_time
        }
        result = commons.trueReturn(returnUser, "请求成功")
    return jsonify(result)
 def wrapper(*args, **kwargs):
     result = auth.identify(request)
     if 0 == result['err_no'] and result['data']:
         return f(*args, **kwargs)
     else:
         return jsonify(err_no=RET.SESSIONERR, err_desc=result['err_desc'])
def collection_info(collection_id):
    """
    数据集--详情
    :return:
    """
    local_time = time.time()
    result = auth.identify(request)
    if 0 == result['err_no'] and result['data']:
        collection = user_identification(collection_id, result['data'])
        if not collection:
            return jsonify(commons.falseReturn(RET.DBERR, '', '不存在的数据集'))
        # try:
        #     ret = redis_store.get('data_info_%s' % collection_id)
        # except Exception as e:
        #     current_app.logger.error(e)
        #     ret = None
        # if ret:
        #     current_app.logger.info('hit redis personage detail info')
        #     return '{"err_no":"0","err_desc":"OK","data":%s}' % ret

        try:
            collection_data = collection.to_dict()
        except Exception as e:
            current_app.logger.error(e)
            return jsonify(
                commons.falseReturn(RET.DBERR, '', 'The query fails'))

        collection_data['images'] = len(collection.images)
        versions = {}
        average_number = 0
        width = 0
        height = 0
        if collection.versions:
            for i in collection.versions:
                if 2 == collection.type:
                    versions[i.name] = {
                        "count": len(i.images),
                        "average_number": i.average_number,
                        "mean_size": i.mean_size
                    }
                    average_number += i.average_number
                    width += float(str(i.mean_size).split('*')[0])
                    height += float(str(i.mean_size).split('*')[1])
                else:
                    versions[i.name] = {"count": len(i.images)}
            if 2 == collection.type:
                collection_data.update(versions=versions,
                                       average_number=average_number,
                                       mean_size="{}*{}".format(
                                           width / len(collection.versions),
                                           height / len(collection.versions)))
            else:
                collection_data['versions'] = versions
        label = Label.query.filter_by(collection_id=collection_id).all()
        labels = {}
        if label:
            collection_data['label_num'] = len(label)
            for i in label:
                labels[int(i.label_id)] = [i.name, i.count]
            collection_data['labels'] = labels
        collection_json = json.dumps(collection_data)
        # try:
        #     redis_store.setex('data_info_%s' % collection_id, 7200, collection_json)
        # except Exception as e:
        #     current_app.logger.error(e)
        try:
            request_id = request.cookies.get('session')[:36]
        except TypeError:
            request_id = {}
        time_used = int((time.time() * 1000) - int(local_time * 1000))
        resp = {
            "time_used": time_used,
            "request_id": request_id,
            "collections": json.loads(collection_json)
        }
        return jsonify(commons.trueReturn(resp, "OK"))
    else:
        return jsonify(result)