[eye] subscription mechanism + methods renaming

This commit is contained in:
Arsentiy Milchakov 2018-10-25 16:16:18 +03:00 committed by Tatiana Yan
parent bf1693e86e
commit c7e389f38c
10 changed files with 202 additions and 37 deletions

View file

@ -8,12 +8,12 @@
extern "C"
{
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_metrics_UserActionsLogger_nativeTipShown(JNIEnv * env, jclass, jint type,
jint event)
Java_com_mapswithme_maps_metrics_UserActionsLogger_nativeTipClicked(JNIEnv * env, jclass, jint type,
jint event)
{
auto const & typeValue = static_cast<eye::Tip::Type>(type);
auto const & eventValue = static_cast<eye::Tip::Event>(event);
eye::Eye::Event::TipShown(typeValue, eventValue);
eye::Eye::Event::TipClicked(typeValue, eventValue);
}
JNIEXPORT void JNICALL

View file

@ -9,9 +9,9 @@ import com.mapswithme.maps.tips.TipsApi;
public class UserActionsLogger
{
public static void logTipShownEvent(@NonNull TipsApi provider, @NonNull TipsAction action)
public static void logTipClickedEvent(@NonNull TipsApi provider, @NonNull TipsAction action)
{
nativeTipShown(provider.ordinal(), action.ordinal());
nativeTipClicked(provider.ordinal(), action.ordinal());
}
public static void logBookingFilterUsedEvent()
@ -39,7 +39,7 @@ public class UserActionsLogger
nativeDiscoveryItemClicked(event.ordinal());
}
private static native void nativeTipShown(int type, int event);
private static native void nativeTipClicked(int type, int event);
private static native void nativeBookingFilterUsed();
private static native void nativeBookmarksCatalogShown();
private static native void nativeDiscoveryShown();

View file

@ -24,7 +24,7 @@ public abstract class AbstractClickInterceptor implements ClickInterceptor
@Override
public final void onInterceptClick(@NonNull MwmActivity activity)
{
UserActionsLogger.logTipShownEvent(getType(), TipsAction.ACTION_CLICKED);
UserActionsLogger.logTipClickedEvent(getType(), TipsAction.ACTION_CLICKED);
onInterceptClickInternal(activity);
}

View file

@ -147,7 +147,7 @@ public enum TipsApi
private void onPromptStateChanged(int state)
{
if (state == MaterialTapTargetPrompt.STATE_DISMISSED)
UserActionsLogger.logTipShownEvent(TipsApi.this, TipsAction.GOT_IT_CLICKED);
UserActionsLogger.logTipClickedEvent(TipsApi.this, TipsAction.GOT_IT_CLICKED);
}
@Nullable

View file

@ -441,7 +441,7 @@ extern NSString * const kAlohalyticsTapEventKey;
- (void)didPressCancel:(MWMTutorialViewController *)viewController
{
[MWMEye tipShownWithType:self.tutorialType event:MWMTipEventGotIt];
[MWMEye tipClickedWithType:self.tutorialType event:MWMTipEventGotIt];
[viewController fadeOutWithCompletion:^{
[viewController willMoveToParentViewController:nil];
[viewController.view removeFromSuperview];
@ -451,7 +451,7 @@ extern NSString * const kAlohalyticsTapEventKey;
- (void)didPressTarget:(MWMTutorialViewController *)viewController
{
[MWMEye tipShownWithType:self.tutorialType event:MWMTipEventAction];
[MWMEye tipClickedWithType:self.tutorialType event:MWMTipEventAction];
[viewController fadeOutWithCompletion:^{
[viewController willMoveToParentViewController:nil];
[viewController.view removeFromSuperview];

View file

@ -28,7 +28,7 @@ typedef NS_ENUM(NSUInteger, MWMEyeDiscoveryEvent)
@interface MWMEye : NSObject
+ (MWMTip)getTipType;
+ (void)tipShownWithType:(MWMTip)type event:(MWMTipEvent)event;
+ (void)tipClickedWithType:(MWMTip)type event:(MWMTipEvent)event;
+ (void)bookingFilterUsed;
+ (void)boomarksCatalogShown;
+ (void)discoveryShown;

View file

@ -11,9 +11,9 @@
return tutorialType ? (MWMTip)*tutorialType : MWMTipNone;
}
+ (void)tipShownWithType:(MWMTip)type event:(MWMTipEvent)event
+ (void)tipClickedWithType:(MWMTip)type event:(MWMTipEvent)event
{
eye::Eye::Event::TipShown((eye::Tip::Type)type, (eye::Tip::Event)event);
eye::Eye::Event::TipClicked((eye::Tip::Type)type, (eye::Tip::Event)event);
}
+ (void)bookingFilterUsed

View file

@ -300,7 +300,7 @@ void TransitReadManager::UpdateViewport(ScreenBase const & screen)
if (hasData && m_trackFirstSchemeData)
{
eye::Eye::Event::LayerUsed(eye::Layer::Type::PublicTransport);
eye::Eye::Event::LayerShown(eye::Layer::Type::PublicTransport);
m_trackFirstSchemeData = false;
}

View file

@ -7,6 +7,7 @@
#include "coding/file_writer.hpp"
#include "base/logging.hpp"
#include "base/assert.hpp"
#include <algorithm>
#include <memory>
@ -19,8 +20,11 @@ namespace
{
void Load(Info & info)
{
std::vector<int8_t> fileData;
if (!Storage::Load(Storage::GetEyeFilePath(), fileData))
Storage::Migrate();
std::vector<int8_t> infoFileData;
std::vector<int8_t> mapObjectsFileData;
if (!Storage::LoadInfo(infoFileData) || !Storage::LoadMapObjects(mapObjectsFileData))
{
info = {};
return;
@ -28,20 +32,39 @@ void Load(Info & info)
try
{
Serdes::Deserialize(fileData, info);
Serdes::DeserializeInfo(infoFileData, info);
Serdes::DeserializeMapObjects(mapObjectsFileData, info.m_mapObjects);
}
catch (Serdes::UnknownVersion const & ex)
{
LOG(LERROR, ("Unknown eye file version, eye will be disabled. Exception:", ex.Msg()));
LOG(LERROR, ("Cannot load metrics files, eye will be disabled. Exception:", ex.Msg()));
info = {};
}
}
bool Save(Info const & info)
{
std::vector<int8_t> fileData;
Serdes::Serialize(info, fileData);
return Storage::Save(Storage::GetEyeFilePath(), fileData);
Serdes::SerializeInfo(info, fileData);
return Storage::SaveInfo(fileData);
}
// TODO: use to trim old map object events.
//bool SaveMapObjects(Info const & info)
//{
// std::vector<int8_t> fileData;
// Serdes::SerializeMapObjects(info.m_mapObjects, fileData);
// return Storage::SaveMapObjects(fileData);
//}
//
// TODO: use it to save map object events with append only flag.
//bool SaveMapObjectEvent(MapObject const & mapObject, MapObject::Event const & event)
//{
// std::vector<int8_t> eventData;
// Serdes::SerializeMapObjectEvent(mapObject, event, eventData);
//
// return Storage::AppendMapObjectEvent(eventData);
//}
} // namespace
namespace eye
@ -65,13 +88,21 @@ Eye::InfoType Eye::GetInfo() const
return m_info.Get();
}
void Eye::Subscribe(Subscriber * subscriber)
{
GetPlatform().RunTask(Platform::Thread::File, [this, subscriber]
{
m_subscribers.push_back(subscriber);
});
}
void Eye::Save(InfoType const & info)
{
if (::Save(*info))
m_info.Set(info);
}
void Eye::AppendTip(Tip::Type type, Tip::Event event)
void Eye::RegisterTipClick(Tip::Type type, Tip::Event event)
{
auto const info = m_info.Get();
auto editableInfo = std::make_shared<Info>(*info);
@ -82,52 +113,76 @@ void Eye::AppendTip(Tip::Type type, Tip::Event event)
return tip.m_type == type;
});
Tip tip;
auto const now = Clock::now();
if (it != editableTips.cend())
{
it->m_eventCounters.Increment(event);
it->m_lastShownTime = now;
tip = *it;
}
else
{
Tip tip;
tip.m_type = type;
tip.m_eventCounters.Increment(event);
tip.m_lastShownTime = now;
editableTips.emplace_back(std::move(tip));
editableTips.emplace_back(tip);
}
Save(editableInfo);
for (auto subscriber : m_subscribers)
{
subscriber->OnTipClicked(tip);
}
}
void Eye::UpdateBookingFilterUsedTime()
{
auto const info = m_info.Get();
auto editableInfo = std::make_shared<Info>(*info);
auto const now = Clock::now();
editableInfo->m_booking.m_lastFilterUsedTime = Clock::now();
editableInfo->m_booking.m_lastFilterUsedTime = now;
Save(editableInfo);
for (auto subscriber : m_subscribers)
{
subscriber->OnBookingFilterUsed(now);
}
}
void Eye::UpdateBoomarksCatalogShownTime()
{
auto const info = m_info.Get();
auto editableInfo = std::make_shared<Info>(*info);
auto const now = Clock::now();
editableInfo->m_bookmarks.m_lastOpenedTime = Clock::now();
editableInfo->m_bookmarks.m_lastOpenedTime = now;
Save(editableInfo);
for (auto subscriber : m_subscribers)
{
subscriber->OnBookmarksCatalogShown(now);
}
}
void Eye::UpdateDiscoveryShownTime()
{
auto const info = m_info.Get();
auto editableInfo = std::make_shared<Info>(*info);
auto const now = Clock::now();
editableInfo->m_discovery.m_lastOpenedTime = Clock::now();
editableInfo->m_discovery.m_lastOpenedTime = now;
Save(editableInfo);
for (auto subscriber : m_subscribers)
{
subscriber->OnDiscoveryShown(now);
}
}
void Eye::IncrementDiscoveryItem(Discovery::Event event)
@ -139,9 +194,14 @@ void Eye::IncrementDiscoveryItem(Discovery::Event event)
editableInfo->m_discovery.m_eventCounters.Increment(event);
Save(editableInfo);
for (auto subscriber : m_subscribers)
{
subscriber->OnDiscoveryItemClicked(event);
}
}
void Eye::AppendLayer(Layer::Type type)
void Eye::RegisterLayerShown(Layer::Type type)
{
auto const info = m_info.Get();
auto editableInfo = std::make_shared<Info>(*info);
@ -152,31 +212,62 @@ void Eye::AppendLayer(Layer::Type type)
return layer.m_type == type;
});
Layer layer;
if (it != editableLayers.end())
{
++it->m_useCount;
it->m_lastTimeUsed = Clock::now();
layer = *it;
}
else
{
Layer layer;
layer.m_type = type;
++layer.m_useCount;
layer.m_lastTimeUsed = Clock::now();
editableLayers.emplace_back(std::move(layer));
editableLayers.emplace_back(layer);
}
Save(editableInfo);
for (auto subscriber : m_subscribers)
{
subscriber->OnLayerUsed(layer);
}
}
void Eye::RegisterPlacePageOpened()
{
}
void Eye::RegisterUgcEditorOpened()
{
}
void Eye::RegisterUgcSaved()
{
}
void Eye::RegisterAddToBookmarkClicked()
{
}
void Eye::RegisterRouteCreatedToObject()
{
}
// Eye::Event methods ------------------------------------------------------------------------------
// static
void Eye::Event::TipShown(Tip::Type type, Tip::Event event)
void Eye::Event::TipClicked(Tip::Type type, Tip::Event event)
{
GetPlatform().RunTask(Platform::Thread::File, [type, event]
{
Instance().AppendTip(type, event);
Instance().RegisterTipClick(type, event);
});
}
@ -217,11 +308,56 @@ void Eye::Event::DiscoveryItemClicked(Discovery::Event event)
}
// static
void Eye::Event::LayerUsed(Layer::Type type)
void Eye::Event::LayerShown(Layer::Type type)
{
GetPlatform().RunTask(Platform::Thread::File, [type]
{
Instance().AppendLayer(type);
Instance().RegisterLayerShown(type);
});
}
// static
void Eye::Event::PlacePageOpened()
{
GetPlatform().RunTask(Platform::Thread::File, []
{
Instance().RegisterPlacePageOpened();
});
}
// static
void Eye::Event::UgcEditorOpened()
{
GetPlatform().RunTask(Platform::Thread::File, []
{
Instance().RegisterUgcEditorOpened();
});
}
//static
void Eye::Event::UgcSaved()
{
GetPlatform().RunTask(Platform::Thread::File, []
{
Instance().RegisterUgcSaved();
});
}
// static
void Eye::Event::AddToBookmarkClicked()
{
GetPlatform().RunTask(Platform::Thread::File, []
{
Instance().RegisterAddToBookmarkClicked();
});
}
// static
void Eye::Event::RouteCreatedToObject()
{
GetPlatform().RunTask(Platform::Thread::File, []
{
Instance().RegisterRouteCreatedToObject();
});
}
} // namespace eye

