• abico (unregistered) in reply to Kazan
    Kazan:
    shimon:
    A full-blown route calculation is, however, computationally expensive and there may also be substantial license fees involved.
    http://www.movable-type.co.uk/scripts/latlong-vincenty.html

    With this little function, you can calculate geodesic distances with accuracy within 0.5mm. For free. Still better than unprojected cartesian. Still giving you something comparable no matter how close to a pole you are.

    and you're still, in your ignorance of actual user desires, still performing crow-flies calculations.

    The User wants driving/walking/bussing directions. That involves using the A* algorithm on a network[see note] graph.

    Note: the 'network' in this case is road/sidewalk/bus/subway watever - transit network.

    Its possible to solve it with something else than A*, though, I'd say A* i easy to implement and gets the job done in a decent time. ;)

  • (cs) in reply to abico
    abico:

    Its possible to solve it with something else than A*, though, I'd say A* i easy to implement and gets the job done in a decent time. ;)

    I know, I'm aware of other solutions I was just using A* because it tends to be the best one for most situations.

  • A. Cube (unregistered) in reply to Observer
    Also, hotels needed to be sorted by distance which could not be a part of the SQL query,

    Why not? Assuming that, if they are using PHP they are probably using an OSS RDBMS, both MySQL and Postgres have spatial extensions allowing you to query points (latitude and longitude?) and the distances between. I also understand that Oracle and DB2 have it. MSSQL Server added it in 2008.

    Even if you can't use these (not likely) or their geospatial extensions (possible), then adding double precision latitude and longitude fields to the hotels tables and doing your calculations doesn't seem out of the question. You can buy databases with zip code to latitude/longitude conversions.

    They were, after all, doing the calculations of distance somewhere--it doesn't seem like it couldn't be done in the database. Since we don't have details that's not to say that it would have been the best way.

  • feugiat (unregistered) in reply to Kazan
    Kazan:
    abico:

    Its possible to solve it with something else than A*, though, I'd say A* i easy to implement and gets the job done in a decent time. ;)

    I know, I'm aware of other solutions I was just using A* because it tends to be the best one for most situations.

    Well, that depends on a few things. Such as the skill of the developer that is supposed to make it. If its a meh dev, then I'd probably go for A*. ;)

  • My Name (unregistered)

    About distances:

    I think it depends on your purpose. If you are using the hotel for business and have your own car, you might be interested in driving distances.

    When I'm on vacation in some city (London, Rome) I mostly walk or take public transportation, so I'm more interested in the direct distance.

  • (cs) in reply to My Name
    My Name:
    About distances:

    I think it depends on your purpose. If you are using the hotel for business and have your own car, you might be interested in driving distances.

    When I'm on vacation in some city (London, Rome) I mostly walk or take public transportation, so I'm more interested in the direct distance.

    you still can't use crow-flies distances for that. you still have to use the transit network graph for that - just in this case you're searching the edges labeled "walk" and/or "mass transit"

  • Zapp Brannigan (unregistered) in reply to Smyle
    Smyle:
    Listening to the bickering here, I've just come up with a great plan for deciding the best way to code a project when I have no idea where to start.

    I explain the problem in great detail, decide on the worst possible implementation, and post it to TDWTF. Let the one-upsmanship begin, and steal the best code posted.

    Too late, I've already patented the process and sold the idea to venture capitalists.

  • Jimmy (unregistered)

    There are so many other real WTF's in this story: why was there no single method for producing the correct, filtered results? Why were they not using Python/Django? What the hell. PHP is the new ASP

  • Billy (unregistered)

    Bah,

    For those who say sorting by distance can't be done in the database, you cant be more wrong. Sure you can do it in PHP, as I have done before (with complex text ranking etc), but its muuch more efficient to do in a DB server considering you usually want to limit the amount of RAM your php scripts are using (because a webserver can dish out thousands of php processes at once).

    Simply SELECT * FROM coords ORDER BY (len(usercoord - coord)) ASC

    coord is a 2d GPS vector DUH! Of course this is as the crow flies, but who is using google maps api to map walking directions PER RESULT?

  • StupidUserThatDoesntCare (unregistered) in reply to Kazan

    Kazan. Your pathfinding exercise is useless to me.

    I don't want to know the distance my hotel of choice is to some place I want to visit, I want to know its proximity. Any real commuter will tell you that distance is not measured in kilometers, its measured in time and your pathfinding elements cannot calculate the difference.

    For instance if I ride my bike home from work its 11km, if I take transit its 9km if I drive its 14km and yet they all take 35 minutes so each is viable depending on financial and other convenience factors. The same thing applies to searching hotels and most of the time when I'm simply localizing the hotel, not actually looking for a route to and from a destination - I have maps and the brain to use them.

    BTW

    I'm a user and I don't care.

  • Gilgad (unregistered) in reply to shimon
    shimon:
    ORDER BY SQUARE(hotels.x - @locationX) + SQUARE(hotels.y - @locationY) ASC

    QED (What to do if there is no SQUARE function is left as an exercise to the reader.)

    And now I have a piece of breaking news for you: the Earth, as the recent researches have shown, is not flat at all!

    And it's enough for the endpoints to be two or three states apart for cartesian distance to go from simply inaccurate to f-cking wildly inaccurate.

    It doesn't matter. Math says that you won't be able to find a situation where order-by-point-to-point and order-by-circumference are not equal.

    If you use that equation to generate that data that you present to the user, that is a different story. But for getting the order it doesn't matter

  • (cs) in reply to StupidUserThatDoesntCare
    StupidUserThatDoesntCare:
    Kazan. Your pathfinding exercise is useless to me.

    I don't want to know the distance my hotel of choice is to some place I want to visit, I want to know its proximity. Any real commuter will tell you that distance is not measured in kilometers, its measured in time and your pathfinding elements cannot calculate the difference.

    google maps traffic data proves you wrong on traffic travel time.

    having a complete transportation network map - bike trails, pedestrian bridges, etc - also could solve that problem.

    just because you refuse to acknowledge a problem is solvable by computers doesn't make it so.

    just because you're fine with "as the crow flies" doesn't mean most users are these days. they've been spoiled by google maps. they want travel time.

  • (cs) in reply to Paul N
    Paul N:
    The final page said it had six, but actually had zero. And on top of that, they weren't sorted correctly.
    The real wtf is the zero results on the final page weren't sorted correctly.

    Your search found ZERO results!

    END SEARCH RESULTS.

    BEGIN SEARCH RESULTS:

  • (cs) in reply to Kazan
    Kazan:
    StupidUserThatDoesntCare:
    Kazan. Your pathfinding exercise is useless to me.

    I don't want to know the distance my hotel of choice is to some place I want to visit, I want to know its proximity. Any real commuter will tell you that distance is not measured in kilometers, its measured in time and your pathfinding elements cannot calculate the difference.

    google maps traffic data proves you wrong on traffic travel time.

    having a complete transportation network map - bike trails, pedestrian bridges, etc - also could solve that problem.

    just because you refuse to acknowledge a problem is solvable by computers doesn't make it so.

    just because you're fine with "as the crow flies" doesn't mean most users are these days. they've been spoiled by google maps. they want travel time.

    However, "most users" in this thread have said the opposite. I have never booked a hotel based on the driving, walking or other non-"as the crow flies" distance. I really don't care. I know pretty much where I want to go, and I want something that's kinda in that general area. I'm not going to say "Oh, that's 50 feet out of the way - can't stay there..." The brand and price are actually more important to me than distance - I'm willing to go a little further if I have warm fuzzies about the brand, and/or if it's not going to break the bank.

  • abbas (unregistered) in reply to Kazan
    Kazan:
    StupidUserThatDoesntCare:
    Kazan. Your pathfinding exercise is useless to me.

    I don't want to know the distance my hotel of choice is to some place I want to visit, I want to know its proximity. Any real commuter will tell you that distance is not measured in kilometers, its measured in time and your pathfinding elements cannot calculate the difference.

    google maps traffic data proves you wrong on traffic travel time.

    having a complete transportation network map - bike trails, pedestrian bridges, etc - also could solve that problem.

    just because you refuse to acknowledge a problem is solvable by computers doesn't make it so.

    just because you're fine with "as the crow flies" doesn't mean most users are these days. they've been spoiled by google maps. they want travel time.

    I have to second Kazan here. There is no reason why a pathfinder AI(or just about any graph traversal AI really) cannot take walking, driving bike or teleporting for that matter into account. You just have to setup the appropriate graph to traverse. Or however the AI is designed to adress the problem.

    That being said, I'd think that most people are pretty happy with rough estimates as far as distance goes as a first vetting method. ;) apart from class of hotel and stuff like that.

  • (cs) in reply to abbas
    abbas:
    Kazan:
    StupidUserThatDoesntCare:
    Kazan. Your pathfinding exercise is useless to me.

    I don't want to know the distance my hotel of choice is to some place I want to visit, I want to know its proximity. Any real commuter will tell you that distance is not measured in kilometers, its measured in time and your pathfinding elements cannot calculate the difference.

    google maps traffic data proves you wrong on traffic travel time.

    having a complete transportation network map - bike trails, pedestrian bridges, etc - also could solve that problem.

    just because you refuse to acknowledge a problem is solvable by computers doesn't make it so.

    just because you're fine with "as the crow flies" doesn't mean most users are these days. they've been spoiled by google maps. they want travel time.

    I have to second Kazan here. There is no reason why a pathfinder AI(or just about any graph traversal AI really) cannot take walking, driving bike or teleporting for that matter into account. You just have to setup the appropriate graph to traverse. Or however the AI is designed to adress the problem.

    That being said, I'd think that most people are pretty happy with rough estimates as far as distance goes as a first vetting method. ;) apart from class of hotel and stuff like that.

    Kazan's protestations aside, nobody is saying it can't be done. Very clearly it can be done, and done very well. However, is it really the necessary solution to this problem?

    Kazan's points seem to be:

    • Distance measurement must not be done in a database
    • Distance measurement must only use a concrete path-finding algorithm based on real-world map data.

    OTOH, Kazan's persistent trolling has managed to keep a bunch of us going for quite a while now. A golf clap for you, sir! Very nicely done, indeed!

  • (cs)

    Yeah I usually only decide between one hotel and the next based on the prices at the bar.

    These comment threads are always interesting. What I'm thinking after reading these is "this is why programmers don't get invited to meetings"

    I find it funny that this article was about someone who was given the algorithm for solving his problem, and decided to complicate it beyond what was given, and the comment thread shows a strong desire to do just that.

  • Microtrash (unregistered) in reply to Smyle
    Smyle:
    Listening to the bickering here, I've just come up with a great plan for deciding the best way to code a project when I have no idea where to start.

    I explain the problem in great detail, decide on the worst possible implementation, and post it to TDWTF. Let the one-upsmanship begin, and steal the best code posted.

    NOTED

  • *snicker* (unregistered) in reply to shimon
    shimon:
    Those which don't usually needs to be separated - why would I want a hotel in another state?

    Why would I need a hotel in a city where I have a house/apartment I already pay for?

    Really? I can think of a few uses for one... you must be a REAL nerd^Wprogrammer if you've never had the need.... ;)

  • (cs) in reply to GalacticCowboy
    GalacticCowboy:
    OTOH, Kazan's persistent trolling has managed to keep a bunch of us going for quite a while now. A golf clap for you, sir! Very nicely done, indeed!
    I bowed out when a post of mine (containing the phrase "zero social skills") and the one it quoted both disappeared. Assholiness I can deal with, but I can't fight random censorship.
  • (cs) in reply to jasmine2501
    jasmine2501:
    Yeah I usually only decide between one hotel and the next based on the prices at the bar.

    These comment threads are always interesting. What I'm thinking after reading these is "this is why programmers don't get invited to meetings"

    I find it funny that this article was about someone who was given the algorithm for solving his problem, and decided to complicate it beyond what was given, and the comment thread shows a strong desire to do just that.

    Agreed

  • not ogden (unregistered)

    Too clever is dumb.

  • not nash (unregistered) in reply to GalacticCowboy

    It's like (real estate) searches that assume you know the name of every possible suburb in a city, and the only UI is sorted alphabetically in a huge dropdown. Most people only want to point at a map and say 'look here in a 10 block grid'.

    With too few results, a smart search will also search a larger grid and say 'I know you wanted x, but I also found y a little outside of what you were asking'

  • JayC (unregistered) in reply to kastein
    kastein:
    for all of you guys saying "why are you returning all results for a search instead of having the db filter it"... how exactly are you going to do "order by driving distance desc" in a db? driving distance is a non trivial calculation. The best I can think of is to throw in a stored proc that does as-the-crow-flies distance calculation and uses that to sort/limit the results, and then further filter in the frontend/business logic layer to do actual driving distance. Of course, I'm no GIS expert... so I might be completely wrong. But you can't ALL be GIS experts.

    This isn't that hard to do for small data sets:

    1. Write one SQL function taking 4 parameters that returns the distance between two points on the globe
    2. Calculate with distance between every item of interest and point of interest.
    3. Sort by resulting distances

    steps 2 & 3 can be implemented in a single SQL select statement.

    For larger data sets, it makes sense to cull the results of those points not even remotely close without having to calculate the precise distance (or even look at all the points). To do that efficiently, you'd have to use some sort of external quad-tree like structure. (in other words, not SQL, unless your database can handle it, like MS Sql 2008)

  • Gumpy Guss (unregistered) in reply to uzytkownik

    Um, Manitowok, WI is about 60 miles From Ludington, Michigan as the crow files. But most people without a yacht have to go the long way around Lake Michigan's shoreline, making it more like 420 miles.

    So you can't use Pythagoras for this.

  • xeno (unregistered) in reply to Kazan
    you're not finding WTFs though, you're creating new ones with your "everything should be done in the database"

    NO. IT SHOULD NOT.

    A database is a highly efficient data storage and retrieval system. Full stop. it is NOT supposed to do anything but data storage and retrieval. Just because you can abuse stored procedures, etc to do things that should be done in code doesn't mean you should.

    In short, complicator's gloves.

    Kazan may be agitated, but that doesn't mean he's any less correct. Maintaining complex code written in a different language from the primary language used in the organisation and which is stored in the database (not the best debugging environment) is a maintenance nightmare. I've seen what should be simple applications developed in this way that are bloated bug-beasts after three years of effort. Their specs did not contain anything as complicated as route calculation.

    Jamming data processing into the data storage layer like this is a perfect example of doing something stupid to conform with a model that wasn't a good idea in the first place. It has to be remembered that database functions like this often represent a "Schlemiel the Painter's Algorithm", and that it's much quicker to do this in the (in this case) PHP layer. On bigger applications you can be looking at the difference between seconds and hours. As far as I can tell, the main attraction of this approach is as ammunition in interdepartmental turf-wars between the "development" and "database administration" teams.

    Bear in mind we're not economists, and the "model" needs to evaluated against it's real world performance if you believe the "science" in "computer science" means anything at all. You should not attempt to develop all your CGI in C because of 15 year old notations of efficiency, but you shouldn't jump straight to uncritical model-worship either.

    On a different note, PHP is a very effective web development tool, especially if you observe the software engineering basics and use some of the frameworks out there for it (in moderation, some of them suffer from the old "every array and if-statement should be an object" mania). Unfortunately, there are a lot of mouthbreaters at the bottom end giving it a bad name.

  • JayC (unregistered) in reply to Kazan
    Kazan:
    Miksu:
    Kazan:
    most peolpe want driving distances. and driving distance can be MUCH LARGER than crow-flies distance.

    When booking a hotel from another city I for one am much more interested in knowing the hotel's distance from some clear landmarks in the city than the driving distance from point A. The driving distance doesn't give me any idea about the hotel's location within the city whereas the distance from say Times Square tells a lot more.

    still driving distance.

    No. If I'm wanting within 5 miles from somewhere, I mean crows distance. It generally doesn't matter to me about the driving distance (unless there's obviously something geological like a mountain or a river). Hell, I might be walking, so your driving distance calculation wouldn't do me any good.

  • StupidUserThatDoesntCare (unregistered) in reply to Kazan
    Kazan:

    google maps traffic data proves you wrong on traffic travel time.

    having a complete transportation network map - bike trails, pedestrian bridges, etc - also could solve that problem.

    just because you refuse to acknowledge a problem is solvable by computers doesn't make it so.

    just because you're fine with "as the crow flies" doesn't mean most users are these days. they've been spoiled by google maps. they want travel time.

    I apologize, I do think that the problem is solvable by computers, I just don't think the problem is solvable by programmers.

    This is like handing a physicist an n-Body problem where n>3. Giving a programmer real-world real-time geographical, traffic, route, weather and path-finding information isn't going to make a workable system that can be used remotely.

    And I think that the issue with your "they've been spoiled by google maps. they want travel time" argument is that no reservation site I've been to offers any kind of adjustment to proximity surfing based on time.

    I've not seen a reservation site that says "Okay, you want to stay somewhere within 1 hour of Fort Henry in Kingston, which method of travel would you like to estimate by: Foot, Bicycle, Automobile, Bus, Train or Boat? Do you care to estimate with travel times for Foot, Bicycle, or Automobile adjusted for Ferry usage? If so will your travel times be outside of the Ferry service availability? Please wait while we adjust the travel times based on local weather conditions and announced construction and local emergency services activity."

    Cumbersome is the word I would use.

    Instead they say - "Hey how close to you want to be?" And give you a drop down list of distances to select from, a distance not measured by a clock.

    Simple and it allows the user of the site to make assumptions about proximity based on their own knowledge.

    Sure it might be nice to say you want to stay within 30 minutes of Old Montreal by car, but you'd only have choices of hotels in Old Montreal - if you were able to select the option of walking then you could actually stay near the train station. (I've done both - admitedly on a rainy Saturday night in the late spring on either side of a Habs game - not the time to drive in downtown Montreal!)

    Has anyone complained to a concierge or hotel manager that the distance predicted by the web site is different than the distance they walk/rode/drove? Likely, but pedantic fools like that should be ignored (maybe even shot) as God intended.

  • StupidUserThatDoesntCare (unregistered) in reply to not nash
    not nash:
    It's like (real estate) searches that assume you know the name of every possible suburb in a city, and the only UI is sorted alphabetically in a huge dropdown. Most people only want to point at a map and say 'look here in a 10 block grid'.

    With too few results, a smart search will also search a larger grid and say 'I know you wanted x, but I also found y a little outside of what you were asking'

    not nash check out the Canadian Multiple Listings Service, they come really close to capturing that usage. (and I just happened to confirm that house prices have been stable in my area over the past 12 months - whew)

  • StupidUserThatDoesntCare (unregistered) in reply to Gumpy Guss
    Gumpy Guss:
    Um, Manitowok, WI is about 60 miles From Ludington, Michigan as the crow files. But most people without a yacht have to go the long way around Lake Michigan's shoreline, making it more like 420 miles.

    So you can't use Pythagoras for this.

    Or they can take the Manitowok-Ludington ferry which takes the route Pythagoras describes (mostly).

    A better example would be comparing the distances between Roseau Minnesota, Baudette Minnesota and Northwest Angle Minnesota. In "great circle" terms Buadette and Roseau are almost equidistant from Northwest Angle but by route map Roseau is an hour (30 miles) by car.

    Oddly its 61 miles by car between Roseau and Northwest Angle but only 60 miles walking.

  • JayC (unregistered) in reply to Kazan
    Kazan:
    <snip>

    you still can't use crow-flies distances for that. you still have to use the transit network graph for that - just in this case you're searching the edges labeled "walk" and/or "mass transit"

    Sure I can. Crow flies are obviously lower bounds. I'd just gamble whatever actual distance is hopefully within 141% of the driving distance (obviously, circuitous routes and routes taking you out of the circle, would take a lot more)

    And I'm also guarantying you I'd be walking in places where you wouldn't nor couldn't legally call walking space (and yes, I can do this all legally, too). You'd be giving me an upper bound I could use, sure, and that's useful, but I doubt your graph would have all the shortcuts I'd take, and potentially has a chance to be quite far off the actual walking distance I will take for a route as compared to the crow's distance.

    The point being, if I'm asking somebody about interesting items 5 miles from here, I'm not going to require them to perform an A* algorithm to do it. If I want a SPECIFIC route from A to B, well, then yes, I do want a quick route, and I'm going to expect that route to be longer.

  • consequat (unregistered)

    Neither of these two programmers would last very long at my company. In this scenario, it would always we wise to filter and sort at the database level by way of a parametrized stored procedure and no need to do filtering on the web server. At least they weren't trying to filter, sort and paginate client-side with javascript. :O

  • Real-modo (unregistered) in reply to Kazan
    Kazan:
    ... A database is a ... data storage and retrieval system. Full stop. it is NOT supposed to do anything but data storage and retrieval.
    Hmmm... to pick the ignorant comment, just look for the universals.

    In the real world, different situations call for different responses.

  • you (unregistered)

    You know, yeah, this is pretty bad, but I can easily imagine myself getting into a mess like this during one of my college jobs, or even my first couple years out of college. Yeah, if "Greg" has had a long career, there isn't really any excuse for this, but I see a whole lot of programmers overestimating their own brilliance, and there are still a whole lot of death march projects out there.

    I've been working full time for about three years now and I'm probably not much better of a "coder" than my senior year of college. But I've definitely learned a lot about how to read the "real" requirements between the lines, how to get help, and how to push back. Sounds like Greg should have swallowed his pride and asked for some more hands-on mentoring.

  • (cs)

    Gloves anyone?

  • Nick (unregistered) in reply to leppie

    I worked with a Greg, he used to get all records from the warehouse DB using an SP then do all the aggregating in the reporting tool.

    eg. Getting 13000 records from the DB and grouping them into months in the report Vs grouping them into months straight from the DB and dumping the rows to the report.

    He's gone now, but I still have to fix them whenever I come across them.

  • andreas (unregistered)

    having implemented such a feature in java - i can tell you that the problem described is not the real wtf. the problem, implemented correctly is not simple and not implemented in one day. user request page 5 of X for hotels surrounding point A which are available. steps to make:

    1. determine query center
    2. query DB for nearest elements using a spatially-enabled DB
    3. take first Z elements where Z is a rough estimation of how many hotels you might need considering step 4. 4)weed out all unavailable hotels using a web service.
    4. either sort elements by distance -> apply wgs->utm coordinate calculation or use a webservice for sorting the elements. (not recommended, can take infinite amount of time.)
    5. apply windowing function on the resultset to display the exact number of results to the user.

    there are so many fallacies here, even my captcha:facilisis

  • Erica (unregistered)

    Post processing of results....

    In a hotel app, there are many reasons for this. Just two are

    • remove those with no available inventory for the dates in question [not held on your database - that's a lookup per eligible hotel on external DBs]

    • prioritize listing order by complex criteria [star ratings, closeness to city center, likely profit margin for you, whether you got a clear result on the availability lookup]

    You could theoretically shoehorn the some of the prioritizing into an Order by clause, but such a clause is not really designed for embedding complex business logic. Prioritizing the listing to to "best according to complex criteria, including several user-selected ones" is a separate business subsystem in its own right.

    Don't even think about going into the hotel availability business if you under-estimate the complexity of that subsystem

  • mara (unregistered) in reply to StupidUserThatDoesntCare
    StupidUserThatDoesntCare:

    I apologize, I do think that the problem is solvable by computers, I just don't think the problem is solvable by programmers.

    This is like handing a physicist an n-Body problem where n>3. Giving a programmer real-world real-time geographical, traffic, route, weather and path-finding information isn't going to make a workable system that can be used remotely.

    And I think that the issue with your "they've been spoiled by google maps. they want travel time" argument is that no reservation site I've been to offers any kind of adjustment to proximity surfing based on time.

    I've not seen a reservation site that says "Okay, you want to stay somewhere within 1 hour of Fort Henry in Kingston, which method of travel would you like to estimate by: Foot, Bicycle, Automobile, Bus, Train or Boat? Do you care to estimate with travel times for Foot, Bicycle, or Automobile adjusted for Ferry usage? If so will your travel times be outside of the Ferry service availability? Please wait while we adjust the travel times based on local weather conditions and announced construction and local emergency services activity."

    Cumbersome is the word I would use.

    Instead they say - "Hey how close to you want to be?" And give you a drop down list of distances to select from, a distance not measured by a clock.

    Simple and it allows the user of the site to make assumptions about proximity based on their own knowledge.

    Sure it might be nice to say you want to stay within 30 minutes of Old Montreal by car, but you'd only have choices of hotels in Old Montreal - if you were able to select the option of walking then you could actually stay near the train station. (I've done both - admitedly on a rainy Saturday night in the late spring on either side of a Habs game - not the time to drive in downtown Montreal!)

    Has anyone complained to a concierge or hotel manager that the distance predicted by the web site is different than the distance they walk/rode/drove? Likely, but pedantic fools like that should be ignored (maybe even shot) as God intended.

    The only reason it would be cumbersome is that you envisage a horrible user interface. And there is no reason that the graph traversal will be measurably slower when taking weather, traffic and geographic data into consideration as long as you have, as you put it, in real time. If you have craptons of access times for that information then it will of course be slow as a dev just having been woken by a frantic boss support call in the middle of the night after a binge at the local pub. That is, unless you cache it in your graphs and update it either on a rolling schedule or just however you feel like it. ;)

    As far as "Is it necessary?" Nope. I'd rather think that my "What hotel will I pick" score system has a very low weight on travel distances from places. I rate quality of service and price (especially where the two have an optimal converging point) a lot higher.

  • Jasper (unregistered)

    OK...

    The REAL WTF here is fetching the WHOLE database, and filtering out the results you want to display in PHP code, instead of doing the proper query in the database to get only those results you need.

  • AshG (unregistered)

    No reason for all these complicated arithmetics. Break your map into square 5x5 tiles, keep tile IDs for each hotel record. Each hotel record will have 9 fields for tile IDs - its own and 8 neighbor tiles. Then just select all hotels where tile ID=my tile ID. Dump the result list onto the screen. Forget lats and longs.

  • Mayhem (unregistered) in reply to Jasper
    Jasper:
    OK...

    The REAL WTF here is fetching the WHOLE database, and filtering out the results you want to display in PHP code, instead of doing the proper query in the database to get only those results you need.

    He was never fetching the WHOLE database, merely a large subset. The number of hotels in their database for a given location is probably a number between 1 and 500, not exactly an earthshattering amount of data to handle in a data structure.

  • Wulf0r (unregistered)

    TRWTF is pagination because of a few hundred entries ... Or pagination EVER.

    It's such an user unfriendly approach especially when it doesn't work correctly with table sorting. Maybe if I select ALL hotels in New York I really want them all displayed? Or say, I need to extract a thousand userids but the STUPID FUCKING UI won't display more then 500 entries at a time and paginates them in batches of 10.

  • Andrew Brehm (unregistered)

    "The obvious, simple solution? Split up the results into multiple pages."

    I hate, hate, hate Web sites that do this.

    Web browser already allow for pagination since they only show the part of the page that is actually visible in the window.

    The only thing pagination does for me, like the "summary" view in The Daily WTF, is create a need to load the page (or the next page) once more.

    This is particularly annoying on mobile devices when you wait two minutes for the page to load only to find six summaries of stories rather than six stories or ten hotel listings rather than hundreds that can easily be scrolled through.

    Yes, loading one very long page takes longer than loading a short version, but it also means that after it has loaded one is DONE with loading and can start reading.

    Especially with hotels pagination only causes the user to decide between ten visible hotels or clicking another link not knowing if the next ten results are better or worse than the current ten results.

    So my vote is that the real WTF in this story is the idea that the results should appear on more than one page. (Whereas I think that pages with random numbers of hotels being displayed are at least more entertaining than unnecessary ten-hotel lists.)

    Luctus?

  • (cs) in reply to Jasper
    Jasper:
    The REAL WTF here is fetching the WHOLE database, and filtering out the results you want to display in PHP code, instead of doing the proper query in the database to get only those results you need.
    You're expecting hundreds of hotels across a large city, run by lots of different companies, to keep their live reservations database(s) together in one spot just so that you can run an efficient SQL query for a poxy website? That's so not going to work, but if you ever decide to pitch that to a VC, please give me a call first so I can watch the aftermath. Give me time to get the popcorn first. Enough time and we could even sell pay-per-view for it.
  • (cs) in reply to Wulf0r
    Wulf0r:
    [Pagination is] such an user unfriendly approach especially when it doesn't work correctly with table sorting. Maybe if I select ALL hotels in New York I really want them all displayed?
    You really want that? Even the ones that charge by the hour? How the heck would you fit that much information on the screen and get the user to understand anything other than “Shit! There's lots of hotels in New York”.
    Wulf0r:
    Or say, I need to extract a thousand userids but the STUPID FUCKING UI won't display more then 500 entries at a time and paginates them in batches of 10.
    Wrong tool for that job. Why would you do things through a poxy UI when you could do a database query? If you can't do the database query, that's the real problem right there…
  • (cs) in reply to Andrew Brehm
    Andrew Brehm:
    "The obvious, simple solution? Split up the results into multiple pages."

    I hate, hate, hate Web sites that do this.

    Web browser already allow for pagination since they only show the part of the page that is actually visible in the window.

    The only thing pagination does for me, like the "summary" view in The Daily WTF, is create a need to load the page (or the next page) once more.

    This is particularly annoying on mobile devices when you wait two minutes for the page to load only to find six summaries of stories rather than six stories or ten hotel listings rather than hundreds that can easily be scrolled through.

    Yes, loading one very long page takes longer than loading a short version, but it also means that after it has loaded one is DONE with loading and can start reading.

    Especially with hotels pagination only causes the user to decide between ten visible hotels or clicking another link not knowing if the next ten results are better or worse than the current ten results.

    So my vote is that the real WTF in this story is the idea that the results should appear on more than one page. (Whereas I think that pages with random numbers of hotels being displayed are at least more entertaining than unnecessary ten-hotel lists.)

    Luctus?

    Yeah I hate Google too. http://www.google.com/search?q=wtf has only 38 million results. But if I want to know what's on the last page then I have to go to through millions of pages. If only I could click on Search, go to sleep and then in the morning when the page has loaded, I could simply press End on my keyboard.

    The first 10 pages of results are irrelevant anyway. All the good stuff is hidden away on the last page because Google doesn't want us to find it.

    luctus indeed

  • Chris Smith (unregistered) in reply to shimon
    shimon:
    ORDER BY SQUARE(hotels.x - @locationX) + SQUARE(hotels.y - @locationY) ASC

    QED (What to do if there is no SQUARE function is left as an exercise to the reader.)

    And now I have a piece of breaking news for you: the Earth, as the recent researches have shown, is not flat at all!

    And it's enough for the endpoints to be two or three states apart for cartesian distance to go from simply inaccurate to f-cking wildly inaccurate.

    Yebbut, it doesn't matter, as the distances are calculated as if they are flat (if you look at a grid of long/lat, you'll see that the lines are already curved) so it takes into account the curvature in the positions.

  • Patrick (unregistered)
    ps aux:
    http://php.about.com/od/mysqlcommands/g/Limit_sql.htm

    items = pageNumber * 10;

    LIMIT items, 10

    Or, to be more precise, and so you don't have to run the query a second time:

    http://dev.mysql.com/doc/refman/5.0/en/select.html

    SELECT CALC_FOUND_ROWS * FROM table LIMIT items, 10; SELECT FOUND_ROWS();

  • (cs) in reply to JayC
    JayC:
    Sure I can. Crow flies are obviously lower bounds. I'd just gamble whatever actual distance is hopefully within 141% of the driving distance (obviously, circuitous routes and routes taking you out of the circle, would take a lot more)
    It's really variable. In some cities, cartesian distances are pretty good estimates. In others (with awkward things like large rivers, the sea, or a major railroad terminus) then you're going to be massively misleading. It's a problem that's much tricker than you'd really like when you come to the Real World, and you can't easily go from a simple case to a complex one.

    The other issue that comes up is that you can't just precompute for landmarks, because people have this nasty habit of wanting to go to other things. For example, a number of times when I've been on business trips I've optimized for location based on proximity to the office I'm visiting. Most office blocks, even nice ones, aren't tourist landmarks. To complete the picture, it's the business travel market that these hotel finder sites really prioritize anyway because people doing that sort of thing are much more likely to want to find somewhere good enough NOW.

    (These days, the good booking sites will show you hotels mashed up with Google Maps and manage the amount of info displayed intelligently as you zoom in and out. Slick.)

Leave a comment on “Pagination Consternation”

Log In or post as a guest

Replying to comment #:

« Return to Article