ims_envista.station_data   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 146
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 86
dl 0
loc 146
rs 10
c 0
b 0
f 0
wmc 9

4 Functions

Rating   Name   Duplication   Size   Complexity  
A monitor_from_json() 0 11 1
A region_from_json() 0 6 1
A station_from_json() 0 14 1
A location_from_json() 0 3 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A Location.__repr__() 0 3 1
A StationInfo.__repr__() 0 12 2
A Monitor.__repr__() 0 2 1
A RegionInfo.__repr__() 0 3 1
1
"""Data Class for Station Data."""
2
3
from __future__ import annotations
4
5
import textwrap
6
from dataclasses import dataclass, field
7
8
9
@dataclass
10
class Location:
11
    """Location (Lat/Long)."""
12
13
    latitude: float
14
    """Latitude"""
15
    longitude: float
16
    """Longitude"""
17
18
    def __repr__(self) -> str:
19
        return textwrap.dedent("""[Lat-{}/Long-{}]""").format(
20
            self.latitude, self.longitude
21
        )
22
23
24
def location_from_json(json: dict) -> Location:
25
    """Convert a JSON object to a Location object."""
26
    return Location(json["latitude"], json["longitude"])
27
28
@dataclass
29
class Monitor:
30
    """Monitor."""
31
32
    channel_id: int
33
    """Channel ID"""
34
    name: str
35
    """Monitored Condition Name"""
36
    alias: str
37
    """Monitored Condition Alias"""
38
    active: bool
39
    """Is the monitored condition active"""
40
    type_id: int
41
    """Monitored Condition Type ID"""
42
    pollutant_id: int
43
    """Monitored Condition Pollutant ID"""
44
    units: str
45
    """Monitored Condition Units"""
46
    description: str
47
    """Monitored Condition Description"""
48
    def __repr__(self) -> str:
49
        return textwrap.dedent("""{}({})""").format(self.name, self.units)
50
51
52
def monitor_from_json(json: dict) -> Monitor:
53
    """Convert a JSON object to a Monitor object."""
54
    return Monitor(
55
        json["channelId"],
56
        json["name"],
57
        json["alias"],
58
        json["active"],
59
        json["typeId"],
60
        json["pollutantId"],
61
        json["units"],
62
        json["description"],
63
    )
64
65
@dataclass
66
class StationInfo:
67
    """Station Information."""
68
69
    station_id: int
70
    """Station ID"""
71
    name: str
72
    """Station name"""
73
    short_name: str
74
    """Station short name"""
75
    stations_tag: str
76
    """Station tags"""
77
    location: Location
78
    """Station Location (Lat/Long)"""
79
    timebase: int
80
    """Timebase"""
81
    active: bool
82
    """Is the station Active"""
83
    owner: str
84
    """Station owner"""
85
    region_id: int
86
    """Region ID"""
87
    station_target: str
88
    """Station Target"""
89
    monitors: list[Monitor] = field(default_factory=list)
90
    """List of Monitored Conditions"""
91
92
    def __repr__(self) -> str:
93
        return textwrap.dedent(
94
            """{} ({}) - Location: {}, {}ctive, Owner: {}, RegionId: {}, Monitors: {}, StationTarget: {}"""
95
        ).format(
96
            self.name,
97
            self.station_id,
98
            self.location,
99
            ("A" if self.active else "Ina"),
100
            self.owner,
101
            self.region_id,
102
            self.monitors,
103
            self.station_target,
104
        )
105
106
107
def station_from_json(json: dict) -> StationInfo:
108
    """Convert a JSON object to a Station object."""
109
    return StationInfo(
110
        json["stationId"],
111
        json["name"],
112
        json["shortName"],
113
        json["stationsTag"],
114
        location_from_json(json["location"]),
115
        json["timebase"],
116
        json["active"],
117
        json["owner"],
118
        json["regionId"],
119
        json["StationTarget"],
120
        [monitor_from_json(monitor) for monitor in json["monitors"]],
121
    )
122
123
@dataclass
124
class RegionInfo:
125
    """Region Information."""
126
127
    region_id: int
128
    """Region ID"""
129
    name: str
130
    """Region Name"""
131
    stations: list[StationInfo] = field(default_factory=list)
132
    """List of Stations in the Region"""
133
134
    def __repr__(self) -> str:
135
        return textwrap.dedent("""{}({}), Stations: {}""").format(
136
            self.name, self.region_id, self.stations
137
        )
138
139
140
def region_from_json(json: dict) -> RegionInfo:
141
    """Convert a JSON object to a Region object."""
142
    return RegionInfo(
143
        json["regionId"],
144
        json["name"],
145
        [station_from_json(station) for station in json["stations"]],
146
    )
147