コード例 #1
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})
コード例 #2
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
    })
コード例 #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}
コード例 #4
0
def learn():
    payload = request.get_json()
    if 'family' not in payload:
        return jsonify({'success': False, 'message': 'must provide family'})
    if 'csv_file' not in payload:
        return jsonify({'success': False, 'message': 'must provide CSV file'})
    data_folder = '.'
    if 'data_folder' in payload:
        data_folder = payload['data_folder']
    else:
        logger.debug("could not find data_folder in payload")

    logger.debug(data_folder)

    ai = AI(to_base58(payload['family']), data_folder)
    fname = os.path.join(data_folder, payload['csv_file'])
    try:
        ai.learn(fname)
    except FileNotFoundError:
        return jsonify({
            "success": False,
            "message": "could not find '{}'".format(fname)
        })

    ai.save(
        os.path.join(data_folder,
                     to_base58(payload['family']) + ".find3.ai"))
    return jsonify({"success": True, "message": "calibrated data"})
コード例 #5
0
ファイル: api.py プロジェクト: sjsafranek/find3
def learn(payload):
    if payload is None:
        return {'success': False, 'message': 'must provide sensor data'}
    if 'family' not in payload:
        return {'success': False, 'message': 'must provide family'}
    if 'csv_file' not in payload:
        return {'success': False, 'message': 'must provide CSV file'}
    data_folder = '.'
    if 'data_folder' in payload:
        data_folder = payload['data_folder']
    else:
        logger.debug("could not find data_folder in payload")

    logger.debug(data_folder)

    ai = AI(to_base58(payload['family']), data_folder)
    fname = os.path.join(data_folder, payload['csv_file'])
    try:
        ai.learn(fname)
    except FileNotFoundError:
        return {
            "success": False,
            "message": "could not find '{}'".format(fname)
        }

    print(payload['family'])
    ai.save(
        os.path.join(data_folder,
                     to_base58(payload['family']) + ".find3.ai"))
    ai_cache[payload['family']] = ai
    return {"success": True, "message": "calibrated data"}
コード例 #6
0
ファイル: api.py プロジェクト: sjsafranek/find3
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
    }
コード例 #7
0
def learn(payload):
    if payload is None:
        return {'success': False, 'message': 'must provide sensor data'}
    if 'family' not in payload:
        return {'success': False, 'message': 'must provide family'}
    if 'csv_file' not in payload and 'file_data' not in payload:
        return {'success': False, 'message': 'must provide CSV file'}

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

    ai = AI(to_base58(payload['family']))

    # encoded file in request payload
    if 'file_data' in payload:
        ai.learn("", file_data=payload['file_data'])
    # # file on disk
    # # requires absolute path
    # elif 'csv_file' in payload:
    #     try:
    #         ai.learn( payload['csv_file'] )
    #     except FileNotFoundError:
    #         return {"success": False, "message": "could not find '{0}'".format( payload['csv_file'] )}

    fname = out_file(data_folder, payload['family'])
    ai.save(fname, redis_cache=True)

    ai_cache[payload['family']] = ai
    return {"success": True, "message": "calibrated data"}
コード例 #8
0
def learn():
    payload = request.get_json()
    family = 'posifi'
    if payload is None:
        return jsonify({'success': False, 'message': 'must provide sensor data'})
    if 'csv_file' not in payload:
        return jsonify({'success': False, 'message': 'must provide CSV file'})

    ai = AI(to_base58(family))
    try:
        ai.learn(payload['csv_file'])
    except Exception as e:
        return jsonify({"success": False, "message": f"ERROR learning {e}"})

    ai.save(to_base58(family) + ".ai")
    ai_cache[family] = ai
    return jsonify({"success": True, "message": "calibrated data"})