{"action":"created","comment":{"url":"https://api.github.com/repos/bayesimpact/encompass/pulls/comments/172268609","pull_request_review_id":101254174,"id":172268609,"diff_hunk":"@@ -121,8 +106,81 @@ def closest_with_early_exit(self, origin, point_list, exit_distance):\n \n         return self.closest(origin=origin, point_list=relevant_points)\n \n+    def closest(self, origin, point_list):\n+        \"\"\"\n+        Find closest point in a list of points and returns min_measurement, min_point.\n+\n+        min_measurement is returned in minutes.\n+        \"\"\"\n+        distance_responses = self.measure_one_to_many_points(origin=origin, point_list=point_list)\n \n-class MapBoxDrivingTime(Measurer):\n+        min_idx, min_measurement = min(\n+            enumerate(distance_responses),\n+            key=operator.itemgetter(1)\n+        )\n+        return float(min_measurement) / 60.0, point_list[min_idx]\n+\n+\n+class OSRMDrivingTime(ApiDrivingTime):\n+    \"\"\"\n+    Class for OSRM driving time measurements.\n+\n+    Uses the `table` OSRM API endpoint.\n+    \"\"\"\n+\n+    def __init__(self, api_url=None, early_exit_outer_radius=120.0 * 10**3):\n+        \"\"\"Initialize the distance class with the OSRM URL.\"\"\"\n+        # FIXME: Once the API accepts distances, enable a `distance` mode.\n+        logger.debug('Initializing OSRM measurer.')\n+        super().__init__()\n+        self.api_url = api_url or os.getenv('OSRM_URL')\n+        self._haversine_measurer = distance.HaversineDistance()\n+        self.early_exit_outer_radius = early_exit_outer_radius\n+\n+    @staticmethod\n+    def _represent_point_as_str(point):\n+        \"\"\"Represent a point dictionary in the format (longitude,latitude).\"\"\"\n+        return '{lng},{lat}'.format(lat=point.latitude, lng=point.longitude)\n+\n+    @retry(retry_on_result=_retry_if_result_none, stop_max_attempt_number=10, wait_fixed=2000)\n+    def get_matrix(self, source_points, destination_points):\n+        \"\"\"\n+        Retrieve a time matrix from the matrix API.\n+\n+        Time is expressed in seconds.\n+        \"\"\"\n+        all_points = source_points + destination_points\n+        if len(all_points) > self.max_matrix_size:\n+            raise RuntimeError(\n+                'OSRM matrix API only accepts {} locations.'.format(self.max_matrix_size)\n+            )\n+        coordinates = ';'.join([\n+            '{longitude},{latitude}'.format(longitude=point[1], latitude=point[0])\n+            for point in all_points\n+        ])\n+\n+        url = '{base_url}/{api_string}'.format(\n+            base_url=self.api_url,\n+            api_string='table/v1/car/{coords}'.format(coords=coordinates)\n+        )\n+\n+        params = {\n+            'sources': 0,\n+            'destinations': ';'.join(\n+                [str(1 + i) for i, _ in enumerate(destination_points)]\n+            )\n+        }\n+        response = requests.get(url, params=params)\n+\n+        # TODO - Add retrying for common HTTP errors.","path":"backend/models/time.py","position":193,"original_position":193,"commit_id":"54fdac46a4b32b3285b387a9181fce3d0f5269b3","original_commit_id":"54fdac46a4b32b3285b387a9181fce3d0f5269b3","user":{"login":"tetraptych","id":19229500,"avatar_url":"https://avatars1.githubusercontent.com/u/19229500?v=4","gravatar_id":"","url":"https://api.github.com/users/tetraptych","html_url":"https://github.com/tetraptych","followers_url":"https://api.github.com/users/tetraptych/followers","following_url":"https://api.github.com/users/tetraptych/following{/other_user}","gists_url":"https://api.github.com/users/tetraptych/gists{/gist_id}","starred_url":"https://api.github.com/users/tetraptych/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tetraptych/subscriptions","organizations_url":"https://api.github.com/users/tetraptych/orgs","repos_url":"https://api.github.com/users/tetraptych/repos","events_url":"https://api.github.com/users/tetraptych/events{/privacy}","received_events_url":"https://api.github.com/users/tetraptych/received_events","type":"User","site_admin":false},"body":"We can easily implement this via \r\n```\r\ntry:\r\n    response.raise_for_status()\r\nexcept requests.HTTPError:\r\n    return None\r\n```","created_at":"2018-03-05T17:39:30Z","updated_at":"2018-03-05T17:50:09Z","html_url":"https://github.com/bayesimpact/encompass/pull/478#discussion_r172268609","pull_request_url":"https://api.github.com/repos/bayesimpact/encompass/pulls/478","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/bayesimpact/encompass/pulls/comments/172268609"},"html":{"href":"https://github.com/bayesimpact/encompass/pull/478#discussion_r172268609"},"pull_request":{"href":"https://api.github.com/repos/bayesimpact/encompass/pulls/478"}}},"pull_request":{"url":"https://api.github.com/repos/bayesimpact/encompass/pulls/478","id":172628093,"html_url":"https://github.com/bayesimpact/encompass/pull/478","diff_url":"https://github.com/bayesimpact/encompass/pull/478.diff","patch_url":"https://github.com/bayesimpact/encompass/pull/478.patch","issue_url":"https://api.github.com/repos/bayesimpact/encompass/issues/478","number":478,"state":"open","locked":false,"title":"Add OpenRoute API","user":{"login":"ericboucher","id":16843267,"avatar_url":"https://avatars3.githubusercontent.com/u/16843267?v=4","gravatar_id":"","url":"https://api.github.com/users/ericboucher","html_url":"https://github.com/ericboucher","followers_url":"https://api.github.com/users/ericboucher/followers","following_url":"https://api.github.com/users/ericboucher/following{/other_user}","gists_url":"https://api.github.com/users/ericboucher/gists{/gist_id}","starred_url":"https://api.github.com/users/ericboucher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ericboucher/subscriptions","organizations_url":"https://api.github.com/users/ericboucher/orgs","repos_url":"https://api.github.com/users/ericboucher/repos","events_url":"https://api.github.com/users/ericboucher/events{/privacy}","received_events_url":"https://api.github.com/users/ericboucher/received_events","type":"User","site_admin":false},"body":null,"created_at":"2018-03-02T23:17:29Z","updated_at":"2018-03-05T17:50:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3f410f5c2ad4ac75357dbf8033a5853ad9eda57d","assignee":{"login":"tetraptych","id":19229500,"avatar_url":"https://avatars1.githubusercontent.com/u/19229500?v=4","gravatar_id":"","url":"https://api.github.com/users/tetraptych","html_url":"https://github.com/tetraptych","followers_url":"https://api.github.com/users/tetraptych/followers","following_url":"https://api.github.com/users/tetraptych/following{/other_user}","gists_url":"https://api.github.com/users/tetraptych/gists{/gist_id}","starred_url":"https://api.github.com/users/tetraptych/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tetraptych/subscriptions","organizations_url":"https://api.github.com/users/tetraptych/orgs","repos_url":"https://api.github.com/users/tetraptych/repos","events_url":"https://api.github.com/users/tetraptych/events{/privacy}","received_events_url":"https://api.github.com/users/tetraptych/received_events","type":"User","site_admin":false},"assignees":[{"login":"philipdickinson","id":970955,"avatar_url":"https://avatars0.githubusercontent.com/u/970955?v=4","gravatar_id":"","url":"https://api.github.com/users/philipdickinson","html_url":"https://github.com/philipdickinson","followers_url":"https://api.github.com/users/philipdickinson/followers","following_url":"https://api.github.com/users/philipdickinson/following{/other_user}","gists_url":"https://api.github.com/users/philipdickinson/gists{/gist_id}","starred_url":"https://api.github.com/users/philipdickinson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/philipdickinson/subscriptions","organizations_url":"https://api.github.com/users/philipdickinson/orgs","repos_url":"https://api.github.com/users/philipdickinson/repos","events_url":"https://api.github.com/users/philipdickinson/events{/privacy}","received_events_url":"https://api.github.com/users/philipdickinson/received_events","type":"User","site_admin":false},{"login":"tetraptych","id":19229500,"avatar_url":"https://avatars1.githubusercontent.com/u/19229500?v=4","gravatar_id":"","url":"https://api.github.com/users/tetraptych","html_url":"https://github.com/tetraptych","followers_url":"https://api.github.com/users/tetraptych/followers","following_url":"https://api.github.com/users/tetraptych/following{/other_user}","gists_url":"https://api.github.com/users/tetraptych/gists{/gist_id}","starred_url":"https://api.github.com/users/tetraptych/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tetraptych/subscriptions","organizations_url":"https://api.github.com/users/tetraptych/orgs","repos_url":"https://api.github.com/users/tetraptych/repos","events_url":"https://api.github.com/users/tetraptych/events{/privacy}","received_events_url":"https://api.github.com/users/tetraptych/received_events","type":"User","site_admin":false}],"requested_reviewers":[{"login":"philipdickinson","id":970955,"avatar_url":"https://avatars0.githubusercontent.com/u/970955?v=4","gravatar_id":"","url":"https://api.github.com/users/philipdickinson","html_url":"https://github.com/philipdickinson","followers_url":"https://api.github.com/users/philipdickinson/followers","following_url":"https://api.github.com/users/philipdickinson/following{/other_user}","gists_url":"https://api.github.com/users/philipdickinson/gists{/gist_id}","starred_url":"https://api.github.com/users/philipdickinson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/philipdickinson/subscriptions","organizations_url":"https://api.github.com/users/philipdickinson/orgs","repos_url":"https://api.github.com/users/philipdickinson/repos","events_url":"https://api.github.com/users/philipdickinson/events{/privacy}","received_events_url":"https://api.github.com/users/philipdickinson/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[{"id":793096926,"url":"https://api.github.com/repos/bayesimpact/encompass/labels/in%20progress","name":"in progress","color":"ededed","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/bayesimpact/encompass/pulls/478/commits","review_comments_url":"https://api.github.com/repos/bayesimpact/encompass/pulls/478/comments","review_comment_url":"https://api.github.com/repos/bayesimpact/encompass/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bayesimpact/encompass/issues/478/comments","statuses_url":"https://api.github.com/repos/bayesimpact/encompass/statuses/54fdac46a4b32b3285b387a9181fce3d0f5269b3","head":{"label":"bayesimpact:eric.p.boucher-add-ors","ref":"eric.p.boucher-add-ors","sha":"54fdac46a4b32b3285b387a9181fce3d0f5269b3","user":{"login":"bayesimpact","id":7692453,"avatar_url":"https://avatars1.githubusercontent.com/u/7692453?v=4","gravatar_id":"","url":"https://api.github.com/users/bayesimpact","html_url":"https://github.com/bayesimpact","followers_url":"https://api.github.com/users/bayesimpact/followers","following_url":"https://api.github.com/users/bayesimpact/following{/other_user}","gists_url":"https://api.github.com/users/bayesimpact/gists{/gist_id}","starred_url":"https://api.github.com/users/bayesimpact/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bayesimpact/subscriptions","organizations_url":"https://api.github.com/users/bayesimpact/orgs","repos_url":"https://api.github.com/users/bayesimpact/repos","events_url":"https://api.github.com/users/bayesimpact/events{/privacy}","received_events_url":"https://api.github.com/users/bayesimpact/received_events","type":"Organization","site_admin":false},"repo":{"id":108600344,"name":"encompass","full_name":"bayesimpact/encompass","owner":{"login":"bayesimpact","id":7692453,"avatar_url":"https://avatars1.githubusercontent.com/u/7692453?v=4","gravatar_id":"","url":"https://api.github.com/users/bayesimpact","html_url":"https://github.com/bayesimpact","followers_url":"https://api.github.com/users/bayesimpact/followers","following_url":"https://api.github.com/users/bayesimpact/following{/other_user}","gists_url":"https://api.github.com/users/bayesimpact/gists{/gist_id}","starred_url":"https://api.github.com/users/bayesimpact/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bayesimpact/subscriptions","organizations_url":"https://api.github.com/users/bayesimpact/orgs","repos_url":"https://api.github.com/users/bayesimpact/repos","events_url":"https://api.github.com/users/bayesimpact/events{/privacy}","received_events_url":"https://api.github.com/users/bayesimpact/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bayesimpact/encompass","description":"Bayes Impact Encompass Tool for Time & Distance Standards Calculations","fork":false,"url":"https://api.github.com/repos/bayesimpact/encompass","forks_url":"https://api.github.com/repos/bayesimpact/encompass/forks","keys_url":"https://api.github.com/repos/bayesimpact/encompass/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bayesimpact/encompass/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bayesimpact/encompass/teams","hooks_url":"https://api.github.com/repos/bayesimpact/encompass/hooks","issue_events_url":"https://api.github.com/repos/bayesimpact/encompass/issues/events{/number}","events_url":"https://api.github.com/repos/bayesimpact/encompass/events","assignees_url":"https://api.github.com/repos/bayesimpact/encompass/assignees{/user}","branches_url":"https://api.github.com/repos/bayesimpact/encompass/branches{/branch}","tags_url":"https://api.github.com/repos/bayesimpact/encompass/tags","blobs_url":"https://api.github.com/repos/bayesimpact/encompass/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bayesimpact/encompass/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bayesimpact/encompass/git/refs{/sha}","trees_url":"https://api.github.com/repos/bayesimpact/encompass/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bayesimpact/encompass/statuses/{sha}","languages_url":"https://api.github.com/repos/bayesimpact/encompass/languages","stargazers_url":"https://api.github.com/repos/bayesimpact/encompass/stargazers","contributors_url":"https://api.github.com/repos/bayesimpact/encompass/contributors","subscribers_url":"https://api.github.com/repos/bayesimpact/encompass/subscribers","subscription_url":"https://api.github.com/repos/bayesimpact/encompass/subscription","commits_url":"https://api.github.com/repos/bayesimpact/encompass/commits{/sha}","git_commits_url":"https://api.github.com/repos/bayesimpact/encompass/git/commits{/sha}","comments_url":"https://api.github.com/repos/bayesimpact/encompass/comments{/number}","issue_comment_url":"https://api.github.com/repos/bayesimpact/encompass/issues/comments{/number}","contents_url":"https://api.github.com/repos/bayesimpact/encompass/contents/{+path}","compare_url":"https://api.github.com/repos/bayesimpact/encompass/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bayesimpact/encompass/merges","archive_url":"https://api.github.com/repos/bayesimpact/encompass/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bayesimpact/encompass/downloads","issues_url":"https://api.github.com/repos/bayesimpact/encompass/issues{/number}","pulls_url":"https://api.github.com/repos/bayesimpact/encompass/pulls{/number}","milestones_url":"https://api.github.com/repos/bayesimpact/encompass/milestones{/number}","notifications_url":"https://api.github.com/repos/bayesimpact/encompass/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bayesimpact/encompass/labels{/name}","releases_url":"https://api.github.com/repos/bayesimpact/encompass/releases{/id}","deployments_url":"https://api.github.com/repos/bayesimpact/encompass/deployments","created_at":"2017-10-27T22:11:13Z","updated_at":"2018-03-05T08:22:28Z","pushed_at":"2018-03-04T19:31:50Z","git_url":"git://github.com/bayesimpact/encompass.git","ssh_url":"git@github.com:bayesimpact/encompass.git","clone_url":"https://github.com/bayesimpact/encompass.git","svn_url":"https://github.com/bayesimpact/encompass","homepage":"","size":74277,"stargazers_count":6,"watchers_count":6,"language":"Jupyter Notebook","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":70,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":1,"open_issues":70,"watchers":6,"default_branch":"master"}},"base":{"label":"bayesimpact:master","ref":"master","sha":"5d9f83b4a1cbc93484d8727618b3cff0badf1719","user":{"login":"bayesimpact","id":7692453,"avatar_url":"https://avatars1.githubusercontent.com/u/7692453?v=4","gravatar_id":"","url":"https://api.github.com/users/bayesimpact","html_url":"https://github.com/bayesimpact","followers_url":"https://api.github.com/users/bayesimpact/followers","following_url":"https://api.github.com/users/bayesimpact/following{/other_user}","gists_url":"https://api.github.com/users/bayesimpact/gists{/gist_id}","starred_url":"https://api.github.com/users/bayesimpact/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bayesimpact/subscriptions","organizations_url":"https://api.github.com/users/bayesimpact/orgs","repos_url":"https://api.github.com/users/bayesimpact/repos","events_url":"https://api.github.com/users/bayesimpact/events{/privacy}","received_events_url":"https://api.github.com/users/bayesimpact/received_events","type":"Organization","site_admin":false},"repo":{"id":108600344,"name":"encompass","full_name":"bayesimpact/encompass","owner":{"login":"bayesimpact","id":7692453,"avatar_url":"https://avatars1.githubusercontent.com/u/7692453?v=4","gravatar_id":"","url":"https://api.github.com/users/bayesimpact","html_url":"https://github.com/bayesimpact","followers_url":"https://api.github.com/users/bayesimpact/followers","following_url":"https://api.github.com/users/bayesimpact/following{/other_user}","gists_url":"https://api.github.com/users/bayesimpact/gists{/gist_id}","starred_url":"https://api.github.com/users/bayesimpact/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bayesimpact/subscriptions","organizations_url":"https://api.github.com/users/bayesimpact/orgs","repos_url":"https://api.github.com/users/bayesimpact/repos","events_url":"https://api.github.com/users/bayesimpact/events{/privacy}","received_events_url":"https://api.github.com/users/bayesimpact/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bayesimpact/encompass","description":"Bayes Impact Encompass Tool for Time & Distance Standards Calculations","fork":false,"url":"https://api.github.com/repos/bayesimpact/encompass","forks_url":"https://api.github.com/repos/bayesimpact/encompass/forks","keys_url":"https://api.github.com/repos/bayesimpact/encompass/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bayesimpact/encompass/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bayesimpact/encompass/teams","hooks_url":"https://api.github.com/repos/bayesimpact/encompass/hooks","issue_events_url":"https://api.github.com/repos/bayesimpact/encompass/issues/events{/number}","events_url":"https://api.github.com/repos/bayesimpact/encompass/events","assignees_url":"https://api.github.com/repos/bayesimpact/encompass/assignees{/user}","branches_url":"https://api.github.com/repos/bayesimpact/encompass/branches{/branch}","tags_url":"https://api.github.com/repos/bayesimpact/encompass/tags","blobs_url":"https://api.github.com/repos/bayesimpact/encompass/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bayesimpact/encompass/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bayesimpact/encompass/git/refs{/sha}","trees_url":"https://api.github.com/repos/bayesimpact/encompass/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bayesimpact/encompass/statuses/{sha}","languages_url":"https://api.github.com/repos/bayesimpact/encompass/languages","stargazers_url":"https://api.github.com/repos/bayesimpact/encompass/stargazers","contributors_url":"https://api.github.com/repos/bayesimpact/encompass/contributors","subscribers_url":"https://api.github.com/repos/bayesimpact/encompass/subscribers","subscription_url":"https://api.github.com/repos/bayesimpact/encompass/subscription","commits_url":"https://api.github.com/repos/bayesimpact/encompass/commits{/sha}","git_commits_url":"https://api.github.com/repos/bayesimpact/encompass/git/commits{/sha}","comments_url":"https://api.github.com/repos/bayesimpact/encompass/comments{/number}","issue_comment_url":"https://api.github.com/repos/bayesimpact/encompass/issues/comments{/number}","contents_url":"https://api.github.com/repos/bayesimpact/encompass/contents/{+path}","compare_url":"https://api.github.com/repos/bayesimpact/encompass/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bayesimpact/encompass/merges","archive_url":"https://api.github.com/repos/bayesimpact/encompass/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bayesimpact/encompass/downloads","issues_url":"https://api.github.com/repos/bayesimpact/encompass/issues{/number}","pulls_url":"https://api.github.com/repos/bayesimpact/encompass/pulls{/number}","milestones_url":"https://api.github.com/repos/bayesimpact/encompass/milestones{/number}","notifications_url":"https://api.github.com/repos/bayesimpact/encompass/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bayesimpact/encompass/labels{/name}","releases_url":"https://api.github.com/repos/bayesimpact/encompass/releases{/id}","deployments_url":"https://api.github.com/repos/bayesimpact/encompass/deployments","created_at":"2017-10-27T22:11:13Z","updated_at":"2018-03-05T08:22:28Z","pushed_at":"2018-03-04T19:31:50Z","git_url":"git://github.com/bayesimpact/encompass.git","ssh_url":"git@github.com:bayesimpact/encompass.git","clone_url":"https://github.com/bayesimpact/encompass.git","svn_url":"https://github.com/bayesimpact/encompass","homepage":"","size":74277,"stargazers_count":6,"watchers_count":6,"language":"Jupyter Notebook","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":70,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":1,"open_issues":70,"watchers":6,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bayesimpact/encompass/pulls/478"},"html":{"href":"https://github.com/bayesimpact/encompass/pull/478"},"issue":{"href":"https://api.github.com/repos/bayesimpact/encompass/issues/478"},"comments":{"href":"https://api.github.com/repos/bayesimpact/encompass/issues/478/comments"},"review_comments":{"href":"https://api.github.com/repos/bayesimpact/encompass/pulls/478/comments"},"review_comment":{"href":"https://api.github.com/repos/bayesimpact/encompass/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bayesimpact/encompass/pulls/478/commits"},"statuses":{"href":"https://api.github.com/repos/bayesimpact/encompass/statuses/54fdac46a4b32b3285b387a9181fce3d0f5269b3"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"tetraptych"}}