-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathinsight.py
206 lines (154 loc) · 5.02 KB
/
insight.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import json
import sys
from .utils import DSSTaggableObjectListItem, DSSTaggableObjectSettings
if sys.version_info >= (3,0):
import urllib.parse
dku_quote_fn = urllib.parse.quote
else:
import urllib
dku_quote_fn = urllib.quote
INSIGHTS_URI_FORMAT = "/projects/%s/insights/"
INSIGHT_URI_FORMAT = INSIGHTS_URI_FORMAT + "%s/"
class DSSInsight(object):
"""
A handle to interact with an insight on the DSS instance.
.. important::
Do not instantiate directly, use :meth:`dataikuapi.dss.project.DSSProject.get_insight` instead
"""
def __init__(self, client, project_key, insight_id):
self.client = client
self.project_key = project_key
self.insight_id = insight_id
def delete(self):
"""
Delete the insight
"""
return self.client._perform_empty("DELETE", INSIGHT_URI_FORMAT % (self.project_key, self.insight_id))
def get_settings(self):
"""
Get the insight's definition
:return: a handle to inspect the insight definition
:rtype: :class:`dataikuapi.dss.insight.DSSInsightSettings`
"""
return DSSInsightSettings(self.client, self.client._perform_json("GET", INSIGHT_URI_FORMAT % (self.project_key, self.insight_id)))
class DSSInsightListItem(DSSTaggableObjectListItem):
"""
An item in a list of insights.
.. important::
Do not instantiate this class, use :meth:`dataikuapi.dss.project.DSSProject.list_insights`
"""
def __init__(self, client, data):
super(DSSInsightListItem, self).__init__(data)
self.client = client
@property
def id(self):
"""
Get the identifier of the insight
.. note::
The id is generated by DSS upon creation and random.
:rtype: string
"""
return self._data["id"]
@property
def name(self):
"""
Get the name of the insight
.. note::
The name is user-provided and not necessarily unique.
:rtype: str
"""
return self._data['name']
@property
def type(self):
"""
Get the type of the insight (ex: "chart")
:rtype: str
"""
return self._data['type']
@property
def listed(self):
"""
Get the boolean indicating whether the insight is private or public (i.e. promoted)
:rtype: bool
"""
return self._data['listed']
@property
def owner(self):
"""
Get the login of the owner of the insight
:rtype: str
"""
return self._data['owner']
def to_insight(self):
"""
Get a handle to interact with this insight
:return: a handle on the insight
:rtype: :class:`dataikuapi.dss.insight.DSSInsight`
"""
return DSSInsight(self.client, self._data["projectKey"], self._data["id"])
class DSSInsightSettings(DSSTaggableObjectSettings):
"""
Settings for an insight
.. important::
Do not instantiate directly, use :meth:`dataikuapi.dss.insight.DSSInsight.get_settings` instead
"""
def __init__(self, client, settings):
super(DSSInsightSettings, self).__init__(settings)
self.client = client
self.project_key = settings['projectKey']
self.settings = settings
def get_raw(self):
"""
Gets all settings as a raw dictionary.
:return: the settings, as a dict. Fields are:
* **projectKey** and **id** : identify the insight
* **name** : name (label) of the insight
* **owner** : login of the owner of the insight
* **versionTag**, **creationTag**, **checklists**, **tags**, **customFields** : common fields on DSS objects
:rtype: dict
"""
return self.settings
def save(self):
"""
Save the settings to the insight
"""
return self.client._perform_json("POST", INSIGHT_URI_FORMAT % (self.project_key, self.id), body = {'insight': self.settings})
@property
def id(self):
"""
Get the identifier of the insight
.. note::
The id is generated by DSS upon creation and random.
:rtype: string
"""
return self.settings["id"]
@property
def name(self):
"""
Get the name of the insight
.. note::
The name is user-provided and not necessarily unique.
:rtype: str
"""
return self.settings['name']
@property
def type(self):
"""
Get the type of the insight (ex: "chart")
:rtype: str
"""
return self.settings['type']
@property
def listed(self):
"""
Get the boolean indicating whether the insight is private or public (i.e. promoted)
:rtype: bool
"""
return self.settings['listed']
@property
def owner(self):
"""
Get the login of the owner of the insight
:rtype: str
"""
return self.settings['owner']