Hi ,
It looks like you're using an ad blocker.



The revenue generated from the adverts on the site is a critical part of our funding - and it's because of these ads that I can offer the site for free. But using the site for free AND blocking the ads doesn't feel like a great thing to do, which is why this box is so large and inconvenient. Some sites will completely block your access, but I'm not doing that - I'm appealing to your good nature instead. Did you know that you can allow ads for specific sites, whilst still blocking them on others?

Thanks,
Ian Williams aka Fetch
or for an ad-free Fetcheveryone experience!

SERIOUSLY LORD FETCH - SORT IT OUT!

71 watchers
Oct 2012
2:47pm, 23 Oct 2012
4,160 posts
  • Quote
  • Pin
sprouty76
Oh yeah, it'll work, but will probably be less efficient.

For example, think about the case where somebody does 5 laps of a park. In the old scheme each subsequent lap doesn't increase the area under consideration, because the area covered by the min & max of lat & long will remain the same (assuming no deviation from the previous lap)

In the new scheme, you'll be going along the route, breaking it into lengths of (say) 1 mile and building each rectangle. Unless the route is an exact multiple of 1 mile, each lap will produce rectangles overlapping the rectangles from previous laps that will need to be queried from the database.
Oct 2012
3:16pm, 23 Oct 2012
3,102 posts
  • Quote
  • Pin
runningmumof3boys
I don't think even the crow fly route from me in st Neots is 49 miles to Farnham Surrey. Not when it's 60miles
Down A1 to outer London ?!
Oct 2012
3:18pm, 23 Oct 2012
6,473 posts
  • Quote
  • Pin
McGoohan
When I do that race finder thing it draws a circle X miles around my home. Does your circle include Farnham RM?
Oct 2012
4:27pm, 23 Oct 2012
11,841 posts
  • Quote
  • Pin
fetcheveryone
Sprouty - point taken - it could effectively be making a similar query over and over. It's definitely something worth thinking about, but I'm not sure it affects so many routes that it will end up having a negative impact overall.

So far I've been doing all my testing and profiling on one 11 mile route, for consistency (making sure that to switch off those parts of the process that would remove any markers, and ensuring that none of the queries I'm using get cached by mysql). I have a function that's set up so that I can vary N, but I've also been able to profile the other parts of the process, and I've picked up some nice improvements already:

1) I was using the split() function to convert a comma-separated latitude and longitude into two separate variables. It turns out that explode() is umpteen times faster, as well as not being deprecated :-) On my 11 mile run, there are 1800 data points, so I had a loop with 1800 'split()' calls. Easy money.

2) Reducing the number of returned markers has a nice impact on the subsequent checking process. Each returned marker is currently checked against each point from the route (yeah, I know), so this has the potential to be another big saving.

3) When checking proximity between the points on the route and markers, I was calculating the exact distance between the two - this meant 11 multiplications, five divisions, one minus, one add, two sines, three cosines, and one acosine. Accurate, but unnecessary. Just checking the latitude, and returning 'false' for anything ridiculous, and then doing the same for longitude, made the proximity checking element about 42% faster.

To take my 11 mile circular loop as an example - the processing on my test box (which isn't as powerful as the server by a long way) was taking a median of 28.7 seconds to process, pulling in 1508 markers for testing (and hitting just 222 of them). Changing to 'explode' brought this time down to 25.1s, and adding the proximity sanity check brought this down further to 10.1s. Using an N of 20 (i.e. breaking the route into 20 equal chunks) reduced the number of markers being tested down to 541, and the processing time down to 3.87 seconds.

More testing now, with different types of route (out-and-backs, laps, point to point, horizontal, diagonal etc), and in different parts of the country (Hebrides, Hyde Park). Having fun :-)
Oct 2012
4:40pm, 23 Oct 2012
18,299 posts
  • Quote
  • Pin
HappyG(rrr)
Good work that man. That's a hooge saving. You are Code Warrior! :-)G
Oct 2012
4:52pm, 23 Oct 2012
4,161 posts
  • Quote
  • Pin
sprouty76
Sounds like you're using the spherical law of cosines - if you already know the points being compared are close by (which you do in this case), do you really need to take curvature of the earth into account?
Oct 2012
4:56pm, 23 Oct 2012
11,842 posts
  • Quote
  • Pin
fetcheveryone
Can you point me at the simplified formula?

(I'm just testing a 30 mile route that goes out of Manchester and back in. With no modifications it just falls over when the script times out after 5 mins (undoubtedly quicker on the server), having found 7017 markers. I'm adding my modifications one at a time to see how much they help).
Oct 2012
5:01pm, 23 Oct 2012
4,162 posts
  • Quote
  • Pin
sprouty76
I was having a glance through this: movable-type.co.uk , in particular the bit about equirectangular approximation.
Oct 2012
5:06pm, 23 Oct 2012
10,843 posts
  • Quote
  • Pin
Stander
You just made that long word up.
Oct 2012
5:07pm, 23 Oct 2012
4,163 posts
  • Quote
  • Pin
sprouty76
It's a perfectly cromulent word.

About This Thread

Maintained by SPKoF
Fetch says: I ignore this thread. If you've got a bug to report or a favour to ask, please use the feedback link at the top of every page.
  • Show full description...

Related Threads

  • fun
  • gripes
  • website

Report This Content

You can report any content you believe to be unsafe. Please let me know why you believe this content is unsafe by choosing a category below.



Thank you for your report. The content will be assessed as soon as possible.










Back To Top

Tag A User

To tag a user, start typing their name here:
X

Free training & racing tools for runners, cyclists, swimmers & walkers.

Fetcheveryone lets you analyse your training, find races, plot routes, chat in our forum, get advice, play games - and more! Nothing is behind a paywall, and it'll stay that way thanks to our awesome community!
Get Started
Click here to join 114,544 Fetchies!
Already a Fetchie? Sign in here