G2A Many GEOs
SHARE
TWEET

OLD

dragonbane Dec 9th, 2018 (edited) 296 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -Lower default radius to 2 km in form and DB
  2.  
  3. -Run SELECT and get the first best quick_ride that is still status = 0 and has last_route_attempt either empty OR > 60 seconds (LIMIT 1)
  4.  
  5. -If found quick_rides are empty exit here
  6.  
  7. -Run SELECT and get all quick_ride ids where the status = 0 and the creator != the current array element's creator and (origin_country_code is equal or destination_country_code is equal) and current array element id is NOT in previously_matched list and current array previously_matched doesn't contain the id and dwithin of both origin spots or both dest spots is within 100 km (keep working with this set)
  8.  
  9. -Trigger UPDATE statement which updates the main quick_ride id entry and add the list of found quick_ride ids to its previously_matched array (as an addition) + set the last_route_attempt to current UTC time ( timezone('utc'::text, now()) )
  10.  
  11. -If found quick_rides are empty exit here
  12.  
  13. -Run SELECT and return all element ids where the id is contained in the found quick_ride id list and use a custom function to compare current array element route with waypoints and if there is an overlap (x km flight line distance max using dwithin; for this use BOTH custom search radius by user) between a major route point of person A and person B's origin position (or vice versa), save the match index position and then compare the entire route of person A to his destination with person B route from the match point onwards and only if every further point matches with the same max distance in km (of both users) until one of the persons reaches its destination we have a 100% weight match. If the vice versa check has not yet been done, do it now. If it also results in 100% then lower the weighting value to 99% as it is not fully clear which person should pickup the other and exit the check.
  14. Count the number of waypoints that matched (including origin) and calc weight in relation to total waypoints in case they dont fully match (full match is auto 100%). Formel is: (matchedWaypoints / totalWaypointsPickedUpPerson) * 100. > 100 gets adjusted to 100. < 1 gets adjusted to 1%. Round otherwise
  15. If no match at all earlier return weight 0% asap. Otherwise if the origin matched at least the minimum weight the function can return is 1%.
  16.  
  17. -result_match_route_order (originID, origin2ID, destID, destID2 e.g. 'a-b-b-a')
  18.  
  19. -if both origin positions are both within user radius then make origin ambiguous
  20. -if both dest positions are both within user radius then make destination ambiguous
  21.  
  22. -keep too close checks
  23. -create linestring for entire route a then b from all waypoints, no array for loop
  24. -check if b origin is close to linestring
  25. -if no = weight 0%
  26. -if yes = compare all further b points to linestring
  27. -if b runs out = weight 100%
  28. -on each b point check also if A destination is within radius of the current b point. If yes consider A has finished
  29.  
  30. -Function returns the route order and the weight value. Outer SELECT orders by weight descending
  31.  
  32. -If highest weight is = 0 exit
  33.  
  34. -Grab the highest weighted entry from the set and verify current array element's creator is not inside blocked_users list of the other ride's creator and vice versa.
  35. If check passes return true. Otherwise check the next highest weighted entry until one returns true
  36.  
  37. OLD:
  38. if no direct, but an indirect best match was found let both combination (or maybe only postgis top combination) A route/B origin and B route/A origin get routed by mapbox (origin, other person origin, other person destination = 3 waypoints) and see if the total distance increase in km for the person doing the divergence is under his total route length and a certain threshold (users's searchRadius). If it stays under the threshold for person A, perform map box query (A origin, B origin, B dest, A dest = 4 waypoints) and see if total increase now compared to the original route length (A origin, A dest) stays under A's total route length and a certain threshold (users's searchRadius A). If it does trigger a match if the increase doesn't violate the threshold of person B. If not swap destinations and test again. If not test both combinations starting from B.
  39. (cost: every user costs 1 initial mapbox request, every pair deep search costs 6 queries = 8 total for a pair of users)
  40.  
  41. -If origin is ambiguous, route ABXX (XX = destination) and BAXX and see which one is shorter (2+2 = 4 total queries)
  42. -If destination is ambiguous, route XXAB (XX = origin) and XXBA and see which one is shorter (2+2 = 4 total queries)
  43. -If both are ambiguous, route ABAB and ABBA and see which one is shorter. Then test BAXX (XX=shortest destination) and see which is shorter (2+3 = 5 total queries)
  44. -If none are ambiguous (has a matching 100% weight) perform a single map box request to route from person X to person Y to destination 1 to destination 2 = 4 waypoints (total cost: 2+1 = 3 mapBox queries)
  45.  
  46. -After routing is finished, calculate the entire distance X (the true origin) has to drive alone to get to Y and after Y is delivered to X destination (if X ends first this is omitted and then calc the distance Y has to drive alone until Y's destination) . Calculate the entire distance both will travel together = sharedDistance
  47.  
  48. -Find points (e.g. start/end) for accurate calculation by checking if they are on a polyline formed by 2 route points. If it is end point the polyline's first point is taken for distance between it and the point, if it is a start point calculate from the point to the polyline's second point. On leaflet side use: https://stackoverflow.com/questions/45766312/check-existence-of-point-on-leaflet-route?rq=1
  49.  
  50. -Ensure that X's alone distance  + sharedDistance / 2 < X's prior total distance in m and Y's alone distance (might be 0m) + sharedDistance / 2 < Y's prior total distance.
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top