Passed
Pull Request — master (#166)
by Antonio
06:14
created

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

Complexity

Conditions 1

Size

Total Lines 25
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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