示例#1
0
def store_graph(scene):
    mongo = Mongo(scene + '_test')
    mongo_automata = automata.Mongo_automata('127.0.0.1', 'automata_test')
    data = ''
    for line in bottle.request.body.readlines():
        if type(line) == bytes:
            line = line.decode('utf8')
        data += line
    if data == '':
        return {'result': 'data null'}
    try:
        data = json.loads(data)
    except:
        traceback.print_exc()
        return {'result': 'data format error : not json'}
    if type(data) != dict:
        return {'result': 'data format error : not dict'}
    try:
        if not mongo_automata.insert_graph_config(data['config']):
            return {'result': 'update config error'}
        if not mongo.store('instruction', data['instruction']):
            return {'result': 'update instruction error'}
        if not mongo.store('automata', data['automata']):
            return {'result': 'update automata error'}
    except:
        traceback.print_exc()
        return {'result': 'error'}
    return {'result': 'ok'}
示例#2
0
def load_graph(scene):
    try:
        mongo = Mongo(scene + '_test')
        mongo_automata = automata.Mongo_automata('127.0.0.1', 'automata_test')
        config = mongo_automata.load_graph_config(scene_id=scene)
        if not config:
            return {'result': 'scene_id error'}
        nodes = mongo.search('instruction', {'fields': ['instruction', '_id']})
        edges = mongo.search('automata', {'fields': ['intent', '_id']})
        #nodes = list(map(lambda x:x['instruction'], nodes))
        #edges = list(map(lambda x:x['intent'], edges))

        result = json.dumps(
            {
                'config': config,
                'instruction': nodes,
                'automata': edges
            },
            ensure_ascii=False,
            sort_keys=True)
        result = result.encode('utf-8')
        return result
    except:
        traceback.print_exc()
        return {'result': 'error'}
示例#3
0
def load_group(db, collection, query):
    mongo = Mongo(db)
    if collection == 'dialogue':
        data = mongo.load_dialogue_business() 
    else:
        data = mongo.load_group(collection)
    result = json.dumps({'result':data}, ensure_ascii=False, sort_keys=True)
    return result.encode('utf-8')
示例#4
0
def update_master(db, log_id):
    mongo = Mongo(db)
    if not mongo.copydb('10.89.14.67'):
        return {'result': 'copydb error'}
    up = Update('127.0.0.1', db)
    if not up.update('master'):
        return {'result': 'update data error'}
    backup = Data_backup(db)
    if not backup.data_dump(DATA_PATH, log_id):
        return {'result': 'data dump error'}
    if not restart_sys(db):
        return {'result': 'restart system error'}
    return {'result': 'ok'}
示例#5
0
def search_automata(db, collection, query):
    mongo = Mongo(db)
    if type(query) == bytes:
        query = query.decode('utf-8')
    try:
        query = json.loads(query)
    except Exception:
        return {'result':'query format error'}
    if type(query) != dict:
        return {'result':'query format error'}
    data = mongo.search_automata(collection, query)
    result = json.dumps({'result':data}, ensure_ascii=False, sort_keys=True)
    result = result.encode('utf-8')
    return result
示例#6
0
def load_data(db, collection, query):
    mongo = Mongo(db)
    if type(query) == bytes:
        query = query.decode('utf-8')
    try:
        query = json.loads(query)
    except Exception:
        traceback.print_exc()
        return {'result': 'query format error : not json'}
    if type(query) != dict:
        return {'result': 'query format error : not dict'}
    if collection == 'dialogue':
        data = mongo.load_dialogue_data(query)
    else:
        data = mongo.load_data(collection, query)
    result = json.dumps({'result': data}, ensure_ascii=False, sort_keys=True)
    return result.encode('utf-8')
示例#7
0
def commit(db, collection, query):
    mongo = Mongo(db)
    data = ''
    for line in bottle.request.body.readlines():
        if type(line) == bytes:
            line = line.decode('utf8')
        data += line
    if data == '':
        return {'result':'data null'}
    try:
        data = json.loads(data)
    except Exception:
        return {'result':'data format error'}
    if type(data) != dict:
        return {'result':'data format error'}
    if not mongo.commit(collection, data):
        return {'result':'xxerror'} 
    return {'result':'ok'}
示例#8
0
def load_label(db, collection, query):
    mongo = Mongo(db)
    if type(query) == bytes:
        query = query.decode('utf-8')
    try:
        query = json.loads(query)
    except Exception:
        return {'result':'query format error'}
    if type(query) != dict:
        return {'result':'query format error'}
    if 'group' in query.keys():
        group = query['group']
    else:
        group = ''
    if collection == 'dialogue':
        data = mongo.load_dialogue_intention(group)
    else:
        data = mongo.load_label(collection, group)
    result = json.dumps({'result':data}, ensure_ascii=False, sort_keys=True)
    return result.encode('utf-8')
示例#9
0
def store_data(db, collection, query):
    mongo = Mongo(db)
    data = ''
    for line in bottle.request.body.readlines():
        if type(line) == bytes:
            line = line.decode('utf8')
        data += line
    if data == '':
        return {'result':'data null'}
    try:
        data = json.loads(data)
    except Exception:
        return {'result':'data format error'}
    if type(data) != dict:
        return {'result':'data format error'}
    if collection == 'dialogue':
        result = mongo.store_dialogue(data)
    else:
        result = mongo.store(collection, data)
    if not result:
        return {'result':'error'}
    return {'result':'ok'}
示例#10
0
def delete_collection(db, collection):
    mongo = Mongo(db)
    if not mongo.delete_collection(collection):
        return {'result':'error'} 
    return {'result':'ok'}
示例#11
0
def delete_db(db):
    mongo = Mongo(db)
    if not mongo.delete_db():
        return {'result':'error'} 
    return {'result':'ok'}
示例#12
0
def create(db, collection, query):
    mongo = Mongo(db)
    if not mongo.create_collection(collection):
        return {'result':'xxerror'} 
    return {'result':'ok'}
示例#13
0
def count_data(db, collection, query):
    mongo = Mongo(db)
    data = mongo.count(collection)
    result = json.dumps({'result':data}, ensure_ascii=False, sort_keys=True)
    return result.encode('utf-8')