1
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
|
2
|
|
|
|
3
|
|
|
try: |
4
|
|
|
import logging |
5
|
|
|
import sys |
6
|
|
|
from sqlalchemy import Column, ForeignKey, ForeignKeyConstraint, UniqueConstraint |
|
|
|
|
7
|
|
|
from sqlalchemy import Boolean, Integer, BigInteger, Unicode, DateTime, Time, Enum, Float, JSON, func |
|
|
|
|
8
|
|
|
from sqlalchemy.ext.declarative import declarative_base |
9
|
|
|
from sqlalchemy.orm import synonym, relationship |
10
|
|
|
from geoalchemy2 import Geometry |
11
|
|
|
import enum |
12
|
|
|
from osm_poi_matchmaker.utils import config |
13
|
|
|
except ImportError as err: |
14
|
|
|
logging.error('Error %s import module: %s', __name__, err) |
15
|
|
|
logging.exception('Exception occurred') |
16
|
|
|
|
17
|
|
|
sys.exit(128) |
18
|
|
|
|
19
|
|
|
Base = declarative_base() |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
class OSM_object_type(enum.Enum): |
|
|
|
|
23
|
|
|
node = 0 |
24
|
|
|
way = 1 |
25
|
|
|
relation = 2 |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
class POI_type(enum.Enum): |
|
|
|
|
29
|
|
|
shop = 0 |
30
|
|
|
fuel = 1 |
31
|
|
|
bank = 2 |
32
|
|
|
atm = 3 |
33
|
|
|
post_office = 4 |
34
|
|
|
vending_machine = 5 |
35
|
|
|
pharmacy = 6 |
36
|
|
|
chemist = 7 |
37
|
|
|
bicycle_rental = 8 |
38
|
|
|
vending_machine_cheques = 9 |
39
|
|
|
vending_machine_parcel_pickup = 10 |
40
|
|
|
vending_machine_parcel_mail_in = 11 |
41
|
|
|
vending_machine_parcel_pickup_and_mail_in = 12 |
42
|
|
|
vending_machine_parking_tickets = 13 |
43
|
|
|
tobacco = 14 |
44
|
|
|
clothes = 15 |
45
|
|
|
doityourself = 16 |
46
|
|
|
cosmetics = 17 |
47
|
|
|
furniture = 18 |
48
|
|
|
charging_station = 19 |
49
|
|
|
waterway_fuel = 20 |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
class POI_address(Base): |
|
|
|
|
53
|
|
|
__tablename__ = 'poi_address' |
54
|
|
|
_plural_name_ = 'poi_address' |
55
|
|
|
pa_id = Column(Integer, primary_key=True, index=True) |
56
|
|
|
id = synonym('pa_id') |
57
|
|
|
poi_common_id = Column(ForeignKey('poi_common.pc_id'), index=True) |
58
|
|
|
poi_branch = Column(Unicode(128), nullable=True, index=True) |
59
|
|
|
poi_addr_city = Column(ForeignKey('city.city_id'), index=True) |
60
|
|
|
poi_postcode = Column(Integer) |
61
|
|
|
poi_city = Column(Unicode(64)) |
62
|
|
|
poi_addr_street = Column(Unicode(128)) |
63
|
|
|
poi_addr_housenumber = Column(Unicode(16)) |
64
|
|
|
poi_conscriptionnumber = Column(Unicode(16)) |
65
|
|
|
poi_geom = Column(Geometry('POINT, {}'.format(config.get_geo_default_projection()))) |
66
|
|
|
original = Column(Unicode(128)) |
67
|
|
|
poi_website = Column(Unicode(256)) |
68
|
|
|
poi_description = Column(Unicode(1024)) |
69
|
|
|
poi_fuel_adblue = Column(Boolean) |
70
|
|
|
poi_fuel_octane_100 = Column(Boolean) |
71
|
|
|
poi_fuel_octane_98 = Column(Boolean) |
72
|
|
|
poi_fuel_octane_95 = Column(Boolean) |
73
|
|
|
poi_fuel_diesel_gtl = Column(Boolean) |
74
|
|
|
poi_fuel_diesel = Column(Boolean) |
75
|
|
|
poi_fuel_lpg = Column(Boolean) |
76
|
|
|
poi_fuel_e85 = Column(Boolean) |
77
|
|
|
poi_rent_lpg_bottles = Column(Boolean) |
78
|
|
|
poi_compressed_air = Column(Boolean) |
79
|
|
|
poi_restaurant = Column(Boolean) |
80
|
|
|
poi_food = Column(Boolean) |
81
|
|
|
poi_truck = Column(Boolean) |
82
|
|
|
poi_ref = Column(Unicode(32)) |
83
|
|
|
poi_phone = Column(Unicode(64)) |
84
|
|
|
poi_email = Column(Unicode(64)) |
85
|
|
|
poi_authentication_app = Column(Boolean) |
86
|
|
|
poi_authentication_none = Column(Boolean) |
87
|
|
|
poi_authentication_membership_card = Column(Boolean) |
88
|
|
|
poi_capacity = Column(Integer) |
89
|
|
|
poi_fee = Column(Boolean) |
90
|
|
|
poi_parking_fee = Column(Boolean) |
91
|
|
|
poi_motorcar = Column(Boolean) |
92
|
|
|
poi_socket_chademo = Column(Integer) |
93
|
|
|
poi_socket_chademo_output = Column(Unicode(16)) |
94
|
|
|
poi_socket_type2_combo = Column(Integer) |
95
|
|
|
poi_socket_type2_combo_output = Column(Unicode(16)) |
96
|
|
|
poi_socket_type2_cable = Column(Integer) |
97
|
|
|
poi_socket_type2_cable_output = Column(Unicode(16)) |
98
|
|
|
poi_socket_type2 = Column(Integer) |
99
|
|
|
poi_socket_type2_output = Column(Unicode(16)) |
100
|
|
|
poi_manufacturer = Column(Unicode(32)) |
101
|
|
|
poi_model = Column(Unicode(32)) |
102
|
|
|
poi_opening_hours_nonstop = Column(Boolean) |
103
|
|
|
poi_opening_hours_mo_open = Column(Time) |
104
|
|
|
poi_opening_hours_tu_open = Column(Time) |
105
|
|
|
poi_opening_hours_we_open = Column(Time) |
106
|
|
|
poi_opening_hours_th_open = Column(Time) |
107
|
|
|
poi_opening_hours_fr_open = Column(Time) |
108
|
|
|
poi_opening_hours_sa_open = Column(Time) |
109
|
|
|
poi_opening_hours_su_open = Column(Time) |
110
|
|
|
poi_opening_hours_mo_close = Column(Time) |
111
|
|
|
poi_opening_hours_tu_close = Column(Time) |
112
|
|
|
poi_opening_hours_we_close = Column(Time) |
113
|
|
|
poi_opening_hours_th_close = Column(Time) |
114
|
|
|
poi_opening_hours_fr_close = Column(Time) |
115
|
|
|
poi_opening_hours_sa_close = Column(Time) |
116
|
|
|
poi_opening_hours_su_close = Column(Time) |
117
|
|
|
poi_opening_hours_summer_mo_open = Column(Time) |
118
|
|
|
poi_opening_hours_summer_tu_open = Column(Time) |
119
|
|
|
poi_opening_hours_summer_we_open = Column(Time) |
120
|
|
|
poi_opening_hours_summer_th_open = Column(Time) |
121
|
|
|
poi_opening_hours_summer_fr_open = Column(Time) |
122
|
|
|
poi_opening_hours_summer_sa_open = Column(Time) |
123
|
|
|
poi_opening_hours_summer_su_open = Column(Time) |
124
|
|
|
poi_opening_hours_summer_mo_close = Column(Time) |
125
|
|
|
poi_opening_hours_summer_tu_close = Column(Time) |
126
|
|
|
poi_opening_hours_summer_we_close = Column(Time) |
127
|
|
|
poi_opening_hours_summer_th_close = Column(Time) |
128
|
|
|
poi_opening_hours_summer_fr_close = Column(Time) |
129
|
|
|
poi_opening_hours_summer_sa_close = Column(Time) |
130
|
|
|
poi_opening_hours_summer_su_close = Column(Time) |
131
|
|
|
poi_opening_hours_lunch_break_start = Column(Time) |
132
|
|
|
poi_opening_hours_lunch_break_stop = Column(Time) |
133
|
|
|
poi_public_holiday_open = Column(Boolean) |
134
|
|
|
poi_opening_hours = Column(Unicode(256), nullable=True, unique=False, index=True) |
135
|
|
|
poi_good = Column(JSON, nullable=True, index=False) |
136
|
|
|
poi_bad = Column(JSON, nullable=True, index=False) |
137
|
|
|
poi_hash = Column(Unicode(128), nullable=True, unique=False, index=True) |
138
|
|
|
poi_created = Column(DateTime(True), nullable=False, server_default=func.now()) |
139
|
|
|
poi_updated = Column(DateTime(True)) |
140
|
|
|
poi_deleted = Column(DateTime(True)) |
141
|
|
|
|
142
|
|
|
common = relationship('POI_common', primaryjoin='POI_address.poi_common_id == POI_common.pc_id', |
143
|
|
|
backref='poi_address') |
144
|
|
|
city = relationship('City', primaryjoin='POI_address.poi_addr_city == City.city_id', backref='poi_address') |
|
|
|
|
145
|
|
|
|
146
|
|
|
# def __repr__(self): |
147
|
|
|
# return '<POI address {}: {}>'.format(self.pa_id, self.poi_name) |
148
|
|
|
|
149
|
|
|
|
150
|
|
|
class POI_common(Base): |
|
|
|
|
151
|
|
|
__tablename__ = 'poi_common' |
152
|
|
|
_plural_name_ = 'poi_common' |
153
|
|
|
pc_id = Column(Integer, primary_key=True, index=True) |
154
|
|
|
id = synonym('pc_id') |
155
|
|
|
poi_name = Column(Unicode(64), unique=False, nullable=False, index=True) |
156
|
|
|
poi_type = Column(Enum(POI_type)) |
157
|
|
|
poi_tags = Column(JSON, nullable=False, index=False) |
158
|
|
|
poi_url_base = Column(Unicode(32)) |
159
|
|
|
poi_code = Column(Unicode(10), unique=True, nullable=False, index=True) |
160
|
|
|
poi_search_name = Column(Unicode(64)) |
161
|
|
|
poi_search_avoid_name = Column(Unicode(64)) |
162
|
|
|
preserve_original_name = Column(Boolean, nullable=False, default=False) |
163
|
|
|
preserve_original_post_code = Column(Boolean, nullable=False, default=False) |
164
|
|
|
osm_search_distance_perfect = Column(Integer, nullable=True, index=False) |
165
|
|
|
osm_search_distance_safe = Column(Integer, nullable=True, index=False) |
166
|
|
|
osm_search_distance_unsafe = Column(Integer, nullable=True, index=False) |
167
|
|
|
|
168
|
|
|
def __repr__(self): |
169
|
|
|
return '<POI common {}: {}>'.format(self.pc_id, self.poi_name) |
170
|
|
|
|
171
|
|
|
|
172
|
|
|
class POI_OSM_cache(Base): |
|
|
|
|
173
|
|
|
__tablename__ = 'poi_osm_cache' |
174
|
|
|
_plural_name_ = 'poi_osm_cache' |
175
|
|
|
poc_id = Column(Integer, primary_key=True, index=True) |
176
|
|
|
id = synonym('poc_id') |
177
|
|
|
# poi_type = Column(Enum(POI_type)) |
178
|
|
|
osm_id = Column(BigInteger, nullable=False, index=True) |
179
|
|
|
osm_object_type = Column(Enum(OSM_object_type)) |
180
|
|
|
osm_version = Column(Integer, nullable=False, index=True) |
181
|
|
|
osm_user = Column(Unicode(64), nullable=True, index=False) |
182
|
|
|
osm_user_id = Column(Integer, nullable=True, index=True) |
183
|
|
|
osm_changeset = Column(Integer, nullable=False, index=True) |
184
|
|
|
osm_timestamp = Column(DateTime(True), nullable=False) |
185
|
|
|
osm_lat = Column(Float, nullable=True, index=True) |
186
|
|
|
osm_lon = Column(Float, nullable=True, index=True) |
187
|
|
|
osm_nodes = Column(JSON, nullable=True, index=False) |
188
|
|
|
# osm_distance = Column(Integer, nullable=True, index=False) |
189
|
|
|
osm_live_tags = Column(JSON, nullable=True, index=False) |
190
|
|
|
|
191
|
|
|
|
192
|
|
|
class City(Base): |
|
|
|
|
193
|
|
|
__tablename__ = 'city' |
194
|
|
|
_plural_name_ = 'city' |
195
|
|
|
city_id = Column(Integer, primary_key=True, index=True) |
196
|
|
|
id = synonym('city_id') |
197
|
|
|
city_name = Column(Unicode) |
198
|
|
|
city_post_code = Column(Integer) |
199
|
|
|
|
200
|
|
|
__table_args__ = (UniqueConstraint('city_name', 'city_post_code', name='uc_city_name_post_code'),) |
|
|
|
|
201
|
|
|
|
202
|
|
|
def __repr__(self): |
203
|
|
|
return '<City {}: {} ({})>'.format(self.city_id, self.city_name, self.city_post_code) |
204
|
|
|
|
205
|
|
|
|
206
|
|
|
class Street_type(Base): |
|
|
|
|
207
|
|
|
__tablename__ = 'street_type' |
208
|
|
|
_plural_name_ = 'street_type' |
209
|
|
|
st_id = Column(Integer, primary_key=True, index=True) |
210
|
|
|
id = synonym('st_id') |
211
|
|
|
street_type = Column(Unicode(20)) |
212
|
|
|
|
213
|
|
|
def __repr__(self): |
214
|
|
|
return '<Street type {}: {}>'.format(self.st_id, self.street_type) |
215
|
|
|
|
216
|
|
|
|
217
|
|
|
class POI_osm(Base): |
|
|
|
|
218
|
|
|
__tablename__ = 'poi_osm' |
219
|
|
|
_plural_name_ = 'poi_osm' |
220
|
|
|
po_id = Column(Integer, primary_key=True, index=True) |
221
|
|
|
id = synonym('po_id') |
222
|
|
|
poi_osm_id = Column(BigInteger, unique=True, index=True) |
223
|
|
|
poi_osm_object_type = Column(Enum(OSM_object_type)) |
224
|
|
|
poi_hash = Column(Unicode(128), nullable=True, unique=False, index=True) |
225
|
|
|
geom_hint = Column(Geometry('POINT, {}'.format(config.get_geo_default_projection()))) |
226
|
|
|
|
227
|
|
|
__table_args__ = (UniqueConstraint('poi_osm_id', 'poi_osm_object_type', name='uc_poi_osm_osm_type'),) |
|
|
|
|
228
|
|
|
|