numerapi 2.15.1__tar.gz → 2.16.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: numerapi
3
- Version: 2.15.1
3
+ Version: 2.16.0
4
4
  Summary: Automatically download and upload data for the Numerai machine learning competition
5
5
  Home-page: https://github.com/uuazed/numerapi
6
6
  Maintainer: uuazed
@@ -833,7 +833,6 @@ class Api:
833
833
  utils.replace(score, "payoutSettled", fun)
834
834
  return performances
835
835
 
836
-
837
836
  def round_model_performances(self, username: str) -> List[Dict]:
838
837
  """Fetch round model performance of a user.
839
838
 
@@ -1427,3 +1426,83 @@ class Api:
1427
1426
  item["name"]: item["id"]
1428
1427
  for item in data["computePickleDockerImages"]}
1429
1428
  return res
1429
+
1430
+ def submission_ids(self, model_id: str):
1431
+ """ Get all submission ids from a model
1432
+
1433
+ Args:
1434
+ model_id (str)
1435
+
1436
+ Returns:
1437
+ list of dicts: list of submissions
1438
+
1439
+ For each entry in the list, there is a dict with the following
1440
+ content:
1441
+
1442
+ * insertedAt (`datetime`)
1443
+ * filename (`str`)
1444
+ * id (`str`)
1445
+
1446
+ Example:
1447
+ >>> api = NumerAPI(secret_key="..", public_id="..")
1448
+ >>> model_id = napi.get_models()["uuazed"]
1449
+ >>> api.submission_ids(model_id)
1450
+ """
1451
+ query = """
1452
+ query($modelId: String) {
1453
+ submissions(modelId: $modelId) {
1454
+ id
1455
+ filename
1456
+ insertedAt
1457
+ }
1458
+ }
1459
+ """
1460
+ raw = self.raw_query(query, {"modelId": model_id}, authorization=True)
1461
+ data = raw["data"]["submissions"]
1462
+ utils.replace(data, "insertedAt", utils.parse_datetime_string)
1463
+ return data
1464
+
1465
+ def download_submission(self, submission_id: str = None,
1466
+ model_id: str = None, dest_path: str = None) -> str:
1467
+ """ Download previous submissions from numerai
1468
+
1469
+ Args:
1470
+ submission_id (str, optional): the submission to be downloaded
1471
+ model_id (str, optional): if provided, the latest submission of that
1472
+ model gets downloaded
1473
+ dest_path (str, optional): where to save the downloaded file
1474
+
1475
+ Returns:
1476
+ str: path to downloaded file
1477
+
1478
+ Example:
1479
+ # fetch latest submission
1480
+ >>> api = NumerAPI(secret_key="..", public_id="..")
1481
+ >>> model_id = napi.get_models()["uuazed"]
1482
+ >>> api.download_submission(model_id=model_id)
1483
+ # fetch older submssion
1484
+ >>> ids = submission_ids(model_id)
1485
+ >>> import random; submission_id = random.choice(ids)["id"]
1486
+ >>> api.download_submission(submission_id=submission_id)
1487
+ """
1488
+ msg = "You need to provide one of `model_id` and `submission_id"
1489
+ assert model_id or submission_id, msg
1490
+ auth_query = '''
1491
+ query($id: String) {
1492
+ submissionDownloadAuth(id: $id) {
1493
+ filename
1494
+ url
1495
+ }
1496
+ }
1497
+ '''
1498
+ if not submission_id:
1499
+ ids = self.submission_ids(model_id)
1500
+ submission_id = max(ids, key=lambda x: x['insertedAt'])["id"]
1501
+
1502
+ data = self.raw_query(
1503
+ auth_query, {'id': submission_id},
1504
+ authorization=True)['data']["submissionDownloadAuth"]
1505
+ if dest_path is None:
1506
+ dest_path = data["filename"]
1507
+ path = utils.download_file(data["url"], dest_path)
1508
+ return path
@@ -71,13 +71,13 @@ class NumerAPI(base_api.Api):
71
71
  args = {'round': round_num}
72
72
  return self.raw_query(query, args)['data']['listDatasets']
73
73
 
74
- def download_dataset(self, filename: str = "numerai_live_data.csv",
74
+ def download_dataset(self, filename: str = None,
75
75
  dest_path: str = None,
76
76
  round_num: int = None) -> None:
77
77
  """ Download specified file for the given round.
78
78
 
79
79
  Args:
80
- filename (str): file to be downloaded, defaults to live data
80
+ filename (str, optional): file to be downloaded
81
81
  dest_path (str, optional): complete path where the file should be
82
82
  stored, defaults to the same name as the source file
83
83
  round_num (int, optional): tournament round you are interested in.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: numerapi
3
- Version: 2.15.1
3
+ Version: 2.16.0
4
4
  Summary: Automatically download and upload data for the Numerai machine learning competition
5
5
  Home-page: https://github.com/uuazed/numerapi
6
6
  Maintainer: uuazed
@@ -6,7 +6,7 @@ def load(path):
6
6
  return open(path, 'r').read()
7
7
 
8
8
 
9
- numerapi_version = '2.15.1'
9
+ numerapi_version = '2.16.0'
10
10
 
11
11
 
12
12
  classifiers = [
File without changes
File without changes
File without changes
File without changes
File without changes