Ejemplo n.º 1
0
def classify():
    t = time.time()

    payload = request.get_json()
    if 'sensor_data' not in payload:
        return jsonify({
            'success': False,
            'message': 'must provide sensor data'
        })

    data_folder = '.'
    if 'data_folder' in payload:
        data_folder = payload['data_folder']

    fname = os.path.join(data_folder,
                         to_base58(payload['sensor_data']['f']) + ".find3.ai")

    ai = AI(to_base58(payload['sensor_data']['f']), data_folder)
    logger.debug("loading {}".format(fname))
    try:
        ai.load(fname)
    except FileNotFoundError:
        return jsonify({
            "success": False,
            "message": "could not find '{p}'".format(p=fname)
        })

    classified = ai.classify(payload['sensor_data'])

    logger.debug("{:d} ms".format(int(1000 * (t - time.time()))))
    return jsonify({
        "success": True,
        "message": "data analyzed",
        'analysis': classified
    })
Ejemplo n.º 2
0
def classify():
    t = time.time()

    payload = request.get_json()
    if payload is None:
        return jsonify({'success': False, 'message': 'must provide sensor data'})

    if 'sensor_data' not in payload:
        return jsonify({'success': False, 'message': 'must provide sensor data'})

    fname = to_base58(payload['sensor_data']['f']) + ".ai"

    ai = ai_cache.get(payload['sensor_data']['f'])
    if ai is None:
        ai = AI(to_base58(payload['sensor_data']['f']))
        logger.debug("loading {}".format(fname))
        try:
            ai.load(fname)
        except Exception:
            return jsonify({"success": False, "message": "could not find '{p}'".format(p=fname)})
        ai_cache[payload['sensor_data']['f']] = ai

    classified = ai.classify(payload['sensor_data'])

    logger.debug("classifed for {} {:d} ms".format(
        payload['sensor_data']['f'], int(1000 * (t - time.time()))))
    return jsonify({"success": True, "message": "data analyzed", 'analysis': classified})
Ejemplo n.º 3
0
def classify(payload):

    if payload is None:
        return {'success': False, 'message': 'must provide sensor data'}

    if 'sensor_data' not in payload:
        return {'success': False, 'message': 'must provide sensor data'}

    t = time.time()

    data_folder = (payload['data_folder'] if 'data_folder' in payload else DEFAULT_DATA_DIRECTORY)

    fname = out_file(data_folder, payload['sensor_data']['f'])

    ai = ai_cache.get(payload['sensor_data']['f'])
    if ai == None:
        ai = AI(to_base58(payload['sensor_data']['f']))
        logger.debug("loading {}".format(fname))
        try:
            ai.load(fname, redis_cache=True)
        except FileNotFoundError:
            logger.error('File not found')
            return {"success": False, "message": "could not find '{p}'".format(p=fname)}
        ai_cache[payload['sensor_data']['f']] = ai

    classified = ai.classify(payload['sensor_data'])

    logger.debug("classifed for {} {:d} ms".format(
        payload['sensor_data']['f'], int(1000 * (t - time.time()))))
    return {"success": True, "message": "data analyzed", 'analysis': classified}
Ejemplo n.º 4
0
def classify(payload):

    if payload is None:
        return {'success': False, 'message': 'must provide sensor data'}

    if 'sensor_data' not in payload:
        return {'success': False, 'message': 'must provide sensor data'}

    t = time.time()

    data_folder = '.'
    if 'data_folder' in payload:
        data_folder = payload['data_folder']

    fname = os.path.join(data_folder,
                         to_base58(payload['sensor_data']['f']) + ".find3.ai")

    ai = ai_cache.get(payload['sensor_data']['f'])
    if ai == None:
        ai = AI(to_base58(payload['sensor_data']['f']), data_folder)
        logger.debug("loading {}".format(fname))
        try:
            ai.load(fname)
        except FileNotFoundError:
            logger.error('File not found')
            return {
                "success": False,
                "message": "could not find '{p}'".format(p=fname)
            }
        ai_cache[payload['sensor_data']['f']] = ai

    classified = ai.classify(payload['sensor_data'])

    logger.debug("classifed for {} {:d} ms".format(
        payload['sensor_data']['f'], int(1000 * (t - time.time()))))
    return {
        "success": True,
        "message": "data analyzed",
        'analysis': classified
    }