-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds model.rankings() : Player Rankings Adds model.pre_tournament_pred : Pre Tournament Model Predictions
- Loading branch information
Showing
5 changed files
with
81 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
) |