forked from organicmaps/organicmaps
[ugc] Various fixes.
This commit is contained in:
parent
7da3a5c85d
commit
880bc83c8a
4 changed files with 36 additions and 41 deletions
|
@ -49,7 +49,7 @@ public:
|
|||
template <typename T>
|
||||
void operator()(vector<T> const & vs)
|
||||
{
|
||||
SerVarUint(vs.size());
|
||||
SerVarUint(static_cast<uint32_t>(vs.size()));
|
||||
for (auto const & v : vs)
|
||||
(*this)(v);
|
||||
}
|
||||
|
@ -84,12 +84,12 @@ public:
|
|||
(*this)(text.m_text);
|
||||
}
|
||||
|
||||
void operator()(Review::Sentiment sentiment)
|
||||
void operator()(Sentiment sentiment)
|
||||
{
|
||||
switch (sentiment)
|
||||
{
|
||||
case Review::Sentiment::Negative: return (*this)(static_cast<uint8_t>(0));
|
||||
case Review::Sentiment::Positive: return (*this)(static_cast<uint8_t>(1));
|
||||
case Sentiment::Negative: return (*this)(static_cast<uint8_t>(0));
|
||||
case Sentiment::Positive: return (*this)(static_cast<uint8_t>(1));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -160,7 +160,7 @@ public:
|
|||
template <typename T>
|
||||
void operator()(vector<T> & vs)
|
||||
{
|
||||
auto const size = DesVarUint<size_t>();
|
||||
auto const size = DesVarUint<uint32_t>();
|
||||
vs.resize(size);
|
||||
for (auto & v : vs)
|
||||
(*this)(v);
|
||||
|
@ -190,14 +190,14 @@ public:
|
|||
(*this)(text.m_text);
|
||||
}
|
||||
|
||||
void operator()(Review::Sentiment & sentiment)
|
||||
void operator()(Sentiment & sentiment)
|
||||
{
|
||||
uint8_t s = 0;
|
||||
(*this)(s);
|
||||
switch (s)
|
||||
{
|
||||
case 0: sentiment = Review::Sentiment::Negative; break;
|
||||
case 1: sentiment = Review::Sentiment::Positive; break;
|
||||
case 0: sentiment = Sentiment::Negative; break;
|
||||
case 1: sentiment = Sentiment::Positive; break;
|
||||
default: CHECK(false, ("Can't parse sentiment from:", static_cast<int>(s))); break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,22 @@
|
|||
namespace ugc
|
||||
{
|
||||
using TranslationKey = std::string;
|
||||
using Time = std::chrono::time_point<std::chrono::system_clock>;
|
||||
|
||||
enum class Sentiment
|
||||
{
|
||||
Positive,
|
||||
Negative
|
||||
};
|
||||
|
||||
inline std::string DebugPrint(Sentiment const & sentiment)
|
||||
{
|
||||
switch (sentiment)
|
||||
{
|
||||
case Sentiment::Positive: return "Positive";
|
||||
case Sentiment::Negative: return "Negative";
|
||||
}
|
||||
}
|
||||
|
||||
struct RatingRecord
|
||||
{
|
||||
|
@ -54,7 +70,7 @@ struct Rating
|
|||
friend std::string DebugPrint(Rating const & rating)
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << "Rating [ ratings:" << DebugPrint(rating.m_ratings) << ", aggValue:" << rating.m_aggValue
|
||||
os << "Rating [ ratings:" << ::DebugPrint(rating.m_ratings) << ", aggValue:" << rating.m_aggValue
|
||||
<< " ]";
|
||||
return os.str();
|
||||
}
|
||||
|
@ -123,13 +139,6 @@ struct Text
|
|||
struct Review
|
||||
{
|
||||
using ReviewId = uint32_t;
|
||||
using Time = std::chrono::time_point<std::chrono::system_clock>;
|
||||
|
||||
enum class Sentiment
|
||||
{
|
||||
Positive,
|
||||
Negative
|
||||
};
|
||||
|
||||
Review() = default;
|
||||
Review(ReviewId id, Text const & text, Author const & author, float const rating,
|
||||
|
@ -156,15 +165,6 @@ struct Review
|
|||
m_time = Time(hours);
|
||||
}
|
||||
|
||||
friend std::string DebugPrint(Sentiment const sentiment)
|
||||
{
|
||||
switch (sentiment)
|
||||
{
|
||||
case Sentiment::Positive: return "Positive";
|
||||
case Sentiment::Negative: return "Negative";
|
||||
}
|
||||
}
|
||||
|
||||
friend std::string DebugPrint(Review const & review)
|
||||
{
|
||||
std::ostringstream os;
|
||||
|
@ -231,8 +231,8 @@ struct UGC
|
|||
std::ostringstream os;
|
||||
os << "UGC [ ";
|
||||
os << "rating:" << DebugPrint(ugc.m_rating) << ", ";
|
||||
os << "reviews:" << DebugPrint(ugc.m_reviews) << ", ";
|
||||
os << "attributes:" << DebugPrint(ugc.m_attributes) << " ]";
|
||||
os << "reviews:" << ::DebugPrint(ugc.m_reviews) << ", ";
|
||||
os << "attributes:" << ::DebugPrint(ugc.m_attributes) << " ]";
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
@ -243,26 +243,21 @@ struct UGC
|
|||
|
||||
struct ReviewFeedback
|
||||
{
|
||||
ReviewFeedback(bool const evaluation,
|
||||
std::chrono::time_point<std::chrono::system_clock> const time)
|
||||
: m_evaluation(evaluation), m_time(time)
|
||||
ReviewFeedback(Sentiment const sentiment, Time const & time)
|
||||
: m_sentiment(sentiment), m_time(time)
|
||||
{
|
||||
}
|
||||
|
||||
bool m_evaluation;
|
||||
std::chrono::time_point<std::chrono::system_clock> m_time;
|
||||
Sentiment m_sentiment;
|
||||
Time 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)
|
||||
{
|
||||
}
|
||||
ReviewAbuse(std::string const & reason, Time const & time) : m_reason(reason), m_time(time) {}
|
||||
|
||||
std::string m_reason;
|
||||
std::chrono::time_point<std::chrono::system_clock> m_time;
|
||||
Time m_time;
|
||||
};
|
||||
|
||||
struct UGCUpdate
|
||||
|
|
|
@ -10,6 +10,7 @@ include($$ROOT_DIR/common.pri)
|
|||
|
||||
HEADERS += \
|
||||
api.hpp \
|
||||
serdes.hpp \
|
||||
types.hpp \
|
||||
|
||||
SOURCES += \
|
||||
|
|
|
@ -44,12 +44,11 @@ UGC GetTestUGC()
|
|||
vector<Review> reviews;
|
||||
reviews.emplace_back(20 /* id */, Text("Damn good coffee", StringUtf8Multilang::kEnglishCode),
|
||||
Author(UID(987654321 /* hi */, 123456789 /* lo */), "Cole"),
|
||||
5.0 /* rating */, Review::Sentiment::Positive,
|
||||
Review::Time(FromDays(10)));
|
||||
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 */,
|
||||
Review::Sentiment::Positive, Review::Time(FromDays(1)));
|
||||
Sentiment::Positive, Time(FromDays(1)));
|
||||
|
||||
vector<Attribute> attributes;
|
||||
attributes.emplace_back("best-drink", "Coffee");
|
||||
|
|
Loading…
Add table
Reference in a new issue