-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculatorThreads.py
More file actions
4897 lines (4402 loc) · 222 KB
/
CalculatorThreads.py
File metadata and controls
4897 lines (4402 loc) · 222 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
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*-coding:utf8;-*-
# qpy:2
# ts=4:sw=4:expandtab
'''
Created on 01.07.2014
@author: rkoraschnigg
'''
from __future__ import division
import os
import ssl
import time, calendar
from datetime import datetime
import certifi
import joblib
import requests
from Logger import Logger
import math
import copy
import json
import unicodedata
from random import randint
from urllib.request import urlopen
from urllib.error import URLError, HTTPError
from kivy.clock import Clock
import geopy.geocoders
from geopy.geocoders import Nominatim
from decimal import Decimal
from collections import OrderedDict, Counter
from ThreadBase import StoppableThread, ThreadPool
from OSMWrapper import Maps
from LinkedListGenerator import DoubleLinkedListNodes
from TreeGenerator import BinarySearchTree
from enum import Enum
from collections import defaultdict
from ServiceAccount import upload_file_to_google_drive, \
build_drive_from_credentials, add_camera_to_json, FILE_ID, FOLDER_ID
from ai.ai_predictive_analytics import predict_speed_camera # Import the predictive function
ctx = ssl.create_default_context(cafile=certifi.where())
geopy.geocoders.options.default_ssl_context = ctx
class FilteredRoadClasses(Enum):
# A = 9
# B = 10
# C = 11
# D = 12
# E = 13
# F = 14
# G = 15
# H = 16
# II = 17
J = 10000
@classmethod
def has_value(cls, value):
return value in cls._value2member_map_
class MostProbableWay(Logger):
def __init__(self, rectangle_calculator_thread):
self.mostprobable_road = "<>"
self.mostprobable_speed = ""
self.previous_road = "<>"
self.previous_speed = ""
self.mostprobable_tags = False
self.previous_tags = False
self.first_lookup = True
self.next_mpr_list_complete = False
self.last_roadname_list = []
self.next_possible_mpr_list = []
self.max_road_names = 0
self.max_possible_mpr_candidates = 0
self.unstable_counter = 0
self.rectangle_calculator_thread = rectangle_calculator_thread
# MAX for unstable roads
self.unstable_limit = 3
Logger.__init__(self, self.__class__.__name__)
def increase_unstable_counter(self):
self.unstable_counter += 1
def get_unstable_counter(self):
return self.unstable_counter
def reset_unstable_counter(self):
self.unstable_counter = 0
def set_maximum_number_of_road_names(self, maxnum):
self.max_road_names = maxnum
def set_maximum_number_of_next_possible_mprs(self, maxnum):
self.max_possible_mpr_candidates = maxnum
def get_last_roadname_list(self):
return self.last_roadname_list
def get_next_possible_mpr_list(self):
return self.next_possible_mpr_list
# list of functional road class -> roadname tuples indicating the road that has a chance of
# becoming the next most probable road
def add_attributes_to_next_possible_mpr_list(self, current_fr, roadname):
if len(
self.next_possible_mpr_list) >= self.max_possible_mpr_candidates:
return 'MAX_REACHED'
self.next_possible_mpr_list.append((current_fr, roadname))
return 'MAX_NOT_REACHED'
def clear_next_possible_mpr_list(self):
del self.next_possible_mpr_list[:]
# list of most current road name updates
def add_roadname_to_roadname_list(self, roadname):
if len(self.last_roadname_list) == self.max_road_names:
del self.last_roadname_list[:]
self.last_roadname_list.append(roadname)
def is_next_possible_mpr_new_mpr(self,
current_fr,
most_probable_road_class,
ramp,
next_mpr_list_complete):
if 0 <= most_probable_road_class <= 1:
self.set_maximum_number_of_next_possible_mprs(6)
else:
self.set_maximum_number_of_next_possible_mprs(4)
# dismiss false positive motorway lookups if mpr is on another road class
if (isinstance(current_fr, int) and 0 <= current_fr <= 1) or ramp:
if most_probable_road_class > 1:
try:
rc_index = self.rectangle_calculator_thread.road_candidates.index(
most_probable_road_class)
self.rectangle_calculator_thread.road_candidates[
rc_index] = current_fr
except:
return True
self.print_log_line(
' Dismiss motorway/trunk/ramp, we are still on road class %s'
% str(most_probable_road_class))
return False
return True
road_class_entries = []
road_name_entries = []
for attributes in self.next_possible_mpr_list:
road_class_entries.append(attributes[0])
road_name_entries.append(attributes[1])
crossroad_0 = None
crossroad_1 = None
crossroad_mpr = True
for road_name in road_name_entries:
crossroad = road_name.split('/')
# we found a crossroad
if len(crossroad) == 2:
crossroad_0 = crossroad[0]
crossroad_1 = crossroad[1]
break
crossroad_name = ''
if isinstance(crossroad_0, str) and isinstance(crossroad_1, str):
crossroad_name = '/'.join((crossroad_0, crossroad_1))
# check all roadnames if the crossing is a substring of all road names
# check the first part of the crossroad
for road_name in road_name_entries:
if road_name.find(crossroad_0) == -1:
crossroad_mpr = False
break
# check the second part of the crossroad
crossroad_mpr = True
if not crossroad_mpr:
for road_name in road_name_entries:
if road_name.find(crossroad_0) == -1:
crossroad_mpr = False
break
return next_mpr_list_complete and (
len(set(self.next_possible_mpr_list)) == 1 or
Counter(road_class_entries)[current_fr] == len(
road_class_entries) or crossroad_mpr)
def is_first_lookup(self):
return self.first_lookup
def set_first_lookup(self, lookup):
self.first_lookup = lookup
def set_most_probable_road(self, roadname):
self.mostprobable_road = roadname
def set_most_probable_speed(self, speed):
self.mostprobable_speed = speed
def set_previous_road(self, roadname):
self.previous_road = roadname
def set_previous_speed(self, speed):
self.previous_speed = speed
def set_most_probable_tags(self, combined_tags):
self.mostprobable_tags = combined_tags
def set_previous_tags(self, combined_tags):
self.previous_tags = combined_tags
def get_most_probable_road(self):
return self.mostprobable_road
def get_most_probable_speed(self):
return self.mostprobable_speed
def get_most_probable_tags(self):
return self.mostprobable_tags
def get_previous_road(self):
return self.previous_road
def get_previous_speed(self):
return self.previous_speed
def get_previous_tags(self):
return self.previous_tags
class Point(object):
# A point identified by (x,y) coordinates.
def __init__(self, x=0.0, y=0.0):
self.x = x
self.y = y
def add(self, p):
# Point(x1+x2, y1+y2)
return Point(self.x + p.x, self.y + p.y)
class Rect(object):
# A rectangle identified by 2 points or by a point list.
def __init__(self, pt1=None, pt2=None, point_list=[]):
self.height = 0
self.width = 0
self.ident = ''
self.rect_string = ''
# close to border max values
self.max_close_to_border_value = 0.300
self.max_close_to_border_value_look_ahead = 0.200
# initialize a rectangle from 2 points
self.set_points(pt1, pt2, point_list)
def delete_rect(self):
del self
def set_points(self, pt1, pt2, point_list):
# reset the rectangle
x1 = 0
y1 = 0
x2 = 0
y2 = 0
if 0 < len(point_list) < 4:
self.left = 0
self.top = 0
self.right = 0
self.bottom = 0
return
if len(point_list) == 4:
self.left = point_list[0]
self.top = point_list[1]
self.right = point_list[2]
self.bottom = point_list[3]
return
if pt1 == None or pt2 == None:
self.left = 0
self.top = 0
self.right = 0
self.bottom = 0
return
if isinstance(pt1, Point):
(x1, y1) = pt1.x, pt1.y
(x2, y2) = pt2.x, pt2.y
else:
(x1, y1) = pt1[0], pt1[1]
(x2, y2) = pt2[0], pt2[1]
self.left = min(x1, x2)
self.top = min(y1, y2)
self.right = max(x1, x2)
self.bottom = max(y1, y2)
return
def set_rectangle_ident(self, ident):
self.ident = ident
def get_rectangle_ident(self):
return self.ident
def set_rectangle_string(self, rect_string):
self.rect_string = rect_string
def get_rectangle_string(self):
return self.rect_string
def rect_height(self):
self.height = self.bottom - self.top
return self.height
def rect_width(self):
self.width = self.right - self.left
return self.width
def top_left(self):
# returns the top left corner as a point
return Point(self.left, self.top)
def bottom_right(self):
# return the bottom right corner as a point
return Point(self.right, self.bottom)
def top_right(self):
# return the top right corner as a point
return Point(self.right, self.top)
def bottom_left(self):
# return the bottom left corner as a point
return Point(self.left, self.bottom)
def expanded_by(self, n):
"""Return a rectangle with extended borders.
Create a new rectangle that is wider and taller than the
immediate one. All sides are extended by n points.
"""
pt1 = Point(self.left - n, self.top - n)
pt2 = Point(self.right + n, self.bottom + n)
return Rect(pt1, pt2)
def intersect_rect_with(self, rect, rectangle_string):
if isinstance(rect, Rect):
left = min(self.left, rect.left)
right = max(self.right, rect.right)
bottom = min(self.bottom, rect.bottom)
top = max(self.top, rect.top)
return rectangle_string, Rect(point_list=[left, top, right, bottom])
else:
return None, None
# parameters: x, y in tile format
# rect consisting of 4 Points(x,y) given in a list
def point_in_rect(self, xtile, ytile):
inside = False
x, y = xtile, ytile
if x is None or y is None:
return False
rect = [self.top_left(), self.top_right(), self.bottom_left(),
self.bottom_right()]
# len of rect
n = len(rect)
pt1x, pt1y = rect[0].x, rect[0].y
for i in range(n + 1):
pt2x, pt2y = rect[i % n].x, rect[i % n].y
if y >= min(pt1y, pt2y):
if y <= max(pt1y, pt2y):
if x >= min(pt1x, pt2x):
if x <= max(pt1x, pt2x):
if pt1y != pt2y:
inside = not inside
if inside:
return inside
pt1x, pt1y = pt2x, pt2y
return inside
def points_close_to_border(self, xtile, ytile,
look_ahead=False, look_ahead_mode="Speed Camera lookahead"):
if look_ahead_mode == "Construction area lookahead":
return False
x, y = xtile, ytile
if look_ahead:
max_val = self.max_close_to_border_value_look_ahead
else:
max_val = self.max_close_to_border_value
rect = [self.top_left(), self.top_right(), self.bottom_left(),
self.bottom_right()]
# len of rect
n = len(rect)
pt1x, pt1y = rect[0].x, rect[0].y
for i in range(n + 1):
pt2x, pt2y = rect[i % n].x, rect[i % n].y
if abs(y - min(pt1y, pt2y)) <= max_val or abs(
y - max(pt1y, pt2y)) <= max_val or abs(
x - max(pt1x, pt2x)) <= max_val or abs(
x - min(pt1x, pt2x)) <= max_val:
return True
pt1x, pt1y = pt2x, pt2y
return False
class RectangleCalculatorThread(StoppableThread, Logger):
thread_lock = False
log_viewer = None
def __init__(self,
main_app,
cv_vector,
cv_voice,
cv_interrupt,
cv_speedcam,
cv_overspeed,
cv_border,
cv_border_reverse,
voice_prompt_queue,
interruptqueue,
speedcamqueue,
overspeed_queue,
cv_currentspeed,
currentspeed_queue,
cv_poi,
poi_queue,
cv_map,
cv_map_osm,
cv_map_construction,
map_queue,
ms,
s,
ml,
vector_data,
osm_wrapper,
cond):
StoppableThread.__init__(self)
Logger.__init__(self, self.__class__.__name__, RectangleCalculatorThread.log_viewer)
self.main_app = main_app
self.cv_vector = cv_vector
self.cv_voice = cv_voice
self.cv_interrupt = cv_interrupt
self.cv_speedcam = cv_speedcam
self.cv_overspeed = cv_overspeed
self.cv_border = cv_border
self.cv_border_reverse = cv_border_reverse
self.voice_prompt_queue = voice_prompt_queue
self.interruptqueue = interruptqueue
self.speed_cam_queue = speedcamqueue
self.overspeed_queue = overspeed_queue
self.cv_currentspeed = cv_currentspeed
self.currentspeed_queue = currentspeed_queue
self.poi_queue = poi_queue
self.cv_map = cv_map
self.cv_map_osm = cv_map_osm
self.cv_map_construction = cv_map_construction
self.map_queue = map_queue
self.cv_poi = cv_poi
self.ms = ms
self.s = s
self.ml = ml
self.vector_data = vector_data
self.cond = cond
self.osm_wrapper = osm_wrapper
self.matching_rect = "NOTSET"
self.previous_rect = "NOTSET"
self.failed_rect = ""
# global items
self.direction_cached = ""
self.osm_lookup_properties = []
self.osm_lookup_properties_extrapolated = []
self.combined_tags_array = []
self.RECT_ATTRIBUTES_EXTRAPOLATED = {}
self.RECT_ATTRIBUTES_EXTRAPOLATED_KEYS = []
self.RECT_ATTRIBUTES = {}
self.RECT_KEYS = []
self.RECT_VALUES = []
self.RECT_VALUES_EXTRAPOLATED = []
self.RECT_ATTRIBUTES_INTERSECTED = {}
self.RECT_SPEED_CAM_LOOKAHAEAD = None
self.RECT_CONSTRUCTION_AREAS_LOOKAHAEAD = None
self.speed_cam_dict = []
self.construction_areas = []
self.road_candidates = []
self.predictive_cam_list = []
# default timeout
self.url_timeout = 25
self.extrapolated_number = 0
self.download_time = 0
self.fix_cams = 0
self.traffic_cams = 0
self.distance_cams = 0
self.mobile_cams = 0
self.predictive_cams = 0
self.cspeed = 0
self.cspeed_cached = 0
self.cspeed_converted = 0
self.accuracy = 0
self.number_distance_cams = 0
self.rectangle_radius = 0.0
self.longitude_cached = 0.0
self.latitude_cached = 0.0
self.bearing_cached = 0.0
self.longitude_extrapolated = 0.0
self.latitude_extrapolated = 0.0
self.XTILE_MIN = None
self.YTILE_MIN = None
self.XTILE_MAX = None
self.YTILE_MAX = None
self.longitude = None
self.latitude = None
self.CURRENT_RECT = None
self.linkedListGenerator = None
self.treeGenerator = None
self.bearing = None
self.direction = None
self.gpsstatus = None
self.current_online_status = None
self.last_online_status = None
self.osm_data_error = None
self.xtile = None
self.ytile = None
self.xtile_cached = None
self.ytile_cached = None
self.tunnel_node_id = None
self.last_road_name = None
self.last_max_speed = None
self.found_combined_tags = None
self.isCcpStable = None
self.startup_extrapolation = False
self.startup_calculation = True
self.is_filled = False
self.is_cam = False
self.already_online = False
self.already_offline = False
self.new_rectangle = True
self.border_reached = False
self.osm_error_reported = False
self.slow_data_reported = False
self.internet_connection = True
self.was_speed0 = True
self.motorway_flag = False
self.hazards_on_road = False
self.hazard_voice = False
self.waterway = False
self.water_voice = False
self.access_control = False
self.access_control_voice = False
self.empty_dataset_received = False
self.cam_in_progress = False
self.empty_dataset_rect = ""
# set config items
self.set_configs()
# create object for most probable way class once during startup,
# usage is defined by self.enable_mpr
self.mpw = MostProbableWay(self)
self.mpw.set_maximum_number_of_road_names(4)
self.mpw.set_maximum_number_of_next_possible_mprs(4)
# Load the trained predictive model
model_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), "ai", "speed_camera_model.pkl")
self.model = joblib.load(model_path)
# create an object for the fallback location lookup
def set_configs(self):
# Report slow downloads if this time has been reached
# Also the rect size will be constantly reduced in case of high delays (> this time)
self.max_download_time = 20
# download time timeout for osm data (use a larger timeout for
# motorways since rects are larger)
self.osm_timeout = 20
self.osm_timeout_motorway = 30
# DOS attack prevention interval in seconds for camera download operations
# When setting this parameter, please consider the distances for
# speed_cam_look_ahead_distance and construction_area_lookahead_distance
self.dos_attack_prevention_interval_downloads = 30
# speed cam lookahead distance in km
self.speed_cam_look_ahead_distance = 300
# construction area lookahead distance in km
# Use the radius with CAUTION! Do not provide a huge radius due to performance
# reasons
self.construction_area_lookahead_distance = 30
# Trigger construction area lookups after this counter has passed during the startup
# phase. This ensures the overall performance during the startup phase.
self.construction_area_startup_trigger_max = 60
# initial rect distance in km after app startup
self.initial_rect_distance = 3
# increasing the rect boundaries if this defined speed limit is exceeded
self.speed_influence_on_rect_boundary = 110
# angle paramter used for current rect in degrees
# (only for initial rect calculation and look aheads)
self.current_rect_angle = 90
# angle paramter used for fallback rect in degrees (only for initial rect calculation)
self.fallback_rect_angle = 123
# zoom factor , osm database layer used (1..18), speed cams are available
# from layer 16 to 18, the higher the number the more data is retrieved
self.zoom = 17
# maximum number of cross roads to be displayed (reasonable value is 2 or 3)
self.max_cross_roads = 3
# disable road lookup in case the performance on your phone is not good
self.disable_road_lookup = False
# Disable all rectangle operations except the Nominatim road lookup if explicitly
# enabled via parameter alternative_road_lookup. This option it the most effective one.
# Concept:
# If enabled, the cameras and construction areas are fetched and processed from OSM
# using a bounding rectangle but not added to a linked list and binary search tree.
# -----------------------------------------------------------------------------------------
# There are 2 operation modes:
# * If this parameter is enabled, cameras and construction areas are fetched using
# one single lookahead rectangle.
# * If this parameter is disabled, OSM data in general is fetched from OSM based on
# multiple bounding rectangles around the car position.
# As well the fetched data is stored in binary search trees
self.cameras_look_ahead_mode = True
# Use the Nominatim library as alternative method to retrieve a road name
# Notes:
# * This will use more bandwidth
# * Nominatim is the standard road name lookup method if cameras_look_ahead_mode == True
# Per default the road name is retrieved via the REST API interface to OpenStreetMap
self.alternative_road_lookup = True
# self.geolocator = Nominatim(user_agent="MasterWarner", scheme='http')
# Instead of two extrapolated rects, only one can be used (increases performance
# but might lead to less speed cameras found)
# If we are on a motorway only one extrapolated rect larger in size will be used
# regardless of parameter self.use_only_one_extrapolated_rect
self.use_only_one_extrapolated_rect = False
# Calculate a small rectangle in opposite driving direction as fallback
# instead of a larger extrapolated rect
# The feature applies for the next calculation cycle in case condition of CCP was
# outside all rectangle borders
self.consider_backup_rects = True
# dismiss POIS if set to True. If set to False
# POIs will be displayed as following:
# -> MaxSpeed: POI
# -> RoadName: AMENITY: RoadName|| GASSTATION: RoadName
#
# Note this feature is only active
# if disable_road_lookup is set to False
self.dismiss_pois = True
# enable an algorithm for faster rectangle lookup applying to extrapolated rects
self.enable_ordered_rects_extrapolated = True
# max number of extrapolated rects to keep.
# If this number is reached, all extrapolated rects will be deleted
# and new one is calculated
self.max_number_exptrapolated_rects = 6
# defaut speed limits per country, 'motorway' is the default for
# all countries except Germany and Austria
self.MAXSPEED_COUNTRIES = {'AT:motorway': 130,
'DE:motorway': 'UNLIMITED',
'motorway_general': 130}
# speed per road class in OSM
self.ROAD_CLASSES_TO_SPEED = {'trunk': 100,
'primary': 100,
'unclassified': 70,
'secondary': 50,
'tertiary': 50,
'service': 50,
'track': 30,
'residential': 30,
'bus_guideway': 30,
'escape': 30,
'bridleway': 30,
'living_street': 20,
'path': 20,
'cycleway': 20,
'pedestrian': 10,
'footway': 10,
'road': 10,
# inside urban area
'urban': 50
}
# FU per road class
self.FUNCTIONAL_ROAD_CLASSES = {'motorway': 0,
'_link': 0,
'trunk': 1,
'primary': 2,
'unclassified': 3,
'secondary': 4,
'tertiary': 5,
'service': 6,
'residential': 7,
'living_street': 8,
# to be filtered out
'track': 9,
'bridleway': 10,
'cycleway': 11,
'pedestrian': 12,
'footway': 13,
'path': 14,
'bus_guideway': 15,
'escape': 16,
'road': 17
}
self.FUNCTIONAL_ROAD_CLASSES_REVERSE = {0: 'motorway',
1: 'trunk',
2: 'primary',
3: 'unclassified',
4: 'secondary',
5: 'tertiary',
6: 'service',
7: 'residential',
8: 'living_street',
# to be filtered out
9: 'track',
10: 'bridleway',
11: 'cycleway',
12: 'pedestrian',
13: 'footway',
14: 'path',
15: 'bus_guideway',
16: 'escape',
17: 'road'
}
##SpeedLimits Base URL##
# baseurl = 'http://overpass.osm.rambler.ru/cgi/interpreter?'
self.baseurl = 'http://overpass-api.de/api/interpreter?'
self.querystring1 = 'data=[out:json];(node'
self.querystring2 = ';rel(bn)->.x;way(bn);rel(bw););out+body;'
self.querystring_amenity = 'data=[out:json];(node["amenity"="*"]'
self.querystring_cameras1 = 'data=[out:json][timeout:25];(node["highway"="speed_camera"]'
self.querystring_cameras2 = 'way["highway"="speed_camera"]'
self.querystring_cameras3 = 'relation["highway"="speed_camera"]'
self.querystring_hazard1 = 'data=[out:json][timeout:20];(node["hazard"="falling_rocks"]'
self.querystring_hazard2 = 'node["hazard"="road_narrows"]'
self.querystring_hazard3 = 'node["hazard"="slippery"]'
self.querystring_hazard4 = 'node["hazard"="damaged_road"]'
self.querystring_hazard5 = 'node["hazard"="ice"]'
self.querystring_hazard6 = 'node["hazard"="fog"]'
self.querystring_distance_cams = 'data=[out:json][timeout:25];(relation["enforcement"="mindistance"]'
self.querystring_construction_areas = 'data=[out:json][timeout:25];(way["highway"="construction"]'
self.querystring_construction_areas2 = 'relation["highway"="construction"]'
self.node_lookup = 'data=[out:json][timeout:25];(node(*););out+body;'
# rect boundaries
self.rectangle_periphery_poi_reader = {'TOP-N': (20, 20),
'N': (20, 20),
'NNO': (20, 24),
'NO': (20, 20),
'ONO': (20, 24),
'O': (20, 20),
'TOP-O': (20, 20),
'OSO': (20, 20),
'SO': (20, 20),
'SSO': (20, 20),
'S': (20, 20),
'TOP-S': (20, 20),
'SSW': (20, 20),
'SW': (20, 20),
'WSW': (20, 20),
'W': (20, 20),
'TOP-W': (20, 24),
'WNW': (20, 20),
'NW': (20, 20),
'NNW': (20, 20)
}
self.rectangle_periphery_lower_roadclass = {'TOP-N': (9, 9),
'N': (8, 8),
'NNO': (7, 11),
'NO': (7, 7),
'ONO': (10, 14),
'O': (8, 8),
'TOP-O': (9, 9),
'OSO': (5, 5),
'SO': (5, 5),
'SSO': (6, 6),
'S': (8, 8),
'TOP-S': (8, 8),
'SSW': (8, 8),
'SW': (13, 13),
'WSW': (15, 15),
'W': (17, 17),
'TOP-W': (17, 22),
'WNW': (12, 12),
'NW': (10, 12),
'NNW': (9, 9)
}
self.rectangle_periphery_fallback_lower_roadclass = {'TOP-N': (6, 6),
'N': (6, 6),
'NNO': (5, 9),
'NO': (6, 6),
'ONO': (8, 12),
'O': (8, 8),
'TOP-O': (6, 6),
'OSO': (4, 4),
'SO': (4, 4),
'SSO': (5, 5),
'S': (7, 7),
'TOP-S': (7, 7),
'SSW': (8, 8),
'SW': (8, 8),
'WSW': (8, 8),
'W': (8, 8),
'TOP-W': (8, 12),
'WNW': (8, 8),
'NW': (8, 12),
'NNW': (8, 8)
}
self.rectangle_periphery_motorway = {'TOP-N': (11, 11),
'N': (11, 11),
'NNO': (9, 13),
'NO': (8, 8),
'ONO': (10, 14),
'O': (10, 10),
'TOP-O': (11, 11),
'OSO': (6, 6),
'SO': (5, 5),
'SSO': (8, 8),
'S': (12, 12),
'TOP-S': (12, 12),
'SSW': (14, 14),
'SW': (14, 14),
'WSW': (18, 18),
'W': (19, 19),
'TOP-W': (19, 24),
'WNW': (12, 12),
'NW': (12, 15),
'NNW': (12, 12)
}
self.rectangle_periphery_motorway_fallback = {'TOP-N': (7, 7),
'N': (7, 7),
'NNO': (7, 9),
'NO': (7, 7),
'ONO': (7, 9),
'O': (7, 7),
'TOP-O': (8, 8),
'OSO': (5, 5),
'SO': (5, 5),
'SSO': (6, 6),
'S': (7, 7),
'TOP-S': (7, 7),
'SSW': (7, 7),
'SW': (7, 7),
'WSW': (7, 7),
'W': (7, 7),
'TOP-W': (7, 9),
'WNW': (7, 7),
'NW': (7, 7),
'NNW': (7, 7)
}
self.rectangle_periphery_backup = {'TOP-N': (4, 4),
'N': (4, 4),
'NNO': (4, 6),
'NO': (4, 4),
'ONO': (4, 6),
'O': (4, 4),
'TOP-O': (4, 4),
'OSO': (4, 4),
'SO': (4, 4),
'SSO': (4, 4),
'S': (4, 4),
'TOP-S': (4, 4),
'SSW': (4, 4),
'SW': (4, 4),
'WSW': (4, 4),
'W': (4, 4),
'TOP-W': (4, 6),
'WNW': (4, 4),
'NW': (4, 4),
'NNW': (4, 4)
}
self.rectangle_fallback_directions = {'TOP-N': (
'TOP-W', 'TOP-O', 'TOP-W-2', 'TOP-O-2', 'TOP-N-2', 'NNW', 'NNO',
'NW',
'NO', 'SSW', 'TOP-S', 'ONO'),
'N': (
'W', 'O', 'W-2', 'O-2', 'N-2',
'NNO', 'TOP-N', 'NO', 'NNW',
'SSO', 'S', 'TOP-W'),
'NNO': (
'NNW', 'SSO', 'NNW-2', 'SSO-2',
'NNO-2', 'NO', 'N', 'ONO',
'TOP-N', 'SO', 'SSW', 'NW'),
'NO': (
'SO', 'NW', 'SO-2', 'NW-2',
'NO-2', 'ONO', 'NNO', 'O', 'N',
'OSO', 'SW', 'W'),
'ONO': (
'WSW', 'WNW', 'WSW-2', 'WNW-2',
'ONO-2', 'O', 'NO', 'OSO', 'NNO',
'S', 'WNW', 'SSO'),
'O': (
'N', 'S', 'N-2', 'S-2', 'O-2',
'OSO', 'ONO', 'SO', 'NO', 'WSW',
'W', 'N'),
'TOP-O': (
'TOP-N', 'TOP-S', 'TOP-N-2',
'TOP-S-2', 'TOP-O-2', 'OSO', 'O',
'SO', 'ONO', 'WSW', 'TOP-W',
'NNO'),
'OSO': (
'WNW', 'WSW', 'WNW-2', 'WSW-2',
'OSO-2', 'SO', 'O', 'SSO',
'TOP-O', 'NO', 'WNW', 'TOP-S'),
'SO': (
'NO', 'SW', 'NO-2', 'SW-2',
'SO-2', 'SSO', 'OSO', 'S', 'O',
'NNO', 'NW', 'ONO'),
'SSO': (
'SSW', 'NNW', 'SSW-2', 'NNW-2',
'SSO-2', 'S', 'SO', 'TOP-S',
'OSO', 'W', 'WNW', 'SW'),
'S': (
'W', 'O', 'W-2', 'O-2', 'S-2',
'TOP-S', 'SSO', 'SSW', 'SO',
'WNW', 'N', 'W'),
'TOP-S': (
'TOP-W', 'TOP-O', 'TOP-W-2',
'TOP-O-2', 'TOP-S-2', 'SSW', 'S',
'SW', 'SSO', 'NW', 'TOP-N', 'W'),
'SSW': (
'WNW', 'ONO', 'WNW-2', 'ONO-2',
'SSW-2', 'SW', 'S', 'WSW', 'SSO',
'NNW', 'NNO', 'S'),
'SW': (
'NW', 'NO', 'NW-2', 'NO-2',
'SW-2', 'WSW', 'SSW', 'SW', 'S',
'N', 'NO', 'NW'),
'WSW': (
'ONO', 'OSO', 'ONO-2', 'OSO-2',
'WSW-2', 'W', 'SW', 'TOP-W',
'SSW', 'WNW', 'ONO', 'S'),
'W': (
'N', 'S', 'N-2', 'S-2', 'W-2',
'WSW', 'TOP-W', 'SW', 'WNW',
'NNO', 'O', 'TOP-S'),
'TOP-W': (
'TOP-N', 'TOP-S', 'TOP-N-2',
'TOP-S-2', 'TOP-W-2', 'W', 'WNW',
'WSW', 'NW', 'NNO', 'TOP-O',
'N'),
'WNW': (
'ONO', 'S', 'ONO-2', 'S-2',
'WNW-2', 'W', 'NW', 'WSW', 'NNW',
'NO', 'SSO', 'SW'),
'NW': (
'NO', 'SW', 'NO-2', 'SW-2',
'NW-2', 'WNW', 'NNW', 'W', 'N',
'NNO', 'SO', 'WSW'),
'NNW': (
'NNO', 'SSW', 'NNO-2', 'SSW-2',
'NNW-2', 'NW', 'N', 'WNW',
'TOP-N', 'N', 'SSO', 'W')
}
self.rectangle_fallback_directions_motorway = {'TOP-N': ('TOP-N-2'),
'N': ('N-2'),
'NNO': ('NNO-2'),
'NO': ('NO-2'),
'ONO': ('ONO-2'),
'O': ('O-2'),
'TOP-O': ('TOP-O-2'),
'OSO': ('OSO-2'),
'SO': ('SO-2'),
'SSO': ('SSO-2'),
'S': ('S-2'),
'TOP-S': ('TOP-S-2'),
'SSW': ('SSW-2'),
'SW': ('SW-2'),
'WSW': ('WSW-2'),
'W': ('W-2'),
'TOP-W': ('TOP-W-2'),
'WNW': ('WNW-2'),
'NW': ('NW-2'),
'NNW': ('NNW-2')
}
self.rectangle_periphery = self.rectangle_periphery_lower_roadclass
self.rectangle_periphery_fallback = self.rectangle_periphery_fallback_lower_roadclass
def run(self):
start_time = time.time()
while not self.cond.terminate:
if self.main_app.run_in_back_ground:
self.main_app.main_event.wait()