defmodule NBA.Stats.PlayerCompare do @moduledoc """ Provides functions to interact with the NBA stats API for PlayerCompare. See `get/2` for parameter and usage details. """ @moduledoc since: "0.1.0" require NBA.Utils NBA.Utils.def_get_bang(__MODULE__) @endpoint "playercompare" @accepted_types %{ LastNGames: [:integer], MeasureType: [:string], Month: [:integer], OpponentTeamID: [:integer, :string], PaceAdjust: [:string], PerMode: [:string], Period: [:integer], PlayerIDList: [:string], PlusMinus: [:string], Rank: [:string], Season: [:string], SeasonType: [:string], VsPlayerIDList: [:string], VsDivision: [:string], VsConference: [:string], ShotClockRange: [:string], SeasonSegment: [:string], Outcome: [:string], Location: [:string], LeagueID: [:string], GameSegment: [:string], Division: [:string], DateTo: [:string], DateFrom: [:string], Conference: [:string] } @default [ LastNGames: 0, MeasureType: "Base", Month: 0, OpponentTeamID: 0, PaceAdjust: "N", PerMode: "PerGame", Period: 0, PlayerIDList: nil, PlusMinus: "N", Rank: "N", Season: nil, SeasonType: "Regular Season", VsPlayerIDList: nil, VsDivision: nil, VsConference: nil, ShotClockRange: nil, SeasonSegment: nil, Outcome: nil, Location: nil, LeagueID: "00", GameSegment: nil, Division: nil, DateTo: nil, DateFrom: nil, Conference: nil ] @required [ :PlayerIDList, :Season, :VsPlayerIDList ] @doc """ Fetches PlayerCompare data. ## Parameters - `params`: A keyword list of parameters to filter the data. - `PlayerIDList`: **(Required)** Comma-separated list of player IDs. - _Type(s)_: `String` - _Example_: `PlayerIDList: "201939,202691"` - _Default_: `nil` - `Season`: **(Required)** The season. - _Type(s)_: `String` - _Example_: `Season: "2024-25"` - _Default_: `nil` - `VsPlayerIDList`: **(Required)** Comma-separated list of vs player IDs. - _Type(s)_: `String` - _Example_: `VsPlayerIDList: "201939,202691"` - _Default_: `nil` - `LastNGames`: Number of last games to include. - _Type(s)_: `Integer` - _Example_: `LastNGames: 10` - _Default_: `0` - `MeasureType`: The type of measure. - _Type(s)_: `String` - _Example_: `MeasureType: "Base"` - _Default_: `"Base"` - _Valueset_: - `"Base"` - `"Advanced"` - `"Misc"` - `"Four Factors"` - `"Scoring"` - `"Opponent"` - `"Usage"` - `"Defense"` - `Month`: The month number. - _Type(s)_: `Integer` - _Example_: `Month: 1` - _Default_: `0` - `OpponentTeamID`: The opponent team ID. - _Type(s)_: `Integer | String` - _Example_: `OpponentTeamID: 1610612737` - _Default_: `0` - `PaceAdjust`: Whether to adjust for pace. - _Type(s)_: `String` - _Example_: `PaceAdjust: "Y"` - _Default_: `"N"` - _Valueset_: - `"Y"` - `"N"` - `PerMode`: How to aggregate stats. - _Type(s)_: `String` - _Example_: `PerMode: "PerGame"` - _Default_: `"PerGame"` - _Valueset_: - `"Totals"` - `"PerGame"` - `"MinutesPer"` - `"Per48"` - `"Per40"` - `"Per36"` - `"PerMinute"` - `"PerPossession"` - `"PerPlay"` - `"Per100Possessions"` - `"Per100Plays"` - `Period`: The period number. - _Type(s)_: `Integer` - _Example_: `Period: 1` - _Default_: `0` - `PlusMinus`: Whether to include plus/minus. - _Type(s)_: `String` - _Example_: `PlusMinus: "Y"` - _Default_: `"N"` - _Valueset_: - `"Y"` - `"N"` - `Rank`: Whether to include rank. - _Type(s)_: `String` - _Example_: `Rank: "Y"` - _Default_: `"N"` - _Valueset_: - `"Y"` - `"N"` - `SeasonType`: The type of season. - _Type(s)_: `String` - _Example_: `SeasonType: "Regular Season"` - _Default_: `"Regular Season"` - _Valueset_: - `"Regular Season"` - `"Pre Season"` - `"Playoffs"` - `VsDivision`: The vs division. - _Type(s)_: `String` - _Example_: `VsDivision: "Atlantic"` - _Default_: `nil` - _Valueset_: - `"Atlantic"` - `"Central"` - `"Northwest"` - `"Pacific"` - `"Southeast"` - `"Southwest"` - `"East"` - `"West"` - `VsConference`: The vs conference. - _Type(s)_: `String` - _Example_: `VsConference: "East"` - _Default_: `nil` - _Valueset_: - `"East"` - `"West"` - `ShotClockRange`: The shot clock range. - _Type(s)_: `String` - _Example_: `ShotClockRange: "24-22"` - _Default_: `nil` - `SeasonSegment`: The season segment. - _Type(s)_: `String` - _Example_: `SeasonSegment: "Pre All-Star"` - _Default_: `nil` - _Valueset_: - `"Post All-Star"` - `"Pre All-Star"` - `Outcome`: The outcome. - _Type(s)_: `String` - _Example_: `Outcome: "W"` - _Default_: `nil` - _Valueset_: - `"W"` - `"L"` - `Location`: The location. - _Type(s)_: `String` - _Example_: `Location: "Home"` - _Default_: `nil` - _Valueset_: - `"Home"` - `"Road"` - `LeagueID`: The league ID. - _Type(s)_: `String` - _Example_: `LeagueID: "00"` - _Default_: `"00"` - _Valueset_: - `"00"` (NBA) - `"01"` (ABA) - `"10"` (WNBA) - `"20"` (G League) - `GameSegment`: The game segment. - _Type(s)_: `String` - _Example_: `GameSegment: "First Half"` - _Default_: `nil` - _Valueset_: - `"First Half"` - `"Overtime"` - `"Second Half"` - `Division`: The division. - _Type(s)_: `String` - _Example_: `Division: "Atlantic"` - _Default_: `nil` - `DateTo`: The end date. - _Type(s)_: `String` - _Example_: `DateTo: "2024-01-31"` - _Default_: `nil` - `DateFrom`: The start date. - _Type(s)_: `String` - _Example_: `DateFrom: "2024-01-01"` - _Default_: `nil` - `Conference`: The conference. - _Type(s)_: `String` - _Example_: `Conference: "East"` - _Default_: `nil` - _Valueset_: - `"East"` - `"West"` - `opts`: A keyword list of additional options for the request, such as headers or timeout settings. - For a full list of options, see the [Req documentation](https://hexdocs.pm/req/Req.html#new/1). ## Returns - `{:ok, data}`: On success, returns the data from the API. - `{:error, reason}`: On failure, returns an error tuple with the reason. ## Example iex> NBA.Stats.PlayerCompare.get(LastNGames: 10, MeasureType: "Base", Month: 1, OpponentTeamID: 1610612737, PaceAdjust: "N", PerMode: "PerGame", Period: 1, PlayerIDList: "201939,202691", PlusMinus: "N", Rank: "N", Season: "2024-25", SeasonType: "Regular Season", VsPlayerIDList: "201939,202691") {:ok, %{"PlayerCompare" => [%{...}, ...]}} """ def get(params \\ @default, opts \\ []) do with :ok <- NBA.Utils.validate_input(params, opts, @accepted_types, @required), params <- Keyword.merge(@default, params) do case NBA.API.Stats.get(@endpoint, params, opts) do {:ok, %{data: data}} -> {:ok, data} other -> NBA.Utils.handle_api_error(other) end else err -> NBA.Utils.handle_validation_error(err) end end end