Skip to content

Commit

Permalink
feat: task infos by id
Browse files Browse the repository at this point in the history
  • Loading branch information
antwxne committed Jun 14, 2022
1 parent cbfe14b commit 05dc0f5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="CVAT wrapper",
version="0.0.15",
version="0.0.16",
author="antwxne",
author_email="[email protected]",
description="Python wrapper for CVAT API",
Expand Down
22 changes: 19 additions & 3 deletions src/CVAT/_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get_user_by_username(self, username: str) -> Optional[BasicUser]:
response: Response = self.session.get(url=f'{self.url}/api/users?search={username}&limit=10&is_active=true')
return None if response.json()["count"] < 1 else BasicUser.from_json(response.json()["results"][0])

def get_task_by_name(self, task_name: str):
def get_task_by_name(self, task_name: str) -> Optional[Task]:
"""
> This function takes a task name as a string and returns a Task object if it exists, otherwise it returns None
Expand All @@ -43,6 +43,21 @@ def get_task_by_name(self, task_name: str):
response: Response = self.session.get(url=f'{self.url}/api/tasks?search={task_name}&limit=10&is_active=true')
return None if response.json()["count"] < 1 else Task.from_json(response.json()["results"][0])

def get_task_by_id(self, task_id: int) -> Task:
"""
> This function takes in a task id and returns a task object
Args:
task_id (int): The ID of the task you want to get.
Returns:
A Task object
"""
response: Response = self.session.get(url=f'{self.url}/api/tasks/{task_id}')
if response.status_code != 200:
raise Exception(response.content)
return Task.from_json(response.json())

def get_map_external_ids_frame(self, task: Union[Task, str]) -> dict:
"""
> This function takes a task name or a task object and returns a dictionary of image objects
Expand Down Expand Up @@ -112,7 +127,8 @@ def get_prediction_from_file(self, task: Union[Task, str], prediction_type: str,
labels_map: dict = self.get_labels_map(task)
return Get.PREDICTION_FACTORY[prediction_type](prediction_json, frame_map, labels_map)

def get_prediction_from_json(self, task: Union[Task, str], prediction_type: str, prediction: Union[dict, list[dict]]) -> IPrediction:
def get_prediction_from_json(self, task: Union[Task, str], prediction_type: str,
prediction: Union[dict, list[dict]]) -> IPrediction:
"""
> The function takes a task, a prediction type, and a prediction dictionary, and returns a prediction object
Expand Down Expand Up @@ -161,4 +177,4 @@ def get_project_infos(self, project_name: str) -> dict:
response: Response = self.session.get(url=f'{self.url}/api/projects?search={project_name}')
if response.status_code != 200:
raise Exception(response.content)
return response.json()["results"][0]
return response.json()["results"][0]

0 comments on commit 05dc0f5

Please sign in to comment.