forked from ExpDev07/coronavirus-tracker-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoordinates.py
More file actions
47 lines (37 loc) · 1.36 KB
/
coordinates.py
File metadata and controls
47 lines (37 loc) · 1.36 KB
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
"""app.coordinates.py"""
class Latitude:
"""
A numeric representation of a latitudinal position north or south of the Earth's equator, to track Coronavirus spread nation to nation latitudinally.
"""
def __init__(self, value: float):
self.data = value
def sum(other: Latitude):
self.data += other.data
def merge(other: Longitude):
return Coordinates(self, other)
class Longitude:
"""
A numeric representation of a longitudinal position measuring east to west, to track Coronavirus spread nation to nation longitudinally
"""
def __init__(self, value: float):
self.data = value
def sum(other: Longitude):
self.data += other.data
def merge(other: Latitude):
return Coordinates(self, other)
class Coordinates:
"""
A position on earth using decimal coordinates (latitude and longitude).
"""
def __init__(self, latitude: Latitude, longitude:Longitude):
self.latitude = latitude
self.longitude = longitude
def serialize(self):
"""
Serializes the coordinates into a dict.
:returns: The serialized coordinates.
:rtype: dict
"""
return {"latitude": self.latitude.data, "longitude": self.longitude.data}
def __str__(self):
return "lat: %s, long: %s" % (self.latitude.data, self.longitude.data)