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

Proposed by JkB
Status: Superseded
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 Needs Fixing
costales Needs Fixing
Review via email: mp+291542@code.launchpad.net

This proposal has been superseded by a proposal from 2016-04-14.

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.
44. By JkB

* remove unnecessary comments

45. By JkB

*reduce coord accuracy to reduce data being send.

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

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 :

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 :

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 :

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 :

@Joerg pls merge the latest trunk lp:unav.

review: Needs Fixing
46. By JkB

*merge with trunk

47. By JkB

*add marcos fixes.

48. By JkB

* minor fix: found wrong toFixed() values

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'nav/class/WebAPI.js'
--- nav/class/WebAPI.js 2016-04-06 17:07:14 +0000
+++ nav/class/WebAPI.js 2016-04-14 20:18:35 +0000
@@ -58,7 +58,7 @@
58 api_key: 'valhalla-4DcFzeQ' // TODO debug58 api_key: 'valhalla-4DcFzeQ' // TODO debug
59 },59 },
60 dataType: 'json',60 dataType: 'json',
61 timeout: 30000,61 timeout: 50000,
62 success: this.OK_callback_set_route.bind(this),62 success: this.OK_callback_set_route.bind(this),
63 error: this.KO_callback_set_route.bind()63 error: this.KO_callback_set_route.bind()
64 });64 });
@@ -126,7 +126,7 @@
126 api_key: 'valhalla-4DcFzeQ' // TODO debug126 api_key: 'valhalla-4DcFzeQ' // TODO debug
127 },127 },
128 dataType: 'json',128 dataType: 'json',
129 timeout: 30000,129 timeout: 50000,
130 success: this.OK_callback_simulate.bind(this),130 success: this.OK_callback_simulate.bind(this),
131 error: this.KO_callback_simulate.bind()131 error: this.KO_callback_simulate.bind()
132 });132 });
@@ -139,8 +139,8 @@
139 139
140 if (data.trip.status == 0) {140 if (data.trip.status == 0) {
141 this.nav.set_route( (data.trip.summary.length*1000),141 this.nav.set_route( (data.trip.summary.length*1000),
142 data.trip.summary.time, // totals (meters & seconds)142 data.trip.summary.time, // totals (meters & seconds)
143 data.trip.legs[0].shape, // Map line143 data.trip.legs[0].shape, // Map line
144 data.trip.legs[0].maneuvers // Route stracks144 data.trip.legs[0].maneuvers // Route stracks
145 );145 );
146 // Avoid wait for GPS146 // Avoid wait for GPS
@@ -174,7 +174,7 @@
174174
175175
176// Radars176// Radars
177WebAPI.prototype.set_radars = function(lat1, lng1, lat2, lng2) {177WebAPI.prototype.set_radars = function() {
178 // Refresh current radars178 // Refresh current radars
179 this.nav.radars_clear();179 this.nav.radars_clear();
180 this.ui.markers_radar_clear();180 this.ui.markers_radar_clear();
@@ -182,18 +182,93 @@
182 // Search radars?182 // Search radars?
183 if (!this.settings.get_alert_radars() || this.settings.get_routing_mode() != 0)183 if (!this.settings.get_alert_radars() || this.settings.get_routing_mode() != 0)
184 return;184 return;
185 185
186 // Search in extra border 5km186 var lng1, lat1, lng2, lat2, lng2_ext, lat2_ext, lng1_ext, lat1_ext;
187 var bbox = "[bbox=" +187 var lng_rt, lat_rt, rt_l, lng_rt_n, lat_rt_n;
188 (Number(Math.min(lng1, lng2)) - 0.049999989569187164 + ",").toString() +188 var n1, n2, n_l, n1_n, n2_n, k;
189 (Number(Math.min(lat1, lat2)) - 0.049999989569187164 + ",").toString() +189
190 (Number(Math.max(lng1, lng2)) + 0.049999989569187164 + ",").toString() +190 var routeBoundaryPolygon_1 = "";
191 (Number(Math.max(lat1, lat2)) + 0.049999989569187164).toString() + "]";191 var routeBoundaryPolygon_2 = "";
192 192
193 // MAXPOINTS: maximum fixpoints for the Polygon (2x +4).
194 // The higher the value, the higher the accuracy.
195 // the faster getting all relevant radars
196 // the closer to the route you are. might be limited by overpass.
197 var MAXPOINTS = 75;
198
199 //complete_line:
200 var line = this.nav.route['complete_line'].geometry.coordinates
201 var iter = Math.ceil(line.length/MAXPOINTS);
202 lng1 = line[0][0];
203 lat1 = line[0][1];
204
205 //iterate over fixpoints:
206 for (i = 0; i < line.length; i+=iter) {
207
208 k = (i+iter).toFixed(0);
209 if (k >= line.length) {k = line.length-1;}
210 lng2 = line[k][0];
211 lat2 = line[k][1];
212
213 // route segment vector:
214 lng_rt = lng2 - lng1;
215 lat_rt = lat2 - lat1;
216 // normalized (|1|) vector components
217 rt_l = Math.sqrt(lat_rt*lat_rt + lng_rt*lng_rt);
218 lng_rt_n = lng_rt/rt_l
219 lat_rt_n = lat_rt/rt_l
220
221 //route segment normal vector components to line
222 n1 = lat2 - lat1; //lng
223 n2 = lng1 - lng2; //lat
224 // normalized (|1|) normal vector components
225 n_l = Math.sqrt(n1*n1 + n2*n2);
226 n1_n = n1/n_l;
227 n2_n = n2/n_l;
228
229 // init tolerance of route segment expansion:
230 var d_neg_min = -0.005;
231 var d_pos_max = 0.005;
232 // extent route segment start/end points
233 lng1_ext = lng1 - lng_rt_n*0.0005;
234 lat1_ext = lat1 - lat_rt_n*0.0005;
235 lng2_ext = lng2 + lng_rt_n*0.0005;
236 lat2_ext = lat2 + lat_rt_n*0.0005;
237
238 // iterate over route segment points to get max expansion of the route segment
239 for (j = i+1; j < k; j++) {
240 var lng_pt = line[j][0];
241 var lat_pt = line[j][1];
242 var lng_d_pt = lng1 - lng_pt;
243 var lat_d_pt = lat1 - lat_pt;
244 var distance_to_pt = (lng_rt*lat_d_pt - lng_d_pt*lat_rt) / Math.sqrt( lng_rt*lng_rt + lat_rt*lat_rt )
245 if (distance_to_pt <= 0 && distance_to_pt < d_neg_min) { d_neg_min = distance_to_pt - 0.001; }
246 if (distance_to_pt > 0 && distance_to_pt > d_pos_max) { d_pos_max = distance_to_pt + 0.001 ; }
247 }
248
249 // add fixpoints to polygon point set (routeBoundaryPolygon_x):
250 if (i==0) { routeBoundaryPolygon_1 = Number(lat1_ext + n2_n*d_pos_max - lat_rt_n*0.005).toFixed(5) +
251 " " + Number(lng1_ext + n1_n*d_pos_max - lng_rt_n*0.005).toFixed(5) + " " ;
252 routeBoundaryPolygon_2 = Number(lat1_ext + n2_n*d_neg_min - lat_rt_n*0.005).toFixed(5) +
253 " " + Number(lng1_ext + n1_n*d_neg_min- lng_rt_n*0.005).toFixed(5);
254 }
255 routeBoundaryPolygon_1 = //forward
256 routeBoundaryPolygon_1 +
257 Number(lat2_ext + n2_n*d_pos_max).toFixed(5) + " " + Number(lng2_ext + n1_n*d_pos_max).toFixed(5) + " " ;
258 routeBoundaryPolygon_2 = //backward
259 Number(lat2_ext + n2_n*d_neg_min).toFixed(5) + " " + Number(lng2_ext + n1_n*d_neg_min).toFixed(5) + " " +
260 routeBoundaryPolygon_2;
261
262 //set segment end to segment start
263 lat1 = lat2;
264 lng1 = lng2;
265 }
266
193 // Search radars POI http://wiki.openstreetmap.org/wiki/Overpass_API267 // Search radars POI http://wiki.openstreetmap.org/wiki/Overpass_API
268 var poly_box = '(poly:\"' + routeBoundaryPolygon_1 + routeBoundaryPolygon_2 + '\");out;'
194 $.ajax({269 $.ajax({
195 url: 'https://www.overpass-api.de/api/xapi?node[highway=speed_camera]' + bbox,270 url: 'https://overpass-api.de/api/interpreter?data=node[highway=speed_camera]' + poly_box,
196 timeout: 30000,271 timeout: 50000,
197 dataType: 'xml',272 dataType: 'xml',
198 success: this.OK_callback_set_radars.bind(this),273 success: this.OK_callback_set_radars.bind(this),
199 error: this.KO_callback_set_radars.bind()274 error: this.KO_callback_set_radars.bind()
@@ -201,11 +276,6 @@
201}276}
202277
203WebAPI.prototype.OK_callback_set_radars = function(xml) {278WebAPI.prototype.OK_callback_set_radars = function(xml) {
204 $('#p_txt_ind').html(t("Analyzing speed cameras… This could take a while"));
205 setTimeout(this.analize_radars, 75, xml); // Need this setTimeout because the message will not apply if not
206}
207
208WebAPI.prototype.analize_radars = function(xml) {
209 // For each radar...279 // For each radar...
210 var aux_nav = this.nav;280 var aux_nav = this.nav;
211 $(xml).find('node').each(function() {281 $(xml).find('node').each(function() {
212282
=== modified file 'nav/index.html'
--- nav/index.html 2016-04-10 16:36:44 +0000
+++ nav/index.html 2016-04-14 20:18:35 +0000
@@ -114,7 +114,6 @@
114 <h1 data-localize="Route so long">Route so long</h1>114 <h1 data-localize="Route so long">Route so long</h1>
115 <p>115 <p>
116 <span data-localize="More than 1000km could affect the performance">More than 1000km could affect the performance</span><br>116 <span data-localize="More than 1000km could affect the performance">More than 1000km could affect the performance</span><br>
117 <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>
118 <span data-localize="We recommend you a waypoint in the middle as destination">We recommend you a waypoint in the middle as destination</span>117 <span data-localize="We recommend you a waypoint in the middle as destination">We recommend you a waypoint in the middle as destination</span>
119 </p>118 </p>
120 <menu>119 <menu>
@@ -250,9 +249,9 @@
250 <script src="class/Maths.js"></script>249 <script src="class/Maths.js"></script>
251 <script>250 <script>
252 var settings = new Settings();251 var settings = new Settings();
253 var maths = new Maths();252 var maths = new Maths();
254 var nav = new Navigator(maths, lang);253 var nav = new Navigator(maths, lang);
255 var ui = new UI(map, nav, settings, maths, lang);254 var ui = new UI(map, nav, settings, maths, lang);
256 var webapi = new WebAPI(nav, ui, settings);255 var webapi = new WebAPI(nav, ui, settings);
257 256
258 // Navigation (map in review mode by default, without read GPS for not drain battery)257 // Navigation (map in review mode by default, without read GPS for not drain battery)
@@ -310,10 +309,7 @@
310 ui.route(false);309 ui.route(false);
311 nav.set_route_status('yes');310 nav.set_route_status('yes');
312 }311 }
313 if (route_indication['distance_total'] <= 1000000) {312 webapi.set_radars();
314 var gps_data = nav.get_pos_data();
315 webapi.set_radars(gps_data['now_lat'], gps_data['now_lng'], gps_data['end_lat'], gps_data['end_lng']);
316 }
317 break;313 break;
318 case 'waiting4signal':314 case 'waiting4signal':
319 id_auto_accept = 0; // ask recalculating315 id_auto_accept = 0; // ask recalculating

Subscribers

People subscribed via source and target branches