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

Ranked stats rough draft #4

Open
wants to merge 2 commits into
base: master
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
20 changes: 19 additions & 1 deletion src/pubg_clj/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
(cond-> "https://api.pubg.com/"
(or platform region) (concat "shards/")
platform (concat platform)
region (concat "-" region)
;; region (concat "-" region)
endpoint (concat "/" endpoint)
true str/join))

Expand Down Expand Up @@ -91,6 +91,9 @@
(defn- season-stats-endpoint
[player-id season-id]
(str "players/" player-id "/seasons/" season-id))
(defn- season-ranked-stats-endpoint
[player-id season-id]
(str "players/" player-id "/seasons/" season-id "/ranked"))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Status
Expand Down Expand Up @@ -271,3 +274,18 @@
:endpoint (season-stats-endpoint id season-id)})
:body
p/player-season-stats-parse)))

(defn fetch-player-season-ranked-stats
"Fetches the ranked season stats for a given player and season. The
region is required for PS4, Xbox, and for stats of PC players prior
to and including division.bro.official.2018-09. It is probably best
to always include the region, as the API will respond with stats for
EVERY region in the cases where it is depracated."
[player season-id & [region]]
(let [{:keys [pubg.player/id pubg/shard-id]} player]
(->> (pubg-fetch
{:platform shard-id,
:region (or region ""),
:endpoint (season-ranked-stats-endpoint id season-id)})
:body
p/player-season-ranked-stats-parse)))
41 changes: 40 additions & 1 deletion src/pubg_clj/api/parsers.clj
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,39 @@
:pubg.season.stats/wins {:from [:wins]}
})

(defparser season-ranked-stats-parse
{:pubg/game-mode {:from [:game-mode]},
:pubg.season.stats/kills {:from [:kills]},
:pubg.season.stats/kill-streak {:from [:kill-streak]},
:pubg.season.stats/boosts {:from [:boosts]},
:pubg.season.stats/team-kills {:from [:team-kills]},
:pubg.season.stats/revives {:from [:revives]},
:pubg.season.stats/assists {:from [:assists]},
:pubg.season.stats/kdr {:from [:kdr]},
:pubg.season.stats/revive-ratio {:from [:revive-ratio]},
:pubg.season.stats/avg-rank {:from [:avg-rank]},
:pubg.season.stats/deaths {:from [:deaths]},
:pubg.season.stats/damage-dealt {:from [:damage-dealt]},
:pubg.season.stats/weapons-acquired {:from [:weapons-acquired]},
:pubg.season.stats/heals {:from [:heals]},
:pubg.season.stats/play-time {:from [:play-time]},
:pubg.season.stats/top-10-ratio {:from [:top-10-ratio]},
:pubg.season.stats/kda {:from [:kda]},
:pubg.season.stats/headshot-kill-ratio {:from [:headshot-kill-ratio]},
:pubg.season.stats/current-rank-point {:from [:current-rank-point]},
:pubg.season.stats/dbnos {:from [:d-bn-os]},
:pubg.season.stats/best-tier {:from [:best-tier :tier]},
:pubg.season.stats/avg-survival-time {:from [:avg-survival-time]},
:pubg.season.stats/round-most-kills {:from [:round-most-kills]},
:pubg.season.stats/headshot-kills {:from [:headshot-kills]},
:pubg.season.stats/current-tier {:from [:current-tier :tier]},
:pubg.season.stats/current-sub-tier {:from [:current-tier :sub-tier]},
:pubg.season.stats/best-rank-point {:from [:best-rank-point]},
:pubg.season.stats/longest-kill {:from [:longest-kill]},
:pubg.season.stats/wins {:from [:wins]},
:pubg.season.stats/win-ratio {:from [:win-ratio]},
:pubg.season.stats/rounds-played {:from [:rounds-played]}})

(defn- pack-game-mode-stats
[[game-mode-key stats-map]]
(assoc stats-map :game-mode (name game-mode-key)))
Expand All @@ -184,6 +217,13 @@
:using #(let [stats (map pack-game-mode-stats %)]
(mapv season-stats-parse stats))}})

(defparser
player-season-ranked-stats-parse
{:pubg.player/id {:from [:data :relationships :player :data :id]},
:pubg.player/season-ranked-stats {:from [:data :attributes :ranked-game-mode-stats]
:using #(let [stats (map pack-game-mode-stats %)]
(mapv season-ranked-stats-parse stats))}})

(defparser telemetry-common-parse
{:pubg.match.telemetry.common/is-game {:from [:is-game]}})

Expand Down Expand Up @@ -366,4 +406,3 @@
maybe-discard (fn [x]
(if (map? x) (discard-nil-vals x) x))]
(walk/postwalk maybe-discard evts))}})