-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
58 lines (40 loc) · 1.21 KB
/
models.py
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
from enum import Enum
from pymongo import MongoClient
from bunnet import Document, init_bunnet, Link
from config import settings
class TurfTypes(str, Enum):
natural = "natural"
artificial = "artificial"
hybrid = "hybrid"
class Pitch(Document):
name: str
location: str
turf_type: TurfTypes
condition_score: int = 10
# maintenance
can_be_maintained: bool = False
last_maintained: float = 0
next_maintenance: float = 0
# replacement
replacement_date: float = 0
must_be_replaced: bool = False
def get_score(self) -> int:
return self.condition_score
def set_score(self, new_score: int) -> None:
self.condition_score = new_score
class MaintenanceStatuses(str, Enum):
scheduled = "scheduled"
rescheduled = "rescheduled"
done = "done"
canceled = "canceled"
class Maintenance(Document):
pitch: Link[Pitch]
timestamp: float
status: MaintenanceStatuses = MaintenanceStatuses.scheduled
# Bunnet uses Pymongo client under the hood
client = MongoClient(settings.MONGO_CONNECTION_STRING)
# Initialize bunnet with the Product document class
init_bunnet(
database=client.db_name,
document_models=[Pitch, Maintenance],
)