Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Magidovich <mgsergio@mapswithme.com>2017-06-19 16:50:56 +0300
committerYuri Gorshenin <mipt.vi002@gmail.com>2017-07-05 16:41:38 +0300
commitdec8b3f4876eada9585a1df710965397c728d7d3 (patch)
treeed57f9427ce7a4d6e7a1043da06def4258d35c2f
parent2abc1da6f13ef3c3e875dfc9f218b8274a732cba (diff)
Add ugc datatypes.
-rw-r--r--ugc/CMakeLists.txt1
-rw-r--r--ugc/api.cpp21
-rw-r--r--ugc/api.hpp14
-rw-r--r--ugc/types.hpp180
4 files changed, 202 insertions, 14 deletions
diff --git a/ugc/CMakeLists.txt b/ugc/CMakeLists.txt
index 20baffbe60..f1a77d90bb 100644
--- a/ugc/CMakeLists.txt
+++ b/ugc/CMakeLists.txt
@@ -4,6 +4,7 @@ set(
SRC
api.cpp
api.hpp
+ types.hpp
)
add_library(${PROJECT_NAME} ${SRC})
diff --git a/ugc/api.cpp b/ugc/api.cpp
index 12ffd23e15..c8e47b9cca 100644
--- a/ugc/api.cpp
+++ b/ugc/api.cpp
@@ -10,25 +10,30 @@ namespace ugc
{
Api::Api(Index const & index) : m_index(index) {}
-void Api::GetStaticUGC(FeatureID const & id, Callback callback)
+void Api::GetUGC(FeatureID const & id, UGCCallback callback)
{
- m_thread.Push([=]() { GetStaticUGCImpl(id, callback); });
+ m_thread.Push([=]() { GetUGCImpl(id, callback); });
}
-void Api::GetDynamicUGC(FeatureID const & id, Callback callback)
+void Api::GetUGCUpdate(FeatureID const & id, UGCUpdateCallback callback)
{
- m_thread.Push([=]() { GetDynamicUGCImpl(id, callback); });
+ m_thread.Push([=]() { GetUGCUpdateImpl(id, callback); });
}
-void Api::GetStaticUGCImpl(FeatureID const & /* id */, Callback callback)
+void Api::GetUGCImpl(FeatureID const & /* id */, UGCCallback callback)
{
// TODO (@y, @mgsergio): retrieve static UGC
- GetPlatform().RunOnGuiThread(callback);
+ UGC ugc(Rating({}, {}), {}, {});
+ GetPlatform().RunOnGuiThread([ugc, callback] { callback(ugc); });
}
-void Api::GetDynamicUGCImpl(FeatureID const & /* id */, Callback callback)
+void Api::GetUGCUpdateImpl(FeatureID const & /* id */, UGCUpdateCallback callback)
{
// TODO (@y, @mgsergio): retrieve dynamic UGC
- GetPlatform().RunOnGuiThread(callback);
+ UGCUpdate ugc(Rating({}, {}),
+ Attribute({}, {}),
+ ReviewAbuse({}, {}),
+ ReviewFeedback({}, {}));
+ GetPlatform().RunOnGuiThread([ugc, callback] { callback(ugc); });
}
} // namespace ugc
diff --git a/ugc/api.hpp b/ugc/api.hpp
index 8b13853eae..eb6f731f39 100644
--- a/ugc/api.hpp
+++ b/ugc/api.hpp
@@ -2,6 +2,8 @@
#include "base/worker_thread.hpp"
+#include "ugc/types.hpp"
+
#include <functional>
class Index;
@@ -12,17 +14,17 @@ namespace ugc
class Api
{
public:
- // TODO (@y, @mgsergio): replace void() by void(UGC const &).
- using Callback = std::function<void()>;
+ using UGCCallback = std::function<void(UGC const &)>;
+ using UGCUpdateCallback = std::function<void(UGCUpdate const &)>;
explicit Api(Index const & index);
- void GetStaticUGC(FeatureID const & id, Callback callback);
- void GetDynamicUGC(FeatureID const & id, Callback callback);
+ void GetUGC(FeatureID const & id, UGCCallback callback);
+ void GetUGCUpdate(FeatureID const & id, UGCUpdateCallback callback);
private:
- void GetStaticUGCImpl(FeatureID const & id, Callback callback);
- void GetDynamicUGCImpl(FeatureID const & id, Callback callback);
+ void GetUGCImpl(FeatureID const & id, UGCCallback callback);
+ void GetUGCUpdateImpl(FeatureID const & id, UGCUpdateCallback callback);
Index const & m_index;
base::WorkerThread m_thread;
diff --git a/ugc/types.hpp b/ugc/types.hpp
new file mode 100644
index 0000000000..1a4aa3b956
--- /dev/null
+++ b/ugc/types.hpp
@@ -0,0 +1,180 @@
+#pragma once
+
+#include "indexer/feature_decl.hpp"
+
+#include <chrono>
+#include <cstdint>
+#include <memory>
+#include <string>
+#include <vector>
+
+namespace ugc
+{
+struct RatingRecord
+{
+ RatingRecord(std::string const & key, float const value)
+ : m_key(key)
+ , m_value(value)
+ {
+ }
+
+ std::string m_key;
+ float m_value;
+};
+
+struct Rating
+{
+ Rating(std::vector<RatingRecord> const & ratings, float const aggValue)
+ : m_ratings(ratings)
+ , m_aggValue(aggValue)
+ {
+ }
+
+ std::vector<RatingRecord> m_ratings;
+ float m_aggValue;
+};
+
+class UID
+{
+public:
+ UID(uint64_t const hi, uint64_t const lo)
+ : m_hi(hi)
+ , m_lo(lo)
+ {
+ }
+
+ std::string ToString() const;
+
+private:
+ uint64_t m_hi;
+ uint64_t m_lo;
+};
+
+struct Author
+{
+ Author(UID const & uid, std::string const & name)
+ : m_uid(uid)
+ , m_name(name)
+ {
+ }
+
+ UID m_uid;
+ std::string m_name;
+};
+
+struct Text
+{
+ Text(std::string const & text, uint8_t const lang)
+ : m_text(text)
+ , m_lang(lang)
+ {
+ }
+
+ std::string m_text;
+ uint8_t m_lang;
+};
+
+struct Review
+{
+ using ReviewId = uint32_t;
+
+ Review(Text const & text, Author const & author,
+ float const rating, bool const evaluation,
+ std::chrono::time_point<std::chrono::system_clock> const & time)
+ : m_text(text)
+ , m_author(author)
+ , m_rating(rating)
+ , m_evaluation(evaluation)
+ , m_time(time)
+ {
+ }
+
+ ReviewId m_id;
+
+ Text m_text;
+ Author m_author;
+ // A rating of a review itself. It is accumulated from other users likes or dislakes.
+ float m_rating;
+ // A positive/negative evaluation given to a place by a user.
+ bool m_evaluation;
+ std::chrono::time_point<std::chrono::system_clock> m_time;
+};
+
+struct Attribute
+{
+ Attribute(std::string const & key, std::string const & value)
+ : m_key(key)
+ , m_value(value)
+ {
+ }
+
+ std::string m_key;
+ std::string m_value;
+};
+
+// struct Media
+// {
+// std::unique_ptr<MediaImpl> m_data;
+// };
+
+struct UGC
+{
+ UGC(Rating const & rating,
+ std::vector<Review> const & reviews,
+ std::vector<Attribute> const & attributes)
+ : m_rating(rating)
+ , m_reviews(reviews)
+ , m_attributes(attributes)
+ {
+ }
+
+ Rating m_rating;
+ std::vector<Review> m_reviews;
+ std::vector<Attribute> m_attributes;
+ // Media m_media;
+};
+
+struct ReviewFeedback
+{
+ ReviewFeedback(bool const evaluation,
+ std::chrono::time_point<std::chrono::system_clock> const time)
+ : m_evaluation(evaluation)
+ , m_time(time)
+ {
+ }
+
+ bool m_evaluation;
+ std::chrono::time_point<std::chrono::system_clock> m_time;
+};
+
+struct ReviewAbuse
+{
+ ReviewAbuse(std::string const & reason,
+ std::chrono::time_point<std::chrono::system_clock> const & time)
+ : m_reason(reason)
+ , m_time(time)
+ {
+ }
+
+ std::string m_reason;
+ std::chrono::time_point<std::chrono::system_clock> m_time;
+};
+
+struct UGCUpdate
+{
+ UGCUpdate(Rating ratings, Attribute attribute,
+ ReviewAbuse abuses, ReviewFeedback feedbacks)
+ : m_ratings(ratings)
+ , m_attribute(attribute)
+ , m_abuses(abuses)
+ , m_feedbacks(feedbacks)
+ {
+ }
+
+ Rating m_ratings;
+ Attribute m_attribute;
+
+ ReviewAbuse m_abuses;
+ ReviewFeedback m_feedbacks;
+};
+} // namespace ugc