Skip to content

Commit

Permalink
Feature: Model Pred Endpoints
Browse files Browse the repository at this point in the history
Adds model.rankings() : Player Rankings
Adds model.pre_tournament_pred : Pre Tournament Model Predictions
  • Loading branch information
coreyjs committed Jun 10, 2024
1 parent 8b5406f commit 544cfd9
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 6 deletions.
10 changes: 5 additions & 5 deletions data_golf/api/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ def player_list(self, format: str = "json") -> List[dict]:
"""
return self.client.get(resource="/get-player-list", format=format)

def tour_schedule(self, tour: str = "all", format: str = "json") -> dict:
def tour_schedule(self, tour: str = "all", f_format: str = "json") -> dict:
"""
Current season schedule for PGA Tour, European Tour, Korn Ferry Tour, and LIV.
:param tour: str optional defaults to 'all', the tour you want the schedule for. values: all, pga, euro, kft, alt, liv
:param format:
:return:
"""
return self.client.get(resource=f"/get-schedule?tour={tour}", format=format)
return self.client.get(resource=f"/get-schedule?tour={tour}", format=f_format)

def field_updates(self, tour: str = None, format: str = "json") -> List[dict]:
def field_updates(self, tour: str = None, f_format: str = "json") -> List[dict]:
"""
Up-to-the-minute field updates on WDs, Monday Qualifiers, tee times, and fantasy salaries for PGA Tour,
European Tour, and Korn Ferry Tour events. Includes data golf IDs and tour-specific IDs for
each player in the field.
:return:
"""
q = f"?tour={tour}" if tour else ""
return self.client.get(resource=f"/field-updates{q}", format=format)
return self.client.get(resource=f"/field-updates{q}", format=f_format)
40 changes: 40 additions & 0 deletions data_golf/api/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
class Model:
def __init__(self, client):
self.client = client
self._path = "/preds"

def rankings(self, f_format: str = "json") -> dict:
"""
Returns top 500 players according to DG model predictions.
:return: dict
"""
return self.client.get(
resource=f"{self._path}/get-dg-rankings", format=f_format
)

def pre_tournament_pred(
self,
tour: str = "pga",
add_position: str = None,
dead_heat: bool = True,
odds_format: str = "percent",
f_format: str = "json",
) -> dict:
"""
:param tour: pga, euro, kft, opp, alt
:param add_position: 1, 2, 3 (csv separated values)
:param dead_heat: bool - Adjust odds for dead-heat rules.
:param odds_format: percent (default), american, decimal, fraction
:param f_format: json (default)
:return:
"""
# i think there is a better way to handle building and appending query params.
q_p = f"tour={tour}"
q_p += f"&add_position={add_position}" if add_position else ""
q_p += "&dead_heat=yes" if dead_heat else "&dead_heat=no"
q_p += f"&odds_format={odds_format}"

return self.client.get(
resource=f"{self._path}/pre-tournament?{q_p}", format=f_format
)
2 changes: 2 additions & 0 deletions data_golf/client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from data_golf.api.model import Model
from data_golf.config import DGConfig
from data_golf.http import HttpClient
from data_golf.api.general import General
Expand All @@ -24,6 +25,7 @@ def __init__(

# Endpoints
self.general = General(self._http_client)
self.model = Model(self._http_client)

def _validate_api_key(self, api_key: str) -> None:
"""
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "data_golf"
version = "0.2.1"
version = "0.2.2"
description = "API Wrapper for Data golf endpoints"
authors = ["Corey Schaf <cschaf@gmail.com>"]
readme = "README.md"
Expand Down
33 changes: 33 additions & 0 deletions tests/api/test_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from unittest import mock


@mock.patch("httpx.Client.get")
def test_rankings(d_m, dg_client):
dg_client.model.rankings()
d_m.assert_called_once()
assert (
d_m.call_args[1]["url"]
== "https://feeds.datagolf.com/preds/get-dg-rankings?key=test_key&file_format=json"
)


@mock.patch("httpx.Client.get")
def test_pre_tournament_pred(d_m, dg_client):
dg_client.model.pre_tournament_pred()
d_m.assert_called_once()
assert (
d_m.call_args[1]["url"]
== "https://feeds.datagolf.com/preds/pre-tournament?tour=pga&dead_heat=yes&odds_format=percent&key=test_key&file_format=json"
)


@mock.patch("httpx.Client.get")
def test_pre_tournament_with_params(d_m, dg_client):
dg_client.model.pre_tournament_pred(
tour="euro", add_position="1,2,3", dead_heat=False, odds_format="american"
)
d_m.assert_called_once()
assert (
d_m.call_args[1]["url"]
== "https://feeds.datagolf.com/preds/pre-tournament?tour=euro&add_position=1,2,3&dead_heat=no&odds_format=american&key=test_key&file_format=json"
)

0 comments on commit 544cfd9

Please sign in to comment.