Merge lp:~joergberroth/unav/improved_set_radars into lp:unav

Proposed by JkB
Status: Merged
Merged at revision: 48
Proposed branch: lp:~joergberroth/unav/improved_set_radars
Merge into: lp:unav
Diff against target: 194 lines (+94/-28)
2 files modified
nav/class/WebAPI.js (+90/-20)
nav/index.html (+4/-8)
To merge this branch: bzr merge lp:~joergberroth/unav/improved_set_radars
Reviewer Review Type Date Requested Status
Nekhelesh Ramananthan Approve
costales Pending
Review via email: mp+291943@code.launchpad.net

This proposal supersedes a proposal from 2016-04-11.

Commit message

* improved search algorithm to set radars by adding more intelligent bounding polygons instead of a rectangular bounding box.
* big performance improvement

Description of the change

* improved search algorithm to set radars by adding more intelligent bounding polygons instead of a rectangular bounding box.

To post a comment you must log in.
Revision history for this message
Nekhelesh Ramananthan (nik90) wrote : Posted in a previous version of this proposal

Hmm I don't have a car to check the radar performance. To be honest, I have never used the radar feature as well.

@Joerg, if you give me clear steps to test your MP, I can do it.

review: Needs Information
Revision history for this message
JkB (joergberroth) wrote : Posted in a previous version of this proposal

That's easy:
Activate radars.
Choose a route (best a long one accross france, not longer than 999km)
Youll see the improvement while the radars are being analyzed.
m Mittwoch, 13. April 2016 14:45:45 CEST schrieb Nekhelesh Ramananthan
<email address hidden>:
> Review: Needs Information
>
> Hmm I don't have a car to check the radar performance. To be
> honest, I have never used the radar feature as well.
>
> @Joerg, if you give me clear steps to test your MP, I can do it.

--
Versandt, mit Dekko von meinem Ubuntu-Gerät

Revision history for this message
Nekhelesh Ramananthan (nik90) wrote : Posted in a previous version of this proposal

OMG Are you kidding me? @Joerg what kind of magic did you do? Massive performance improvement! Excellent job!

In my testing, a route from Delft, Netherlands to Bern, Germany (~750 km) took about 3-4 minutes in trunk. With your branch it takes hardly 5-6 seconds!

I am so approving this! +100000000000000

review: Approve (testing)
Revision history for this message
costales (costales) wrote : Posted in a previous version of this proposal

So awesome work Joerg |o/ Incredible :D

Could you merge my propose branch lp:~costales/unav/0.59-improved_set_radars in this branch?
I merged with trunk and adjusted a few minor things.

Thanks a lot mate!

review: Needs Fixing
Revision history for this message
Nekhelesh Ramananthan (nik90) wrote : Posted in a previous version of this proposal

@Joerg pls merge the latest trunk lp:unav.

review: Needs Fixing
Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

