-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodels.py
executable file
·54 lines (48 loc) · 1.91 KB
/
models.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
47
48
49
50
51
52
53
54
from osgeo import ogr
from itertools import chain
def get_wkt_line(coords: list) -> str:
"""
transforms list of coordinates list([x, y]) to WKT string (LineString)
:param coords: list of lists with len==2, e.g. [[x, y], [x, y]...]
:return: str
"""
line = ogr.Geometry(ogr.wkbLineString)
if len(coords) == 1:
coords = list(chain(*coords))
for i in coords:
line.AddPoint(i[0], i[1])
return line.ExportToWkt()
class Category:
def __init__(self, _id, checked, parent, name):
self._id = _id
self.checked = checked
self.parent = parent
self.name = name
class Parking:
def __init__(self, data: dict):
self.category = data['category']['_id']
self._id = data['_id']
self.street = data['address']['street']['ru']
self.house = data['address']['house']['ru']
self.wkt = get_wkt_line(data['location']['coordinates'])
self.name = data['name']['ru']
self.space = data['spaces']['total']
if 'handicapped' in data['spaces'].keys():
self.handicapped = data['spaces']['handicapped']
else:
self.handicapped = 0
if 'congestion' in data.keys():
self.congestion = data['congestion']['rawInfo']['occupied']
self.congestion_time = data['congestion']['updateDate']
else:
self.congestion = None
self.congestion_time = None
if 'zone' in data.keys():
self.description = data['zone']['description']['ru']
if 'prices' in data['zone'].keys():
self.car_price_min = data['zone']['prices'][0]['price']['min'] / 100
self.car_price_max = data['zone']['prices'][0]['price']['max'] / 100
else:
self.description = None
self.car_price_max = None
self.car_price_min = None