Skip to content

Commit 0fbec00

Browse files
authored
Embed enums in their corresponding codecs (#5)
This undoes a change I made to bring all enums out into the bf_codecs module. We believe that this will allow users to have a better understanding of where the enums are intended to be used.
1 parent c13b610 commit 0fbec00

9 files changed

Lines changed: 134 additions & 147 deletions

File tree

brainframe/api/bf_codecs/__init__.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,21 @@
55
ZoneAlarmCountCondition,
66
ZoneAlarmRateCondition,
77
IntersectionPointType,
8-
CountConditionTestType,
9-
RateConditionTestType,
10-
DirectionType,
118
)
12-
from .config_codecs import StreamConfiguration, ConnType
9+
from .config_codecs import StreamConfiguration
1310
from .identity_codecs import Identity, Encoding
1411
from .detection_codecs import Attribute, Detection
1512
from .zone_codecs import Zone, ZoneStatus
1613
from .plugin_codecs import (
1714
PluginOption,
1815
Plugin,
1916
NodeDescription,
20-
OptionType,
21-
SizeType,
2217
)
2318
from .premises_codecs import Premises
24-
from .user_codecs import User, RoleType
19+
from .user_codecs import User
2520
from .license_codecs import (
2621
LicenseTerms,
2722
LicenseInfo,
2823
DATE_FORMAT,
29-
LicenseState,
3024
)
3125
from .sorting import SortOptions, Ordering

brainframe/api/bf_codecs/base_codecs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ class Codec(abc.ABC):
99
def to_dict(self) -> dict:
1010
pass
1111

12-
@abc.abstractstaticmethod
12+
@staticmethod
13+
@abc.abstractmethod
1314
def from_dict(d: dict):
1415
pass
1516

brainframe/api/bf_codecs/condition_codecs.py

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,6 @@
1515
"!=": "Not Equal To"}
1616

1717

18-
class CountConditionTestType(Enum):
19-
"""Defines the way a count condition compares the actual value to the
20-
alarm's test value.
21-
"""
22-
23-
GREATER_THAN = ">"
24-
LESS_THAN = "<"
25-
EQUAL_TO = "="
26-
NOT_EQUAL_TO = "!="
27-
28-
@classmethod
29-
def values(cls):
30-
return [v.value for v in cls]
31-
32-
3318
class IntersectionPointType(Enum):
3419
"""The point on a detection that must be inside a zone for the detection to
3520
count as being inside the zone. The most commonly used intersection point
@@ -54,7 +39,21 @@ class ZoneAlarmCountCondition(Codec):
5439
of objects in a zone to some number.
5540
"""
5641

57-
test: CountConditionTestType
42+
class TestType(Enum):
43+
"""Defines the way a count condition compares the actual value to the
44+
alarm's test value.
45+
"""
46+
47+
GREATER_THAN = ">"
48+
LESS_THAN = "<"
49+
EQUAL_TO = "="
50+
NOT_EQUAL_TO = "!="
51+
52+
@classmethod
53+
def values(cls):
54+
return [v.value for v in cls]
55+
56+
test: TestType
5857
"""The way that the check value will be compared to the actual count
5958
"""
6059

@@ -109,7 +108,7 @@ def from_dict(d: dict):
109108
with_attribute = None
110109
if d["with_attribute"] is not None:
111110
with_attribute = Attribute.from_dict(d["with_attribute"])
112-
test = CountConditionTestType(d["test"])
111+
test = ZoneAlarmCountCondition.TestType(d["test"])
113112

114113
return ZoneAlarmCountCondition(
115114
test=test,
@@ -122,42 +121,40 @@ def from_dict(d: dict):
122121
id=d["id"])
123122

124123

125-
class RateConditionTestType(Enum):
126-
"""Defines the way a rate condition compares the actual rate value to the
127-
alarm's test value.
124+
@dataclass
125+
class ZoneAlarmRateCondition(Codec):
126+
"""A condition that must be met for an alarm to go off. Compares the rate
127+
of change in the count of some object against a test value.
128128
"""
129129

130-
GREATER_THAN_OR_EQUAL_TO = ">="
131-
LESS_THAN_OR_EQUAL_TO = "<="
130+
class TestType(Enum):
131+
"""Defines the way a rate condition compares the actual rate value to
132+
the alarm's test value.
133+
"""
132134

133-
@classmethod
134-
def values(cls):
135-
return [v.value for v in cls]
135+
GREATER_THAN_OR_EQUAL_TO = ">="
136+
LESS_THAN_OR_EQUAL_TO = "<="
136137

138+
@classmethod
139+
def values(cls):
140+
return [v.value for v in cls]
137141

138-
class DirectionType(Enum):
139-
"""Defines the direction of flow that a rate condition pertains to."""
140-
141-
ENTERING = "entering"
142-
EXITING = "exiting"
143-
ENTERING_OR_EXITING = "entering_or_exiting"
144-
145-
@classmethod
146-
def values(cls):
147-
return [v.value for v in cls]
142+
class DirectionType(Enum):
143+
"""Defines the direction of flow that a rate condition pertains to."""
148144

145+
ENTERING = "entering"
146+
EXITING = "exiting"
147+
ENTERING_OR_EXITING = "entering_or_exiting"
149148

150-
@dataclass
151-
class ZoneAlarmRateCondition(Codec):
152-
"""A condition that must be met for an alarm to go off. Compares the rate
153-
of change in the count of some object against a test value.
154-
"""
149+
@classmethod
150+
def values(cls):
151+
return [v.value for v in cls]
155152

156153
_direction_map = {DirectionType.ENTERING: "entered",
157154
DirectionType.EXITING: "exited",
158155
DirectionType.ENTERING_OR_EXITING: "entered or exited"}
159156

160-
test: RateConditionTestType
157+
test: TestType
161158
"""The way that the change value will be compared to the actual rate"""
162159

163160
duration: float
@@ -210,13 +207,13 @@ def from_dict(d: dict):
210207
with_attribute = None
211208
if d["with_attribute"] is not None:
212209
with_attribute = Attribute.from_dict(d["with_attribute"])
213-
test = RateConditionTestType(d["test"])
210+
test = ZoneAlarmRateCondition.TestType(d["test"])
214211

215212
return ZoneAlarmRateCondition(
216213
test=test,
217214
duration=d["duration"],
218215
change=d["change"],
219-
direction=DirectionType(d["direction"]),
216+
direction=ZoneAlarmRateCondition.DirectionType(d["direction"]),
220217
with_class_name=d["with_class_name"],
221218
with_attribute=with_attribute,
222219
intersection_point=intersection_point,

brainframe/api/bf_codecs/config_codecs.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,23 @@
66
from .base_codecs import Codec
77

88

9-
class ConnType(Enum):
10-
IP_CAMERA = "ip_camera"
11-
"""A network camera that uses RTSP or HTTP"""
12-
WEBCAM = "webcam"
13-
"""A webcam (usually USB)"""
14-
FILE = "file"
15-
"""An uploaded video file"""
16-
17-
@classmethod
18-
def values(cls):
19-
return [v.value for v in cls]
20-
21-
229
@dataclass
2310
class StreamConfiguration(Codec):
2411
"""Describes a video stream that BrainFrame may connect to and analyze.
2512
"""
2613

14+
class ConnType(Enum):
15+
IP_CAMERA = "ip_camera"
16+
"""A network camera that uses RTSP or HTTP"""
17+
WEBCAM = "webcam"
18+
"""A webcam (usually USB)"""
19+
FILE = "file"
20+
"""An uploaded video file"""
21+
22+
@classmethod
23+
def values(cls):
24+
return [v.value for v in cls]
25+
2726
name: str
2827
"""The human-readable name of the video stream"""
2928

@@ -78,7 +77,7 @@ def to_dict(self):
7877

7978
@staticmethod
8079
def from_dict(d):
81-
connection_t = ConnType(d["connection_type"])
80+
connection_t = StreamConfiguration.ConnType(d["connection_type"])
8281
return StreamConfiguration(name=d["name"],
8382
id=d["id"],
8483
connection_type=connection_t,

brainframe/api/bf_codecs/license_codecs.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,21 @@ def from_dict(d: dict) -> "LicenseTerms":
5454
return terms
5555

5656

57-
class LicenseState(Enum):
58-
VALID = "valid"
59-
"""A valid license is loaded, features should be enabled"""
60-
INVALID = "invalid"
61-
"""A license was provided, but did not pass validation"""
62-
EXPIRED = "expired"
63-
"""A license was provided, but it has expired"""
64-
MISSING = "missing"
65-
"""No license was provided"""
66-
67-
6857
@dataclass
6958
class LicenseInfo(Codec):
7059
"""Information on the licensing status of the server"""
7160

72-
state: LicenseState
61+
class State(Enum):
62+
VALID = "valid"
63+
"""A valid license is loaded, features should be enabled"""
64+
INVALID = "invalid"
65+
"""A license was provided, but did not pass validation"""
66+
EXPIRED = "expired"
67+
"""A license was provided, but it has expired"""
68+
MISSING = "missing"
69+
"""No license was provided"""
70+
71+
state: State
7372
"""The licensing state of the server."""
7473

7574
terms: Optional[LicenseTerms]
@@ -90,7 +89,7 @@ def from_dict(d: dict) -> "LicenseInfo":
9089
terms = LicenseTerms.from_dict(d["terms"])
9190

9291
return LicenseInfo(
93-
state=LicenseState(d["state"]),
92+
state=LicenseInfo.State(d["state"]),
9493
terms=terms,
9594
)
9695

0 commit comments

Comments
 (0)