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

Season stats parsers bury game mode inside inner maps #5

Open
redbeardymcgee opened this issue Oct 11, 2021 · 0 comments
Open

Season stats parsers bury game mode inside inner maps #5

redbeardymcgee opened this issue Oct 11, 2021 · 0 comments

Comments

@redbeardymcgee
Copy link
Contributor

redbeardymcgee commented Oct 11, 2021

The shape of data returned by pubg-fetch is very convenient in the case of season stats. Maybe the data we care about is nested a little deeply, but that's the nature of an API many times. However, you can see that it is simple to walk through the map and start handling the meaningful data. To my mind, one valuable benefit of this result is how each game mode has its own child map of stats.

(get-in (pubg-clj.api/pubg-fetch
         {:url
        "https://api.pubg.com/shards/steam/players/<ACCOUNT-ID>/seasons/division.bro.official.pc-2018-13",
          :api-key my-api-key})
        [:body :data :attributes :game-mode-stats])

=>
{:duo
 {:kills 0,
  :boosts 0,
  :team-kills 0,
  <SNIP-STATS...>},
 :duo-fpp
 {:kills 0,
  :boosts 0,
  :team-kills 0,
  <SNIP-STATS...>},
  <SNIP-MODES...>}

Using the fetch-player-season-stats function threads the data through the player-season-stats-parse function, which then invokes pack-game-mode-stats, burying the game mode inside the related map of its stats.

#:pubg.player{:id "<ACCOUNT-ID>",
              :season-stats
              [{:pubg.season.stats/round-most-kills 0,
                :pubg.season.stats/losses 0,
                :pubg.season.stats/time-survived 0,
                :pubg.season.stats/walk-distance 0,
                :pubg.season.stats/best-rank-point nil,
                :pubg.season.stats/rank-points-title "",
                :pubg/game-mode "duo",
                <SNIP-DUO-STATS...>},
              {<SNIP-MODES...>}]}  

There are two issues here I think. First, it is no longer convenient to get to the game modes. Having the modes buried this way forces the client to resort to a filter matching against :pubg/game-mode to extract those stats by mode. This feels contrary to idiomatic keys as functions of their maps.

Second, it's subtle, but the way this is parsed and packed together results in the value of :pubg.player/season-stats now becoming a vector of maps. This further complicates how we can get to the data for each mode by forcing clients to extract the maps from the vector first. This sneaks up on the user and is very surprising.

I've been trying to understand the rationale for this behavior. Do you have some insight?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant