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 all 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
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 @@ -620,6 +621,20 @@ 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:
player_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 +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 @@ -763,6 +763,9 @@ def _parse_rounds(self) -> pd.DataFrame:
"winningTeam",
"losingTeam",
"roundEndReason",
"mvpName",
"mvpSteamID",
"mvpReason",
"ctFreezeTimeEndEqVal",
"ctRoundStartEqVal",
"ctRoundSpendMoney",
Expand Down
31 changes: 31 additions & 0 deletions awpy/parser/parse_demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,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"`
CTFreezeTimeEndEqVal int64 `json:"ctFreezeTimeEndEqVal"`
CTRoundStartEqVal int64 `json:"ctRoundStartEqVal"`
CTRoundMoneySpend int64 `json:"ctRoundSpendMoney"`
Expand Down Expand Up @@ -556,6 +559,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 @@ -1467,6 +1483,18 @@ 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
playerSteamID := int64(e.Player.SteamID64)
mvpReason := convertRoundMVPReason(e.Reason)
currentRound.MVPSteamID = &playerSteamID
currentRound.MVPReason = &mvpReason
}
})
}

func getBombSite(site rune) string {
switch site {
case rune(events.BombsiteA):
Expand Down Expand Up @@ -2727,6 +2755,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
18 changes: 18 additions & 0 deletions awpy/parser/parse_demo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,26 @@ import (
"testing"

common "github.com/markus-wa/demoinfocs-golang/v3/pkg/demoinfocs/common"
events "github.com/markus-wa/demoinfocs-golang/v3/pkg/demoinfocs/events"
)

func TestConvertRoundMVPReason(t *testing.T) {
t.Parallel()
enumReasons := [3]events.RoundMVPReason{
events.MVPReasonMostEliminations, events.MVPReasonBombDefused, events.MVPReasonBombPlanted,
}
textReasons := []string{
"MVPReasonMostEliminations", "MVPReasonBombDefused", "MVPReasonBombPlanted",
}
for index, reason := range enumReasons {
is := convertRoundMVPReason(reason)
want := textReasons[index]
if is != want {
t.Errorf("Round MVP reason value of %v should convert to %v, got %v", reason, want, is)
}
}
}

func TestConvertRank(t *testing.T) {
t.Parallel()
var rankInt int
Expand Down
4 changes: 4 additions & 0 deletions awpy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,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 @@ -677,6 +680,7 @@ class PlayerStatistics(TypedDict):
success1v4: int
attempts1v5: int
success1v5: int
mvp: int


class KAST(TypedDict):
Expand Down
Loading
Loading