forked from organicmaps/organicmaps
[ugc] Fake UGC are generated in API now.
This commit is contained in:
parent
880bc83c8a
commit
100cc82f2f
4 changed files with 71 additions and 37 deletions
65
ugc/api.cpp
65
ugc/api.cpp
|
@ -4,10 +4,20 @@
|
|||
|
||||
#include "platform/platform.hpp"
|
||||
|
||||
#include <chrono>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace ugc
|
||||
{
|
||||
namespace
|
||||
{
|
||||
chrono::hours FromDays(uint32_t days)
|
||||
{
|
||||
return std::chrono::hours(days * 24);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Api::Api(Index const & index) : m_index(index) {}
|
||||
|
||||
void Api::GetUGC(FeatureID const & id, UGCCallback callback)
|
||||
|
@ -20,10 +30,63 @@ void Api::GetUGCUpdate(FeatureID const & id, UGCUpdateCallback callback)
|
|||
m_thread.Push([=]() { GetUGCUpdateImpl(id, callback); });
|
||||
}
|
||||
|
||||
void Api::GetUGCImpl(FeatureID const & /* id */, UGCCallback callback)
|
||||
// static
|
||||
UGC Api::MakeTestUGC1()
|
||||
{
|
||||
Rating rating;
|
||||
rating.m_ratings.emplace_back("food" /* key */, 4.0 /* value */);
|
||||
rating.m_ratings.emplace_back("service" /* key */, 5.0 /* value */);
|
||||
rating.m_ratings.emplace_back("music" /* key */, 5.0 /* value */);
|
||||
rating.m_aggValue = 4.5;
|
||||
|
||||
vector<Review> reviews;
|
||||
reviews.emplace_back(20 /* id */, Text("Damn good coffee", StringUtf8Multilang::kEnglishCode),
|
||||
Author(UID(987654321 /* hi */, 123456789 /* lo */), "Cole"),
|
||||
5.0 /* rating */, Sentiment::Positive, Time(FromDays(10)));
|
||||
reviews.emplace_back(67812 /* id */,
|
||||
Text("Clean place, reasonably priced", StringUtf8Multilang::kDefaultCode),
|
||||
Author(UID(0 /* hi */, 315 /* lo */), "Cooper"), 5.0 /* rating */,
|
||||
Sentiment::Positive, Time(FromDays(1)));
|
||||
|
||||
vector<Attribute> attributes;
|
||||
attributes.emplace_back("best-drink", "Coffee");
|
||||
|
||||
return UGC(rating, reviews, attributes);
|
||||
}
|
||||
|
||||
// static
|
||||
UGC Api::MakeTestUGC2()
|
||||
{
|
||||
Rating rating;
|
||||
rating.m_ratings.emplace_back("food" /* key */, 5.0 /* value */);
|
||||
rating.m_ratings.emplace_back("service" /* key */, 5.0 /* value */);
|
||||
rating.m_ratings.emplace_back("music" /* key */, 5.0 /* value */);
|
||||
rating.m_aggValue = 5.0;
|
||||
|
||||
vector<Review> reviews;
|
||||
reviews.emplace_back(119 /* id */,
|
||||
Text("This pie's so good it is a crime", StringUtf8Multilang::kDefaultCode),
|
||||
Author(UID(0 /* hi */, 315 /* lo */), "Cooper"), 5.0 /* rating */,
|
||||
Sentiment::Positive, Time(FromDays(1)));
|
||||
|
||||
vector<Attribute> attributes;
|
||||
attributes.emplace_back("best-drink", "Coffee");
|
||||
attributes.emplace_back("best-meal", "Cherry Pie");
|
||||
|
||||
return UGC(rating, reviews, attributes);
|
||||
}
|
||||
|
||||
void Api::GetUGCImpl(FeatureID const & id, UGCCallback callback)
|
||||
{
|
||||
// TODO (@y, @mgsergio): retrieve static UGC
|
||||
UGC ugc(Rating({}, {}), {}, {});
|
||||
|
||||
auto const r = id.m_index % 3;
|
||||
if (r == 1)
|
||||
ugc = MakeTestUGC1();
|
||||
else if (r == 2)
|
||||
ugc = MakeTestUGC2();
|
||||
|
||||
GetPlatform().RunOnGuiThread([ugc, callback] { callback(ugc); });
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,9 @@ public:
|
|||
void GetUGC(FeatureID const & id, UGCCallback callback);
|
||||
void GetUGCUpdate(FeatureID const & id, UGCUpdateCallback callback);
|
||||
|
||||
static UGC MakeTestUGC1();
|
||||
static UGC MakeTestUGC2();
|
||||
|
||||
private:
|
||||
void GetUGCImpl(FeatureID const & id, UGCCallback callback);
|
||||
void GetUGCUpdateImpl(FeatureID const & id, UGCUpdateCallback callback);
|
||||
|
|
|
@ -6,5 +6,5 @@ set(
|
|||
)
|
||||
|
||||
omim_add_test(${PROJECT_NAME} ${SRC})
|
||||
omim_link_libraries(${PROJECT_NAME} platform coding geometry base)
|
||||
omim_link_libraries(${PROJECT_NAME} ugc indexer platform coding geometry base)
|
||||
link_qt5_core(${PROJECT_NAME})
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
#include "testing/testing.hpp"
|
||||
|
||||
#include "ugc/api.hpp"
|
||||
#include "ugc/serdes.hpp"
|
||||
#include "ugc/types.hpp"
|
||||
|
||||
#include "coding/reader.hpp"
|
||||
#include "coding/writer.hpp"
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
|
@ -19,11 +19,6 @@ using Buffer = vector<uint8_t>;
|
|||
using Ser = Serializer<MemWriter<Buffer>>;
|
||||
using Des = DeserializerV0<ReaderSource<MemReader>>;
|
||||
|
||||
chrono::hours FromDays(uint32_t days)
|
||||
{
|
||||
return std::chrono::hours(days * 24);
|
||||
}
|
||||
|
||||
Rating GetTestRating()
|
||||
{
|
||||
vector<RatingRecord> records;
|
||||
|
@ -33,34 +28,7 @@ Rating GetTestRating()
|
|||
return Rating(records, 4.5 /* aggValue */);
|
||||
}
|
||||
|
||||
UGC GetTestUGC()
|
||||
{
|
||||
Rating rating;
|
||||
rating.m_ratings.emplace_back("food" /* key */, 4.0 /* value */);
|
||||
rating.m_ratings.emplace_back("service" /* key */, 5.0 /* value */);
|
||||
rating.m_ratings.emplace_back("music" /* key */, 5.0 /* value */);
|
||||
rating.m_aggValue = 4.5;
|
||||
|
||||
vector<Review> reviews;
|
||||
reviews.emplace_back(20 /* id */, Text("Damn good coffee", StringUtf8Multilang::kEnglishCode),
|
||||
Author(UID(987654321 /* hi */, 123456789 /* lo */), "Cole"),
|
||||
5.0 /* rating */, Sentiment::Positive, Time(FromDays(10)));
|
||||
reviews.emplace_back(67812 /* id */,
|
||||
Text("Clean place, reasonably priced", StringUtf8Multilang::kDefaultCode),
|
||||
Author(UID(0 /* hi */, 315 /* lo */), "Cooper"), 5.0 /* rating */,
|
||||
Sentiment::Positive, Time(FromDays(1)));
|
||||
|
||||
vector<Attribute> attributes;
|
||||
attributes.emplace_back("best-drink", "Coffee");
|
||||
|
||||
return UGC(rating, reviews, attributes);
|
||||
}
|
||||
|
||||
MemWriter<Buffer> MakeSink(Buffer & buffer)
|
||||
{
|
||||
return MemWriter<Buffer>(buffer);
|
||||
}
|
||||
|
||||
MemWriter<Buffer> MakeSink(Buffer & buffer) { return MemWriter<Buffer>(buffer); }
|
||||
ReaderSource<MemReader> MakeSource(Buffer const & buffer)
|
||||
{
|
||||
MemReader reader(buffer.data(), buffer.size());
|
||||
|
@ -93,7 +61,7 @@ UNIT_TEST(SerDes_Rating)
|
|||
|
||||
UNIT_TEST(SerDes_UGC)
|
||||
{
|
||||
auto const expectedUGC = GetTestUGC();
|
||||
auto const expectedUGC = Api::MakeTestUGC1();
|
||||
TEST_EQUAL(expectedUGC, expectedUGC, ());
|
||||
|
||||
HeaderV0 header;
|
||||
|
|
Loading…
Add table
Reference in a new issue