From b415753017fb208eea396e1b2c274fd385d0c147 Mon Sep 17 00:00:00 2001 From: Arsentiy Milchakov Date: Tue, 30 Oct 2018 18:16:40 +0300 Subject: [PATCH] [eye] save mercator pos instead of latlon --- coding/serdes_json.hpp | 17 ++++++++ metrics/eye.cpp | 42 +++++++++---------- metrics/eye.hpp | 22 +++++----- metrics/eye_info.hpp | 7 ++-- metrics/eye_serdes.cpp | 4 +- metrics/metrics_tests/eye_tests.cpp | 28 ++++++------- .../metrics_tests_support/eye_for_testing.cpp | 2 +- .../metrics_tests_support/eye_for_testing.hpp | 2 +- 8 files changed, 71 insertions(+), 53 deletions(-) diff --git a/coding/serdes_json.hpp b/coding/serdes_json.hpp index 65e4565027..4541bfb2ee 100644 --- a/coding/serdes_json.hpp +++ b/coding/serdes_json.hpp @@ -1,6 +1,7 @@ #pragma once #include "geometry/latlon.hpp" +#include "geometry/point2d.hpp" #include "base/exception.hpp" #include "base/scope_guard.hpp" @@ -133,6 +134,14 @@ public: (*this)(static_cast>(t), name); } + void operator()(m2::PointD const & p, char const * name = nullptr) + { + NewScopeWith(base::NewJSONObject(), name, [this, &p] { + (*this)(p.x, "x"); + (*this)(p.y, "y"); + }); + } + void operator()(ms::LatLon const & ll, char const * name = nullptr) { NewScopeWith(base::NewJSONObject(), name, [this, &ll] { @@ -325,6 +334,14 @@ public: t = static_cast(res); } + void operator()(m2::PointD & p, char const * name = nullptr) + { + json_t * outerContext = SaveContext(name); + (*this)(p.x, "x"); + (*this)(p.y, "y"); + RestoreContext(outerContext); + } + void operator()(ms::LatLon & ll, char const * name = nullptr) { json_t * outerContext = SaveContext(name); diff --git a/metrics/eye.cpp b/metrics/eye.cpp index 942a4bf5e7..5d0e3c6fa2 100644 --- a/metrics/eye.cpp +++ b/metrics/eye.cpp @@ -307,7 +307,7 @@ void Eye::RegisterLayerShown(Layer::Type type) } void Eye::RegisterMapObjectEvent(MapObject const & mapObject, MapObject::Event::Type type, - ms::LatLon const & userPos) + m2::PointD const & userPos) { auto const info = m_info.Get(); auto editableInfo = std::make_shared(*info); @@ -400,55 +400,55 @@ void Eye::Event::LayerShown(Layer::Type type) } // static -void Eye::Event::PlacePageOpened(std::string const & bestType, ms::LatLon const & latLon, - ms::LatLon const & userPos) +void Eye::Event::PlacePageOpened(std::string const & bestType, m2::PointD const & pos, + m2::PointD const & userPos) { - GetPlatform().RunTask(Platform::Thread::File, [bestType, latLon, userPos] + GetPlatform().RunTask(Platform::Thread::File, [bestType, pos, userPos] { - Instance().RegisterMapObjectEvent({bestType, latLon}, MapObject::Event::Type::Open, userPos); + Instance().RegisterMapObjectEvent({bestType, pos}, MapObject::Event::Type::Open, userPos); }); } // static -void Eye::Event::UgcEditorOpened(std::string const & bestType, ms::LatLon const & latLon, - ms::LatLon const & userPos) +void Eye::Event::UgcEditorOpened(std::string const & bestType, m2::PointD const & pos, + m2::PointD const & userPos) { - GetPlatform().RunTask(Platform::Thread::File, [bestType, latLon, userPos] + GetPlatform().RunTask(Platform::Thread::File, [bestType, pos, userPos] { - Instance().RegisterMapObjectEvent({bestType, latLon}, MapObject::Event::Type::UgcEditorOpened, + Instance().RegisterMapObjectEvent({bestType, pos}, MapObject::Event::Type::UgcEditorOpened, userPos); }); } // static -void Eye::Event::UgcSaved(std::string const & bestType, ms::LatLon const & latLon, - ms::LatLon const & userPos) +void Eye::Event::UgcSaved(std::string const & bestType, m2::PointD const & pos, + m2::PointD const & userPos) { - GetPlatform().RunTask(Platform::Thread::File, [bestType, latLon, userPos] + GetPlatform().RunTask(Platform::Thread::File, [bestType, pos, userPos] { - Instance().RegisterMapObjectEvent({bestType, latLon}, MapObject::Event::Type::UgcSaved, + Instance().RegisterMapObjectEvent({bestType, pos}, MapObject::Event::Type::UgcSaved, userPos); }); } // static -void Eye::Event::AddToBookmarkClicked(std::string const & bestType, ms::LatLon const & latLon, - ms::LatLon const & userPos) +void Eye::Event::AddToBookmarkClicked(std::string const & bestType, m2::PointD const & pos, + m2::PointD const & userPos) { - GetPlatform().RunTask(Platform::Thread::File, [bestType, latLon, userPos] + GetPlatform().RunTask(Platform::Thread::File, [bestType, pos, userPos] { - Instance().RegisterMapObjectEvent({bestType, latLon}, MapObject::Event::Type::AddToBookmark, + Instance().RegisterMapObjectEvent({bestType, pos}, MapObject::Event::Type::AddToBookmark, userPos); }); } // static -void Eye::Event::RouteCreatedToObject(std::string const & bestType, ms::LatLon const & latLon, - ms::LatLon const & userPos) +void Eye::Event::RouteCreatedToObject(std::string const & bestType, m2::PointD const & pos, + m2::PointD const & userPos) { - GetPlatform().RunTask(Platform::Thread::File, [bestType, latLon, userPos] + GetPlatform().RunTask(Platform::Thread::File, [bestType, pos, userPos] { - Instance().RegisterMapObjectEvent({bestType, latLon}, MapObject::Event::Type::RouteToCreated, + Instance().RegisterMapObjectEvent({bestType, pos}, MapObject::Event::Type::RouteToCreated, userPos); }); } diff --git a/metrics/eye.hpp b/metrics/eye.hpp index b603973fa8..03dd2ca3c6 100644 --- a/metrics/eye.hpp +++ b/metrics/eye.hpp @@ -44,16 +44,16 @@ public: static void DiscoveryShown(); static void DiscoveryItemClicked(Discovery::Event event); static void LayerShown(Layer::Type type); - static void PlacePageOpened(std::string const & bestType, ms::LatLon const & latLon, - ms::LatLon const & userPos); - static void UgcEditorOpened(std::string const & bestType, ms::LatLon const & latLon, - ms::LatLon const & userPos); - static void UgcSaved(std::string const & bestType, ms::LatLon const & latLon, - ms::LatLon const & userPos); - static void AddToBookmarkClicked(std::string const & bestType, ms::LatLon const & latLon, - ms::LatLon const & userPos); - static void RouteCreatedToObject(std::string const & bestType, ms::LatLon const & latLon, - ms::LatLon const & userPos); + static void PlacePageOpened(std::string const & bestType, m2::PointD const & pos, + m2::PointD const & userPos); + static void UgcEditorOpened(std::string const & bestType, m2::PointD const & pos, + m2::PointD const & userPos); + static void UgcSaved(std::string const & bestType, m2::PointD const & pos, + m2::PointD const & userPos); + static void AddToBookmarkClicked(std::string const & bestType, m2::PointD const & pos, + m2::PointD const & userPos); + static void RouteCreatedToObject(std::string const & bestType, m2::PointD const & pos, + m2::PointD const & userPos); }; static Eye & Instance(); @@ -78,7 +78,7 @@ private: void IncrementDiscoveryItem(Discovery::Event event); void RegisterLayerShown(Layer::Type type); void RegisterMapObjectEvent(MapObject const & mapObject, MapObject::Event::Type type, - ms::LatLon const & userPos); + m2::PointD const & userPos); base::AtomicSharedPtr m_info; std::vector m_subscribers; diff --git a/metrics/eye_info.hpp b/metrics/eye_info.hpp index 6c5e35d9ec..b2d939bf5d 100644 --- a/metrics/eye_info.hpp +++ b/metrics/eye_info.hpp @@ -2,7 +2,6 @@ #include "storage/index.hpp" -#include "geometry/latlon.hpp" #include "geometry/point2d.hpp" #include "base/visitor.hpp" @@ -178,7 +177,7 @@ struct MapObject visitor(m_eventTime, "event_time")); Type m_type; - ms::LatLon m_userPos; + m2::PointD m_userPos; Time m_eventTime; }; @@ -188,7 +187,7 @@ struct MapObject { size_t operator()(MapObject const & p) const { - return base::Hash(base::Hash(p.m_pos.lat, p.m_pos.lon), + return base::Hash(base::Hash(p.m_pos.x, p.m_pos.y), base::Hash(p.m_bestType, p.m_bestType)); } }; @@ -202,7 +201,7 @@ struct MapObject visitor(m_readableName, "name")); std::string m_bestType; - ms::LatLon m_pos; + m2::PointD m_pos; std::string m_readableName; }; diff --git a/metrics/eye_serdes.cpp b/metrics/eye_serdes.cpp index 3b87c0c38f..80f7e3b6f3 100644 --- a/metrics/eye_serdes.cpp +++ b/metrics/eye_serdes.cpp @@ -5,6 +5,8 @@ #include "coding/write_to_sink.hpp" #include "coding/writer.hpp" +#include "geometry/point2d.hpp" + #include "base/logging.hpp" #include @@ -19,7 +21,7 @@ struct MapObjectEvent visitor(m_event, "event")); std::string m_bestPoiType; - ms::LatLon m_poiPos; + m2::PointD m_poiPos; eye::MapObject::Event m_event; }; } // namespace diff --git a/metrics/metrics_tests/eye_tests.cpp b/metrics/metrics_tests/eye_tests.cpp index 4ef630b244..9731988739 100644 --- a/metrics/metrics_tests/eye_tests.cpp +++ b/metrics/metrics_tests/eye_tests.cpp @@ -458,8 +458,8 @@ UNIT_CLASS_TEST(ScopedEyeForTesting, TrimExpiredMapObjectEvents) TEST(it != mapObjects.end(), ()); TEST_EQUAL(it->second.size(), 3, ()); TEST_EQUAL(it->second[0].m_type, MapObject::Event::Type::Open, ()); - TEST_EQUAL(it->second[1].m_userPos, ms::LatLon(72.045400, 81.408200), ()); - TEST_EQUAL(it->second[2].m_userPos, ms::LatLon(72.045450, 81.408201), ()); + TEST_EQUAL(it->second[1].m_userPos, m2::PointD(72.045400, 81.408200), ()); + TEST_EQUAL(it->second[2].m_userPos, m2::PointD(72.045450, 81.408201), ()); } { @@ -472,8 +472,8 @@ UNIT_CLASS_TEST(ScopedEyeForTesting, TrimExpiredMapObjectEvents) TEST(it != mapObjects.end(), ()); TEST_EQUAL(it->second.size(), 3, ()); TEST_EQUAL(it->second[0].m_type, MapObject::Event::Type::Open, ()); - TEST_EQUAL(it->second[1].m_userPos, ms::LatLon(53.016347, 158.683327), ()); - TEST_EQUAL(it->second[2].m_userPos, ms::LatLon(53.116347, 158.783327), ()); + TEST_EQUAL(it->second[1].m_userPos, m2::PointD(53.016347, 158.683327), ()); + TEST_EQUAL(it->second[2].m_userPos, m2::PointD(53.116347, 158.783327), ()); } } @@ -503,10 +503,10 @@ UNIT_CLASS_TEST(ScopedEyeForTesting, TrimExpiredMapObjectEvents) TEST(it != mapObjects.end(), ()); TEST_EQUAL(it->second.size(), 2, ()); - TEST_EQUAL(it->second[0].m_userPos, ms::LatLon(53.016347, 158.683327), ()); + TEST_EQUAL(it->second[0].m_userPos, m2::PointD(53.016347, 158.683327), ()); TEST_EQUAL(it->second[0].m_type, MapObject::Event::Type::UgcEditorOpened, ()); - TEST_EQUAL(it->second[1].m_userPos, ms::LatLon(53.116347, 158.783327), ()); + TEST_EQUAL(it->second[1].m_userPos, m2::PointD(53.116347, 158.783327), ()); TEST_EQUAL(it->second[1].m_type, MapObject::Event::Type::UgcSaved, ()); } } @@ -518,7 +518,7 @@ UNIT_CLASS_TEST(ScopedEyeForTesting, RegisterMapObjectEvent) MapObject poi; poi.m_bestType = "cafe"; poi.m_pos = {53.652005, 108.143448}; - ms::LatLon userPos = {53.016347, 158.683327}; + m2::PointD userPos = {53.016347, 158.683327}; EyeForTesting::RegisterMapObjectEvent(poi, MapObject::Event::Type::Open, userPos); @@ -530,7 +530,7 @@ UNIT_CLASS_TEST(ScopedEyeForTesting, RegisterMapObjectEvent) MapObject poi; poi.m_bestType = "shop"; poi.m_pos = {53.652005, 108.143448}; - ms::LatLon userPos = {0.0, 0.0}; + m2::PointD userPos = {0.0, 0.0}; EyeForTesting::RegisterMapObjectEvent(poi, MapObject::Event::Type::RouteToCreated, userPos); @@ -543,7 +543,7 @@ UNIT_CLASS_TEST(ScopedEyeForTesting, RegisterMapObjectEvent) MapObject poi; poi.m_bestType = "amenity-bench"; poi.m_pos = {53.652005, 108.143448}; - ms::LatLon userPos = {0.0, 0.0}; + m2::PointD userPos = {0.0, 0.0}; EyeForTesting::RegisterMapObjectEvent(poi, MapObject::Event::Type::Open, userPos); } @@ -562,10 +562,10 @@ UNIT_CLASS_TEST(ScopedEyeForTesting, RegisterMapObjectEvent) TEST(it != mapObjects.end(), ()); TEST_EQUAL(it->second.size(), 2, ()); - TEST_EQUAL(it->second[0].m_userPos, ms::LatLon(53.016347, 158.683327), ()); + TEST_EQUAL(it->second[0].m_userPos, m2::PointD(53.016347, 158.683327), ()); TEST_EQUAL(it->second[0].m_type, MapObject::Event::Type::Open, ()); - TEST_EQUAL(it->second[1].m_userPos, ms::LatLon(53.016345, 158.683329), ()); + TEST_EQUAL(it->second[1].m_userPos, m2::PointD(53.016345, 158.683329), ()); TEST_EQUAL(it->second[1].m_type, MapObject::Event::Type::RouteToCreated, ()); } @@ -578,10 +578,10 @@ UNIT_CLASS_TEST(ScopedEyeForTesting, RegisterMapObjectEvent) TEST(it != mapObjects.end(), ()); TEST_EQUAL(it->second.size(), 2, ()); - TEST_EQUAL(it->second[0].m_userPos, ms::LatLon(0.0, 0.0), ()); + TEST_EQUAL(it->second[0].m_userPos, m2::PointD(0.0, 0.0), ()); TEST_EQUAL(it->second[0].m_type, MapObject::Event::Type::RouteToCreated, ()); - TEST_EQUAL(it->second[1].m_userPos, ms::LatLon(158.016345, 53.683329), ()); + TEST_EQUAL(it->second[1].m_userPos, m2::PointD(158.016345, 53.683329), ()); TEST_EQUAL(it->second[1].m_type, MapObject::Event::Type::AddToBookmark, ()); } @@ -594,7 +594,7 @@ UNIT_CLASS_TEST(ScopedEyeForTesting, RegisterMapObjectEvent) TEST(it != mapObjects.end(), ()); TEST_EQUAL(it->second.size(), 1, ()); - TEST_EQUAL(it->second[0].m_userPos, ms::LatLon(0.0, 0.0), ()); + TEST_EQUAL(it->second[0].m_userPos, m2::PointD(0.0, 0.0), ()); TEST_EQUAL(it->second[0].m_type, MapObject::Event::Type::Open, ()); } } diff --git a/metrics/metrics_tests_support/eye_for_testing.cpp b/metrics/metrics_tests_support/eye_for_testing.cpp index cc6abb1776..b6506cefec 100644 --- a/metrics/metrics_tests_support/eye_for_testing.cpp +++ b/metrics/metrics_tests_support/eye_for_testing.cpp @@ -80,7 +80,7 @@ void EyeForTesting::TrimExpiredMapObjectEvents() // static void EyeForTesting::RegisterMapObjectEvent(MapObject const & mapObject, MapObject::Event::Type type, - ms::LatLon const & userPos) + m2::PointD const & userPos) { Eye::Instance().RegisterMapObjectEvent(mapObject, type, userPos); } diff --git a/metrics/metrics_tests_support/eye_for_testing.hpp b/metrics/metrics_tests_support/eye_for_testing.hpp index 5180e1ccea..0672acd0fe 100644 --- a/metrics/metrics_tests_support/eye_for_testing.hpp +++ b/metrics/metrics_tests_support/eye_for_testing.hpp @@ -19,7 +19,7 @@ public: static void AppendLayer(Layer::Type type); static void TrimExpiredMapObjectEvents(); static void RegisterMapObjectEvent(MapObject const & mapObject, MapObject::Event::Type type, - ms::LatLon const & userPos); + m2::PointD const & userPos); }; class ScopedEyeForTesting