コード例 #1
0
    async def get_league_results(
            self, league_name, season, options=None, **kwargs):
        """Returns a list containing information about all the results
        (matches) played by the teams in the given league in the given season.

        :param league_name: The league's name.
        :type league_name: str
        :param season: The season.
        :type season: str or int
        :param options: Options to filter the data by, defaults to None.
        :param options: dict, optional
        :return: A list of the results as seen on Understat's league overview.
        :rtype: list
        """

        url = LEAGUE_URL.format(to_league_name(league_name), season)
        dates_data = await get_data(self.session, url, "datesData")
        results = [r for r in dates_data if r["isResult"]]

        if options:
            kwargs = options

        filtered_data = filter_data(results, kwargs)

        return filtered_data
コード例 #2
0
ファイル: understat.py プロジェクト: amosbastian/understat
    async def get_league_players(self,
                                 league_name,
                                 season,
                                 options=None,
                                 **kwargs):
        """Returns a list containing information about all the players in
        the given league in the given season.

        :param league_name: The league's name.
        :type league_name: str
        :param season: The season.
        :param options: Options to filter the data by, defaults to None.
        :param options: dict, optional
        :type season: str or int
        :return: A list of the players as seen on Understat's league overview.
        :rtype: list
        """

        url = LEAGUE_URL.format(to_league_name(league_name), season)
        players_data = await get_data(self.session, url, "playersData")

        if options:
            kwargs = options

        filtered_data = filter_data(players_data, kwargs)

        return filtered_data
コード例 #3
0
ファイル: understat.py プロジェクト: spiz006/understat
    def get_league_table(self, league_name, season, with_headers=True):
        """Returns the latest league table of a specified league in a specified year.

        :param league_name: The league's name.
        :type league_name: str
        :param season: The season.
        :type season: str or int
        :param with_headers: whether or not to include headers in the returned table.
        :type with_headers: bool
        :return: List of lists.
        :rtype: list
        """

        url = LEAGUE_URL.format(to_league_name(league_name), season)
        stats = get_data(url, "teamsData")

        keys = ["wins", "draws", "loses", "scored", "missed",
                "pts", "xG", "npxG", "xGA", "npxGA", "npxGD", "xpts"]
        team_ids = [x for x in stats]

        data = [
            [stats[team_id]["title"], len(stats[team_id]["history"])] +
            [round(sum(x[key] for x in stats[team_id]["history"]), 2)
             for key in keys]
            for team_id in team_ids
        ]

        # sort by pts descending, followed by goal difference descending
        data = sorted(data, key=lambda x: (-x[7], x[6] - x[5]))

        if with_headers:
            data = [["Team", "M", "W", "D", "L", "G", "GA", "PTS", "xG",
                     "NPxG", "xGA", "NPxGA", "NPxGD", "xPTS"]] + data

        return data
コード例 #4
0
ファイル: understat.py プロジェクト: spiz006/understat
    def get_league_fixtures(
            self, league_name, season,  options=None, **kwargs):
        """Returns a list containing information about all the upcoming
        fixtures of the given league in the given season.

        :param league_name: The league's name.
        :type league_name: str
        :param season: The season.
        :type season: str or int
        :param options: Options to filter the data by, defaults to None.
        :param options: dict, optional
        :return: A list of the fixtures as seen on Understat's league overview.
        :rtype: list
        """

        url = LEAGUE_URL.format(to_league_name(league_name), season)
        dates_data = get_data(url, "datesData")
        fixtures = [f for f in dates_data if not f["isResult"]]

        if options:
            kwargs = options

        filtered_data = filter_data(fixtures, kwargs)

        return filtered_data
コード例 #5
0
ファイル: understat.py プロジェクト: amosbastian/understat
    async def get_league_table(self, league_name, season, with_headers=True):
        """Returns the latest league table of a specified league in a specified year.

        :param league_name: The league's name.
        :type league_name: str
        :param season: The season.
        :type season: str or int
        :param with_headers: whether or not to include headers in the returned table.
        :type with_headers: bool
        :return: List of lists.
        :rtype: list
        """

        url = LEAGUE_URL.format(to_league_name(league_name), season)
        stats = await get_data(self.session, url, "teamsData")

        keys = [
            "wins", "draws", "loses", "scored", "missed", "pts", "xG", "npxG",
            "xGA", "npxGA", "npxGD", "deep", "deep_allowed", "xpts"
        ]
        team_ids = [x for x in stats]

        data = []
        for team_id in team_ids:
            team_data = []
            season_stats = stats[team_id]["history"]
            team_data.append(stats[team_id]["title"])
            team_data.append(len(season_stats))
            team_data.extend(
                [round(sum(x[key] for x in season_stats), 2) for key in keys])

            passes = sum(x["ppda"]["att"] for x in season_stats)
            def_act = sum(x["ppda"]["def"] for x in season_stats)

            o_passes = sum(x["ppda_allowed"]["att"] for x in season_stats)
            o_def_act = sum(x["ppda_allowed"]["def"] for x in season_stats)

            # insert PPDA and OPPDA so they match with the positions in the table on the website
            team_data.insert(-3, round(passes / def_act, 2))
            team_data.insert(-3, round(o_passes / o_def_act, 2))

            data.append(team_data)

        # sort by pts descending, followed by goal difference descending
        data = sorted(data, key=lambda x: (-x[7], x[6] - x[5]))

        if with_headers:
            data = [[
                "Team", "M", "W", "D", "L", "G", "GA", "PTS", "xG", "NPxG",
                "xGA", "NPxGA", "NPxGD", "PPDA", "OPPDA", "DC", "ODC", "xPTS"
            ]] + data

        return data
コード例 #6
0
ファイル: understat.py プロジェクト: spiz006/understat
    def get_teams(self, league_name, season, options=None, **kwargs):
        """Returns a list containing information about all the teams in
        the given league in the given season.

        :param league_name: The league's name.
        :type league_name: str
        :param season: The season.
        :param options: Options to filter the data by, defaults to None.
        :param options: dict, optional
        :type season: str or int
        :return: A list of the league's table as seen on Understat's
            league overview.
        :rtype: list
        """

        url = LEAGUE_URL.format(to_league_name(league_name), season)
        teams_data = get_data(url, "teamsData")

        if options:
            kwargs = options

        filtered_data = filter_data(list(teams_data.values()), kwargs)

        return filtered_data