Test Failed
Pull Request — master (#166)
by Antonio
04:21 queued 56s
created

build.db.models.EVCBaseDoc.projection()   A

Complexity

Conditions 1

Size

Total Lines 25
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 24
nop 0
dl 0
loc 25
rs 9.304
c 0
b 0
f 0
1
"""Models for Mongo DB"""
2
3
from datetime import date, datetime
4
from pathlib import Path
5
from typing import Dict, List, Optional
6
from pydantic import BaseModel, Field
7
8
9
class DocumentBaseModel(BaseModel):
10
    """Base model for Mongo documents"""
11
12
    id: str = Field(None, alias="_id")
13
    inserted_at: Optional[datetime]
14
    updated_at: Optional[datetime]
15
16
    def dict(self, **kwargs) -> Dict:
17
        """Return a dictionary representation of the model"""
18
        values = super().dict(**kwargs)
19
        if "id" in values and values["id"]:
20
            values["_id"] = values["id"]
21
        if "exclude" in kwargs and "_id" in kwargs["exclude"]:
22
            del values["_id"]
23
        return values
24
25
26
class CircuitScheduleDoc(BaseModel):
27
    """EVC circuit schedule model"""
28
29
    date: Optional[date]
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable date does not seem to be defined.
Loading history...
30
    frequency: Optional[str]
31
    interval: Optional[int]
32
    action: str
33
34
35
class TAGDoc(BaseModel):
36
    tag_type: int
37
    value: int
38
39
40
class UNIDoc(BaseModel):
41
    """UNI model"""
42
43
    tag: TAGDoc
44
    interface_id: str
45
46
        
47
class EVCBaseDoc(DocumentBaseModel):
48
    """Base model for EVC documents"""
49
50
    uni_a: UNIDoc
51
    uni_z: UNIDoc
52
    name: str
53
    start_date: Optional[datetime]
54
    end_date: Optional[datetime]
55
    queue_id: Optional[int]
56
    bandwidth: int = 0
57
    primary_path: Optional[List]
58
    backup_path: Optional[List]
59
    current_path: Optional[List]
60
    dynamic_backup_path: bool
61
    creation_time: datetime
62
    owner: Optional[str]
63
    priority: int
64
    circuit_scheduler: List[CircuitScheduleDoc]
65
    archived: bool = False
66
    metadata: Optional[Dict] = None
67
    active: bool
68
    enabled: bool
69
    
70
    def __init__(self, *args, **kwargs):
71
        super().__init__(*args, **kwargs)
72
73
    @staticmethod
74
    def projection() -> Dict:
75
        """Base projection of EVCBaseDoc model."""
76
        return {
77
            "_id": 0,
78
            "id": 1,
79
            "uni_a": 1,
80
            "uni_z": 1,
81
            "name": 1,
82
            "start_date": 1,
83
            "end_date": 1,
84
            "queue_id": 1,
85
            "bandwidth": 1,
86
            "primary_path": 1,
87
            "backup_path": 1,
88
            "current_path": 1,
89
            "dynamic_backup_path": 1,
90
            "creation_time": 1,
91
            "owner": 1,
92
            "priority": 1,
93
            "circuit_scheduler": 1,
94
            "archived": 1,
95
            "metadata": 1,
96
            "active": 1,
97
            "enabled": 1,
98
        }