-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2de7287
commit a9a99ad
Showing
19 changed files
with
328 additions
and
49 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 was deleted.
Oops, something went wrong.
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 @@ | ||
from .domain import * |
Empty file.
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,78 @@ | ||
import requests | ||
import typing | ||
import dataclasses | ||
import urllib.parse | ||
import inflection | ||
|
||
from ... import store | ||
from .. import domain | ||
|
||
|
||
@dataclasses.dataclass(frozen=True) | ||
class ClientConfiguration: | ||
|
||
web_base_url: str = dataclasses.field(default_factory=lambda: store.web_base_url) | ||
api_base_url: str = dataclasses.field(default_factory=lambda: store.api_base_url) | ||
debug: bool = dataclasses.field(default_factory=lambda: store.debug) | ||
|
||
|
||
class Client: | ||
|
||
def __init__( | ||
self, | ||
configuration: typing.Optional[ClientConfiguration] = None | ||
): | ||
self._configuration = configuration or ClientConfiguration() | ||
|
||
self._session = requests.Session() | ||
|
||
def _request(self, method, endpoint, *args, **kwargs): | ||
response = super().request( | ||
method, | ||
urllib.parse.urljoin(self._configuration.api_base_url, endpoint), | ||
*args, | ||
**kwargs | ||
) | ||
|
||
status_code = response.status_code | ||
if status_code // 100 != 2: | ||
raise self._convert_error(response) | ||
|
||
return response | ||
|
||
def _convert_error( | ||
self, | ||
response: requests.Response | ||
): | ||
try: | ||
error = response.json() | ||
except: | ||
return ValueError(f"unexpected error: {response.text}") | ||
else: | ||
code = error.pop("code", "") | ||
message = error.pop("message", "") | ||
|
||
error_class = self._find_error_class(code, message) | ||
error = error_class(message) | ||
|
||
for key, value in error.items(): | ||
key = inflection.underscore(key) | ||
setattr(error, key, value) | ||
|
||
return error | ||
|
||
def _find_error_class( | ||
self, | ||
code: str | ||
): | ||
if code: | ||
base_class_name = inflection.camelize(code) | ||
|
||
for suffix in ["Exception", "Error"]: | ||
class_name = base_class_name + suffix | ||
|
||
clazz = getattr(domain, class_name, None) | ||
if clazz is not None: | ||
return clazz | ||
|
||
return domain.ApiException |
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,20 @@ | ||
import typing | ||
|
||
from ._base import Client, ClientConfiguration | ||
|
||
|
||
class PushTokenClient(Client): | ||
|
||
def __init__( | ||
self, | ||
push_token: str, | ||
configuration: typing.Optional[ClientConfiguration]=None, | ||
): | ||
super().__init__(configuration) | ||
|
||
self._session.params.update({ | ||
"pushToken": push_token | ||
}) | ||
|
||
def orthogonalization(): | ||
pass |
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,7 @@ | ||
from ._common import ApiException | ||
from ._crunch import * | ||
from ._common import * | ||
from ._prediction import * | ||
from ._project import * | ||
from ._score import * | ||
from ._submission import * |
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,22 @@ | ||
import datetime | ||
|
||
import dataclasses_json | ||
import marshmallow | ||
|
||
date_config = dataclasses_json.config( | ||
encoder=datetime.date.isoformat, | ||
decoder=datetime.date.fromisoformat, | ||
mm_field=marshmallow.fields.DateTime(format='iso') | ||
) | ||
|
||
datetime_config = dataclasses_json.config( | ||
encoder=datetime.datetime.isoformat, | ||
decoder=datetime.datetime.fromisoformat, | ||
mm_field=marshmallow.fields.Date(format='iso') | ||
) | ||
|
||
|
||
class ApiException(Exception): | ||
|
||
def __init__(self, message: str): | ||
super().__init__(message) |
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,5 @@ | ||
from ._common import ApiException | ||
|
||
|
||
class CurrentCrunchNotFoundException(ApiException): | ||
pass |
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,29 @@ | ||
import dataclasses | ||
import enum | ||
import typing | ||
|
||
import dataclasses_json | ||
|
||
|
||
class PredictionTag(enum.Enum): | ||
|
||
USER_RUN_OUTPUT = "USER_RUN_OUTPUT" | ||
MANAGED_RUN_OUTPUT = "MANAGED_RUN_OUTPUT" | ||
USER_ORTHOGONALIZE = "USER_ORTHOGONALIZE" | ||
|
||
|
||
@dataclasses_json.dataclass_json( | ||
letter_case=dataclasses_json.LetterCase.CAMEL, | ||
undefined=dataclasses_json.Undefined.EXCLUDE | ||
) | ||
@dataclasses.dataclass(frozen=True) | ||
class Prediction: | ||
|
||
id: int | ||
name: typing.Optional[str] | ||
success: typing.Optional[bool] | ||
error: typing.Optional[str] | ||
mean: typing.Optional[float] | ||
tag: PredictionTag | ||
orthogonalized: bool | ||
created_at: bool |
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,5 @@ | ||
from ._common import ApiException | ||
|
||
|
||
class InvalidProjectTokenException(ApiException): | ||
pass |
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,49 @@ | ||
import dataclasses | ||
import datetime | ||
import enum | ||
import typing | ||
|
||
import dataclasses_json | ||
|
||
from ._common import datetime_config | ||
|
||
|
||
class MetricFunction(enum.Enum): | ||
|
||
SPEARMAN = "SPEARMAN" | ||
F1 = "F1" | ||
RECALL = "RECALL" | ||
PRECISION = "PRECISION" | ||
DOT_PRODUCT = "DOT_PRODUCT" | ||
|
||
|
||
@dataclasses_json.dataclass_json( | ||
letter_case=dataclasses_json.LetterCase.CAMEL, | ||
undefined=dataclasses_json.Undefined.EXCLUDE | ||
) | ||
@dataclasses.dataclass(frozen=True) | ||
class Metric: | ||
|
||
id: int | ||
name: str | ||
display_name: str | ||
weight: int | ||
score: bool | ||
multiplier: float | ||
function: MetricFunction | ||
created_at: datetime.datetime = dataclasses.field(metadata=datetime_config) | ||
|
||
|
||
@dataclasses_json.dataclass_json( | ||
letter_case=dataclasses_json.LetterCase.CAMEL, | ||
undefined=dataclasses_json.Undefined.EXCLUDE | ||
) | ||
@dataclasses.dataclass(frozen=True) | ||
class Score: | ||
|
||
id: int | ||
success: bool | ||
metric: Metric | ||
value: typing.Optional[float] | ||
details: typing.Optional[typing.Dict[str, typing.Optional[float]]] | ||
created_at: datetime.datetime = dataclasses.field(metadata=datetime_config) |
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,5 @@ | ||
from ._common import ApiException | ||
|
||
|
||
class NeverSubmittedException(ApiException): | ||
pass |
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
Oops, something went wrong.