Beispiel #1
0
    def export(self, path=None):
        '''
		Saves info to yaml (by default where it was loaded from)

		Filters out any entries with keys that start with '_' or have no value (None)
		
		:return: path to export if one is provided, otherwise all the data that would have been exported as a dict
		'''

        if path is None:
            path = self.get_info_path()

        data = {}
        for k, v in self.__dict__.items():
            if v is not None and k[0] != '_':
                data[k] = v

        if self._updated:  # something was changed
            data['last_update'] = get_now()

        if path is None:
            prt.warning(
                'No export path found, so there is nowhere to save the info')
            return

        save_yaml(data, path)

        prt.debug(f'Exported {repr(self)} to {path}')
        return path
Beispiel #2
0
	def _find_actions_from_state(self, state, persistent=True):
		actions_path = self._get_action_path()
		if actions_path.exists():
			actions = load_yaml(actions_path)
			actions = {player: {action['loc']: action for action in acts} for player, acts in actions.items()}
			return actions
		
		actions = self.generate_actions_from_state(state)
		if persistent:
			save_yaml(actions, actions_path)
		return actions
Beispiel #3
0
	def _find_latest_state(self, state_root, persistent=True):
		state_paths = list(state_root.glob('*'))
		if not len(state_paths):
			state = self.generate_initial_state()
			if persistent:
				save_yaml(state, state_root / '1-1.yaml')
			return state
		
		times = {}
		for path in state_paths:
			year, season, *other = path.stem.split('-')
			times[int(year), int(season), len(other) and other[0] == 'r'] = path
		latest = times[max(times.keys())]
		return load_yaml(latest)
Beispiel #4
0
 def _store_bot_data(self):
     save_yaml(self.persistent, self.bot_data_path)
Beispiel #5
0
    def checkpoint(self, path, ident='dataset'):
        path = Path(path)

        path = path / f'{ident}.yaml'
        save_yaml(self.info, str(path))
Beispiel #6
0
	def _checkpoint_state(self):
		return save_yaml(self.state, self._get_state_path())
Beispiel #7
0
	def _checkpoint_actions(self):
		return save_yaml(self._unformat_actions(self.actions), self._get_action_path())