def save(qlnn, results, context): sys.stdout.write('saving weights into database... ') sys.stdout.flush() with closing(make_db_session(DB_PATH)) as db_session: qlnn.update_in_db(db_session) # save weights and NN attributes for result in results[:-1]: db_save_game( db_session, yellow='qlnn', green=context[GREEN]['name'], winner=int(not result), is_training=True, ) db_save_game( db_session, start_state=context['start_state'], yellow='qlnn', green=context[GREEN]['name'], winner=int(not results[-1]), actions=context.history, is_training=True, ) db_session.commit() sys.stdout.write('saved\n')
def __init__(self, game, db_name): super(NetworkPlayer, self).__init__(game) self.db_name = db_name with closing(make_db_session(DB_PATH)) as db_session: self.load_from_db(db_session)
def wrapper(db_file_path, *args, **kwargs): with closing(make_db_session(db_file_path)) as db_session: setattr(db_session, '__dbfilename__', db_file_path) if with_build_db: build_db(db_session.__dbfilename__) return function(db_session, *args, **kwargs)