-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodels.py
73 lines (61 loc) · 2.24 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from google.appengine.ext import ndb
class CompactElement(object):
def __init__(self, header, id):
self.header = header
self.id = id
@staticmethod
def of(items):
if not items:
return []
items.sort(key=lambda x: x.id)
return [items[0].header] + [item.row() for item in items]
class RegionListElement(CompactElement):
def __init__(self, id=None, name=None):
super(RegionListElement, self).__init__(("id","name"), id)
self.name = name
def row(self):
return [self.id, self.name]
class SystemListElement(CompactElement):
def __init__(self, bike_network):
super(SystemListElement, self).__init__(("id","name","lat","lon","city"), bike_network.key.id())
self.name = bike_network.name
self.lat = float(bike_network.lat)
self.lon = float(bike_network.lon)
self.city = bike_network.city
def row(self):
return [self.id, self.name, self.lat, self.lon, self.city]
class SystemInfoElement(CompactElement):
def __init__(self, id=None, name=None, lat=0.0, lon=0.0, region=None):
super(SystemInfoElement, self).__init__(("id","name","lat","lon","region"),id)
self.id = id
self.name = name
self.lat = float(lat)
self.lon = float(lon)
self.region = region
def row(self):
out = [self.id, self.name, self.lat, self.lon]
if self.region:
out.append(self.region)
return out
class SystemStatusElement(CompactElement):
def __init__(self, id=None, bikes=0, docks=0, mod=0, pts=None):
super(SystemStatusElement, self).__init__(("id","bikes","docks","mod","pts"),id)
self.bikes = bikes
self.docks = docks
self.mod = mod
self.pts = pts
def row(self):
out = [self.id, self.bikes, self.docks, self.mod]
if self.pts:
out.append(self.pts)
return out
class BikeNetwork(ndb.Model):
name = ndb.StringProperty()
city = ndb.StringProperty()
codec = ndb.StringProperty()
config = ndb.JsonProperty()
lat = ndb.FloatProperty()
lon = ndb.FloatProperty()
last_updated = ndb.IntegerProperty()
class BikeNetworkList(ndb.Model):
networks = ndb.JsonProperty()