|
| 1 | +import datetime |
| 2 | + |
1 | 3 | from ..utils import DataikuException |
2 | 4 | from ..utils import DataikuUTF8CSVReader |
3 | 5 | from ..utils import DataikuStreamedHttpUTF8CSVReader |
@@ -522,16 +524,15 @@ def get_metric_history(self, metric, partition=''): |
522 | 524 | "GET", "/projects/%s/datasets/%s/metrics/history/%s" % (self.project_key, self.dataset_name, 'NP' if len(partition) == 0 else partition), |
523 | 525 | params={'metricLookup' : metric if isinstance(metric, str) or isinstance(metric, unicode) else json.dumps(metric)}) |
524 | 526 |
|
525 | | - def get_full_info(self): |
| 527 | + def get_info(self): |
526 | 528 | """ |
527 | 529 | Retrieve all the information about a dataset |
528 | 530 |
|
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` |
531 | 533 | """ |
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) |
535 | 536 |
|
536 | 537 | ######################################################## |
537 | 538 | # Misc |
@@ -869,3 +870,78 @@ def already_exists(self): |
869 | 870 | return True |
870 | 871 | except Exception as e: |
871 | 872 | 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