From a4cd2f822e1065626a0e35328b575404c8fd1117 Mon Sep 17 00:00:00 2001 From: Igor Davidyuk Date: Tue, 16 Jul 2024 15:50:00 +0200 Subject: [PATCH 1/2] add job cost info to job data scheme Signed-off-by: Igor Davidyuk --- geti_sdk/data_models/job.py | 11 +++++++++++ geti_sdk/data_models/project.py | 4 ++-- .../rest_clients/project_client/project_client.py | 12 +++++++----- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/geti_sdk/data_models/job.py b/geti_sdk/data_models/job.py index 9dc23018..c1e14465 100644 --- a/geti_sdk/data_models/job.py +++ b/geti_sdk/data_models/job.py @@ -213,6 +213,16 @@ class JobCancellationInfo: cancel_time: Optional[str] = attr.field(converter=str_to_datetime, default=None) +@attr.define +class JobCost: + """ + Information relating to the cost of a Job in Intel Geti + """ + + requests: List + consumed: List + + @attr.define(slots=False) class Job: """ @@ -248,6 +258,7 @@ class Job: converter=str_to_optional_enum_converter(JobState), default=None ) # Added in Geti v1.7 steps: Optional[List[dict]] = None # Added in Geti v1.7 + cost: Optional[JobCost] = None # Added in Geti v2.2 def __attrs_post_init__(self): """ diff --git a/geti_sdk/data_models/project.py b/geti_sdk/data_models/project.py index 51f391e1..7d99bfe8 100644 --- a/geti_sdk/data_models/project.py +++ b/geti_sdk/data_models/project.py @@ -370,8 +370,8 @@ def summary(self) -> str: @property def training_dataset(self) -> Dataset: """ - Return the training dataset for the project. + Return a training dataset for the project. :return: Training dataset for the project """ - return [dataset for dataset in self.datasets if dataset.use_for_training][0] + return next(dataset for dataset in self.datasets if dataset.use_for_training) diff --git a/geti_sdk/rest_clients/project_client/project_client.py b/geti_sdk/rest_clients/project_client/project_client.py index 1a1f1fdd..776ad7b9 100644 --- a/geti_sdk/rest_clients/project_client/project_client.py +++ b/geti_sdk/rest_clients/project_client/project_client.py @@ -156,7 +156,9 @@ def get_project_by_name( f"the project ID's `{[p.id for p in matches]}` matches the " f"requested id `{project_id}`." ) - return matched_project + return None + else: + return self._get_project_detail(matched_project) else: return None @@ -524,10 +526,10 @@ def delete_project( f"{dataset.id}/statistics", method="GET", ) - if dataset_statistics is dict: - dataset_statistics["overview"].get("image_count", 0) - image_count += dataset_statistics.get("images", 0) - video_count += dataset_statistics.get("videos", 0) + if type(dataset_statistics) is dict: + dataset_overview = dataset_statistics["overview"] + image_count += dataset_overview.get("images", 0) + video_count += dataset_overview.get("videos", 0) else: logging.warning( f"Unable to retrieve statistics for dataset {dataset.name}." From e26f24a0799f61e6fc373445b7ad59cb7c43e1e6 Mon Sep 17 00:00:00 2001 From: Igor Davidyuk Date: Thu, 18 Jul 2024 10:40:51 +0300 Subject: [PATCH 2/2] Update geti_sdk/rest_clients/project_client/project_client.py Co-authored-by: Ludo Cornelissen --- geti_sdk/rest_clients/project_client/project_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geti_sdk/rest_clients/project_client/project_client.py b/geti_sdk/rest_clients/project_client/project_client.py index 776ad7b9..14b60565 100644 --- a/geti_sdk/rest_clients/project_client/project_client.py +++ b/geti_sdk/rest_clients/project_client/project_client.py @@ -526,7 +526,7 @@ def delete_project( f"{dataset.id}/statistics", method="GET", ) - if type(dataset_statistics) is dict: + if isinstance(dataset_statistics, dict): dataset_overview = dataset_statistics["overview"] image_count += dataset_overview.get("images", 0) video_count += dataset_overview.get("videos", 0)