def get_row(self, row, config_path):
        """
        行データ出力
        :param row: スクレイピングした結果の行データ
        :param config_path: config上の定義名
        :return: dict
        """
        config_standings = self.config[config_path]
        team_stats = row
        # 順位を書き換え('位'を抜く)
        key_rank, type_rank = DataSource.get_column_and_data_type(
            config_standings[TeamStandings.KEY_FORMAT.format(index=0)]
        )
        team_stats[key_rank] = DataSource.get_value(type_rank, row[key_rank].replace('位', ''))

        # ピタゴラス勝率を追加
        key_py_ex, type_py_ex = DataSource.get_column_and_data_type(
            config_standings[TeamStandings.KEY_FORMAT.format(index=15)]
        )
        team_stats[key_py_ex] = TeamStandings.calc_pythagorean_expectation(float(row['rs']), float(row['ra']))

        # ピタゴラス勝利数
        key_py_win, type_py_win = DataSource.get_column_and_data_type(
            config_standings[TeamStandings.KEY_FORMAT.format(index=16)]
        )
        team_stats[key_py_win] = DataSource.get_value(type_py_win, round(float(row['game']) * team_stats[key_py_ex], 0))

        # ピタゴラス敗戦数
        key_py_lose, type_py_lose = DataSource.get_column_and_data_type(
            config_standings[TeamStandings.KEY_FORMAT.format(index=17)]
        )
        team_stats[key_py_lose] = row['game'] - team_stats[key_py_win]

        # 得失点差
        key_run_diff, type_run_diff = DataSource.get_column_and_data_type(
            config_standings[TeamStandings.KEY_FORMAT.format(index=18)]
        )
        team_stats[key_run_diff] = row['rs'] - row['ra']
        return team_stats
Ejemplo n.º 2
0
    def get_row(self, row, config_path):
        """
        行データ出力
        :param row: スクレイピングした結果の行データ
        :param config_path: config上の定義名
        :return: dict
        """
        config_batter = self.config[config_path]
        _stats = row
        # OPS
        key_ops, type_ops = DataSource.get_column_and_data_type(
            config_batter[BatterStats.KEY_FORMAT.format(index=25)]
        )
        _stats[key_ops] = round(row['obp'] + row['slg'], 3)

        # Adam dunn
        key_dunn, type_dunn = DataSource.get_column_and_data_type(
            config_batter[BatterStats.KEY_FORMAT.format(index=26)]
        )
        _stats[key_dunn] = Stats.adam_dunn_batter(row['hr'], row['bb'], row['so'], row['pa'])

        # 選手名(チーム名)
        key_name, type_name = DataSource.get_column_and_data_type(
            config_batter[BatterStats.KEY_FORMAT.format(index=27)]
        )
        _stats[key_name] = DataSource.get_player_name_and_team(row['name'], row['team'])

        # iso
        key_iso, type_iso = DataSource.get_column_and_data_type(
            config_batter[BatterStats.KEY_FORMAT.format(index=28)]
        )
        _stats[key_iso] = round(row['slg'] - row['ba'], 3)

        # BABIP
        key_babip, type_babip = DataSource.get_column_and_data_type(
            config_batter[BatterStats.KEY_FORMAT.format(index=29)]
        )
        _stats[key_babip] = Stats.babip(row['h'], row['hr'], row['atbat'], row['so'], row['sf'])

        return _stats