Stats

This module contains functions for calculating statistics, like ADR, KAST and Rating, on Counter-Strik 2 demo files.

awpy.stats

Analytics module to calculate player statistics.

awpy.stats.adr(demo: Demo, *, team_dmg: bool = False, self_dmg: bool = True) DataFrame[source]

Calculates Average Damage Per Round (ADR) for each player.

Parameters:
  • demo (awpy.demo.Demo) – A parsed demo object which has a Polars DataFrame in demo.damages.

  • team_dmg (bool, optional) – If True, remove team damage events (i.e. when the attacker and victim are on the same side). Defaults to False.

  • self_dmg (bool, optional) – If True, remove self damage events (i.e. when attacker_name is missing). Defaults to True.

Returns:

A DataFrame containing columns: name, steamid, team_name, n_rounds, dmg, adr.

Return type:

pl.DataFrame

Raises:

ValueError – If damages are missing in the parsed demo.

awpy.stats.calculate_trades(demo: Demo, trade_length_in_seconds: float = 5.0) DataFrame[source]

Calculates if kills are trades.

A trade is a kill where the attacker of a player who recently died was killed shortly after the initial victim was killed.

Parameters:
  • demo (awpy.demo.Demo) – A parsed Demo.

  • trade_length_in_seconds (float, optional) – Length of trade time in seconds. Defaults to 5.0.

Returns:

The input DataFrame with an additional boolean column was_traded

indicating whether the kill was traded.

Return type:

pl.DataFrame

awpy.stats.impact(demo: Demo, kills_coef: float = 2.13, assists_coef: float = 0.42, intercept: float = -0.41) DataFrame[source]

Calculates impact rating using Polars.

Parameters:
  • demo (awpy.demo.Demo) – A parsed Awpy demo with kills and ticks as Polars DataFrames.

  • kills_coef (float, optional) – Coefficient for kills in the impact formula. Defaults to 2.13.

  • assists_coef (float, optional) – Coefficient for assists in the impact formula. Defaults to 0.42.

  • intercept (float, optional) – Intercept in the impact formula. Defaults to -0.41.

Returns:

A DataFrame of player info with impact rating. The DataFrame contains:
  • name (str): The player’s name.

  • steamid (str): The player’s Steam ID.

  • side (str): The team (“all”, “ct”, or “t”).

  • impact (float): The calculated impact rating.

Return type:

pl.DataFrame

Raises:

ValueError – If kills or ticks are missing in the parsed demo.

awpy.stats.kast(demo: Demo, trade_length_in_seconds: float = 3.0) DataFrame[source]

Calculates Kill-Assist-Survival-Trade % (KAST) using Polars.

Parameters:
  • demo (awpy.demo.Demo) – A parsed Awpy demo with kills and ticks as Polars DataFrames.

  • trade_length_in_seconds (float, optional) – Length of trade time in seconds. Defaults to 3.0.

Returns:

A DataFrame of player info with KAST statistics. The returned DataFrame
contains the following columns:
  • name: The player’s name.

  • steamid: The player’s Steam ID.

  • side: The team (“all”, “ct”, or “t”).

  • kast_rounds: Number of rounds contributing to KAST.

  • n_rounds: Total rounds played.

  • kast: The KAST percentage.

Return type:

pl.DataFrame

Raises:

ValueError – If kills or ticks are missing in the parsed demo.

awpy.stats.rating(demo: Demo, kast_coef: float = 0.0073, kills_coef: float = 0.3591, deaths_coef: float = -0.5329, impact_coef: float = 0.2372, adr_coef: float = 0.0032, intercept: float = 0.1587) DataFrame[source]

Calculates player rating (similar to HLTV) using Polars.

Parameters:
  • demo (awpy.demo.Demo) – A parsed Awpy demo with kills and ticks as Polars DataFrames.

  • kast_coef (float, optional) – Coefficient for KAST in the rating formula. Defaults to 0.0073.

  • kills_coef (float, optional) – Coefficient for kills in the rating formula. Defaults to 0.3591.

  • deaths_coef (float, optional) – Coefficient for deaths in the rating formula. Defaults to -0.5329.

  • impact_coef (float, optional) – Coefficient for impact in the rating formula. Defaults to 0.2372.

  • adr_coef (float, optional) – Coefficient for ADR in the rating formula. Defaults to 0.0032.

  • intercept (float, optional) – Intercept in the rating formula. Defaults to 0.1587.

Returns:

A DataFrame of player info with additional columns:
  • n_rounds (int): Total rounds played.

  • impact (float): Impact rating.

  • rating (float): The overall calculated rating.

Return type:

pl.DataFrame

Raises:

ValueError – If kills or ticks are missing in the parsed demo.