Skip to content

Commit 241029d

Browse files
committed
[sc-80919] new DSSDatasetInfo class
1 parent ca3dcea commit 241029d

File tree

1 file changed

+82
-6
lines changed

1 file changed

+82
-6
lines changed

dataikuapi/dss/dataset.py

Lines changed: 82 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import datetime
2+
13
from ..utils import DataikuException
24
from ..utils import DataikuUTF8CSVReader
35
from ..utils import DataikuStreamedHttpUTF8CSVReader
@@ -522,16 +524,15 @@ def get_metric_history(self, metric, partition=''):
522524
"GET", "/projects/%s/datasets/%s/metrics/history/%s" % (self.project_key, self.dataset_name, 'NP' if len(partition) == 0 else partition),
523525
params={'metricLookup' : metric if isinstance(metric, str) or isinstance(metric, unicode) else json.dumps(metric)})
524526

525-
def get_full_info(self):
527+
def get_info(self):
526528
"""
527529
Retrieve all the information about a dataset
528530
529-
Returns:
530-
a complex JSON object containing all the information about a dataset, such as params, schema, last build infos, status, etc.
531+
:returns: a :class:`DSSDatasetInfo` containing all the information about a dataset, such as params, schema, last build infos, status, etc.
532+
:rtype: :class:`DSSDatasetInfo`
531533
"""
532-
return self.client._perform_json(
533-
"GET", "/projects/%s/datasets/%s/info" % (self.project_key, self.dataset_name)
534-
)
534+
data = self.client._perform_json("GET", "/projects/%s/datasets/%s/info" % (self.project_key, self.dataset_name))
535+
return DSSDatasetInfo(self, data)
535536

536537
########################################################
537538
# Misc
@@ -869,3 +870,78 @@ def already_exists(self):
869870
return True
870871
except Exception as e:
871872
return False
873+
874+
875+
class DSSDatasetInfo(object):
876+
"""
877+
Info class for a DSS dataset (Read-Only).
878+
Do not instantiate this class directly, use :meth:`DSSDataset.get_info`
879+
"""
880+
881+
def __init__(self, dataset, info):
882+
"""
883+
:type dataset: :class:`DSSDataset`
884+
:type info: dict
885+
"""
886+
self.dataset = dataset
887+
self.info = info
888+
889+
def get_raw(self):
890+
"""
891+
Get the raw dataset full information as a dict
892+
893+
:return: the raw dataset full information
894+
:rtype: dict
895+
"""
896+
return self.info
897+
898+
def get_raw_last_build(self):
899+
"""
900+
Get the last build information of the dataset, as a raw dict, or None if there is no last build information.
901+
902+
:return: the last build information
903+
:rtype: dict or None
904+
"""
905+
return self.info.get("lastBuild", None)
906+
907+
def get_last_build_start_time(self, as_date=False):
908+
"""
909+
Get the last build start time of the dataset as a timestamp or as a :class:`datetime.datetime`, or None if there
910+
is no last build information.
911+
912+
:return: the last build start time
913+
:rtype: int or :class:`datetime.datetime` or None
914+
"""
915+
last_build_info = self.info.get("lastBuild", dict())
916+
timestamp = last_build_info.get("buildStartTime", None)
917+
918+
if as_date and timestamp is not None:
919+
return datetime.datetime.fromtimestamp(timestamp / 1000)
920+
return timestamp
921+
922+
def get_last_build_end_time(self, as_date=False):
923+
"""
924+
Get the last build end time of the dataset as a timestamp or as a :class:`datetime.datetime`, or None if there
925+
is no last build information.
926+
927+
:return: the last build end time
928+
:rtype: int or :class:`datetime.datetime` or None
929+
"""
930+
last_build_info = self.info.get("lastBuild", dict())
931+
timestamp = last_build_info.get("buildEndTime", None)
932+
933+
if as_date and timestamp is not None:
934+
return datetime.datetime.fromtimestamp(timestamp / 1000)
935+
return timestamp
936+
937+
def is_last_build_successful(self):
938+
"""
939+
Get whether the last build of the dataset is successful.
940+
941+
:return: True if the last build is successful, False otherwise
942+
:rtype: bool
943+
"""
944+
last_build_info = self.info.get("lastBuild", dict())
945+
success = last_build_info.get("buildSuccess", False)
946+
947+
return success

0 commit comments

Comments
 (0)