Analytics
This is the analytics module. You can use it to calculate statistics on your parsed demos, such as Rating, ADR, and so on. It also provides awpy-exclusive statistics, like map control.
awpy.analytics.map_control
Functions for calculating map control values and metrics.
A team’s map control can be thought of as the sum of it’s individual player’s control.
Example notebook:
- awpy.analytics.map_control.calc_frame_map_control_metric(map_name: str, frame: GameFrame) float [source]
Return map control metric for given awpy frame.
Map Control metric is used to quantify how much of the map is controlled by T/CT. Each tile is given a value between 0 (complete T control) and 1 (complete CT control). If a tile is controlled by both teams, a value is found by taking the ratio between the sum of CT values and sum of CT and T values. Once all of the tiles’ values are calculated, a weighted sum is done on the tiles’ values where the tiles’ area is the weights. This weighted sum is the map control metric returned at the end of the function.
- Parameters:
map_name (str) – Map used position_transform call
frame (GameFrame) – awpy frame to calculate map control metric for
- Returns:
Map Control metric for given frame
- Raises:
ValueError – If map_name is not in awpy.data.NAV
- awpy.analytics.map_control.calc_frame_map_control_values(map_name: str, frame: GameFrame) FrameMapControlValues [source]
Calculate tile map control values for each team given awpy frame object.
Values are allocated to tiles depending on how many tiles are between it and the source tile (aka tile distance). The smaller the tile distance, the close the tile’s value is to 1. Tiles are considered until a player’s tiles’ total area reach the area_threshold. The area threshold is a float between 0 and 1, representing the percentage of the current map’s total area.
- Parameters:
map_name (str) – Map used for find_closest_area and relevant tile neighbor dictionary
frame (GameFrame) – Awpy frame object for map control calculations
- Returns:
FrameMapControlValues object containing each team’s map control values
- Raises:
ValueError – If map_name is not in awpy.data.NAV
- awpy.analytics.map_control.calc_parsed_frame_map_control_values(map_name: str, current_player_data: FrameTeamMetadata) FrameMapControlValues [source]
Calculate tile map control values for each team given parsed frame.
Values are allocated to tiles depending on how many tiles are between it and the source tile (aka tile distance). The smaller the tile distance, the close the tile’s value is to 1. Tiles are considered until a player’s tiles’ total area reach the area_threshold. The area threshold is a float between 0 and 1, representing the percentage of the current map’s total area.
- Parameters:
map_name (str) – Map used for find_closest_area and relevant tile neighbor dictionary
current_player_data (FrameTeamMetadata) – Object containing team metadata (player positions, etc.). Expects extract_team_metadata output format
- Returns:
FrameMapControlValues object containing each team’s map control values
- Raises:
ValueError – If map_name is not in awpy.data.NAV
- awpy.analytics.map_control.calculate_round_map_control_metrics(map_name: str, round_data: GameRound) list[float] [source]
Return list of map control metric for given awpy round.
Map Control metric is used to quantify how much of the map is controlled by T/CT. Each tile is given a value between 0 (complete T control) and 1 (complete CT control). If a tile is controlled by both teams, a value is found by taking the ratio between the sum of CT values and sum of CT and T values. Once all of the tiles’ values are calculated, a weighted sum is done on the tiles’ values where the tiles’ area is the weights. This weighted sum is the map control metric returned at the end of the function.
- Parameters:
map_name (str) – Map used position_transform call
round_data (GameRound) – awpy round to calculate map control metrics
- Returns:
List of map control metric values for given round
- Raises:
ValueError – If map_name is not in awpy.data.NAV
- awpy.analytics.map_control.extract_teams_metadata(frame: GameFrame) FrameTeamMetadata [source]
Parse frame data for alive player locations for both sides.
- Parameters:
frame (GameFrame) – Dictionary in the form of an awpy frame containing relevant data for both sides
- Returns:
- FrameTeamMetadata containing team metadata (player
positions, etc.)
awpy.analytics.states
Functions to generate game stats based on snapshots from a demofile.
- awpy.analytics.states.generate_graph_state(frame: GameFrame) dict [source]
Returns a game state as a graph.
- Parameters:
frame (GameFrame) – Dict output of a frame generated from the DemoParser class
- Returns:
A dict with keys “T”, “CT” and “Global”, where each entry is a vector. Global vector is CT + T concatenated
- awpy.analytics.states.generate_set_state(frame: GameFrame) dict [source]
Returns a game state as a set.
- Parameters:
frame (GameFrame) – Dict output of a frame generated from the DemoParser class
- Returns:
A dict with keys “T”, “CT” and “Global”, where each entry is a vector. Global vector is CT + T concatenated
- awpy.analytics.states.generate_vector_state(frame: GameFrame, map_name: str) dict [source]
Returns a game state in a dictionary format.
- Parameters:
frame (GameFrame) – Dict output of a frame generated from the DemoParser class
map_name (string) – String indicating the map name
- Returns:
A dict with keys for each feature.
awpy.analytics.stats
Functions to calculate statistics for a player or team from a demofile.
Example:
from awpy.parser import DemoParser
from awpy.analytics.stats import player_stats
# Create the parser object.
parser = DemoParser(
demofile = "astralis-vs-liquid-m2-nuke.dem",
demo_id = "AST-TL-BLAST2019-nuke",
parse_frames=False,
)
# Parse the demofile, output results to a dictionary of dataframes.
data = parser.parse()
player_stats_json = player_stats(data["gameRounds"])
player_stats_json[76561197999004010]
https://github.com/pnxenopoulos/awpy/blob/main/examples/01_Basic_CSGO_Analysis.ipynb
- awpy.analytics.stats.initialize_round(cur_round: GameRound, player_statistics: dict[str, awpy.types.PlayerStatistics], active_sides: set[Literal['CT', 'T']]) RoundStatistics [source]
Initialize players and statistics for the given round.
- Parameters:
cur_round (GameRound) – Current CSGO round to initialize for.
player_statistics (dict[str, PlayerStatistics]) – Dict storing player statistics for a given match.
active_sides (set[Literal["CT", "T"]]) – Set of the currently active sides.
- Returns:
Initialized KAST dict for each player. dict[str, int]: Number of kills in the round for each player. set[str]]: Players to track for the given round.
- Return type:
dict[str, KAST]
- awpy.analytics.stats.player_stats(game_rounds: list[awpy.types.GameRound], return_type: str = 'json', selected_side: str = 'all') dict[str, awpy.types.PlayerStatistics] | DataFrame [source]
Generate a stats summary for a list of game rounds as produced by the DemoParser.
- Parameters:
game_rounds (list[GameRound]) – List of game rounds as produced by the DemoParser
return_type (str, optional) – Return format (“json” or “df”). Defaults to “json”.
selected_side (str, optional) – Which side(s) to consider. Defaults to “all”. Other options are “CT” and “T”
- Returns:
Dictionary or Dataframe containing player information
- Return type:
Union[dict[str, PlayerStatistics],pd.Dataframe]
awpy.analytics.wpa
Will provide functionality for WPA and win probabilities.
WPA stands for Win Probability Added and is described in this paper: https://arxiv.org/pdf/2011.01324.pdf.
- awpy.analytics.wpa.round_win_probability(ct_score: int, t_score: int, map_name: str) dict [source]
Estimates of game win probability using information from the HLTV win matrix.
- Parameters:
ct_score (int) – CT Score
t_score (int) – T Score
map_name (str) – Map the demo is from
- Returns:
A dictionary containing the CT game win, T game win and Draw probabilities
- awpy.analytics.wpa.state_win_probability(frame: GameFrame, model: Any) dict [source]
Predicts the win probability of a given frame.
- Parameters:
frame (dict) – Dict output of a frame generated from the DemoParser class
model (Unknown) – Model to predict win probabability from.
- Returns:
A dictionary containing the CT and T round win probabilities