Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds MVP info #253

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions awpy/analytics/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def initialize_round(
"success1v4": 0,
"attempts1v5": 0,
"success1v5": 0,
"mvp": 0,
}
player_statistics[player_key]["totalRounds"] += 1
for player_key in active_players:
Expand Down Expand Up @@ -619,6 +620,20 @@ def _handle_multi_kills(
if player in round_statistics["active_players"]:
_increment_statistic(player_statistics, player, n_kills)

def _handle_mvps(
game_round: GameRound,
player_statistics: dict[str, PlayerStatistics],
round_statistics: RoundStatistics,
) -> None:
if "MVPName" in game_round:
player_key = (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could probably make use of _get_actor_key

game_round["MVPName"]
if game_round["MVPSteamID"] == 0
else str(game_round["MVPSteamID"])
)
if player_key in round_statistics["active_players"]:
player_statistics[player_key]["mvp"] += 1


def _increment_statistic(
player_statistics: dict[str, PlayerStatistics], player: str, n_kills: int
Expand Down Expand Up @@ -665,6 +680,7 @@ def player_stats(
_handle_bomb(game_round, player_statistics, round_statistics)
_handle_kast(player_statistics, round_statistics)
_handle_multi_kills(player_statistics, round_statistics)
_handle_mvps(game_round, player_statistics, round_statistics)

_finalize_statistics(player_statistics)

Expand Down
3 changes: 3 additions & 0 deletions awpy/parser/demoparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,9 @@ def _parse_rounds(self) -> pd.DataFrame:
"winningTeam",
"losingTeam",
"roundEndReason",
"MVPName",
"MVPSteamID",
"MVPReason",
"ctFreezeTimeEndEqVal",
"ctRoundStartEqVal",
"ctRoundSpendMoney",
Expand Down
27 changes: 27 additions & 0 deletions awpy/parser/parse_demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@
WinningTeam *string `json:"winningTeam"`
LosingTeam *string `json:"losingTeam"`
Reason string `json:"roundEndReason"`
MVPName string `json:"MVPName"`
MVPSteamID int64 `json:"MVPSteamID"`
MVPReason string `json:"MVPReason"`
JanEricNitschke marked this conversation as resolved.
Show resolved Hide resolved
CTFreezeTimeEndEqVal int64 `json:"ctFreezeTimeEndEqVal"`
CTRoundStartEqVal int64 `json:"ctRoundStartEqVal"`
CTRoundMoneySpend int64 `json:"ctRoundSpendMoney"`
Expand Down Expand Up @@ -554,6 +557,19 @@
}
}

func convertRoundMVPReason(r events.RoundMVPReason) string {
JanEricNitschke marked this conversation as resolved.
Show resolved Hide resolved
switch reason := r; reason {
case events.MVPReasonMostEliminations:
return "MVPReasonMostEliminations"
case events.MVPReasonBombDefused:
return "MVPReasonBombDefused"
case events.MVPReasonBombPlanted:
return "MVPReasonBombPlanted"
default:
return unknown
}
}

func convertHitGroup(hg events.HitGroup) string {
switch hitGroup := hg; hitGroup {
case events.HitGroupGeneric:
Expand Down Expand Up @@ -1461,6 +1477,14 @@
})
}

func registerRoundMVPHandler(demoParser *dem.Parser, currentGame *Game, currentRound *GameRound) {

Check warning on line 1480 in awpy/parser/parse_demo.go

View workflow job for this annotation

GitHub Actions / build

unused-parameter: parameter 'currentGame' seems to be unused, consider removing or renaming it as _ (revive)
JanEricNitschke marked this conversation as resolved.
Show resolved Hide resolved
(*demoParser).RegisterEventHandler(func(e events.RoundMVPAnnouncement) {
currentRound.MVPName = e.Player.Name
currentRound.MVPSteamID = int64(e.Player.SteamID64)
currentRound.MVPReason = convertRoundMVPReason(e.Reason)
})
JanEricNitschke marked this conversation as resolved.
Show resolved Hide resolved
}

func getBombSite(site rune) string {
switch site {
case rune(events.BombsiteA):
Expand Down Expand Up @@ -2680,6 +2704,9 @@
registerRoundEndOfficialHandler(&p, &currentGame, &currentRound, &roundInEndTime, &RoundRestartDelay)
registerRoundEndHandler(&p, &currentGame, &currentRound, &roundStarted, &roundInEndTime, &RoundRestartDelay)

// Parse MVP announcements
registerRoundMVPHandler(&p, &currentGame, &currentRound)

// Parse bomb defuses
registerBombDefusedHandler(&p, &currentGame, &currentRound)
registerBombDefuseStartHandler(&p, &currentGame, &currentRound)
Expand Down
4 changes: 4 additions & 0 deletions awpy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,9 @@ class GameRound(TypedDict):
winningTeam: str | None
losingTeam: str | None
roundEndReason: str
MVPName: str | None
JanEricNitschke marked this conversation as resolved.
Show resolved Hide resolved
MVPSteamID: int | None
MVPReason: str | None
ctFreezeTimeEndEqVal: int
ctRoundStartEqVal: int
ctRoundSpendMoney: int
Expand Down Expand Up @@ -656,6 +659,7 @@ class PlayerStatistics(TypedDict):
success1v4: int
attempts1v5: int
success1v5: int
mvp: int


class KAST(TypedDict):
Expand Down