{"action":"created","comment":{"url":"https://api.github.com/repos/mapsme/omim/pulls/comments/192696265","pull_request_review_id":125518273,"id":192696265,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5MjY5NjI2NQ==","diff_hunk":"@@ -0,0 +1,164 @@\n+#include \"map/extrapolation/extrapolator.hpp\"\n+\n+#include \"geometry/distance_on_sphere.hpp\"\n+\n+#include \"platform/platform.hpp\"\n+\n+#include \"base/logging.hpp\"\n+\n+#include <chrono>\n+#include <memory>\n+\n+namespace\n+{\n+uint64_t constexpr kMaxExtrapolationTimeMs = 1000;\n+uint64_t constexpr kExtrapolationPeriodMs = 200;\n+double constexpr kMaxExtrapolationSpeedMPS = 120.0;\n+\n+class LinearExtrapolator\n+{\n+public:\n+  LinearExtrapolator(uint64_t timeBetweenMs, uint64_t timeAfterMs)\n+    : m_timeBetweenMs(timeBetweenMs), m_timeAfterMs(timeAfterMs)\n+  {\n+    CHECK_NOT_EQUAL(m_timeBetweenMs, 0, ());\n+  }\n+\n+  double Extrapolate(double x1, double x2)\n+  {\n+    return x2 + ((x2 - x1) / m_timeBetweenMs) * m_timeAfterMs;\n+  }\n+\n+private:\n+  uint64_t m_timeBetweenMs;\n+  uint64_t m_timeAfterMs;\n+};\n+}  // namespace\n+\n+namespace extrapolation\n+{\n+using namespace std;\n+\n+location::GpsInfo LinearExtrapolation(location::GpsInfo const & gpsInfo1,\n+                                      location::GpsInfo const & gpsInfo2,\n+                                      uint64_t timeAfterPoint2Ms)\n+{\n+  CHECK_LESS(gpsInfo1.m_timestamp, gpsInfo2.m_timestamp, ());\n+  auto const timeBetweenPointsMs =\n+      static_cast<uint64_t>((gpsInfo2.m_timestamp - gpsInfo1.m_timestamp) * 1000);\n+\n+  location::GpsInfo result = gpsInfo2;\n+  LinearExtrapolator e(timeBetweenPointsMs, timeAfterPoint2Ms);\n+\n+  result.m_timestamp += timeAfterPoint2Ms;\n+  result.m_longitude = e.Extrapolate(gpsInfo1.m_longitude, gpsInfo2.m_longitude);\n+  result.m_latitude = e.Extrapolate(gpsInfo1.m_latitude, gpsInfo2.m_latitude);\n+  result.m_horizontalAccuracy = e.Extrapolate(gpsInfo1.m_horizontalAccuracy, gpsInfo2.m_horizontalAccuracy);\n+  result.m_altitude = e.Extrapolate(gpsInfo1.m_altitude, gpsInfo2.m_altitude);\n+\n+  if (gpsInfo1.HasVerticalAccuracy() && gpsInfo2.HasVerticalAccuracy())\n+    result.m_verticalAccuracy = e.Extrapolate(gpsInfo1.m_verticalAccuracy, gpsInfo2.m_verticalAccuracy);\n+\n+  // @TODO(bykoianko) Now |result.m_bearing == gpsInfo2.m_bearing|.\n+  // In case of |gpsInfo1.HasBearing() && gpsInfo2.HasBearing() == true|\n+  // consider finding an average value between |gpsInfo1.m_bearing| and |gpsInfo2.m_bearing|\n+  // taking into account that they are periodic. It's important to implement it\n+  // because current implementation leads to changing course by steps. It doesn't\n+  // look nice when the road changes its direction.\n+\n+  if (gpsInfo1.HasSpeed() && gpsInfo2.HasSpeed())\n+    result.m_speed = e.Extrapolate(gpsInfo1.m_speed, gpsInfo2.m_speed);\n+\n+  return result;\n+}\n+\n+// Extrapolator ------------------------------------------------------------------------------------\n+Extrapolator::Extrapolator(ExtrapolatedLocationUpdateFn const & update)\n+  : m_isEnabled(false), m_extrapolatedLocationUpdate(update)\n+{\n+  GetPlatform().RunTask(Platform::Thread::Background, [this]\n+  {\n+    ExtrapolatedLocationUpdate();\n+  });\n+}\n+\n+void Extrapolator::OnLocationUpdate(location::GpsInfo const & gpsInfo)\n+{\n+  // @TODO Consider calling ExtrapolatedLocationUpdate() on background thread immediately\n+  // after OnLocationUpdate() was called.\n+  lock_guard<mutex> guard(m_mutex);\n+  m_beforeLastGpsInfo = m_lastGpsInfo;\n+  m_lastGpsInfo = gpsInfo;\n+  m_extrapolationCounter = 0;\n+}\n+\n+void Extrapolator::Enable(bool enabled)\n+{\n+  lock_guard<mutex> guard(m_mutex);\n+  m_isEnabled = enabled;\n+}\n+\n+void Extrapolator::ExtrapolatedLocationUpdate()\n+{\n+  location::GpsInfo gpsInfo;\n+  do\n+  {\n+    lock_guard<mutex> guard(m_mutex);\n+    uint64_t const extrapolationTimeMs = kExtrapolationPeriodMs * m_extrapolationCounter;\n+    if (extrapolationTimeMs >= kMaxExtrapolationTimeMs || !m_lastGpsInfo.IsValid())\n+      break;\n+\n+    if (DoesExtrapolationWork(extrapolationTimeMs))\n+    {\n+      gpsInfo = LinearExtrapolation(m_beforeLastGpsInfo, m_lastGpsInfo, extrapolationTimeMs);\n+      break;\n+    }\n+\n+    if (m_lastGpsInfo.IsValid())\n+      gpsInfo = m_lastGpsInfo;","path":"map/extrapolation/extrapolator.cpp","position":139,"original_position":118,"commit_id":"1b79a63bdb79feae4c918372ae078ce149ea463f","original_commit_id":"93022012bbb6971431861c7a4953592430432bcb","user":{"login":"bykoianko","id":1768114,"node_id":"MDQ6VXNlcjE3NjgxMTQ=","avatar_url":"https://avatars0.githubusercontent.com/u/1768114?v=4","gravatar_id":"","url":"https://api.github.com/users/bykoianko","html_url":"https://github.com/bykoianko","followers_url":"https://api.github.com/users/bykoianko/followers","following_url":"https://api.github.com/users/bykoianko/following{/other_user}","gists_url":"https://api.github.com/users/bykoianko/gists{/gist_id}","starred_url":"https://api.github.com/users/bykoianko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bykoianko/subscriptions","organizations_url":"https://api.github.com/users/bykoianko/orgs","repos_url":"https://api.github.com/users/bykoianko/repos","events_url":"https://api.github.com/users/bykoianko/events{/privacy}","received_events_url":"https://api.github.com/users/bykoianko/received_events","type":"User","site_admin":false},"body":"Да. Давай так сделаем.","created_at":"2018-06-04T10:34:20Z","updated_at":"2018-06-04T10:34:21Z","html_url":"https://github.com/mapsme/omim/pull/8624#discussion_r192696265","pull_request_url":"https://api.github.com/repos/mapsme/omim/pulls/8624","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/mapsme/omim/pulls/comments/192696265"},"html":{"href":"https://github.com/mapsme/omim/pull/8624#discussion_r192696265"},"pull_request":{"href":"https://api.github.com/repos/mapsme/omim/pulls/8624"}},"in_reply_to_id":190616796},"pull_request":{"url":"https://api.github.com/repos/mapsme/omim/pulls/8624","id":185900411,"node_id":"MDExOlB1bGxSZXF1ZXN0MTg1OTAwNDEx","html_url":"https://github.com/mapsme/omim/pull/8624","diff_url":"https://github.com/mapsme/omim/pull/8624.diff","patch_url":"https://github.com/mapsme/omim/pull/8624.patch","issue_url":"https://api.github.com/repos/mapsme/omim/issues/8624","number":8624,"state":"open","locked":false,"title":"[DNM] Linear extrapolation of GPS position.","user":{"login":"bykoianko","id":1768114,"node_id":"MDQ6VXNlcjE3NjgxMTQ=","avatar_url":"https://avatars0.githubusercontent.com/u/1768114?v=4","gravatar_id":"","url":"https://api.github.com/users/bykoianko","html_url":"https://github.com/bykoianko","followers_url":"https://api.github.com/users/bykoianko/followers","following_url":"https://api.github.com/users/bykoianko/following{/other_user}","gists_url":"https://api.github.com/users/bykoianko/gists{/gist_id}","starred_url":"https://api.github.com/users/bykoianko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bykoianko/subscriptions","organizations_url":"https://api.github.com/users/bykoianko/orgs","repos_url":"https://api.github.com/users/bykoianko/repos","events_url":"https://api.github.com/users/bykoianko/events{/privacy}","received_events_url":"https://api.github.com/users/bykoianko/received_events","type":"User","site_admin":false},"body":"Экстраполятор gps позиции.\r\n\r\nЭта версия не плохо работает в поле на android и iOS. Сейчас тестируется на расход аккумулятора: https://jira.mail.ru/browse/MAPSME-7500\r\n\r\nДо ее мержа в мастер я хочу:\r\n- сделать одно из todo указанных в PR:\r\n// @TODO(bykoinako) Method m_extrapolatedLocationUpdate() is run on gui thread every\r\n// |kExtrapolationPeriodMs| milliseconds. But after changing GPS position\r\n// (that means after a call of method Routine::SetGpsInfo())\r\n// m_extrapolatedLocationUpdate() should be run immediately on gui thread.\r\n\r\n- написать юнит тесты на Extrapolator\r\n- сделать, что экстраполятор включался только в режиме авто навигации\r\n\r\n@rokuz @mpimenov PTAL","created_at":"2018-05-04T06:22:00Z","updated_at":"2018-06-04T10:34:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fa4ae8639e83b19ba0bd37091184a7db71f794b6","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/mapsme/omim/pulls/8624/commits","review_comments_url":"https://api.github.com/repos/mapsme/omim/pulls/8624/comments","review_comment_url":"https://api.github.com/repos/mapsme/omim/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mapsme/omim/issues/8624/comments","statuses_url":"https://api.github.com/repos/mapsme/omim/statuses/1b79a63bdb79feae4c918372ae078ce149ea463f","head":{"label":"mapsme:master-extrapolator","ref":"master-extrapolator","sha":"1b79a63bdb79feae4c918372ae078ce149ea463f","user":{"login":"mapsme","id":14185141,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE0MTg1MTQx","avatar_url":"https://avatars1.githubusercontent.com/u/14185141?v=4","gravatar_id":"","url":"https://api.github.com/users/mapsme","html_url":"https://github.com/mapsme","followers_url":"https://api.github.com/users/mapsme/followers","following_url":"https://api.github.com/users/mapsme/following{/other_user}","gists_url":"https://api.github.com/users/mapsme/gists{/gist_id}","starred_url":"https://api.github.com/users/mapsme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapsme/subscriptions","organizations_url":"https://api.github.com/users/mapsme/orgs","repos_url":"https://api.github.com/users/mapsme/repos","events_url":"https://api.github.com/users/mapsme/events{/privacy}","received_events_url":"https://api.github.com/users/mapsme/received_events","type":"Organization","site_admin":false},"repo":{"id":42798033,"node_id":"MDEwOlJlcG9zaXRvcnk0Mjc5ODAzMw==","name":"omim","full_name":"mapsme/omim","owner":{"login":"mapsme","id":14185141,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE0MTg1MTQx","avatar_url":"https://avatars1.githubusercontent.com/u/14185141?v=4","gravatar_id":"","url":"https://api.github.com/users/mapsme","html_url":"https://github.com/mapsme","followers_url":"https://api.github.com/users/mapsme/followers","following_url":"https://api.github.com/users/mapsme/following{/other_user}","gists_url":"https://api.github.com/users/mapsme/gists{/gist_id}","starred_url":"https://api.github.com/users/mapsme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapsme/subscriptions","organizations_url":"https://api.github.com/users/mapsme/orgs","repos_url":"https://api.github.com/users/mapsme/repos","events_url":"https://api.github.com/users/mapsme/events{/privacy}","received_events_url":"https://api.github.com/users/mapsme/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mapsme/omim","description":"🗺️ MAPS.ME — Offline OpenStreetMap maps for iOS and Android","fork":false,"url":"https://api.github.com/repos/mapsme/omim","forks_url":"https://api.github.com/repos/mapsme/omim/forks","keys_url":"https://api.github.com/repos/mapsme/omim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mapsme/omim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mapsme/omim/teams","hooks_url":"https://api.github.com/repos/mapsme/omim/hooks","issue_events_url":"https://api.github.com/repos/mapsme/omim/issues/events{/number}","events_url":"https://api.github.com/repos/mapsme/omim/events","assignees_url":"https://api.github.com/repos/mapsme/omim/assignees{/user}","branches_url":"https://api.github.com/repos/mapsme/omim/branches{/branch}","tags_url":"https://api.github.com/repos/mapsme/omim/tags","blobs_url":"https://api.github.com/repos/mapsme/omim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mapsme/omim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mapsme/omim/git/refs{/sha}","trees_url":"https://api.github.com/repos/mapsme/omim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mapsme/omim/statuses/{sha}","languages_url":"https://api.github.com/repos/mapsme/omim/languages","stargazers_url":"https://api.github.com/repos/mapsme/omim/stargazers","contributors_url":"https://api.github.com/repos/mapsme/omim/contributors","subscribers_url":"https://api.github.com/repos/mapsme/omim/subscribers","subscription_url":"https://api.github.com/repos/mapsme/omim/subscription","commits_url":"https://api.github.com/repos/mapsme/omim/commits{/sha}","git_commits_url":"https://api.github.com/repos/mapsme/omim/git/commits{/sha}","comments_url":"https://api.github.com/repos/mapsme/omim/comments{/number}","issue_comment_url":"https://api.github.com/repos/mapsme/omim/issues/comments{/number}","contents_url":"https://api.github.com/repos/mapsme/omim/contents/{+path}","compare_url":"https://api.github.com/repos/mapsme/omim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mapsme/omim/merges","archive_url":"https://api.github.com/repos/mapsme/omim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mapsme/omim/downloads","issues_url":"https://api.github.com/repos/mapsme/omim/issues{/number}","pulls_url":"https://api.github.com/repos/mapsme/omim/pulls{/number}","milestones_url":"https://api.github.com/repos/mapsme/omim/milestones{/number}","notifications_url":"https://api.github.com/repos/mapsme/omim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mapsme/omim/labels{/name}","releases_url":"https://api.github.com/repos/mapsme/omim/releases{/id}","deployments_url":"https://api.github.com/repos/mapsme/omim/deployments","created_at":"2015-09-20T02:57:13Z","updated_at":"2018-06-04T10:09:19Z","pushed_at":"2018-06-04T10:10:23Z","git_url":"git://github.com/mapsme/omim.git","ssh_url":"git@github.com:mapsme/omim.git","clone_url":"https://github.com/mapsme/omim.git","svn_url":"https://github.com/mapsme/omim","homepage":"","size":3918508,"stargazers_count":2682,"watchers_count":2682,"language":"C++","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":578,"mirror_url":null,"archived":false,"open_issues_count":703,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":578,"open_issues":703,"watchers":2682,"default_branch":"master"}},"base":{"label":"mapsme:master","ref":"master","sha":"6deb56fbfcd3ef435475269878c28d5f0cac1937","user":{"login":"mapsme","id":14185141,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE0MTg1MTQx","avatar_url":"https://avatars1.githubusercontent.com/u/14185141?v=4","gravatar_id":"","url":"https://api.github.com/users/mapsme","html_url":"https://github.com/mapsme","followers_url":"https://api.github.com/users/mapsme/followers","following_url":"https://api.github.com/users/mapsme/following{/other_user}","gists_url":"https://api.github.com/users/mapsme/gists{/gist_id}","starred_url":"https://api.github.com/users/mapsme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapsme/subscriptions","organizations_url":"https://api.github.com/users/mapsme/orgs","repos_url":"https://api.github.com/users/mapsme/repos","events_url":"https://api.github.com/users/mapsme/events{/privacy}","received_events_url":"https://api.github.com/users/mapsme/received_events","type":"Organization","site_admin":false},"repo":{"id":42798033,"node_id":"MDEwOlJlcG9zaXRvcnk0Mjc5ODAzMw==","name":"omim","full_name":"mapsme/omim","owner":{"login":"mapsme","id":14185141,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE0MTg1MTQx","avatar_url":"https://avatars1.githubusercontent.com/u/14185141?v=4","gravatar_id":"","url":"https://api.github.com/users/mapsme","html_url":"https://github.com/mapsme","followers_url":"https://api.github.com/users/mapsme/followers","following_url":"https://api.github.com/users/mapsme/following{/other_user}","gists_url":"https://api.github.com/users/mapsme/gists{/gist_id}","starred_url":"https://api.github.com/users/mapsme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapsme/subscriptions","organizations_url":"https://api.github.com/users/mapsme/orgs","repos_url":"https://api.github.com/users/mapsme/repos","events_url":"https://api.github.com/users/mapsme/events{/privacy}","received_events_url":"https://api.github.com/users/mapsme/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mapsme/omim","description":"🗺️ MAPS.ME — Offline OpenStreetMap maps for iOS and Android","fork":false,"url":"https://api.github.com/repos/mapsme/omim","forks_url":"https://api.github.com/repos/mapsme/omim/forks","keys_url":"https://api.github.com/repos/mapsme/omim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mapsme/omim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mapsme/omim/teams","hooks_url":"https://api.github.com/repos/mapsme/omim/hooks","issue_events_url":"https://api.github.com/repos/mapsme/omim/issues/events{/number}","events_url":"https://api.github.com/repos/mapsme/omim/events","assignees_url":"https://api.github.com/repos/mapsme/omim/assignees{/user}","branches_url":"https://api.github.com/repos/mapsme/omim/branches{/branch}","tags_url":"https://api.github.com/repos/mapsme/omim/tags","blobs_url":"https://api.github.com/repos/mapsme/omim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mapsme/omim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mapsme/omim/git/refs{/sha}","trees_url":"https://api.github.com/repos/mapsme/omim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mapsme/omim/statuses/{sha}","languages_url":"https://api.github.com/repos/mapsme/omim/languages","stargazers_url":"https://api.github.com/repos/mapsme/omim/stargazers","contributors_url":"https://api.github.com/repos/mapsme/omim/contributors","subscribers_url":"https://api.github.com/repos/mapsme/omim/subscribers","subscription_url":"https://api.github.com/repos/mapsme/omim/subscription","commits_url":"https://api.github.com/repos/mapsme/omim/commits{/sha}","git_commits_url":"https://api.github.com/repos/mapsme/omim/git/commits{/sha}","comments_url":"https://api.github.com/repos/mapsme/omim/comments{/number}","issue_comment_url":"https://api.github.com/repos/mapsme/omim/issues/comments{/number}","contents_url":"https://api.github.com/repos/mapsme/omim/contents/{+path}","compare_url":"https://api.github.com/repos/mapsme/omim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mapsme/omim/merges","archive_url":"https://api.github.com/repos/mapsme/omim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mapsme/omim/downloads","issues_url":"https://api.github.com/repos/mapsme/omim/issues{/number}","pulls_url":"https://api.github.com/repos/mapsme/omim/pulls{/number}","milestones_url":"https://api.github.com/repos/mapsme/omim/milestones{/number}","notifications_url":"https://api.github.com/repos/mapsme/omim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mapsme/omim/labels{/name}","releases_url":"https://api.github.com/repos/mapsme/omim/releases{/id}","deployments_url":"https://api.github.com/repos/mapsme/omim/deployments","created_at":"2015-09-20T02:57:13Z","updated_at":"2018-06-04T10:09:19Z","pushed_at":"2018-06-04T10:10:23Z","git_url":"git://github.com/mapsme/omim.git","ssh_url":"git@github.com:mapsme/omim.git","clone_url":"https://github.com/mapsme/omim.git","svn_url":"https://github.com/mapsme/omim","homepage":"","size":3918508,"stargazers_count":2682,"watchers_count":2682,"language":"C++","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":578,"mirror_url":null,"archived":false,"open_issues_count":703,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":578,"open_issues":703,"watchers":2682,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mapsme/omim/pulls/8624"},"html":{"href":"https://github.com/mapsme/omim/pull/8624"},"issue":{"href":"https://api.github.com/repos/mapsme/omim/issues/8624"},"comments":{"href":"https://api.github.com/repos/mapsme/omim/issues/8624/comments"},"review_comments":{"href":"https://api.github.com/repos/mapsme/omim/pulls/8624/comments"},"review_comment":{"href":"https://api.github.com/repos/mapsme/omim/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mapsme/omim/pulls/8624/commits"},"statuses":{"href":"https://api.github.com/repos/mapsme/omim/statuses/1b79a63bdb79feae4c918372ae078ce149ea463f"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"bykoianko"}}