From 9556cf4b43d95ad5905001963a23bc51c0941039 Mon Sep 17 00:00:00 2001 From: Igor Davidyuk Date: Thu, 18 Jul 2024 10:55:23 +0300 Subject: [PATCH] Add Job Cost info to job data scheme (#467) * add job cost info to job data scheme Signed-off-by: Igor Davidyuk * Update geti_sdk/rest_clients/project_client/project_client.py Co-authored-by: Ludo Cornelissen --------- Signed-off-by: Igor Davidyuk Co-authored-by: Ludo Cornelissen --- 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..14b60565 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 isinstance(dataset_statistics, 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}."