-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathenums.py
More file actions
212 lines (160 loc) · 5.08 KB
/
enums.py
File metadata and controls
212 lines (160 loc) · 5.08 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import typing
from enum import Enum
from types import DynamicClassAttribute
class classproperty: # noqa
def __init__(self, getter):
self.getter = getter
def __get__(self, instance, owner):
return self.getter(owner)
class BaseTitledEnum(int, Enum):
def __new__(cls, title, value):
obj = super().__new__(cls, value)
obj._value_ = value
obj.__doc__ = title
cls._value2member_map_[title] = obj
return obj
def __repr__(self):
return self._name_
@DynamicClassAttribute
def name(self) -> str:
return self.__doc__
@DynamicClassAttribute
def value(self) -> int:
return super().value
def __unicode__(self):
return self.__doc__
@classmethod
def choices(cls) -> typing.Tuple[str]:
"""Return all titles as choices."""
return tuple(cls._value2member_map_.keys())
@property
def title(self) -> str:
return self._name_
@classmethod
def values(cls) -> typing.List[str]:
"""Return all values (names/titles) in lowercase."""
return [enum.__doc__.lower() for enum in cls if enum.__doc__]
@classmethod
def titles(cls) -> typing.Tuple[str]:
"""Return all titles in the enum."""
return tuple(enum.__doc__ for enum in cls)
def equals(self, other: Enum) -> bool:
"""Compare this enum's name/title with another enum's name/title."""
return (
self.__doc__.lower() == other.__doc__.lower()
if self.__doc__ and other.__doc__
else False
)
def __eq__(self, other):
return super().__eq__(other)
def __hash__(self):
return hash(self.name)
@classmethod
def _missing_(cls, value):
"""Handle creation from value, name, or title."""
if isinstance(value, int):
for enum in cls:
if enum.value == value:
return enum
if isinstance(value, str):
for enum in cls:
if enum.__doc__ and enum.__doc__.lower() == value.lower():
return enum
if value in cls.__members__:
return cls.__members__[value]
raise ValueError(f"{value} is not a valid {cls.__name__}")
class ApprovalStatus(BaseTitledEnum):
NOAPPROVAL = None, 0
REJECTED = "Disapproved", 1
APPROVED = "Approved", 2
@classmethod
def get_mapping(cls) -> typing.Dict[str, int]:
return {i.__repr__(): i.value for i in list(cls)}
class AnnotationTypes(str, Enum):
BBOX = "bbox"
EVENT = "event"
POINT = "point"
POLYGON = "polygon"
POLYLINE = "polyline"
class ProjectType(BaseTitledEnum):
VECTOR = "Vector", 1
PIXEL = "Pixel", 2
VIDEO = "Video", 3
DOCUMENT = "Document", 4
TILED = "Tiled", 5
OTHER = "Other", 6
POINT_CLOUD = "PointCloud", 7
MULTIMODAL = "Multimodal", 8
UNSUPPORTED_TYPE_1 = "UnsupportedType", 9
UNSUPPORTED_TYPE_2 = "UnsupportedType", 10
@classproperty
def images(self):
return self.VECTOR.value, self.PIXEL.value, self.TILED.value
class StepsType(Enum):
INITIAL = 1
BASIC = 2
KEYPOINT = 3
class UserRole(BaseTitledEnum):
CONTRIBUTOR = "Contributor", 4
ADMIN = "Admin", 7
class UploadState(Enum):
INITIAL = 1
BASIC = 2
EXTERNAL = 3
class ImageQuality(BaseTitledEnum):
ORIGINAl = "original", 100
COMPRESSED = "compressed", 60
class ProjectStatus(BaseTitledEnum):
Undefined = "Undefined", -1
NotStarted = "NotStarted", 1
InProgress = "InProgress", 2
Completed = "Completed", 3
OnHold = "OnHold", 4
class FolderStatus(BaseTitledEnum):
Undefined = "Undefined", -1
NotStarted = "NotStarted", 1
InProgress = "InProgress", 2
Completed = "Completed", 3
OnHold = "OnHold", 4
class ExportStatus(BaseTitledEnum):
IN_PROGRESS = "inProgress", 1
COMPLETE = "complete", 2
CANCELED = "canceled", 3
ERROR = "error", 4
class ClassTypeEnum(BaseTitledEnum):
OBJECT = "object", 1
TAG = "tag", 2
RELATIONSHIP = "relationship", 3
@classmethod
def get_value(cls, name):
for enum in list(cls):
if enum.__doc__.lower() == name.lower():
return enum.value
return cls.OBJECT.value
class IntegrationTypeEnum(BaseTitledEnum):
AWS = "aws", 1
GCP = "gcp", 2
AZURE = "azure", 3
CUSTOM = "custom", 4
DATABRICKS = "databricks", 5
SNOWFLAKE = "snowflake", 6
class TrainingStatus(BaseTitledEnum):
NOT_STARTED = "NotStarted", 1
IN_PROGRESS = "InProgress", 2
COMPLETED = "Completed", 3
FAILED_BEFORE_EVALUATION = "FailedBeforeEvaluation", 4
FAILED_AFTER_EVALUATION = "FailedAfterEvaluation", 5
FAILED_AFTER_EVALUATION_WITH_SAVE_MODEL = "FailedAfterEvaluationWithSavedModel", 6
class CustomFieldEntityEnum(str, Enum):
CONTRIBUTOR = "Contributor"
TEAM = "Team"
PROJECT = "Project"
class CustomFieldType(Enum):
Text = 1
MULTI_SELECT = 2
SINGLE_SELECT = 3
DATE_PICKER = 4
NUMERIC = 5
class WMUserStateEnum(str, Enum):
Pending = "PENDING"
Confirmed = "CONFIRMED"