Approved!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nav/class/WebAPI.js'
2--- nav/class/WebAPI.js 2016-04-06 17:07:14 +0000
3+++ nav/class/WebAPI.js 2016-04-14 21:14:23 +0000
4@@ -58,7 +58,7 @@
5 api_key: 'valhalla-4DcFzeQ' // TODO debug
6 },
7 dataType: 'json',
8- timeout: 30000,
9+ timeout: 50000,
10 success: this.OK_callback_set_route.bind(this),
11 error: this.KO_callback_set_route.bind()
12 });
13@@ -126,7 +126,7 @@
14 api_key: 'valhalla-4DcFzeQ' // TODO debug
15 },
16 dataType: 'json',
17- timeout: 30000,
18+ timeout: 50000,
19 success: this.OK_callback_simulate.bind(this),
20 error: this.KO_callback_simulate.bind()
21 });
22@@ -139,8 +139,8 @@
23
24 if (data.trip.status == 0) {
25 this.nav.set_route( (data.trip.summary.length*1000),
26- data.trip.summary.time, // totals (meters & seconds)
27- data.trip.legs[0].shape, // Map line
28+ data.trip.summary.time, // totals (meters & seconds)
29+ data.trip.legs[0].shape, // Map line
30 data.trip.legs[0].maneuvers // Route stracks
31 );
32 // Avoid wait for GPS
33@@ -174,7 +174,7 @@
34
35
36 // Radars
37-WebAPI.prototype.set_radars = function(lat1, lng1, lat2, lng2) {
38+WebAPI.prototype.set_radars = function() {
39 // Refresh current radars
40 this.nav.radars_clear();
41 this.ui.markers_radar_clear();
42@@ -182,18 +182,93 @@
43 // Search radars?
44 if (!this.settings.get_alert_radars() || this.settings.get_routing_mode() != 0)
45 return;
46-
47- // Search in extra border 5km
48- var bbox = "[bbox=" +
49- (Number(Math.min(lng1, lng2)) - 0.049999989569187164 + ",").toString() +
50- (Number(Math.min(lat1, lat2)) - 0.049999989569187164 + ",").toString() +
51- (Number(Math.max(lng1, lng2)) + 0.049999989569187164 + ",").toString() +
52- (Number(Math.max(lat1, lat2)) + 0.049999989569187164).toString() + "]";
53-
54+
55+ var lng1, lat1, lng2, lat2, lng2_ext, lat2_ext, lng1_ext, lat1_ext;
56+ var lng_rt, lat_rt, rt_l, lng_rt_n, lat_rt_n;
57+ var n1, n2, n_l, n1_n, n2_n, k;
58+
59+ var routeBoundaryPolygon_1 = "";
60+ var routeBoundaryPolygon_2 = "";
61+
62+ // MAXPOINTS: maximum fixpoints for the Polygon (2x +4).
63+ // The higher the value, the higher the accuracy.
64+ // the faster getting all relevant radars
65+ // the closer to the route you are. might be limited by overpass.
66+ var MAXPOINTS = 75;
67+
68+ //complete_line:
69+ var line = this.nav.route['complete_line'].geometry.coordinates
70+ var iter = Math.ceil(line.length/MAXPOINTS);
71+ lng1 = line[0][0];
72+ lat1 = line[0][1];
73+
74+ //iterate over fixpoints:
75+ for (i = 0; i < line.length; i+=iter) {
76+
77+ k = (i+iter).toFixed(0);
78+ if (k >= line.length) {k = line.length-1;}
79+ lng2 = line[k][0];
80+ lat2 = line[k][1];
81+
82+ // route segment vector:
83+ lng_rt = lng2 - lng1;
84+ lat_rt = lat2 - lat1;
85+ // normalized (|1|) vector components
86+ rt_l = Math.sqrt(lat_rt*lat_rt + lng_rt*lng_rt);
87+ lng_rt_n = lng_rt/rt_l
88+ lat_rt_n = lat_rt/rt_l
89+
90+ //route segment normal vector components to line
91+ n1 = lat2 - lat1; //lng
92+ n2 = lng1 - lng2; //lat
93+ // normalized (|1|) normal vector components
94+ n_l = Math.sqrt(n1*n1 + n2*n2);
95+ n1_n = n1/n_l;
96+ n2_n = n2/n_l;
97+
98+ // init tolerance of route segment expansion:
99+ var d_neg_min = -0.005;
100+ var d_pos_max = 0.005;
101+ // extent route segment start/end points
102+ lng1_ext = lng1 - lng_rt_n*0.0005;
103+ lat1_ext = lat1 - lat_rt_n*0.0005;
104+ lng2_ext = lng2 + lng_rt_n*0.0005;
105+ lat2_ext = lat2 + lat_rt_n*0.0005;
106+
107+ // iterate over route segment points to get max expansion of the route segment
108+ for (j = i+1; j < k; j++) {
109+ var lng_pt = line[j][0];
110+ var lat_pt = line[j][1];
111+ var lng_d_pt = lng1 - lng_pt;
112+ var lat_d_pt = lat1 - lat_pt;
113+ var distance_to_pt = (lng_rt*lat_d_pt - lng_d_pt*lat_rt) / Math.sqrt( lng_rt*lng_rt + lat_rt*lat_rt )
114+ if (distance_to_pt <= 0 && distance_to_pt < d_neg_min) { d_neg_min = distance_to_pt - 0.001; }
115+ if (distance_to_pt > 0 && distance_to_pt > d_pos_max) { d_pos_max = distance_to_pt + 0.001 ; }
116+ }
117+
118+ // add fixpoints to polygon point set (routeBoundaryPolygon_x):
119+ if (i==0) { routeBoundaryPolygon_1 = Number(lat1_ext + n2_n*d_pos_max - lat_rt_n*0.005).toFixed(5) +
120+ " " + Number(lng1_ext + n1_n*d_pos_max - lng_rt_n*0.005).toFixed(5) + " " ;
121+ routeBoundaryPolygon_2 = Number(lat1_ext + n2_n*d_neg_min - lat_rt_n*0.005).toFixed(5) +
122+ " " + Number(lng1_ext + n1_n*d_neg_min- lng_rt_n*0.005).toFixed(5);
123+ }
124+ routeBoundaryPolygon_1 = //forward
125+ routeBoundaryPolygon_1 +
126+ Number(lat2_ext + n2_n*d_pos_max).toFixed(5) + " " + Number(lng2_ext + n1_n*d_pos_max).toFixed(5) + " " ;
127+ routeBoundaryPolygon_2 = //backward
128+ Number(lat2_ext + n2_n*d_neg_min).toFixed(5) + " " + Number(lng2_ext + n1_n*d_neg_min).toFixed(5) + " " +
129+ routeBoundaryPolygon_2;
130+
131+ //set segment end to segment start
132+ lat1 = lat2;
133+ lng1 = lng2;
134+ }
135+
136 // Search radars POI http://wiki.openstreetmap.org/wiki/Overpass_API
137+ var poly_box = '(poly:\"' + routeBoundaryPolygon_1 + routeBoundaryPolygon_2 + '\");out;'
138 $.ajax({
139- url: 'https://www.overpass-api.de/api/xapi?node[highway=speed_camera]' + bbox,
140- timeout: 30000,
141+ url: 'https://overpass-api.de/api/interpreter?data=node[highway=speed_camera]' + poly_box,
142+ timeout: 50000,
143 dataType: 'xml',
144 success: this.OK_callback_set_radars.bind(this),
145 error: this.KO_callback_set_radars.bind()
146@@ -201,11 +276,6 @@
147 }
148
149 WebAPI.prototype.OK_callback_set_radars = function(xml) {
150- $('#p_txt_ind').html(t("Analyzing speed cameras… This could take a while"));
151- setTimeout(this.analize_radars, 75, xml); // Need this setTimeout because the message will not apply if not
152-}
153-
154-WebAPI.prototype.analize_radars = function(xml) {
155 // For each radar...
156 var aux_nav = this.nav;
157 $(xml).find('node').each(function() {
158
159=== modified file 'nav/index.html'
160--- nav/index.html 2016-04-10 16:36:44 +0000
161+++ nav/index.html 2016-04-14 21:14:23 +0000
162@@ -114,7 +114,6 @@
163 <h1 data-localize="Route so long">Route so long</h1>
164 <p>
165 <span data-localize="More than 1000km could affect the performance">More than 1000km could affect the performance</span><br>
166- <span data-localize="In these long routes the speed camera alerts are disabled">In these long routes the speed camera alerts are disabled</span><br>
167 <span data-localize="We recommend you a waypoint in the middle as destination">We recommend you a waypoint in the middle as destination</span>
168 </p>
169 <menu>
170@@ -250,9 +249,9 @@
171 <script src="class/Maths.js"></script>
172 <script>
173 var settings = new Settings();
174- var maths = new Maths();
175- var nav = new Navigator(maths, lang);
176- var ui = new UI(map, nav, settings, maths, lang);
177+ var maths = new Maths();
178+ var nav = new Navigator(maths, lang);
179+ var ui = new UI(map, nav, settings, maths, lang);
180 var webapi = new WebAPI(nav, ui, settings);
181
182 // Navigation (map in review mode by default, without read GPS for not drain battery)
183@@ -310,10 +309,7 @@
184 ui.route(false);
185 nav.set_route_status('yes');
186 }
187- if (route_indication['distance_total'] <= 1000000) {
188- var gps_data = nav.get_pos_data();
189- webapi.set_radars(gps_data['now_lat'], gps_data['now_lng'], gps_data['end_lat'], gps_data['end_lng']);
190- }
191+ webapi.set_radars();
192 break;
193 case 'waiting4signal':
194 id_auto_accept = 0; // ask recalculating

Subscribers

People subscribed via source and target branches