Skip to content

Commit cadca24

Browse files
committed
Relocate /statistics/* on top of /datasets/XXX/statistics/*
1 parent 7600404 commit cadca24

File tree

4 files changed

+66
-73
lines changed

4 files changed

+66
-73
lines changed

dataikuapi/dss/dataset.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import json
55
from .metrics import ComputedMetrics
66
from .discussion import DSSObjectDiscussions
7+
from .worksheet import DSSStatisticsWorksheet, DSSStatisticsCard
78

89
class DSSDataset(object):
910
"""
@@ -204,6 +205,57 @@ def run_checks(self, partition='', checks=None):
204205
"POST" , "/projects/%s/datasets/%s/actions/runChecks" %(self.project_key, self.dataset_name),
205206
params={'partition':partition}, body=checks)
206207

208+
########################################################
209+
# Statistics worksheets
210+
########################################################
211+
212+
def list_statistics_worksheets(self, as_objects=True):
213+
worksheets = self.client._perform_json(
214+
"GET", "/projects/%s/datasets/%s/statistics/worksheets/" % (self.project_key, self.dataset_name))
215+
if as_objects:
216+
return [self.get_statistics_worksheet(worksheet['id']) for worksheet in worksheets]
217+
else:
218+
return worksheets
219+
220+
def create_statistics_worksheet(self, name="My worksheet"):
221+
"""
222+
Create a new worksheet in the project, and return a handle to interact with it.
223+
224+
:param string input_dataset: input dataset of the worksheet
225+
:param string worksheet_name: name of the worksheet
226+
227+
Returns:
228+
A :class:`dataikuapi.dss.dataset.DSSStatisticsWorksheet` dataset handle
229+
"""
230+
231+
worksheet_definition = {
232+
"projectKey": self.project_key,
233+
"name": name,
234+
"dataSpec": {
235+
"inputDatasetSmartName": self.dataset_name,
236+
"datasetSelection": {
237+
"partitionSelectionMethod": "ALL",
238+
"maxRecords": 30000,
239+
"samplingMethod": "FULL"
240+
}
241+
}
242+
}
243+
created_worksheet = self.client._perform_json(
244+
"POST", "/projects/%s/datasets/%s/statistics/worksheets/" % (self.project_key, self.dataset_name),
245+
body=worksheet_definition
246+
)
247+
return self.get_statistics_worksheet(created_worksheet['id'])
248+
249+
def get_statistics_worksheet(self, worksheet_id):
250+
"""
251+
Get a handle to interact with a specific worksheet
252+
253+
:param string worksheet_id: the ID of the desired worksheet
254+
255+
:returns: A :class:`dataikuapi.dss.worksheet.DSSStatisticsWorksheet` worksheet handle
256+
"""
257+
return DSSStatisticsWorksheet(self.client, self.project_key, self.dataset_name, worksheet_id)
258+
207259
########################################################
208260
# Metrics
209261
########################################################

dataikuapi/dss/project.py

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from .savedmodel import DSSSavedModel
66
from .job import DSSJob, DSSJobWaiter
77
from .scenario import DSSScenario
8-
from .worksheet import DSSStatisticsWorksheet, DSSStatisticsCard
98
from .apiservice import DSSAPIService
109
import sys
1110
import os.path as osp
@@ -16,8 +15,7 @@
1615
from .discussion import DSSObjectDiscussions
1716
from .ml import DSSMLTask
1817
from .analysis import DSSAnalysis
19-
from dataikuapi.utils import DataikuException, resolve_smart_name
20-
18+
from dataikuapi.utils import DataikuException
2119

2220

2321
class DSSProject(object):
@@ -794,60 +792,8 @@ def set_tags(self, tags={}):
794792
Set the tags of this project.
795793
@param obj: must be a modified version of the object returned by list_tags
796794
"""
797-
return self.client._perform_empty("PUT", "/projects/%s/tags" % self.project_key, body=tags)
798-
799-
########################################################
800-
# Statistics worksheets
801-
########################################################
802-
803-
def list_statistics_worksheets(self, as_objects=True):
804-
worksheets = self.client._perform_json(
805-
"GET", "/projects/%s/statistics/worksheets/" % self.project_key)
806-
if as_objects:
807-
return [self.get_statistics_worksheet(worksheet['id']) for worksheet in worksheets]
808-
else:
809-
return worksheets
810-
811-
def create_statistics_worksheet(self, input_dataset, name="My worksheet"):
812-
"""
813-
Create a new worksheet in the project, and return a handle to interact with it.
795+
return self.client._perform_empty("PUT", "/projects/%s/tags" % self.project_key, body = tags)
814796

815-
:param string input_dataset: input dataset of the worksheet
816-
:param string worksheet_name: name of the worksheet
817-
818-
Returns:
819-
A :class:`dataikuapi.dss.dataset.DSSStatisticsWorksheet` dataset handle
820-
"""
821-
dataset_project_key, dataset_name = resolve_smart_name(
822-
input_dataset, self.project_key)
823-
824-
worksheet_definition = {
825-
"projectKey": self.project_key,
826-
"name": name,
827-
"dataSpec": {
828-
"dataset": {"id": dataset_name, "projectKey": dataset_project_key},
829-
"datasetSelection": {
830-
"partitionSelectionMethod": "ALL",
831-
"maxRecords": 30000,
832-
"samplingMethod": "FULL"
833-
}
834-
}
835-
}
836-
created_worksheet = self.client._perform_json(
837-
"POST", "/projects/%s/statistics/worksheets/" % self.project_key,
838-
body=worksheet_definition
839-
)
840-
return self.get_statistics_worksheet(created_worksheet['id'])
841-
842-
def get_statistics_worksheet(self, worksheet_id):
843-
"""
844-
Get a handle to interact with a specific worksheet
845-
846-
:param string worksheet_id: the ID of the desired worksheet
847-
848-
:returns: A :class:`dataikuapi.dss.worksheet.DSSStatisticsWorksheet` worksheet handle
849-
"""
850-
return DSSStatisticsWorksheet(self.client, self.project_key, worksheet_id)
851797

852798
########################################################
853799
# Macros

dataikuapi/dss/worksheet.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ class DSSStatisticsWorksheet(object):
1010
A handle to interact with a worksheet on the DSS instance
1111
"""
1212

13-
def __init__(self, client, project_key, worksheet_id):
13+
def __init__(self, client, project_key, dataset_name, worksheet_id):
1414
self.client = client
1515
self.project_key = project_key
16+
self.dataset_name = dataset_name
1617
self.worksheet_id = worksheet_id
1718

1819
########################################################
@@ -24,7 +25,7 @@ def delete(self):
2425
Delete the worksheet
2526
"""
2627
return self.client._perform_empty(
27-
"DELETE", "/projects/%s/statistics/worksheets/%s" % (self.project_key, self.worksheet_id))
28+
"DELETE", "/projects/%s/datasets/%s/statistics/worksheets/%s" % (self.project_key, self.dataset_name, self.worksheet_id))
2829

2930
########################################################
3031
# Worksheet definition
@@ -38,7 +39,7 @@ def get_definition(self):
3839
the definition, as a JSON object
3940
"""
4041
return self.client._perform_json(
41-
"GET", "/projects/%s/statistics/worksheets/%s" % (self.project_key, self.worksheet_id))
42+
"GET", "/projects/%s/datasets/%s/statistics/worksheets/%s" % (self.project_key, self.dataset_name, self.worksheet_id))
4243

4344
def set_definition(self, definition):
4445
"""
@@ -49,7 +50,7 @@ def set_definition(self, definition):
4950
that has been retrieved using the get_definition call.
5051
"""
5152
return self.client._perform_json(
52-
"PUT", "/projects/%s/statistics/worksheets/%s" % (self.project_key, self.worksheet_id), body=definition)
53+
"PUT", "/projects/%s/datasets/%s/statistics/worksheets/%s" % (self.project_key, self.dataset_name, self.worksheet_id), body=definition)
5354

5455
def add_card(self, card_definition):
5556
"""
@@ -73,7 +74,8 @@ def get_standalone_cards(self):
7374
definition = self.get_definition()
7475
standalone_cards = []
7576
for card in definition["rootCard"]["cards"]:
76-
standalone_cards.append(DSSStatisticsCard(self.client, self.project_key, definition['dataSpec'], card))
77+
standalone_cards.append(DSSStatisticsCard(
78+
self.client, self.project_key, self.dataset_name, definition['dataSpec'], card))
7779

7880
return standalone_cards
7981

@@ -89,7 +91,7 @@ def compute(self):
8991
"""
9092

9193
future_response = self.client._perform_json(
92-
"POST", "/projects/%s/statistics/worksheets/%s/actions/compute-worksheet" % (self.project_key, self.worksheet_id))
94+
"POST", "/projects/%s/datasets/%s/statistics/worksheets/%s/actions/compute-worksheet" % (self.project_key, self.dataset_name, self.worksheet_id))
9395

9496
return DSSFuture(self.client, future_response.get("jobId", None), future_response)
9597

@@ -101,9 +103,10 @@ class DSSStatisticsCard(object):
101103
Unlike a worksheet, a standalone card is not persisted on the DSS instance
102104
"""
103105

104-
def __init__(self, client, project_key, data_spec, card):
106+
def __init__(self, client, project_key, dataset_name, data_spec, card):
105107
self.client = client
106108
self.project_key = project_key
109+
self.dataset_name = dataset_name
107110
self.data_spec = data_spec
108111
self.card = card
109112

@@ -115,6 +118,7 @@ def compute(self):
115118
"""
116119

117120
future_response = self.client._perform_json(
118-
"POST", "/projects/%s/statistics/cards/compute-card" % self.project_key,
121+
"POST", "/projects/%s/datasets/%s/statistics/cards/compute-card" % (
122+
self.project_key, self.dataset_name),
119123
body={"card": self.card, "dataSpec": self.data_spec})
120124
return DSSFuture(self.client, future_response.get("jobId", None), future_response)

dataikuapi/utils.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,3 @@ def str_to_bool(s):
9494
doublequote=True):
9595
yield [none_if_throws(caster)(val)
9696
for (caster, val) in dku_zip_longest(casters, uncasted_tuple)]
97-
98-
def resolve_smart_name(smart_name, context_project_key):
99-
parts = smart_name.split('.')
100-
if len(parts) == 1:
101-
return context_project_key, smart_name
102-
elif len(parts) == 2:
103-
return parts[0], parts[1]
104-
else:
105-
raise ValueError('Invalid smart name: %s' % smart_name)

0 commit comments

Comments
 (0)