Skip to content

Commit 2785701

Browse files
committed
Do not use DSSInternalDict in statistics APIs
1 parent 458e9f1 commit 2785701

File tree

1 file changed

+61
-22
lines changed

1 file changed

+61
-22
lines changed

dataikuapi/dss/statistics.py

Lines changed: 61 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from ..utils import DataikuException
22
from .utils import DSSDatasetSelectionBuilder
33
from .future import DSSFuture
4-
from ..utils import DSSInternalDict
54
import json
65
from .metrics import ComputedMetrics
76
from .discussion import DSSObjectDiscussions
@@ -103,10 +102,9 @@ def wrap_computation_result(result):
103102
return future.wait_for_result() if wait else future
104103

105104

106-
class DSSStatisticsWorksheetSettings(DSSInternalDict):
105+
class DSSStatisticsWorksheetSettings(object):
107106
def __init__(self, client, project_key, dataset_name, worksheet_id, worksheet_definition):
108-
super(DSSStatisticsWorksheetSettings,
109-
self).__init__(worksheet_definition)
107+
self._worksheet_definition = worksheet_definition
110108
self.client = client
111109
self.project_key = project_key
112110
self.dataset_name = dataset_name
@@ -120,7 +118,7 @@ def add_card(self, card):
120118
:type card: :class:`DSSStatisticsCardSettings` or dict (obtained from ``DSSStatisticsCardSettings.get_raw()``)
121119
"""
122120
card = DSSStatisticsCardSettings._from_card_or_dict(self.client, card)
123-
self._internal_dict['rootCard']['cards'].append(card.get_raw())
121+
self._worksheet_definition['rootCard']['cards'].append(card.get_raw())
124122

125123
def list_cards(self):
126124
"""
@@ -129,7 +127,15 @@ def list_cards(self):
129127
:rtype: list of :class:`DSSStatisticsCardSettings`
130128
"""
131129
return [DSSStatisticsCardSettings(self.client, card_definition)
132-
for card_definition in self._internal_dict['rootCard']['cards']]
130+
for card_definition in self._worksheet_definition['rootCard']['cards']]
131+
132+
def get_raw(self):
133+
"""
134+
Gets a reference to the raw settings of the worksheet.
135+
136+
:rtype: dict
137+
"""
138+
return self._worksheet_definition
133139

134140
def set_sampling_settings(self, selection):
135141
"""
@@ -139,37 +145,44 @@ def set_sampling_settings(self, selection):
139145
"""
140146
raw_selection = selection.build() if isinstance(
141147
selection, DSSDatasetSelectionBuilder) else selection
142-
self._internal_dict['dataSpec']['datasetSelection'] = raw_selection
148+
self._worksheet_definition['dataSpec']['datasetSelection'] = raw_selection
143149

144150
def get_raw_sampling_settings(self):
145151
"""
146152
Gets a reference to the raw sampling settings of the worksheet.
147153
148154
:rtype: dict
149155
"""
150-
return self._internal_dict['dataSpec']['datasetSelection']
156+
return self._worksheet_definition['dataSpec']['datasetSelection']
151157

152158
def save(self):
153159
"""
154160
Saves the settings to DSS
155161
"""
156-
self._internal_dict = self.client._perform_json(
162+
self._worksheet_definition = self.client._perform_json(
157163
"PUT",
158164
"/projects/%s/datasets/%s/statistics/worksheets/%s" % (
159165
self.project_key, self.dataset_name, self.worksheet_id),
160-
body=self._internal_dict
166+
body=self._worksheet_definition
161167
)
162168

163169

164-
class DSSStatisticsCardSettings(DSSInternalDict):
170+
class DSSStatisticsCardSettings(object):
165171
"""
166172
Object to manipulate the settings of a card
167173
"""
168174

169175
def __init__(self, client, card_definition):
170-
super(DSSStatisticsCardSettings, self).__init__(card_definition)
171176
self.client = client
172-
self._internal_dict = card_definition
177+
self._card_definition = card_definition
178+
179+
def get_raw(self):
180+
"""
181+
Gets a reference to the raw settings of the card.
182+
183+
:rtype: dict
184+
"""
185+
return self._card_definition
173186

174187
def compile(self):
175188
"""
@@ -178,7 +191,7 @@ def compile(self):
178191
:rtype: DSSStatisticsComputationSettings
179192
"""
180193
computation_json = self.client._perform_json(
181-
"POST", "/statistics/cards/compile", body=self._internal_dict
194+
"POST", "/statistics/cards/compile", body=self._card_definition
182195
)
183196
return DSSStatisticsComputationSettings(computation_json)
184197

@@ -189,22 +202,38 @@ def _from_card_or_dict(client, card_or_dict):
189202
return DSSStatisticsCardSettings(client, card_or_dict)
190203

191204

192-
class DSSStatisticsCardResult(DSSInternalDict):
205+
class DSSStatisticsCardResult(object):
193206
"""
194207
Object storing the results of a :class:`DSSStatisticsCardSettings`
195208
"""
196-
pass
197209

210+
def __init__(self, card_result):
211+
self._card_result = card_result
198212

199-
class DSSStatisticsComputationSettings(DSSInternalDict):
213+
def get_raw(self):
214+
"""
215+
Gets a reference to the raw results of the card
216+
217+
:rtype: dict
218+
"""
219+
return self._card_result
220+
221+
222+
class DSSStatisticsComputationSettings(object):
200223
"""
201224
Object to manipulate the settings of a computation
202225
"""
203226

204227
def __init__(self, computation_definition):
205-
super(DSSStatisticsComputationSettings,
206-
self).__init__(computation_definition)
207-
self._internal_dict = computation_definition
228+
self._computation_definition = computation_definition
229+
230+
def get_raw(self):
231+
"""
232+
Gets the raw settings of the computation.
233+
234+
:rtype: dict
235+
"""
236+
return self._computation_definition
208237

209238
@staticmethod
210239
def _from_computation_or_dict(computation_or_dict):
@@ -213,8 +242,18 @@ def _from_computation_or_dict(computation_or_dict):
213242
return DSSStatisticsComputationSettings(computation_or_dict)
214243

215244

216-
class DSSStatisticsComputationResult(DSSInternalDict):
245+
class DSSStatisticsComputationResult(object):
217246
"""
218247
Object storing the results of a :class:`DSSStatisticsComputationSettings`
219248
"""
220-
pass
249+
250+
def __init__(self, computation_result):
251+
self._computation_result = computation_result
252+
253+
def get_raw(self):
254+
"""
255+
Gets a reference to the raw results of the computation
256+
257+
:rtype: dict
258+
"""
259+
return self._computation_result

0 commit comments

Comments
 (0)