Skip to content

Commit b2d3d09

Browse files
authored
Merge pull request #219 from dataiku/feature/dss100-sc-80919-papi-datasets-last-build-information
[sc-80919] new PAPI - dataset get full info
2 parents 6575369 + bc580bd commit b2d3d09

File tree

1 file changed

+69
-2
lines changed

1 file changed

+69
-2
lines changed

dataikuapi/dss/dataset.py

Lines changed: 69 additions & 2 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
@@ -511,7 +513,6 @@ def get_last_metric_values(self, partition=''):
511513
return ComputedMetrics(self.client._perform_json(
512514
"GET", "/projects/%s/datasets/%s/metrics/last/%s" % (self.project_key, self.dataset_name, 'NP' if len(partition) == 0 else partition)))
513515

514-
515516
def get_metric_history(self, metric, partition=''):
516517
"""
517518
Get the history of the values of the metric on this dataset
@@ -523,6 +524,16 @@ def get_metric_history(self, metric, partition=''):
523524
"GET", "/projects/%s/datasets/%s/metrics/history/%s" % (self.project_key, self.dataset_name, 'NP' if len(partition) == 0 else partition),
524525
params={'metricLookup' : metric if isinstance(metric, str) or isinstance(metric, unicode) else json.dumps(metric)})
525526

527+
def get_info(self):
528+
"""
529+
Retrieve all the information about a dataset
530+
531+
:returns: a :class:`DSSDatasetInfo` containing all the information about a dataset.
532+
:rtype: :class:`DSSDatasetInfo`
533+
"""
534+
data = self.client._perform_json("GET", "/projects/%s/datasets/%s/info" % (self.project_key, self.dataset_name))
535+
return DSSDatasetInfo(self, data)
536+
526537
########################################################
527538
# Misc
528539
########################################################
@@ -542,7 +553,7 @@ def move_to_zone(self, zone):
542553
:param object zone: a :class:`dataikuapi.dss.flow.DSSFlowZone` where to move the object
543554
"""
544555
if isinstance(zone, basestring):
545-
zone = self.project.get_flow().get_zone(zone)
556+
zone = self.project.get_flow().get_zone(zone)
546557
zone.add_item(self)
547558

548559
def share_to_zone(self, zone):
@@ -859,3 +870,59 @@ def already_exists(self):
859870
return True
860871
except Exception as e:
861872
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+
self.dataset = dataset
883+
self.info = info
884+
885+
def get_raw(self):
886+
"""
887+
Get the raw dataset full information as a dict
888+
889+
:return: the raw dataset full information
890+
:rtype: dict
891+
"""
892+
return self.info
893+
894+
@property
895+
def last_build_start_time(self):
896+
"""
897+
The last build start time of the dataset as a :class:`datetime.datetime` or None if there is no last build information.
898+
899+
:return: the last build start time
900+
:rtype: :class:`datetime.datetime` or None
901+
"""
902+
last_build_info = self.info.get("lastBuild", dict())
903+
timestamp = last_build_info.get("buildStartTime", None)
904+
return datetime.datetime.fromtimestamp(timestamp / 1000) if timestamp is not None else None
905+
906+
@property
907+
def last_build_end_time(self):
908+
"""
909+
The last build end time of the dataset as a :class:`datetime.datetime` or None if there is no last build information.
910+
911+
:return: the last build end time
912+
:rtype: :class:`datetime.datetime` or None
913+
"""
914+
last_build_info = self.info.get("lastBuild", dict())
915+
timestamp = last_build_info.get("buildEndTime", None)
916+
return datetime.datetime.fromtimestamp(timestamp / 1000) if timestamp is not None else None
917+
918+
@property
919+
def is_last_build_successful(self):
920+
"""
921+
Get whether the last build of the dataset is successful.
922+
923+
:return: True if the last build is successful
924+
:rtype: bool
925+
"""
926+
last_build_info = self.info.get("lastBuild", dict())
927+
success = last_build_info.get("buildSuccess", False)
928+
return success

0 commit comments

Comments
 (0)