View file

@ -5,8 +5,25 @@
#include "base/atomic_shared_ptr.hpp"
#include "base/macros.hpp"
#include <vector>
namespace eye
{
class Subscriber
{
public:
virtual ~Subscriber() {};
public:
virtual void OnTipClicked(Tip const & tip) {};
virtual void OnBookingFilterUsed(Time const & time) {};
virtual void OnBookmarksCatalogShown(Time const & time) {};
virtual void OnDiscoveryShown(Time const & time) {};
virtual void OnDiscoveryItemClicked(Discovery::Event event) {};
virtual void OnLayerUsed(Layer const & layer) {};
virtual void OnPlacePageOpened(MapObject const & poi) {};
};
// Note This class IS thread-safe.
// All write operations are asynchronous and work on Platform::Thread::File thread.
// Read operations are synchronous and return shared pointer with constant copy of internal
@ -20,17 +37,23 @@ public:
class Event
{
public:
static void TipShown(Tip::Type type, Tip::Event event);
static void TipClicked(Tip::Type type, Tip::Event event);
static void BookingFilterUsed();
static void BoomarksCatalogShown();
static void DiscoveryShown();
static void DiscoveryItemClicked(Discovery::Event event);
static void LayerUsed(Layer::Type type);
static void LayerShown(Layer::Type type);
static void PlacePageOpened();
static void UgcEditorOpened();
static void UgcSaved();
static void AddToBookmarkClicked();
static void RouteCreatedToObject();
};
static Eye & Instance();
InfoType GetInfo() const;
void Subscribe(Subscriber * subscriber);
private:
Eye();
@ -38,14 +61,20 @@ private:
void Save(InfoType const & info);
// Event processing:
void AppendTip(Tip::Type type, Tip::Event event);
void RegisterTipClick(Tip::Type type, Tip::Event event);
void UpdateBookingFilterUsedTime();
void UpdateBoomarksCatalogShownTime();
void UpdateDiscoveryShownTime();
void IncrementDiscoveryItem(Discovery::Event event);
void AppendLayer(Layer::Type type);
void RegisterLayerShown(Layer::Type type);
void RegisterPlacePageOpened();
void RegisterUgcEditorOpened();
void RegisterUgcSaved();
void RegisterAddToBookmarkClicked();
void RegisterRouteCreatedToObject();
base::AtomicSharedPtr<Info> m_info;
std::vector<Subscriber *> m_subscribers;
DISALLOW_COPY_AND_MOVE(Eye);
};