Skip to content

Commit

Permalink
Fix #221. Add MVP info.
Browse files Browse the repository at this point in the history
  • Loading branch information
agsalguero committed Apr 19, 2023
1 parent 68eaeae commit 02220f5
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 1,155 deletions.
2 changes: 2 additions & 0 deletions awpy/analytics/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def player_stats(
"success1v4": 0,
"attempts1v5": 0,
"success1v5": 0,
"mvp": 0,
}
player_statistics[player_key]["totalRounds"] += 1
kast[player_key] = {}
Expand Down Expand Up @@ -383,6 +384,7 @@ def player_stats(
for player, n_kills in round_kills.items():
if n_kills in range(6): # 0, 1, 2, 3, 4, 5
player_statistics[player][f"kills{n_kills}"] += 1 # type: ignore[literal-required]
player_statistics[str(r["MVPSteamID"])]["mvp"] += 1

for player in player_statistics.values():
player["kast"] = round(
Expand Down
3 changes: 3 additions & 0 deletions awpy/parser/demoparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,9 @@ def _parse_rounds(self) -> pd.DataFrame:
"winningTeam",
"losingTeam",
"roundEndReason",
"MVPName",
"MVPSteamID",
"MVPReason",
"ctFreezeTimeEndEqVal",
"ctRoundStartEqVal",
"ctRoundSpendMoney",
Expand Down
23 changes: 23 additions & 0 deletions awpy/parser/parse_demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,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 @@ -546,6 +549,19 @@ func convertRoundEndReason(r events.RoundEndReason) string {
}
}

func convertRoundMVPReason(r events.RoundMVPReason) string {
switch reason := r; reason {
case 1:
return "MVPReasonMostEliminations"
case 2:
return "MVPReasonBombDefused"
case 3:
return "MVPReasonBombPlanted"
default:
return "Unknown"
}
}

func convertHitGroup(hg events.HitGroup) string {
switch hitGroup := hg; hitGroup {
case 0:
Expand Down Expand Up @@ -2585,6 +2601,13 @@ func main() {
}
})

// Parse MVP announcements
p.RegisterEventHandler(func(e events.RoundMVPAnnouncement) {
currentRound.MVPName = e.Player.Name
currentRound.MVPSteamID = int64(e.Player.SteamID64)
currentRound.MVPReason = convertRoundMVPReason(e.Reason)
})

// Parse demofile to end
err = p.ParseToEnd()
currentGame.ParsedToFrame = int64(p.CurrentFrame())
Expand Down
2 changes: 2 additions & 0 deletions awpy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,8 @@ class GameRound(TypedDict):
weaponFires: Optional[list[WeaponFireAction]]
flashes: Optional[list[FlashAction]]
frames: Optional[list[GameFrame]]
mvp: Players
mvp_reason: str


class Game(TypedDict):
Expand Down
Loading

0 comments on commit 02220f5

Please sign in to comment.