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

eye_info.hpp « metrics - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4a3b67694ed377e4476307fd0b63ce4aebd1488c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
#pragma once

#include "coding/point_coding.hpp"

#include "geometry/mercator.hpp"
#include "geometry/point2d.hpp"
#include "geometry/tree4d.hpp"

#include "base/assert.hpp"
#include "base/visitor.hpp"

#include <array>
#include <chrono>
#include <cstdint>
#include <deque>
#include <string>
#include <type_traits>
#include <vector>

namespace eye
{
namespace traits
{
namespace impl
{
template <typename T>
auto is_enum_with_count_checker(int) -> decltype(
  T::Count,
  std::is_enum<T> {});

template <typename T>
std::false_type is_enum_with_count_checker(...);
}  // namespace impl

template <typename T>
using is_enum_with_count = decltype(impl::is_enum_with_count_checker<T>(0));
}  // namespace traits

template <typename T>
using EnableIfIsEnumWithCount = std::enable_if_t<traits::is_enum_with_count<T>::value>;

template <typename T, typename R, typename Enable = void>
class Counters;

template <typename T, typename R>
class Counters<T, R, EnableIfIsEnumWithCount<T>>
{
public:
  void Increment(T const key)
  {
    CHECK_NOT_EQUAL(key, T::Count, ());
    ++m_counters[static_cast<size_t>(key)];
  }

  R Get(T const key) const
  {
    return m_counters[static_cast<size_t>(key)];
  }

  DECLARE_VISITOR_AND_DEBUG_PRINT(Counters, visitor(m_counters, "counters"))

private:
  std::array<R, static_cast<size_t>(T::Count)> m_counters = {};
};

enum class Version : int8_t
{
  Unknown = -1,
  V0 = 0,
  Latest = V0
};

inline std::string DebugPrint(Version const & version)
{
  switch (version)
  {
    case Version::Unknown: return "Unknown";
    case Version::V0: return "V0";
  }
}

using Clock = std::chrono::system_clock;
using Time = Clock::time_point;

struct Booking
{
  DECLARE_VISITOR_AND_DEBUG_PRINT(Booking, visitor(m_lastFilterUsedTime, "last_filter_used_time"))

  Time m_lastFilterUsedTime;
};

struct Bookmarks
{
  DECLARE_VISITOR_AND_DEBUG_PRINT(Bookmarks, visitor(m_lastOpenedTime, "last_use_time"))

  Time m_lastOpenedTime;
};

struct Discovery
{
  enum class Event
  {
    HotelsClicked,
    AttractionsClicked,
    CafesClicked,
    LocalsClicked,

    MoreHotelsClicked,
    MoreAttractionsClicked,
    MoreCafesClicked,
    MoreLocalsClicked,

    Count
  };

  DECLARE_VISITOR_AND_DEBUG_PRINT(Discovery, visitor(m_eventCounters, "event_counters"),
                                  visitor(m_lastOpenedTime, "last_opened_time"),
                                  visitor(m_lastClickedTime, "last_clicked_time"))

  Counters<Event, uint32_t> m_eventCounters;
  Time m_lastOpenedTime;
  Time m_lastClickedTime;
};

struct Layer
{
  enum class Type : uint8_t
  {
    TrafficJams,
    PublicTransport
  };

  DECLARE_VISITOR_AND_DEBUG_PRINT(Layer, visitor(m_type, "type"), visitor(m_useCount, "use_count"),
                                  visitor(m_lastTimeUsed, "last_time_used"))

  Type m_type;
  uint64_t m_useCount = 0;
  Time m_lastTimeUsed;
};

using Layers = std::vector<Layer>;

struct Tip
{
  // The order is important.
  // New types must be added before Type::Count item.
  enum class Type : uint8_t
  {
    BookmarksCatalog,
    BookingHotels,
    DiscoverButton,
    PublicTransport,

    Count
  };

  enum class Event : uint8_t
  {
    ActionClicked,
    GotitClicked,

    Count
  };

  DECLARE_VISITOR_AND_DEBUG_PRINT(Tip, visitor(m_type, "type"),
                                  visitor(m_eventCounters, "event_counters"),
                                  visitor(m_lastShownTime, "last_shown_time"))

  Type m_type;
  Counters<Event, uint32_t> m_eventCounters;
  Time m_lastShownTime;
};

using Tips = std::vector<Tip>;

class MapObject
{
public:
  struct Event
  {
    enum class Type : uint8_t
    {
      Open,
      AddToBookmark,
      UgcEditorOpened,
      UgcSaved,
      RouteToCreated,
      BookingBook,
      BookingMore,
      BookingReviews,
      BookingDetails,
    };

    DECLARE_VISITOR(visitor(m_type, "type"), visitor(m_userPos, "user_pos"),
                    visitor(m_eventTime, "event_time"));

    Type m_type;
    m2::PointD m_userPos;
    Time m_eventTime;
  };

  using Events = std::deque<Event>;

  bool operator==(MapObject const & rhs) const
  {
    return GetPos() == rhs.GetPos() && GetBestType() == rhs.GetBestType() &&
           GetDefaultName() == rhs.GetDefaultName();
  }

  bool operator!=(MapObject const & rhs) const { return !((*this) == rhs); }

  bool AlmostEquals(MapObject const & rhs) const
  {
    return GetPos().EqualDxDy(rhs.GetPos(), kMwmPointAccuracy) &&
           GetBestType() == rhs.GetBestType() && GetDefaultName() == rhs.GetDefaultName();
  }

