{"action":"created","comment":{"url":"https://api.github.com/repos/CanalTP/navitia/pulls/comments/89142124","pull_request_review_id":9690709,"id":89142124,"diff_hunk":"@@ -265,71 +477,98 @@ def call_kraken(self, request_type, request, instance, krakens_call):\n         \"\"\"\n         logger = logging.getLogger(__name__)\n         logger.debug('datetime: %s', request['datetime'])\n-        #crow_fly_stop_points is a set of stop_point.uri used to create a crowfly section.\n-        #odt_stop_points is a set of stop_point.uri with is_zonal = true used to manage tad_zonal\n+\n+        # odt_stop_points is a set of stop_point.uri with is_zonal = true used to manage tad_zonal\n         odt_stop_points = set()\n-        crow_fly_stop_points = set()\n+\n+        # crowfly_stop_points is a set of stop_point.uri used to create a crowfly section.\n+        crowfly_stop_points = set()\n+\n         if not g.requested_origin:\n             g.requested_origin = instance.georef.place(request['origin'])\n \n         if not g.requested_destination:\n             g.requested_destination = instance.georef.place(request['destination'])\n \n-        for dep_mode, arr_mode in krakens_call:\n-            if dep_mode not in g.origins_fallback and request.get('max_duration', 0):\n-                g.origins_fallback[dep_mode] = self._get_stop_points(instance,\n-                                                                     g.requested_origin, dep_mode,\n-                                                                     get_max_fallback_duration(request, dep_mode),\n-                                                                     request)\n-\n-                #Fetch all the stop points of this stop_area and replaces all the durations by 0 in the table\n-                #g.origins_fallback[dep_mode]\n-                _update_crowfly_duration(instance, g.origins_fallback, dep_mode, request['origin'], g.requested_origin,\n-                                         crow_fly_stop_points, odt_stop_points)\n-\n-            if arr_mode not in g.destinations_fallback and request.get('max_duration', 0):\n-               g.destinations_fallback[arr_mode] = self._get_stop_points(instance,\n-                                                                         g.requested_destination, arr_mode,\n-                                                                         get_max_fallback_duration(request, arr_mode),\n-                                                                         request,\n-                                                                         reverse=True)\n-\n-               #Fetch all the stop points of this stop_area and replaces all the durations by 0 in the table\n-               #g.destinations_fallback[arr_mode]\n-               _update_crowfly_duration(instance, g.destinations_fallback, arr_mode, request['destination'],\n-                                        g.requested_destination, crow_fly_stop_points, odt_stop_points)\n+        worker = AsyncWorker(instance, krakens_call, request)\n+\n+        if request.get('max_duration', 0):\n+            # Get all stop_points around the requested origin within a crowfly range\n+            # Calls on origins and destinations are asynchronous\n+            orig_futures, dest_futures = worker.get_crowfly_futures(g.requested_origin, g.requested_destination)\n+            gevent.joinall(orig_futures + dest_futures)\n+            for future in orig_futures:\n+                g.origins_places_crowfly.update(future.get())\n+            for future in dest_futures:\n+                g.destinations_places_crowfly.update(future.get())\n+\n+            # Once we get crow fly stop points with origins and destinations, we start\n+            # the computation NM: the fallback matrix which contains the arrival duration for crowfly stop_points\n+            # from origin/destination\n+            # Ex:\n+            #                    stop_point1   stop_point2  stop_point3\n+            # request_origin_1     86400(s)      43200(s)     21600(s)\n+            # As a side note this won't work the day when our ETA will be impacted by the datetime of the journey,\n+            # at least for the arrival when doing a \"departure after\" request.\n+            orig_futures, dest_futures = worker.get_routing_matrix_futures(g.requested_origin,\n+                                                                           g.requested_destination,\n+                                                                           g.origins_places_crowfly,\n+                                                                           g.destinations_places_crowfly)\n+            gevent.joinall(orig_futures + dest_futures)\n+            for future in orig_futures:\n+                g.origins_fallback.update(future.get())\n+            for future in dest_futures:\n+                g.destinations_fallback.update(future.get())\n+\n+            # In Some special cases, like \"odt\" or \"departure(arrive) from(to) a stop_area\",\n+            # the first(last) section should be treated differently\n+            orig_futures, dest_futures = worker.get_update_crowfly_duration_futures()\n+            gevent.joinall(orig_futures + dest_futures)\n+\n+            def _updater(_futures, fb, crowfly_stop_points, odt_stop_points):\n+                for f in _futures:\n+                    crowfly_res, odt_res, fb_res = f.get()\n+                    crowfly_stop_points |= crowfly_res\n+                    odt_stop_points |= odt_res\n+                    for mode in (mode for mode in fb_res if mode in fb):\n+                        fb[mode].update(fb_res[mode])\n+\n+            _updater(orig_futures, g.origins_fallback, crowfly_stop_points, odt_stop_points)\n+            _updater(dest_futures, g.destinations_fallback, crowfly_stop_points, odt_stop_points)\n+\n         resp = []\n         journey_parameters = create_parameters(request)\n-        for dep_mode, arr_mode in krakens_call:\n-            #todo: this is probably shared between multiple thread\n-            self.nb_kraken_calls += 1\n-            direct_path = self._get_direct_path(instance,\n-                                                dep_mode,\n-                                                g.requested_origin,\n-                                                g.requested_destination,\n-                                                request['datetime'],\n-                                                request['clockwise'],\n-                                                request)\n-            if direct_path.journeys:\n-                journey_parameters.direct_path_duration = direct_path.journeys[0].durations.total\n-                #Since _get_direct_method returns a reference instead of an object we don't add in response\n-                #if already exists.\n-                if direct_path not in resp:\n-                    direct_path.journeys[0].internal_id = \"dp_{resp}-{j}\".format(resp=self.nb_kraken_calls, j=0)\n-                    resp.append(direct_path)\n-            else:\n-                journey_parameters.direct_path_duration = None\n \n-            fall_back_origins = g.origins_fallback.get(dep_mode)\n-            fall_back_destinations = g.destinations_fallback.get(arr_mode)\n-            if not fall_back_origins or not fall_back_destinations or not request.get('max_duration', 0):\n+        # Now we compute the direct path with all requested departure mode\n+        # their time will be used to initialized our PT calls\n+        futures = worker.get_direct_path_futures(g.fallback_direct_path,\n+                                                 g.requested_origin,\n+                                                 g.requested_destination,\n+                                                 request['datetime'],\n+                                                 request['clockwise'],\n+                                                 False)\n+        for future in gevent.iwait(futures):\n+            self.nb_kraken_calls += 1","path":"source/jormungandr/jormungandr/scenarios/experimental.py","position":581,"original_position":581,"commit_id":"fb119c9d719eecbc74a37b080fa6304fb92f7899","original_commit_id":"fb119c9d719eecbc74a37b080fa6304fb92f7899","user":{"login":"azime","id":4006603,"avatar_url":"https://avatars.githubusercontent.com/u/4006603?v=3","gravatar_id":"","url":"https://api.github.com/users/azime","html_url":"https://github.com/azime","followers_url":"https://api.github.com/users/azime/followers","following_url":"https://api.github.com/users/azime/following{/other_user}","gists_url":"https://api.github.com/users/azime/gists{/gist_id}","starred_url":"https://api.github.com/users/azime/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/azime/subscriptions","organizations_url":"https://api.github.com/users/azime/orgs","repos_url":"https://api.github.com/users/azime/repos","events_url":"https://api.github.com/users/azime/events{/privacy}","received_events_url":"https://api.github.com/users/azime/received_events","type":"User","site_admin":false},"body":"to delete ?","created_at":"2016-11-22T15:38:58Z","updated_at":"2016-11-22T15:38:58Z","html_url":"https://github.com/CanalTP/navitia/pull/1844#discussion_r89142124","pull_request_url":"https://api.github.com/repos/CanalTP/navitia/pulls/1844","_links":{"self":{"href":"https://api.github.com/repos/CanalTP/navitia/pulls/comments/89142124"},"html":{"href":"https://github.com/CanalTP/navitia/pull/1844#discussion_r89142124"},"pull_request":{"href":"https://api.github.com/repos/CanalTP/navitia/pulls/1844"}}},"pull_request":{"url":"https://api.github.com/repos/CanalTP/navitia/pulls/1844","id":93168923,"html_url":"https://github.com/CanalTP/navitia/pull/1844","diff_url":"https://github.com/CanalTP/navitia/pull/1844.diff","patch_url":"https://github.com/CanalTP/navitia/pull/1844.patch","issue_url":"https://api.github.com/repos/CanalTP/navitia/issues/1844","number":1844,"state":"open","locked":false,"title":"Async experimental","user":{"login":"azime","id":4006603,"avatar_url":"https://avatars.githubusercontent.com/u/4006603?v=3","gravatar_id":"","url":"https://api.github.com/users/azime","html_url":"https://github.com/azime","followers_url":"https://api.github.com/users/azime/followers","following_url":"https://api.github.com/users/azime/following{/other_user}","gists_url":"https://api.github.com/users/azime/gists{/gist_id}","starred_url":"https://api.github.com/users/azime/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/azime/subscriptions","organizations_url":"https://api.github.com/users/azime/orgs","repos_url":"https://api.github.com/users/azime/repos","events_url":"https://api.github.com/users/azime/events{/privacy}","received_events_url":"https://api.github.com/users/azime/received_events","type":"User","site_admin":false},"body":"Support async call kraken in experimental scenario","created_at":"2016-11-10T15:14:45Z","updated_at":"2016-11-22T15:38:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"81868c98002fd1dbb55a6e657296b05348ec2ad3","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/CanalTP/navitia/pulls/1844/commits","review_comments_url":"https://api.github.com/repos/CanalTP/navitia/pulls/1844/comments","review_comment_url":"https://api.github.com/repos/CanalTP/navitia/pulls/comments{/number}","comments_url":"https://api.github.com/repos/CanalTP/navitia/issues/1844/comments","statuses_url":"https://api.github.com/repos/CanalTP/navitia/statuses/fb119c9d719eecbc74a37b080fa6304fb92f7899","head":{"label":"azime:async_experimental","ref":"async_experimental","sha":"fb119c9d719eecbc74a37b080fa6304fb92f7899","user":{"login":"azime","id":4006603,"avatar_url":"https://avatars.githubusercontent.com/u/4006603?v=3","gravatar_id":"","url":"https://api.github.com/users/azime","html_url":"https://github.com/azime","followers_url":"https://api.github.com/users/azime/followers","following_url":"https://api.github.com/users/azime/following{/other_user}","gists_url":"https://api.github.com/users/azime/gists{/gist_id}","starred_url":"https://api.github.com/users/azime/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/azime/subscriptions","organizations_url":"https://api.github.com/users/azime/orgs","repos_url":"https://api.github.com/users/azime/repos","events_url":"https://api.github.com/users/azime/events{/privacy}","received_events_url":"https://api.github.com/users/azime/received_events","type":"User","site_admin":false},"repo":{"id":19149123,"name":"navitia","full_name":"azime/navitia","owner":{"login":"azime","id":4006603,"avatar_url":"https://avatars.githubusercontent.com/u/4006603?v=3","gravatar_id":"","url":"https://api.github.com/users/azime","html_url":"https://github.com/azime","followers_url":"https://api.github.com/users/azime/followers","following_url":"https://api.github.com/users/azime/following{/other_user}","gists_url":"https://api.github.com/users/azime/gists{/gist_id}","starred_url":"https://api.github.com/users/azime/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/azime/subscriptions","organizations_url":"https://api.github.com/users/azime/orgs","repos_url":"https://api.github.com/users/azime/repos","events_url":"https://api.github.com/users/azime/events{/privacy}","received_events_url":"https://api.github.com/users/azime/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/azime/navitia","description":null,"fork":true,"url":"https://api.github.com/repos/azime/navitia","forks_url":"https://api.github.com/repos/azime/navitia/forks","keys_url":"https://api.github.com/repos/azime/navitia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/azime/navitia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/azime/navitia/teams","hooks_url":"https://api.github.com/repos/azime/navitia/hooks","issue_events_url":"https://api.github.com/repos/azime/navitia/issues/events{/number}","events_url":"https://api.github.com/repos/azime/navitia/events","assignees_url":"https://api.github.com/repos/azime/navitia/assignees{/user}","branches_url":"https://api.github.com/repos/azime/navitia/branches{/branch}","tags_url":"https://api.github.com/repos/azime/navitia/tags","blobs_url":"https://api.github.com/repos/azime/navitia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/azime/navitia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/azime/navitia/git/refs{/sha}","trees_url":"https://api.github.com/repos/azime/navitia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/azime/navitia/statuses/{sha}","languages_url":"https://api.github.com/repos/azime/navitia/languages","stargazers_url":"https://api.github.com/repos/azime/navitia/stargazers","contributors_url":"https://api.github.com/repos/azime/navitia/contributors","subscribers_url":"https://api.github.com/repos/azime/navitia/subscribers","subscription_url":"https://api.github.com/repos/azime/navitia/subscription","commits_url":"https://api.github.com/repos/azime/navitia/commits{/sha}","git_commits_url":"https://api.github.com/repos/azime/navitia/git/commits{/sha}","comments_url":"https://api.github.com/repos/azime/navitia/comments{/number}","issue_comment_url":"https://api.github.com/repos/azime/navitia/issues/comments{/number}","contents_url":"https://api.github.com/repos/azime/navitia/contents/{+path}","compare_url":"https://api.github.com/repos/azime/navitia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/azime/navitia/merges","archive_url":"https://api.github.com/repos/azime/navitia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/azime/navitia/downloads","issues_url":"https://api.github.com/repos/azime/navitia/issues{/number}","pulls_url":"https://api.github.com/repos/azime/navitia/pulls{/number}","milestones_url":"https://api.github.com/repos/azime/navitia/milestones{/number}","notifications_url":"https://api.github.com/repos/azime/navitia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/azime/navitia/labels{/name}","releases_url":"https://api.github.com/repos/azime/navitia/releases{/id}","deployments_url":"https://api.github.com/repos/azime/navitia/deployments","created_at":"2014-04-25T14:34:34Z","updated_at":"2014-06-17T14:45:02Z","pushed_at":"2016-11-22T15:29:41Z","git_url":"git://github.com/azime/navitia.git","ssh_url":"git@github.com:azime/navitia.git","clone_url":"https://github.com/azime/navitia.git","svn_url":"https://github.com/azime/navitia","homepage":"http://www.navitia.io/","size":33952,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"dev"}},"base":{"label":"CanalTP:dev","ref":"dev","sha":"738299d0bded65073f6248d422ac60c16ec0bcf6","user":{"login":"CanalTP","id":2743985,"avatar_url":"https://avatars.githubusercontent.com/u/2743985?v=3","gravatar_id":"","url":"https://api.github.com/users/CanalTP","html_url":"https://github.com/CanalTP","followers_url":"https://api.github.com/users/CanalTP/followers","following_url":"https://api.github.com/users/CanalTP/following{/other_user}","gists_url":"https://api.github.com/users/CanalTP/gists{/gist_id}","starred_url":"https://api.github.com/users/CanalTP/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CanalTP/subscriptions","organizations_url":"https://api.github.com/users/CanalTP/orgs","repos_url":"https://api.github.com/users/CanalTP/repos","events_url":"https://api.github.com/users/CanalTP/events{/privacy}","received_events_url":"https://api.github.com/users/CanalTP/received_events","type":"Organization","site_admin":false},"repo":{"id":10797333,"name":"navitia","full_name":"CanalTP/navitia","owner":{"login":"CanalTP","id":2743985,"avatar_url":"https://avatars.githubusercontent.com/u/2743985?v=3","gravatar_id":"","url":"https://api.github.com/users/CanalTP","html_url":"https://github.com/CanalTP","followers_url":"https://api.github.com/users/CanalTP/followers","following_url":"https://api.github.com/users/CanalTP/following{/other_user}","gists_url":"https://api.github.com/users/CanalTP/gists{/gist_id}","starred_url":"https://api.github.com/users/CanalTP/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CanalTP/subscriptions","organizations_url":"https://api.github.com/users/CanalTP/orgs","repos_url":"https://api.github.com/users/CanalTP/repos","events_url":"https://api.github.com/users/CanalTP/events{/privacy}","received_events_url":"https://api.github.com/users/CanalTP/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CanalTP/navitia","description":"The open source software to build cool stuff with locomotion","fork":false,"url":"https://api.github.com/repos/CanalTP/navitia","forks_url":"https://api.github.com/repos/CanalTP/navitia/forks","keys_url":"https://api.github.com/repos/CanalTP/navitia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CanalTP/navitia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CanalTP/navitia/teams","hooks_url":"https://api.github.com/repos/CanalTP/navitia/hooks","issue_events_url":"https://api.github.com/repos/CanalTP/navitia/issues/events{/number}","events_url":"https://api.github.com/repos/CanalTP/navitia/events","assignees_url":"https://api.github.com/repos/CanalTP/navitia/assignees{/user}","branches_url":"https://api.github.com/repos/CanalTP/navitia/branches{/branch}","tags_url":"https://api.github.com/repos/CanalTP/navitia/tags","blobs_url":"https://api.github.com/repos/CanalTP/navitia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CanalTP/navitia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CanalTP/navitia/git/refs{/sha}","trees_url":"https://api.github.com/repos/CanalTP/navitia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CanalTP/navitia/statuses/{sha}","languages_url":"https://api.github.com/repos/CanalTP/navitia/languages","stargazers_url":"https://api.github.com/repos/CanalTP/navitia/stargazers","contributors_url":"https://api.github.com/repos/CanalTP/navitia/contributors","subscribers_url":"https://api.github.com/repos/CanalTP/navitia/subscribers","subscription_url":"https://api.github.com/repos/CanalTP/navitia/subscription","commits_url":"https://api.github.com/repos/CanalTP/navitia/commits{/sha}","git_commits_url":"https://api.github.com/repos/CanalTP/navitia/git/commits{/sha}","comments_url":"https://api.github.com/repos/CanalTP/navitia/comments{/number}","issue_comment_url":"https://api.github.com/repos/CanalTP/navitia/issues/comments{/number}","contents_url":"https://api.github.com/repos/CanalTP/navitia/contents/{+path}","compare_url":"https://api.github.com/repos/CanalTP/navitia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CanalTP/navitia/merges","archive_url":"https://api.github.com/repos/CanalTP/navitia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CanalTP/navitia/downloads","issues_url":"https://api.github.com/repos/CanalTP/navitia/issues{/number}","pulls_url":"https://api.github.com/repos/CanalTP/navitia/pulls{/number}","milestones_url":"https://api.github.com/repos/CanalTP/navitia/milestones{/number}","notifications_url":"https://api.github.com/repos/CanalTP/navitia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CanalTP/navitia/labels{/name}","releases_url":"https://api.github.com/repos/CanalTP/navitia/releases{/id}","deployments_url":"https://api.github.com/repos/CanalTP/navitia/deployments","created_at":"2013-06-19T15:34:30Z","updated_at":"2016-11-21T18:33:43Z","pushed_at":"2016-11-22T15:29:41Z","git_url":"git://github.com/CanalTP/navitia.git","ssh_url":"git@github.com:CanalTP/navitia.git","clone_url":"https://github.com/CanalTP/navitia.git","svn_url":"https://github.com/CanalTP/navitia","homepage":"http://www.navitia.io","size":39610,"stargazers_count":189,"watchers_count":189,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":66,"mirror_url":null,"open_issues_count":32,"forks":66,"open_issues":32,"watchers":189,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/CanalTP/navitia/pulls/1844"},"html":{"href":"https://github.com/CanalTP/navitia/pull/1844"},"issue":{"href":"https://api.github.com/repos/CanalTP/navitia/issues/1844"},"comments":{"href":"https://api.github.com/repos/CanalTP/navitia/issues/1844/comments"},"review_comments":{"href":"https://api.github.com/repos/CanalTP/navitia/pulls/1844/comments"},"review_comment":{"href":"https://api.github.com/repos/CanalTP/navitia/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/CanalTP/navitia/pulls/1844/commits"},"statuses":{"href":"https://api.github.com/repos/CanalTP/navitia/statuses/fb119c9d719eecbc74a37b080fa6304fb92f7899"}}}}
{"actor":{"display_login":"azime"}}