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

add query names, new profile endpoints #53

Open
wants to merge 1 commit 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions numerapi/base_api.py
Expand Up @@ -167,7 +167,7 @@ def get_account(self) -> Dict:
}
"""
query = """
query {
query napi_getAccount{
account {
username
walletAddress
Expand Down Expand Up @@ -218,7 +218,7 @@ def get_models(self, tournament: int = None) -> Dict:
{'uuazed': '9b157d9b-ce61-4ab5-9413-413f13a0c0a6'}
"""
query = """
query {
query napi_getModels{
account {
models {
id
Expand Down Expand Up @@ -255,7 +255,7 @@ def get_current_round(self, tournament: int = None) -> int:
tournament = self.tournament_id
# zero is an alias for the current round!
query = '''
query($tournament: Int!) {
query napi_getCurrentRound($tournament: Int!) {
rounds(tournament: $tournament
number: 0) {
number
Expand Down Expand Up @@ -317,7 +317,7 @@ def get_account_transactions(self) -> Dict:
.. ]}
"""
query = """
query {
query napi_getAccountTransactions{
account {
nmrDeposits {
from
Expand Down Expand Up @@ -426,7 +426,7 @@ def get_transactions(self, model_id: str = None) -> Dict:
self.logger.warning(
"get_transactions is DEPRECATED, use get_account_transactions")
query = """
query($modelId: String) {
query napi_getTransactions($modelId: String) {
user(modelId: $modelId) {
nmrDeposits {
from
Expand Down Expand Up @@ -495,7 +495,7 @@ def set_submission_webhook(self, model_id: str,
True
"""
query = '''
mutation (
mutation napi_setSubmissionWebhook (
$modelId: String!
$newSubmissionWebhook: String
) {
Expand Down
136 changes: 120 additions & 16 deletions numerapi/numerapi.py
Expand Up @@ -210,7 +210,7 @@ def get_competitions(self, tournament=8):
self.logger.info("getting rounds...")

query = '''
query($tournament: Int!) {
query napi_getCompetitions($tournament: Int!) {
rounds(tournament: $tournament) {
number
resolveTime
Expand Down Expand Up @@ -259,7 +259,7 @@ def get_submission_filenames(self, tournament=None, round_num=None,

"""
query = """
query($modelId: String) {
query napi_getSubmissionFilenames($modelId: String) {
model(modelId: $modelId) {
submissions {
filename
Expand Down Expand Up @@ -342,7 +342,7 @@ def get_user(self, model_id: str = None) -> Dict:
"""
self.logger.warning("Method get_user is DEPRECATED, use get_account")
query = """
query($modelId: String) {
query napi_getUser($modelId: String) {
user(modelId: $modelId) {
username
banned
Expand Down Expand Up @@ -433,7 +433,7 @@ def submission_status(self, model_id: str = None) -> Dict:
'validationStdRating': 0.9842992879669488}
"""
query = '''
query($modelId: String) {
query napi_getSubmissionStatus($modelId: String) {
model(modelId: $modelId) {
latestSubmission {
filename
Expand Down Expand Up @@ -507,7 +507,7 @@ def upload_predictions(self, file_path: str = "predictions.csv",
buffer_csv.name = file_path

auth_query = '''
query($filename: String!
query napi_uploadAuth($filename: String!
$tournament: Int!
$modelId: String) {
submission_upload_auth(filename: $filename
Expand All @@ -531,7 +531,7 @@ def upload_predictions(self, file_path: str = "predictions.csv",
requests.put(
submission_auth['url'], data=fh.read(), headers=headers)
create_query = '''
mutation($filename: String!
mutation napi_createSubmission($filename: String!
$tournament: Int!
$modelId: String
$triggerId: String) {
Expand Down Expand Up @@ -567,7 +567,7 @@ def check_new_round(self, hours: int = 24, tournament: int = 8) -> bool:
False
"""
query = '''
query($tournament: Int!) {
query napi_checkNewRound($tournament: Int!) {
rounds(tournament: $tournament
number: 0) {
number
Expand Down Expand Up @@ -636,7 +636,7 @@ def get_leaderboard(self, limit: int = 50, offset: int = 0) -> List[Dict]:

"""
query = '''
query($limit: Int!
query napi_getLeaderboard($limit: Int!
$offset: Int!) {
v2Leaderboard(limit: $limit
offset: $offset) {
Expand Down Expand Up @@ -732,7 +732,7 @@ def stake_get(self, username: str) -> float:
1.1
"""
query = """
query($username: String!) {
query napi_getStake($username: String!) {
v2UserProfile(username: $username) {
dailyUserPerformances {
stakeValue
Expand Down Expand Up @@ -776,7 +776,7 @@ def stake_change(self, nmr, action: str = "decrease",
'status': ''}
"""
query = '''
mutation($value: String!
mutation napi_changeStake($value: String!
$type: String!
$tournamentNumber: Int!
$modelId: String) {
Expand Down Expand Up @@ -890,7 +890,7 @@ def stake_increase(self, nmr, model_id: str = None,
return self.stake_change(nmr, 'increase', model_id, tournament)

def public_user_profile(self, username: str) -> Dict:
"""Fetch the public profile of a user.
"""Fetch the public profile of a user. DEPRECATED

Args:
username (str)
Expand All @@ -914,8 +914,9 @@ def public_user_profile(self, username: str) -> Dict:
'username': 'integration_test'}

"""
self.logger.warning("Method public_user_profile is DEPRECATED, use public_user_profile_v2")
query = """
query($username: String!) {
query napi_getPublicUserProfileV2($username: String!) {
v2UserProfile(username: $username) {
id
startDate
Expand All @@ -931,8 +932,50 @@ def public_user_profile(self, username: str) -> Dict:
utils.replace(data, "startDate", utils.parse_datetime_string)
return data

def public_user_profile_v2(self, username: str) -> Dict:
uuazed marked this conversation as resolved.
Show resolved Hide resolved
"""Fetch the public profile of a user.

Args:
username (str)

Returns:
dict: user profile including the following fields:
* username (`str`)
* startDate (`datetime`)
* id (`string`)
* bio (`str`)
* nmrStaked (`float`)

Example:
>>> api = NumerAPI()
>>> api.public_user_profile("integration_test")
{'bio': 'The official example model. Submits example predictions.',
'id': '59de8728-38e5-45bd-a3d5-9d4ad649dd3f',
'startDate': datetime.datetime(
2018, 6, 6, 17, 33, 21, tzinfo=tzutc()),
'nmrStaked': '57.582371875005243780',
'username': 'integration_test'}

"""
query = """
query napi_getPublicUserProfileV3($username: String!) {
v3UserProfile(modelName: $username) {
id
startDate
username
bio
nmrStaked
}
}
"""
arguments = {'username': username}
data = self.raw_query(query, arguments)['data']['v3UserProfile']
# convert strings to python objects
utils.replace(data, "startDate", utils.parse_datetime_string)
return data

def daily_user_performances(self, username: str) -> List[Dict]:
"""Fetch daily performance of a user.
"""Fetch daily performance of a user. DEPRECATED

Args:
username (str)
Expand Down Expand Up @@ -966,8 +1009,10 @@ def daily_user_performances(self, username: str) -> List[Dict]:
...
]
"""

self.logger.warning("Method daily_user_performances is DEPRECATED, use dailyModelPerformances")
query = """
query($username: String!) {
query napi_getV2DailyUserPerformance($username: String!) {
v2UserProfile(username: $username) {
dailyUserPerformances {
corrRep
Expand All @@ -990,6 +1035,65 @@ def daily_user_performances(self, username: str) -> List[Dict]:
utils.replace(perf, "date", utils.parse_datetime_string)
return performances

def daily_model_performances(self, username: str) -> List[Dict]:
uuazed marked this conversation as resolved.
Show resolved Hide resolved
"""Fetch daily performance of a user.

Args:
username (str)

Returns:
list of dicts: list of daily model performance entries

For each entry in the list, there is a dict with the following
content:

* date (`datetime`)
* corrRank (`int`)
* corrRep (`float` or None)
* mmcRank (`int`)
* mmcRep (`float` or None)
* fncRank (`int`)
* fncRep (`float` or None)

Example:
>>> api = NumerAPI()
>>> api.daily_model_performances("uuazed")
[{
"corrRank": 1550,
"corrRep": 0.03522116352297695,
"date": "2021-07-17T00:00:00Z",
"fncRank": 774,
"fncRep": 0.01958124424503465,
"mmcRank": 1844,
"mmcRep": -0.00010916983051246563
},
...
]
"""

query = """
query napi_getDailyModelPerformance($username: String!) {
v3UserProfile(modelName: $username) {
dailyModelPerformances {
date
corrRep
corrRank
mmcRep
mmcRank
fncRep
fncRank
}
}
}
"""
arguments = {'username': username}
data = self.raw_query(query, arguments)['data']['v3UserProfile']
performances = data['dailyModelPerformances']
# convert strings to python objects
for perf in performances:
utils.replace(perf, "date", utils.parse_datetime_string)
return performances

def round_details(self, round_num: int) -> List[Dict]:
"""Fetch all correlation scores of a round.

Expand All @@ -1016,7 +1120,7 @@ def round_details(self, round_num: int) -> List[Dict]:
]
"""
query = """
query($roundNumber: Int!) {
query napi_getRoundDetails($roundNumber: Int!) {
v2RoundDetails(roundNumber: $roundNumber) {
userPerformances {
date
Expand Down Expand Up @@ -1066,7 +1170,7 @@ def daily_submissions_performances(self, username: str) -> List[Dict]:
]
"""
query = """
query($username: String!) {
query napi_getDailySubmissionPerformances($username: String!) {
v2UserProfile(username: $username) {
dailySubmissionPerformances {
date
Expand Down