  std::string const & GetBestType() const { return m_bestType; }

  void SetBestType(std::string const & bestType) { m_bestType = bestType; }

  m2::PointD const & GetPos() const { return m_pos; }

  void SetPos(m2::PointD const & pos)
  {
    m_pos = pos;
    m_limitRect = MercatorBounds::RectByCenterXYAndOffset(pos, kMwmPointAccuracy);
  }

  std::string const & GetDefaultName() const { return m_defaultName; }

  void SetDefaultName(std::string const & defaultName) { m_defaultName = defaultName; }

  std::string const & GetReadableName() const { return m_readableName; }

  void SetReadableName(std::string const & readableName) { m_readableName = readableName; }

  MapObject::Events & GetEditableEvents() const { return m_events; }

  MapObject::Events const & GetEvents() const { return m_events; }

  m2::RectD GetLimitRect() const { return m_limitRect; }

  bool IsEmpty() const { return m_bestType.empty(); }

  DECLARE_VISITOR(visitor(m_bestType, "type"), visitor(m_pos, "pos"),
                  visitor(m_readableName, "readable_name"), visitor(m_defaultName, "default_name"),
                  visitor(m_events, "events"))

private:
  std::string m_bestType;
  m2::PointD m_pos;
  std::string m_defaultName;
  std::string m_readableName;
  // Mutable because of interface of the m4::Tree provides constant references in ForEach methods,
  // but we need to add events into existing objects to avoid some overhead (copy + change +
  // remove + insert operations). The other solution is to use const_cast in ForEach methods.
  mutable MapObject::Events m_events;
  m2::RectD m_limitRect;
};

struct Promo
{
  Promo() = default;

  DECLARE_VISITOR_AND_DEBUG_PRINT(Promo,
                                  visitor(m_transitionToBookingTime, "transitionToBookingTime"),
                                  visitor(m_lastTimeShownAfterBooking, "lastTimeShownAfterBooking"))
  Time m_transitionToBookingTime;
  Time m_lastTimeShownAfterBooking;
  std::string m_lastTimeShownAfterBookingCityId;
};

using MapObjects = m4::Tree<MapObject>;

struct InfoV0
{
  static Version GetVersion() { return Version::V0; }
  DECLARE_VISITOR_AND_DEBUG_PRINT(InfoV0, visitor(m_booking, "booking"),
                                  visitor(m_bookmarks, "bookmarks"),
                                  visitor(m_discovery, "discovery"), visitor(m_layers, "layers"),
                                  visitor(m_tips, "tips"), visitor(m_promo, Promo(), "promo"))

  Booking m_booking;
  Bookmarks m_bookmarks;
  Discovery m_discovery;
  Layers m_layers;
  Tips m_tips;
  MapObjects m_mapObjects;
  Promo m_promo;
};

using Info = InfoV0;

inline std::string DebugPrint(Tip::Type const & type)
{
  switch (type)
  {
  case Tip::Type::BookmarksCatalog: return "BookmarksCatalog";
  case Tip::Type::BookingHotels: return "BookingHotels";
  case Tip::Type::DiscoverButton: return "DiscoverButton";
  case Tip::Type::PublicTransport: return "PublicTransport";
  case Tip::Type::Count: return "Count";
  }
  UNREACHABLE();
}

inline std::string DebugPrint(Tip::Event const & type)
{
  switch (type)
  {
  case Tip::Event::ActionClicked: return "ActionClicked";
  case Tip::Event::GotitClicked: return "GotitClicked";
  case Tip::Event::Count: return "Count";
  }
  UNREACHABLE();
}

inline std::string DebugPrint(Layer::Type const & type)
{
  switch (type)
  {
  case Layer::Type::TrafficJams: return "TrafficJams";
  case Layer::Type::PublicTransport: return "PublicTransport";
  }
  UNREACHABLE();
}

inline std::string DebugPrint(Discovery::Event const & event)
{
  switch (event)
  {
    case Discovery::Event::HotelsClicked: return "HotelsClicked";
    case Discovery::Event::AttractionsClicked: return "AttractionsClicked";
    case Discovery::Event::CafesClicked: return "CafesClicked";
    case Discovery::Event::LocalsClicked: return "LocalsClicked";
    case Discovery::Event::MoreHotelsClicked: return "MoreHotelsClicked";
    case Discovery::Event::MoreAttractionsClicked: return "MoreAttractionsClicked";
    case Discovery::Event::MoreCafesClicked: return "MoreCafesClicked";
    case Discovery::Event::MoreLocalsClicked: return "MoreLocalsClicked";
    case Discovery::Event::Count: return "Count";
  }
  UNREACHABLE();
}

inline std::string DebugPrint(MapObject::Event::Type const & type)
{
  switch (type)
  {
  case MapObject::Event::Type::Open: return "Open";
  case MapObject::Event::Type::AddToBookmark: return "AddToBookmark";
  case MapObject::Event::Type::UgcEditorOpened: return "UgcEditorOpened";
  case MapObject::Event::Type::UgcSaved: return "UgcSaved";
  case MapObject::Event::Type::RouteToCreated: return "RouteToCreated";
  case MapObject::Event::Type::BookingBook: return "BookingBook";
  case MapObject::Event::Type::BookingMore: return "BookingMore";
  case MapObject::Event::Type::BookingReviews: return "BookingReviews";
  case MapObject::Event::Type::BookingDetails: return "BookingDetails";
  }
  UNREACHABLE();
}
}  // namespace eye