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 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 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 @@ -620,6 +621,21 @@ def _handle_multi_kills(
_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
) -> None:
Expand Down Expand Up @@ -665,6 +681,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
29 changes: 29 additions & 0 deletions awpy/parser/parse_demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ type GameRound struct {
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 convertRoundEndReason(r events.RoundEndReason) string {
}
}

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,16 @@ func registerRoundEndHandler(demoParser *dem.Parser, currentGame *Game, currentR
})
}

func registerRoundMVPHandler(demoParser *dem.Parser, currentRound *GameRound) {
(*demoParser).RegisterEventHandler(func(e events.RoundMVPAnnouncement) {
if e.Player != nil {
currentRound.MVPName = e.Player.Name
currentRound.MVPSteamID = int64(e.Player.SteamID64)
currentRound.MVPReason = convertRoundMVPReason(e.Reason)
}
})
}

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

// Parse MVP announcements
registerRoundMVPHandler(&p, &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
Loading