Exemplo n.º 1
0
    def epa_data_from_xls(self, game_ids):
        """Populate predictions from Excel files

        TODO: Remove from player class

        Args:
            game_ids (list): List of tournament game id's
        """

        predictions = dict()
        root = self._settings.root
        excel_file = os.path.join(root, self._settings.data.dir, 'predictions',
                                  self.name + '.xls')
        json_file = os.path.join(root, self._settings.data.dir, 'predictions',
                                 self.name + '.json')
        mapping = read_json_to_attrdict(
            os.path.join(root, 'util', 'johroge_mapping.json'))
        excel_sheet = read_xls_to_class(excel_file).sheet_by_name('Tips')
        all_results_read = True

        for key in game_ids:
            tmp_dict = mapping(str(key))
            home = tmp_dict['home']
            away = tmp_dict['away']
            home_result = read_cell(excel_sheet, home[0], home[1])
            away_result = read_cell(excel_sheet, away[0], away[1])
            if home_result is not None and away_result is not None:
                predictions[key] = {'home': home_result, 'away': away_result}
            else:
                self._log.error(
                    'Could not read excel score {} at {}, {}'.format(
                        key, home[0], home[1]))
                all_results_read = False
        if all_results_read:
            write_dict_to_json(predictions, json_file)
Exemplo n.º 2
0
    def __init__(self, data_path):
        """Init"""
        self.alpha_attack = int()
        self.alpha_defence = int()
        self.beta = int()

        self.stats = read_json_to_attrdict(data_path)
        if self.stats:
            self.totals = get_totals(self.stats)
Exemplo n.º 3
0
def main():
    settings = read_json_to_attrdict(META_SETTINGS)
    log_file = '{}.log'.format(datetime.now().strftime('%Y%m%d_%H%M%S'))
    setup_logger(
        log_path=os.path.join(settings.root, settings.logdir, log_file))
    tournament = Tournament(settings)
    tournament.populate()
    tournament.print_groups()
    tournament.print_playoff()
Exemplo n.º 4
0
    def predictions_from_json(self):
        """Game predictions from JSON file.

        File at data_dir/predictions/name.json

        File written by self.epa_data_from_xls
        """
        root = self._settings.root
        json_file = os.path.join(root, self._settings.data.dir, 'predictions',
                                 self.name + '.json')

        dict_ = read_json_to_attrdict(json_file)
        self.predictions = {
            int(key): AttrDict(value)
            for key, value in dict_.items()
        }
Exemplo n.º 5
0
    def _populate_from_json(self):
        """Ugly mash up to force the Github JSON data to the class structure"""
        self._log.info("Setting teams")

        data_dict = read_json_to_attrdict(self.data_file)
        for team_data in data_dict.teams:
            team = Team()
            team.init_from_json(team_data)
            self.teams[team.id] = team

        self._log.info("Setting groups")
        for group_id in data_dict.groups:
            group_data = AttrDict(data_dict.groups[group_id])
            group = Group()
            group.init_from_json(group_data,
                                 self._settings.naming.group_prefix)
            for game_data in group_data.matches:
                game = GroupGame()
                game.init_from_json(game_data, self.teams)
                game.set_group(group)
                self.games[game.id] = game  # maybe redundant

                group.add_game(game)
                group.add_teams(game.home_team, game.away_team)

            self.groups[group.id] = group
        self._sort_groups()

        self._log.info("Settings playoff")
        for id_ in data_dict.knockout:
            round_data = AttrDict(data_dict.knockout[id_])
            round_ = Round(id_)

            for game_data in round_data.matches:
                game = PlayoffGame()
                game.init_from_json(game_data, self.teams)
                game.set_order(round_.order)
                self.games[game.id] = game
                round_.add_game(game)
            self.playoff.rounds.append(round_)
        self.playoff.sort()
Exemplo n.º 6
0
class Config(object):
    SETTINGS = read_json_to_attrdict(os.path.join(basedir, META_SETTINGS))
    ROOT = basedir