-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathtasks.py
More file actions
125 lines (97 loc) · 3.57 KB
/
tasks.py
File metadata and controls
125 lines (97 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
from enum import Enum
from typing import List
class TaskType(Enum):
"""Task Type List"""
Annotation = "annotation"
Categorization = "categorization"
Comparison = "comparison"
CuboidAnnotation = "cuboidannotation"
DataCollection = "datacollection"
DocumentModel = "documentmodel"
DocumentTranscription = "documenttranscription"
ImageAnnotation = "imageannotation"
LaneAnnotation = "laneannotation"
LidarAnnotation = "lidarannotation"
LidarLinking = "lidarlinking"
LidarSegmentation = "lidarsegmentation"
LidarTopdown = "lidartopdown"
LineAnnotation = "lineannotation"
NamedEntityRecognition = "namedentityrecognition"
PointAnnotation = "pointannotation"
PolygonAnnotation = "polygonannotation"
SegmentAnnotation = "segmentannotation"
Transcription = "transcription"
TextCollection = "textcollection"
VideoAnnotation = "videoannotation"
VideoBoxAnnotation = "videoboxannotation"
VideoPlaybackAnnotation = "videoplaybackannotation"
VideoCuboidAnnotation = "videocuboidannotation"
SensorFusion = "sensorfusion"
Chat = "chat"
ChatExperimental = "chatexperimental"
ChatLite = "chatlite"
MultiChat = "multichat"
MultiStage = "multistage"
Federal2dVideoAnnotation = "federal2dvideoannotation"
class TaskReviewStatus(Enum):
"""Customer Audit Status of Task"""
Accepted = "accepted"
Fixed = "fixed"
Commented = "commented"
Rejected = "rejected"
Pending = "pending"
class TaskStatus(Enum):
"""Status of Task"""
Pending = "pending"
Completed = "completed"
Canceled = "canceled"
class Task:
"""Task class, containing task information."""
def __init__(self, json, client):
self._client = client
self._json = json
self.id = json["task_id"]
def __getattr__(self, name):
if name in self._json:
return self._json[name]
raise AttributeError(f"'{type(self).__name__}' object has no attribute {name}")
def __hash__(self):
return hash(self.id)
def __str__(self):
return f"Task(id={self.id})"
def __repr__(self):
return f"Task({self._json})"
def as_dict(self):
"""Returns object details as a dictionary
`Task.as_dict()['params']`
Returns:
Dict with object content
"""
return self._json
def refresh(self):
"""Refreshes the task details."""
self._json = self._client.get_task(self.id).as_dict()
def cancel(self, clear_unique_id: bool = False):
"""Cancels the task"""
self._client.cancel_task(self.id, clear_unique_id)
def audit(self, accepted: bool, comments: str = None):
"""Submit an audit to a completed task"""
self._client.audit_task(self.id, accepted, comments)
def update_unique_id(self, unique_id: str):
"""Updates unique_id of a task"""
self._client.update_task_unique_id(self.id, unique_id)
def clear_unique_id(self):
"""Clears unique_id of a task"""
self._client.clear_task_unique_id(self.id)
def set_metadata(self, metadata: dict):
"""Sets the metadata of a task"""
self._client.set_task_metadata(self.id, metadata)
def set_tags(self, tags: List[str]):
"""Sets tags of a task"""
self._client.set_task_tags(self.id, tags)
def add_tags(self, tags: List[str]):
"""Adds tags for a task"""
self._client.add_task_tags(self.id, tags)
def delete_tags(self, tags: List[str]):
"""Sets tags for a task"""
self._client.delete_task_tags(self.id, tags)