generated from CambridgeEngineering/PartIA-Flood-Warning-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
station.py
46 lines (36 loc) · 1.5 KB
/
station.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
# Copyright (C) 2018 Garth N. Wells
#
# SPDX-License-Identifier: MIT
"""This module provides a model for a monitoring station, and tools
for manipulating/modifying station data
"""
class MonitoringStation:
"""This class represents a river level monitoring station"""
def __init__(self, station_id, measure_id, label, coord, typical_range,
river, town):
self.station_id = station_id
self.measure_id = measure_id
# Handle case of erroneous data where data system returns
# '[label, label]' rather than 'label'
self.name = label
if isinstance(label, list):
self.name = label[0]
self.coord = coord
self.typical_range = typical_range
self.river = river
self.town = town
self.latest_level = None
def __repr__(self):
d = "Station name: {}\n".format(self.name)
d += " id: {}\n".format(self.station_id)
d += " measure id: {}\n".format(self.measure_id)
d += " coordinate: {}\n".format(self.coord)
d += " town: {}\n".format(self.town)
d += " river: {}\n".format(self.river)
d += " typical range: {}".format(self.typical_range)
return d
def relative_water_level(self):
try:
return ((self.latest_level - self.typical_range[0]) / (self.typical_range[1] - self.typical_range[0]))
except Exception:
return None