{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Calculating Counter-Strike 2 Stats\n",
"\n",
"Awpy can also help calculate basic Counter-Strike statistics, such as average damage per round (ADR), kill-assist-survival-trade (KAST%) or Rating."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"from awpy import Demo\n",
"\n",
"# Demo: https://www.hltv.org/matches/2372746/spirit-vs-natus-vincere-blast-premier-spring-final-2024 (de_dust2, Map 2)\n",
"dem = Demo(\"spirit-vs-natus-vincere-m2-dust2.dem\")\n",
"dem.parse()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Average Damage per Round (ADR)\n",
"\n",
"Average Damage per Round (ADR) is a common metric to evaluate Counter-Strike players. It is simply the total damage divided by the number of rounds. We can can calculate ADR in Awpy as follows:"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"
shape: (30, 6)| name | steamid | side | n_rounds | dmg | adr |
|---|
| str | u64 | str | u32 | i32 | f64 |
| "w0nderful" | 76561199063068840 | "t" | 12 | 671 | 55.916667 |
| "sh1ro" | 76561198081484775 | "ct" | 12 | 1186 | 98.833333 |
| "jL" | 76561198176878303 | "ct" | 10 | 801 | 80.1 |
| "donk" | 76561198386265483 | "t" | 10 | 946 | 94.6 |
| "sh1ro" | 76561198081484775 | "t" | 10 | 1059 | 105.9 |
| … | … | … | … | … | … |
| "jL" | 76561198176878303 | "all" | 22 | 1885 | 85.681818 |
| "Aleksib" | 76561198013243326 | "all" | 22 | 2232 | 101.454545 |
| "donk" | 76561198386265483 | "all" | 22 | 2647 | 120.318182 |
| "chopper" | 76561198045898864 | "all" | 22 | 1208 | 54.909091 |
| "zont1x" | 76561198995880877 | "all" | 22 | 1714 | 77.909091 |
"
],
"text/plain": [
"shape: (30, 6)\n",
"┌───────────┬───────────────────┬──────┬──────────┬──────┬────────────┐\n",
"│ name ┆ steamid ┆ side ┆ n_rounds ┆ dmg ┆ adr │\n",
"│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │\n",
"│ str ┆ u64 ┆ str ┆ u32 ┆ i32 ┆ f64 │\n",
"╞═══════════╪═══════════════════╪══════╪══════════╪══════╪════════════╡\n",
"│ w0nderful ┆ 76561199063068840 ┆ t ┆ 12 ┆ 671 ┆ 55.916667 │\n",
"│ sh1ro ┆ 76561198081484775 ┆ ct ┆ 12 ┆ 1186 ┆ 98.833333 │\n",
"│ jL ┆ 76561198176878303 ┆ ct ┆ 10 ┆ 801 ┆ 80.1 │\n",
"│ donk ┆ 76561198386265483 ┆ t ┆ 10 ┆ 946 ┆ 94.6 │\n",
"│ sh1ro ┆ 76561198081484775 ┆ t ┆ 10 ┆ 1059 ┆ 105.9 │\n",
"│ … ┆ … ┆ … ┆ … ┆ … ┆ … │\n",
"│ jL ┆ 76561198176878303 ┆ all ┆ 22 ┆ 1885 ┆ 85.681818 │\n",
"│ Aleksib ┆ 76561198013243326 ┆ all ┆ 22 ┆ 2232 ┆ 101.454545 │\n",
"│ donk ┆ 76561198386265483 ┆ all ┆ 22 ┆ 2647 ┆ 120.318182 │\n",
"│ chopper ┆ 76561198045898864 ┆ all ┆ 22 ┆ 1208 ┆ 54.909091 │\n",
"│ zont1x ┆ 76561198995880877 ┆ all ┆ 22 ┆ 1714 ┆ 77.909091 │\n",
"└───────────┴───────────────────┴──────┴──────────┴──────┴────────────┘"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from awpy.stats import adr\n",
"\n",
"adr(dem)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"ADR takes two optional arguments, `team_dmg` (default `False`), which removes team damage from the overall damage calculation, and `self_dmg` (default `True`), which removes any damage the player did to themselves. It is advised to leave these defaults as is in order to match most websites."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Kill, Assist, Survival and Trade % (KAST%)\n",
"Another common Counter-Strike statistic is KAST%, or the % of rounds where a player achieves a kill, assist, survives or trades. We can calculate KAST% in Awpy as follows:"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"
shape: (30, 6)| name | steamid | side | kast_rounds | n_rounds | kast |
|---|
| str | u64 | str | u32 | u32 | f64 |
| "chopper" | 76561198045898864 | "all" | 14 | 22 | 63.636364 |
| "donk" | 76561198386265483 | "all" | 18 | 22 | 81.818182 |
| "w0nderful" | 76561199063068840 | "all" | 18 | 22 | 81.818182 |
| "sh1ro" | 76561198081484775 | "all" | 17 | 22 | 77.272727 |
| "jL" | 76561198176878303 | "all" | 15 | 22 | 68.181818 |
| … | … | … | … | … | … |
| "magixx" | 76561199063238565 | "t" | 8 | 10 | 80.0 |
| "w0nderful" | 76561199063068840 | "t" | 11 | 12 | 91.666667 |
| "jL" | 76561198176878303 | "t" | 9 | 12 | 75.0 |
| "zont1x" | 76561198995880877 | "t" | 6 | 10 | 60.0 |
| "chopper" | 76561198045898864 | "t" | 6 | 10 | 60.0 |
"
],
"text/plain": [
"shape: (30, 6)\n",
"┌───────────┬───────────────────┬──────┬─────────────┬──────────┬───────────┐\n",
"│ name ┆ steamid ┆ side ┆ kast_rounds ┆ n_rounds ┆ kast │\n",
"│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │\n",
"│ str ┆ u64 ┆ str ┆ u32 ┆ u32 ┆ f64 │\n",
"╞═══════════╪═══════════════════╪══════╪═════════════╪══════════╪═══════════╡\n",
"│ chopper ┆ 76561198045898864 ┆ all ┆ 14 ┆ 22 ┆ 63.636364 │\n",
"│ donk ┆ 76561198386265483 ┆ all ┆ 18 ┆ 22 ┆ 81.818182 │\n",
"│ w0nderful ┆ 76561199063068840 ┆ all ┆ 18 ┆ 22 ┆ 81.818182 │\n",
"│ sh1ro ┆ 76561198081484775 ┆ all ┆ 17 ┆ 22 ┆ 77.272727 │\n",
"│ jL ┆ 76561198176878303 ┆ all ┆ 15 ┆ 22 ┆ 68.181818 │\n",
"│ … ┆ … ┆ … ┆ … ┆ … ┆ … │\n",
"│ magixx ┆ 76561199063238565 ┆ t ┆ 8 ┆ 10 ┆ 80.0 │\n",
"│ w0nderful ┆ 76561199063068840 ┆ t ┆ 11 ┆ 12 ┆ 91.666667 │\n",
"│ jL ┆ 76561198176878303 ┆ t ┆ 9 ┆ 12 ┆ 75.0 │\n",
"│ zont1x ┆ 76561198995880877 ┆ t ┆ 6 ┆ 10 ┆ 60.0 │\n",
"│ chopper ┆ 76561198045898864 ┆ t ┆ 6 ┆ 10 ┆ 60.0 │\n",
"└───────────┴───────────────────┴──────┴─────────────┴──────────┴───────────┘"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from awpy.stats import kast\n",
"\n",
"kast(dem, trade_length_in_seconds=5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"KAST takes one argument, `trade_length_in_seconds`, which specifies the length of a trade time in seconds. The default is 5 seconds."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Rating\n",
"\n",
"HLTV developed Rating and [Rating 2.0](https://www.hltv.org/news/20695/introducing-rating-20), which are well-described [here](https://www.youtube.com/watch?v=4rs1E4eKZcg) and an example is reverse-engineered [here](https://flashed.gg/posts/reverse-engineering-hltv-rating/). We provide a rating-esque statistic in `awpy.stats.rating`. You can calculate rating in Awpy as follows:"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"
shape: (30, 6)| name | steamid | side | n_rounds | impact | rating |
|---|
| str | u64 | str | u32 | f64 | f64 |
| "chopper" | 76561198045898864 | "all" | 22 | 0.556818 | 0.66615 |
| "donk" | 76561198386265483 | "all" | 22 | 1.931364 | 1.562747 |
| "jL" | 76561198176878303 | "all" | 22 | 1.526364 | 1.231553 |
| "magixx" | 76561199063238565 | "all" | 22 | 1.001364 | 1.185146 |
| "sh1ro" | 76561198081484775 | "all" | 22 | 1.912273 | 1.587677 |
| … | … | … | … | … | … |
| "chopper" | 76561198045898864 | "t" | 10 | 0.568 | 0.7551796 |
| "jL" | 76561198176878303 | "t" | 12 | 1.72 | 1.273859 |
| "iM" | 76561198050250233 | "t" | 12 | 0.51 | 0.51913 |
| "zont1x" | 76561198995880877 | "t" | 10 | 0.397 | 0.5996484 |
| "w0nderful" | 76561199063068840 | "t" | 12 | 0.5475 | 0.7978 |
"
],
"text/plain": [
"shape: (30, 6)\n",
"┌───────────┬───────────────────┬──────┬──────────┬──────────┬───────────┐\n",
"│ name ┆ steamid ┆ side ┆ n_rounds ┆ impact ┆ rating │\n",
"│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │\n",
"│ str ┆ u64 ┆ str ┆ u32 ┆ f64 ┆ f64 │\n",
"╞═══════════╪═══════════════════╪══════╪══════════╪══════════╪═══════════╡\n",
"│ chopper ┆ 76561198045898864 ┆ all ┆ 22 ┆ 0.556818 ┆ 0.66615 │\n",
"│ donk ┆ 76561198386265483 ┆ all ┆ 22 ┆ 1.931364 ┆ 1.562747 │\n",
"│ jL ┆ 76561198176878303 ┆ all ┆ 22 ┆ 1.526364 ┆ 1.231553 │\n",
"│ magixx ┆ 76561199063238565 ┆ all ┆ 22 ┆ 1.001364 ┆ 1.185146 │\n",
"│ sh1ro ┆ 76561198081484775 ┆ all ┆ 22 ┆ 1.912273 ┆ 1.587677 │\n",
"│ … ┆ … ┆ … ┆ … ┆ … ┆ … │\n",
"│ chopper ┆ 76561198045898864 ┆ t ┆ 10 ┆ 0.568 ┆ 0.7551796 │\n",
"│ jL ┆ 76561198176878303 ┆ t ┆ 12 ┆ 1.72 ┆ 1.273859 │\n",
"│ iM ┆ 76561198050250233 ┆ t ┆ 12 ┆ 0.51 ┆ 0.51913 │\n",
"│ zont1x ┆ 76561198995880877 ┆ t ┆ 10 ┆ 0.397 ┆ 0.5996484 │\n",
"│ w0nderful ┆ 76561199063068840 ┆ t ┆ 12 ┆ 0.5475 ┆ 0.7978 │\n",
"└───────────┴───────────────────┴──────┴──────────┴──────────┴───────────┘"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from awpy.stats import rating\n",
"\n",
"rating(dem)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can control the individual coefficients as arguments, via `kast_coef=...`, `kills_coef=...` and so on."
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}