(record_json_dir, agents, finished_at, config, info)
Combines all of the json state files into one
Combines all of the json state files into one
Combines all of the json state files into one
def join_json_state(record_json_dir, agents, finished_at, config, info):
    '''Combines all of the json state files into one'''
    json_schema = {"properties": {"state": {"mergeStrategy": "append"}}}

    json_template = {
        "agents": agents,
        "finished_at": finished_at,
        "config": config,
        "result": {
            "name": info['result'].name,
            "id": info['result'].value
        }
    }

    if info['result'] is not constants.Result.Tie:
        json_template['winners'] = info['winners']

    json_template['state'] = []

    merger = Merger(json_schema)
    base = merger.merge({}, json_template)

    for root, dirs, files in os.walk(record_json_dir):
        for name in files:
            path = os.path.join(record_json_dir, name)
            if name.endswith('.json') and "game_state" not in name:
                with open(path) as data_file:
                    data = json.load(data_file)
                    head = {"state": [data]}
                    base = merger.merge(base, head)

    with open(os.path.join(record_json_dir, 'game_state.json'), 'w') as f:
        f.write(json.dumps(base, sort_keys=True, indent=4))

    for root, dirs, files in os.walk(record_json_dir):
        for name in files:
            if "game_state" not in name:
                os.remove(os.path.join(record_json_dir, name))
def join_json_state ( record_json_dir , agents , finished_at , config , info ) : json_schema = { "properties" : { "state" : { "mergeStrategy" : "append" } } } json_template = { "agents" : agents , "finished_at" : finished_at , "config" : config , "result" : { "name" : info [ 'result' ] . name , "id" : info [ 'result' ] . value } } if info [ 'result' ] is not constants . Result . Tie : json_template [ 'winners' ] = info [ 'winners' ] json_template [ 'state' ] = [ ] merger = Merger ( json_schema ) base = merger . merge ( { } , json_template ) for root , dirs , files in os . walk ( record_json_dir ) : for name in files : path = os . path . join ( record_json_dir , name ) if name . endswith ( '.json' ) and "game_state" not in name : with open ( path ) as data_file : data = json . load ( data_file ) head = { "state" : [ data ] } base = merger . merge ( base , head ) with open ( os . path . join ( record_json_dir , 'game_state.json' ) , 'w' ) as f : f . write ( json . dumps ( base , sort_keys = True , indent = 4 ) ) for root , dirs , files in os . walk ( record_json_dir ) : for name in files : if "game_state" not in name : os . remove ( os . path . join ( record_json_dir , name ) )