From f9c4591fee76e7e536088d1d8c9512463104caa0 Mon Sep 17 00:00:00 2001 From: Marcin Masternak Date: Tue, 12 Apr 2016 17:23:35 +0200 Subject: [PATCH] Applying Tizen C++ coding style to place context provider(recognition) part 2. Change-Id: Ic8c198dc776eae2261ced0e48b0814ecd0419a5b Signed-off-by: Marcin Masternak --- src/place/PlaceContextProvider.cpp | 4 +- src/place/recognition/place_recognition.cpp | 32 +-- src/place/recognition/place_recognition.h | 12 +- .../recognition/place_recognition_types.h | 4 +- src/place/recognition/user_places/gmap.cpp | 16 +- src/place/recognition/user_places/gmap.h | 6 +- src/place/recognition/user_places/graph.cpp | 14 +- .../user_places/location_logger.cpp | 98 +++++----- .../recognition/user_places/location_logger.h | 15 +- src/place/recognition/user_places/mahal.cpp | 6 +- src/place/recognition/user_places/mahal.h | 4 +- .../recognition/user_places/place_categer.cpp | 77 ++++---- .../recognition/user_places/place_categer.h | 10 +- .../user_places/places_detector.cpp | 184 +++++++++--------- .../recognition/user_places/places_detector.h | 14 +- .../recognition/user_places/user_places.cpp | 24 +-- .../recognition/user_places/user_places.h | 4 +- .../user_places/user_places_types.cpp | 62 +++--- .../user_places/user_places_types.h | 66 ++++--- .../recognition/user_places/visit_categer.cpp | 79 ++++---- .../recognition/user_places/visit_categer.h | 30 +-- .../user_places/visit_detector.cpp | 171 ++++++++-------- .../recognition/user_places/visit_detector.h | 34 ++-- .../user_places/wifi_listener_iface.h | 2 +- .../recognition/user_places/wifi_logger.cpp | 72 +++---- .../recognition/user_places/wifi_logger.h | 16 +- 26 files changed, 532 insertions(+), 524 deletions(-) diff --git a/src/place/PlaceContextProvider.cpp b/src/place/PlaceContextProvider.cpp index f168dd1..8eb7596 100644 --- a/src/place/PlaceContextProvider.cpp +++ b/src/place/PlaceContextProvider.cpp @@ -43,8 +43,8 @@ EXTAPI bool ctx::initPlaceContextProvider() PlaceGeofenceProvider::submitTriggerItem(); #ifndef _DISABLE_RECOG_ENGINE_ - place_recognition_provider::create(NULL); - registerProvider(PLACE_SUBJ_RECOGNITION, PLACE_PRIV_RECOGNITION); + PlaceRecognitionProvider::create(NULL); + registerProvider(PLACE_SUBJ_RECOGNITION, PLACE_PRIV_RECOGNITION); #endif /* _DISABLE_RECOG_ENGINE_ */ #endif /* _MOBILE_ */ diff --git a/src/place/recognition/place_recognition.cpp b/src/place/recognition/place_recognition.cpp index 60b174f..76c09e1 100644 --- a/src/place/recognition/place_recognition.cpp +++ b/src/place/recognition/place_recognition.cpp @@ -19,18 +19,18 @@ #include "place_recognition.h" #include "user_places/user_places.h" -ctx::place_recognition_provider *ctx::place_recognition_provider::__instance = NULL; +ctx::PlaceRecognitionProvider *ctx::PlaceRecognitionProvider::__instance = NULL; -ctx::ContextProviderBase *ctx::place_recognition_provider::create(void *data) +ctx::ContextProviderBase *ctx::PlaceRecognitionProvider::create(void *data) { IF_FAIL_RETURN(!__instance, __instance); - __instance = new(std::nothrow) place_recognition_provider(); + __instance = new(std::nothrow) PlaceRecognitionProvider(); IF_FAIL_RETURN_TAG(__instance, NULL, _E, "Memory allocation failed"); _I(BLUE("Created")); return __instance; } -void ctx::place_recognition_provider::destroy(void *data) +void ctx::PlaceRecognitionProvider::destroy(void *data) { IF_FAIL_VOID(__instance); delete __instance; @@ -38,40 +38,42 @@ void ctx::place_recognition_provider::destroy(void *data) _I(BLUE("Destroyed")); } -int ctx::place_recognition_provider::subscribe(const char *subject, ctx::Json option, ctx::Json* requestResult) +int ctx::PlaceRecognitionProvider::subscribe(const char *subject, ctx::Json option, ctx::Json* requestResult) { return ERR_NOT_SUPPORTED; } -int ctx::place_recognition_provider::unsubscribe(const char *subject, ctx::Json option) +int ctx::PlaceRecognitionProvider::unsubscribe(const char *subject, ctx::Json option) { return ERR_NOT_SUPPORTED; } -int ctx::place_recognition_provider::read(const char *subject, ctx::Json option, ctx::Json* requestResult) +int ctx::PlaceRecognitionProvider::read(const char *subject, ctx::Json option, ctx::Json* requestResult) { _I(BLUE("Read")); _J("Option", option); - std::vector> places = engine.getPlaces(); + std::vector> places = __engine.getPlaces(); Json dataRead = UserPlaces::composeJson(places); - // The below function needs to be called once. - // It does not need to be called within this read() function. - // In can be called later, in another scope. - // Please just be sure that, the 2nd input parameter "option" should be the same to the - // "option" parameter received via ctx::place_recognition_provider::read(). + /* + * The below function needs to be called once. + * It does not need to be called within this read() function. + * In can be called later, in another scope. + * Please just be sure that, the 2nd input parameter "option" should be the same to the + * "option" parameter received via ctx::PlaceRecognitionProvider::read(). + */ ctx::context_manager::replyToRead(PLACE_SUBJ_RECOGNITION, option, ERR_NONE, dataRead); return ERR_NONE; } -int ctx::place_recognition_provider::write(const char *subject, ctx::Json data, ctx::Json* requestResult) +int ctx::PlaceRecognitionProvider::write(const char *subject, ctx::Json data, ctx::Json* requestResult) { return ERR_NOT_SUPPORTED; } -bool ctx::place_recognition_provider::isSupported() +bool ctx::PlaceRecognitionProvider::isSupported() { return true; } diff --git a/src/place/recognition/place_recognition.h b/src/place/recognition/place_recognition.h index f5de60e..545c953 100644 --- a/src/place/recognition/place_recognition.h +++ b/src/place/recognition/place_recognition.h @@ -23,7 +23,7 @@ namespace ctx { - class place_recognition_provider : public ContextProviderBase { + class PlaceRecognitionProvider : public ContextProviderBase { public: static ContextProviderBase *create(void *data); @@ -36,13 +36,13 @@ namespace ctx { int write(const char *subject, ctx::Json data, ctx::Json *requestResult); private: - static place_recognition_provider *__instance; - UserPlaces engine; + static PlaceRecognitionProvider *__instance; + UserPlaces __engine; - place_recognition_provider() : engine(PLACE_RECOG_HIGH_ACCURACY_MODE) {} - ~place_recognition_provider() {} + PlaceRecognitionProvider() : __engine(PLACE_RECOG_HIGH_ACCURACY_MODE) {} + ~PlaceRecognitionProvider() {} - }; /* class place_recognition_provider */ + }; /* class PlaceRecognitionProvider */ } /* namespace ctx */ diff --git a/src/place/recognition/place_recognition_types.h b/src/place/recognition/place_recognition_types.h index 435ea4a..9576331 100644 --- a/src/place/recognition/place_recognition_types.h +++ b/src/place/recognition/place_recognition_types.h @@ -81,9 +81,9 @@ enum PlaceCategId { PLACE_CATEG_ID_OTHER = 3 }; -typedef enum { +enum PlaceRecogMode { PLACE_RECOG_HIGH_ACCURACY_MODE = 0, PLACE_RECOG_LOW_POWER_MODE = 1 -} place_recog_mode_e; +}; #endif /* End of _CONTEXT_PLACE_RECOGNITION_TYPES_ */ diff --git a/src/place/recognition/user_places/gmap.cpp b/src/place/recognition/user_places/gmap.cpp index 99b155a..845b3cf 100644 --- a/src/place/recognition/user_places/gmap.cpp +++ b/src/place/recognition/user_places/gmap.cpp @@ -18,7 +18,7 @@ #include #include -const std::string ctx::Gmap::__htmlHeader = R"( +const std::string ctx::Gmap::__HTML_HEADER = R"( @@ -42,7 +42,7 @@ function initialize() { var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); )"; -const std::string ctx::Gmap::__htmlFooter = R"( +const std::string ctx::Gmap::__HTML_FOOTER = R"( } google.maps.event.addDomListener(window, 'load', initialize); @@ -55,9 +55,9 @@ google.maps.event.addDomListener(window, 'load', initialize); )"; -std::string ctx::Gmap::__iconForCategId(PlaceCategId categ_id) +std::string ctx::Gmap::__iconForCategId(PlaceCategId categId) { - switch (categ_id) { + switch (categId) { case PLACE_CATEG_ID_HOME: return "markerH.png"; case PLACE_CATEG_ID_WORK: return "markerW.png"; case PLACE_CATEG_ID_OTHER: return "markerO.png"; @@ -68,22 +68,22 @@ std::string ctx::Gmap::__iconForCategId(PlaceCategId categ_id) void ctx::Gmap::__placeMarker2Stream(const ctx::Place& place, std::ostream& out) { - if (place.location_valid) { + if (place.locationValid) { out << "new google.maps.Marker({" << std::endl; out << " position: new google.maps.LatLng(" << place.location.latitude << "," << place.location.longitude << ")," << std::endl; out << " map: map," << std::endl; - out << " icon: \"http://maps.google.com/mapfiles/" << __iconForCategId(place.categ_id)<< "\"" << std::endl; + out << " icon: \"http://maps.google.com/mapfiles/" << __iconForCategId(place.categId)<< "\"" << std::endl; out << "});" << std::endl; } } void ctx::Gmap::__html2Stream(const std::vector>& places, std::ostream& out) { - out << __htmlHeader; + out << __HTML_HEADER; for (std::shared_ptr place : places) { __placeMarker2Stream(*place, out); } - out << __htmlFooter; + out << __HTML_FOOTER; } void ctx::Gmap::writeMap(const std::vector>& places) diff --git a/src/place/recognition/user_places/gmap.h b/src/place/recognition/user_places/gmap.h index 5d1f885..29eacd2 100644 --- a/src/place/recognition/user_places/gmap.h +++ b/src/place/recognition/user_places/gmap.h @@ -31,9 +31,9 @@ namespace ctx { class Gmap { private: - const static std::string __htmlHeader; - const static std::string __htmlFooter; - static std::string __iconForCategId(PlaceCategId categ_id); + static const std::string __HTML_HEADER; + static const std::string __HTML_FOOTER; + static std::string __iconForCategId(PlaceCategId categId); static void __placeMarker2Stream(const Place& place, std::ostream& out); static void __html2Stream(const std::vector>& places, std::ostream& out); diff --git a/src/place/recognition/user_places/graph.cpp b/src/place/recognition/user_places/graph.cpp index b8bab27..53daeb3 100644 --- a/src/place/recognition/user_places/graph.cpp +++ b/src/place/recognition/user_places/graph.cpp @@ -32,17 +32,17 @@ std::shared_ptr ctx::graph::connectedComponents(Graph &g ccs->push_back(c); fringe.insert(i); while (!fringe.empty()) { - Node curr_node = *fringe.begin(); + Node currNode = *fringe.begin(); fringe.erase(fringe.begin()); - c->insert(curr_node); + c->insert(currNode); - std::shared_ptr curr_nhood = graph[curr_node]; - for (Node nhood_node : *curr_nhood) { - if (graph[nhood_node] && fringe.find(nhood_node) == fringe.end()) { - fringe.insert(nhood_node); + std::shared_ptr currNhood = graph[currNode]; + for (Node nhoodNode : *currNhood) { + if (graph[nhoodNode] && fringe.find(nhoodNode) == fringe.end()) { + fringe.insert(nhoodNode); } } - graph[curr_node].reset(); // removing current node + graph[currNode].reset(); // removing current node } } return ccs; diff --git a/src/place/recognition/user_places/location_logger.cpp b/src/place/recognition/user_places/location_logger.cpp index 47b5e37..ed9ea6f 100644 --- a/src/place/recognition/user_places/location_logger.cpp +++ b/src/place/recognition/user_places/location_logger.cpp @@ -24,7 +24,7 @@ #include "debug_utils.h" #ifdef TIZEN_ENGINEER_MODE -#define LOCATION_CREATE_TABLE_COLUMNS \ +#define __LOCATION_CREATE_TABLE_COLUMNS \ LOCATION_COLUMN_LATITUDE " REAL NOT NULL, "\ LOCATION_COLUMN_LONGITUDE " REAL NOT NULL, "\ LOCATION_COLUMN_ACCURACY " REAL, "\ @@ -32,14 +32,14 @@ LOCATION_COLUMN_TIMESTAMP_HUMAN " TEXT, "\ LOCATION_COLUMN_METHOD " INTEGER " #else /* TIZEN_ENGINEER_MODE */ -#define LOCATION_CREATE_TABLE_COLUMNS \ +#define __LOCATION_CREATE_TABLE_COLUMNS \ LOCATION_COLUMN_LATITUDE " REAL NOT NULL, "\ LOCATION_COLUMN_LONGITUDE " REAL NOT NULL, "\ LOCATION_COLUMN_ACCURACY " REAL, "\ LOCATION_COLUMN_TIMESTAMP " timestamp NOT NULL " #endif /* TIZEN_ENGINEER_MODE */ -#define _LOCATION_ERROR_LOG(error) { \ +#define __LOCATION_ERROR_LOG(error) { \ if (error != LOCATIONS_ERROR_NONE) { \ _E("ERROR == %s", __locationError2Str(error)); \ } else { \ @@ -47,9 +47,9 @@ } \ } -void ctx::LocationLogger::__locationServiceStateChangedCb(location_service_state_e state, void *user_data) +void ctx::LocationLogger::__locationServiceStateChangedCb(location_service_state_e state, void *userData) { - ctx::LocationLogger* locationLogger = (ctx::LocationLogger *)user_data; + ctx::LocationLogger* locationLogger = (ctx::LocationLogger *)userData; locationLogger->__locationServiceState = state; if (state == LOCATIONS_SERVICE_ENABLED) { _D("LOCATIONS_SERVICE_ENABLED"); @@ -73,9 +73,9 @@ void ctx::LocationLogger::__locationServiceStateChangedCb(location_service_state } } -void ctx::LocationLogger::__locationSettingChangedCb(location_method_e method, bool enable, void *user_data) +void ctx::LocationLogger::__locationSettingChangedCb(location_method_e method, bool enable, void *userData) { - ctx::LocationLogger* locationLogger = (ctx::LocationLogger *)user_data; + ctx::LocationLogger* locationLogger = (ctx::LocationLogger *)userData; locationLogger->__locationMethodState = enable; if (method == locationLogger->__locationMethod) { if (enable) { @@ -106,10 +106,10 @@ void ctx::LocationLogger::__locationSettingChangedCb(location_method_e method, b } void ctx::LocationLogger::__positionUpdatedCb(double latitude, double longitude, - double altitude, time_t timestamp, void *user_data) + double altitude, time_t timestamp, void *userData) { _D(""); - ctx::LocationLogger* locationLogger = (ctx::LocationLogger *)user_data; + ctx::LocationLogger* locationLogger = (ctx::LocationLogger *)userData; double horizontal = locationLogger->__locationManagerGetHorizontalAccuracy(); #ifdef TIZEN_ENGINEER_MODE ctx::LocationEvent location(latitude, longitude, horizontal, timestamp, LOCATION_METHOD_REQUEST); @@ -121,10 +121,10 @@ void ctx::LocationLogger::__positionUpdatedCb(double latitude, double longitude, } void ctx::LocationLogger::__locationUpdatedCb(location_error_e error, double latitude, double longitude, - double altitude, time_t timestamp, double speed, double direction, double climb, void *user_data) + double altitude, time_t timestamp, double speed, double direction, double climb, void *userData) { _D(""); - __positionUpdatedCb(latitude, longitude, altitude, timestamp, user_data); + __positionUpdatedCb(latitude, longitude, altitude, timestamp, userData); } const char* ctx::LocationLogger::__locationError2Str(int error) @@ -175,26 +175,26 @@ void ctx::LocationLogger::__log(location_accessibility_state_e state) int ctx::LocationLogger::__dbCreateTable() { - bool ret = db_manager::create_table(0, LOCATION_TABLE_NAME, LOCATION_CREATE_TABLE_COLUMNS, NULL, NULL); + bool ret = db_manager::create_table(0, LOCATION_TABLE_NAME, __LOCATION_CREATE_TABLE_COLUMNS, NULL, NULL); _D("%s -> Table Creation Request", ret ? "SUCCESS" : "FAIL"); return 0; } -int ctx::LocationLogger::__dbInsertLog(LocationEvent location_event) +int ctx::LocationLogger::__dbInsertLog(LocationEvent locationEvent) { Json data; - data.set(NULL, LOCATION_COLUMN_LATITUDE, location_event.coordinates.latitude); - data.set(NULL, LOCATION_COLUMN_LONGITUDE, location_event.coordinates.longitude); - data.set(NULL, LOCATION_COLUMN_ACCURACY, location_event.coordinates.accuracy); - data.set(NULL, LOCATION_COLUMN_TIMESTAMP, static_cast(location_event.timestamp)); + data.set(NULL, LOCATION_COLUMN_LATITUDE, locationEvent.coordinates.latitude); + data.set(NULL, LOCATION_COLUMN_LONGITUDE, locationEvent.coordinates.longitude); + data.set(NULL, LOCATION_COLUMN_ACCURACY, locationEvent.coordinates.accuracy); + data.set(NULL, LOCATION_COLUMN_TIMESTAMP, static_cast(locationEvent.timestamp)); #ifdef TIZEN_ENGINEER_MODE - std::string time_human = DebugUtils::humanReadableDateTime(location_event.timestamp, "%F %T", 80); - data.set(NULL, LOCATION_COLUMN_TIMESTAMP_HUMAN, time_human); - data.set(NULL, LOCATION_COLUMN_METHOD, static_cast(location_event.method)); + std::string timeHuman = DebugUtils::humanReadableDateTime(locationEvent.timestamp, "%F %T", 80); + data.set(NULL, LOCATION_COLUMN_TIMESTAMP_HUMAN, timeHuman); + data.set(NULL, LOCATION_COLUMN_METHOD, static_cast(locationEvent.method)); #endif /* TIZEN_ENGINEER_MODE */ - int64_t row_id; - bool ret = db_manager::insert_sync(LOCATION_TABLE_NAME, data, &row_id); + int64_t rowId; + bool ret = db_manager::insert_sync(LOCATION_TABLE_NAME, data, &rowId); _D("%s -> DB: location table insert result", ret ? "SUCCESS" : "FAIL"); return ret; } @@ -243,46 +243,46 @@ ctx::LocationLogger::~LocationLogger() void ctx::LocationLogger::__locationManagerCreate() { int ret = location_manager_create(__locationMethod, &__locationManager); - _LOCATION_ERROR_LOG(ret); + __LOCATION_ERROR_LOG(ret); } void ctx::LocationLogger::__locationManagerDestroy() { int ret = location_manager_destroy(__locationManager); - _LOCATION_ERROR_LOG(ret); + __LOCATION_ERROR_LOG(ret); } void ctx::LocationLogger::__locationManagerSetServiceStateChangedCb() { int ret = location_manager_set_service_state_changed_cb(__locationManager, __locationServiceStateChangedCb, this); - _LOCATION_ERROR_LOG(ret); + __LOCATION_ERROR_LOG(ret); } void ctx::LocationLogger::__locationManagerUnsetServiceStateChangedCb() { int ret = location_manager_unset_service_state_changed_cb(__locationManager); - _LOCATION_ERROR_LOG(ret); + __LOCATION_ERROR_LOG(ret); } void ctx::LocationLogger::__locationManagerStart() { int ret = location_manager_start(__locationManager); - _LOCATION_ERROR_LOG(ret); + __LOCATION_ERROR_LOG(ret); __startServiceTimerStart(); } void ctx::LocationLogger::__locationManagerStop() { int ret = location_manager_stop(__locationManager); - _LOCATION_ERROR_LOG(ret); + __LOCATION_ERROR_LOG(ret); } double ctx::LocationLogger::__locationManagerGetHorizontalAccuracy() { - location_accuracy_level_e accuracy_level; + location_accuracy_level_e accuracyLevel; double horizontal, vertical; - int ret = location_manager_get_accuracy(__locationManager, &accuracy_level, &horizontal, &vertical); - _LOCATION_ERROR_LOG(ret); + int ret = location_manager_get_accuracy(__locationManager, &accuracyLevel, &horizontal, &vertical); + __LOCATION_ERROR_LOG(ret); return horizontal; } @@ -290,20 +290,20 @@ location_accessibility_state_e ctx::LocationLogger::__locationManagerGetAccessib { location_accessibility_state_e state; int ret = location_manager_get_accessibility_state(&state); - _LOCATION_ERROR_LOG(ret); + __LOCATION_ERROR_LOG(ret); return state; } void ctx::LocationLogger::__locationManagerSetSettingChangedCb() { int ret = location_manager_set_setting_changed_cb(__locationMethod, __locationSettingChangedCb, this); - _LOCATION_ERROR_LOG(ret); + __LOCATION_ERROR_LOG(ret); } void ctx::LocationLogger::__locationManagerUnsetSettingChangedCb() { int ret = location_manager_unset_setting_changed_cb(__locationMethod); - _LOCATION_ERROR_LOG(ret); + __LOCATION_ERROR_LOG(ret); } bool ctx::LocationLogger::__locationManagerRequestSingleLocation() @@ -321,7 +321,7 @@ bool ctx::LocationLogger::__locationManagerRequestSingleLocation() LOCATION_LOGGER_MAX_LOCATION_ATTEMPTS, __locationCount, LOCATION_LOGGER_MAX_LOCATION_COUNT); - _LOCATION_ERROR_LOG(ret); + __LOCATION_ERROR_LOG(ret); __activeRequestAttempts++; __activeAttempts++; __allAttempts++; @@ -350,7 +350,7 @@ bool ctx::LocationLogger::__locationManagerGetLocation() LOCATION_LOGGER_MAX_LOCATION_ATTEMPTS, __locationCount, LOCATION_LOGGER_MAX_LOCATION_COUNT); - _LOCATION_ERROR_LOG(ret); + __LOCATION_ERROR_LOG(ret); __activeAttempts++; __allAttempts++; if (ret == LOCATIONS_ERROR_NONE) { @@ -384,7 +384,7 @@ void ctx::LocationLogger::__locationManagerGetLastLocation() LOCATION_LOGGER_MAX_LOCATION_ATTEMPTS, __locationCount, LOCATION_LOGGER_MAX_LOCATION_COUNT); - _LOCATION_ERROR_LOG(ret); + __LOCATION_ERROR_LOG(ret); __allAttempts++; if (ret == LOCATIONS_ERROR_NONE) { #ifdef TIZEN_ENGINEER_MODE @@ -400,7 +400,7 @@ bool ctx::LocationLogger::__locationManagerIsEnabledMethod(location_method_e met { bool enable; int ret = location_manager_is_enabled_method(method, &enable); - _LOCATION_ERROR_LOG(ret); + __LOCATION_ERROR_LOG(ret); return enable; } @@ -425,19 +425,19 @@ bool ctx::LocationLogger::__checkActiveRequestLimits() void ctx::LocationLogger::__locationRequest() { _D(""); - bool request_single_location_ret = false; - bool get_location_ret = false; + bool requestSingleLocationRet = false; + bool getLocationRet = false; if (__checkGeneralLimits() && __checkActiveLimits() && __checkActiveRequestLimits()) { - request_single_location_ret = __locationManagerRequestSingleLocation(); + requestSingleLocationRet = __locationManagerRequestSingleLocation(); } - if (__checkGeneralLimits() && __checkActiveLimits() && !request_single_location_ret) { - get_location_ret = __locationManagerGetLocation(); + if (__checkGeneralLimits() && __checkActiveLimits() && !requestSingleLocationRet) { + getLocationRet = __locationManagerGetLocation(); } - if (__checkGeneralLimits() && !request_single_location_ret && !get_location_ret + if (__checkGeneralLimits() && !requestSingleLocationRet && !getLocationRet && __activeAttempts >= LOCATION_LOGGER_MAX_ACTIVE_LOCATION_ATTEMPTS) { __locationManagerGetLastLocation(); } - if (!request_single_location_ret) { + if (!requestSingleLocationRet) { __locationManagerStop(); __setNextTimer(); } @@ -477,15 +477,15 @@ void ctx::LocationLogger::__onActiveLocationSucceeded() __activeLocationSucceeded = true; } -void ctx::LocationLogger::__broadcast(ctx::LocationEvent location_event) +void ctx::LocationLogger::__broadcast(ctx::LocationEvent locationEvent) { _D(""); __locationCount++; if (__listener) { - __listener->onNewLocation(location_event); + __listener->onNewLocation(locationEvent); } if (LOCATION_LOGGER_DATABASE) { - __dbInsertLog(location_event); + __dbInsertLog(locationEvent); } } @@ -612,4 +612,4 @@ void ctx::LocationLogger::onVisitEnd() } } -#undef _LOCATION_ERROR_LOG +#undef __LOCATION_ERROR_LOG diff --git a/src/place/recognition/user_places/location_logger.h b/src/place/recognition/user_places/location_logger.h index caa1f21..ae4c9bd 100644 --- a/src/place/recognition/user_places/location_logger.h +++ b/src/place/recognition/user_places/location_logger.h @@ -65,8 +65,7 @@ namespace ctx { class LocationLogger : public ITimerListener, public IVisitListener { public: - LocationLogger(ILocationListener *listener = nullptr, - bool testMode = false); + LocationLogger(ILocationListener *listener = nullptr, bool testMode = false); ~LocationLogger(); private: @@ -76,7 +75,7 @@ namespace ctx { /* OUTPUT */ ILocationListener * const __listener; - void __broadcast(LocationEvent location_event); + void __broadcast(LocationEvent locationEvent); /* INTERNAL */ bool __testMode; @@ -115,7 +114,7 @@ namespace ctx { /* DATABASE */ static int __dbCreateTable(); - int __dbInsertLog(LocationEvent location_event); + int __dbInsertLog(LocationEvent locationEvent); /* DEBUG */ static const char* __locationError2Str(int error); @@ -131,7 +130,7 @@ namespace ctx { /* LOCATION MANAGER : LOCATION SERVICE STATE */ location_service_state_e __locationServiceState; - static void __locationServiceStateChangedCb(location_service_state_e state, void *user_data); + static void __locationServiceStateChangedCb(location_service_state_e state, void *userData); void __locationManagerSetServiceStateChangedCb(); void __locationManagerUnsetServiceStateChangedCb(); @@ -139,7 +138,7 @@ namespace ctx { location_method_e __locationMethod; bool __locationMethodState; bool __locationManagerIsEnabledMethod(location_method_e method); - static void __locationSettingChangedCb(location_method_e method, bool enable, void *user_data); + static void __locationSettingChangedCb(location_method_e method, bool enable, void *userData); void __locationManagerSetSettingChangedCb(); void __locationManagerUnsetSettingChangedCb(); @@ -152,10 +151,10 @@ namespace ctx { /* LOCATION MANAGER : LOCATION : ASYNCHRONOUS */ static void __positionUpdatedCb(double latitude, double longitude, - double altitude, time_t timestamp, void *user_data); + double altitude, time_t timestamp, void *userData); static void __locationUpdatedCb(location_error_e error, double latitude, double longitude, double altitude, time_t timestamp, double speed, - double direction, double climb, void *user_data); + double direction, double climb, void *userData); bool __locationManagerRequestSingleLocation(); }; /* class LocationLogger */ diff --git a/src/place/recognition/user_places/mahal.cpp b/src/place/recognition/user_places/mahal.cpp index f1bdae8..cd7ff78 100644 --- a/src/place/recognition/user_places/mahal.cpp +++ b/src/place/recognition/user_places/mahal.cpp @@ -18,7 +18,7 @@ #include #include -ctx::num_t ctx::MahalModel::dist_s(const std::vector &v1, const std::vector &v2, const std::vector &m) +ctx::num_t ctx::MahalModel::distance(const std::vector &v1, const std::vector &v2, const std::vector &m) { size_t n = v1.size(); if (m.size() != n * n) { @@ -40,7 +40,7 @@ ctx::num_t ctx::MahalModel::dist_s(const std::vector &v1, const std::vect return sqrt(dist2); } -ctx::num_t ctx::MahalModel::dist(const std::vector &v) +ctx::num_t ctx::MahalModel::distance(const std::vector &v) { - return dist_s(v, __mean, __sigma); + return distance(v, __mean, __sigma); } diff --git a/src/place/recognition/user_places/mahal.h b/src/place/recognition/user_places/mahal.h index 34093f2..9e733c7 100644 --- a/src/place/recognition/user_places/mahal.h +++ b/src/place/recognition/user_places/mahal.h @@ -32,11 +32,11 @@ namespace ctx { std::vector __sigma; // represents square matrix row-wise public: - static num_t dist_s(const std::vector &v1, const std::vector &v2, const std::vector &m); + static num_t distance(const std::vector &v1, const std::vector &v2, const std::vector &m); MahalModel(std::vector mean, std::vector sigma) : __mean(mean), __sigma(sigma) { } - num_t dist(const std::vector &v); + num_t distance(const std::vector &v); }; /* class MahalModel */ diff --git a/src/place/recognition/user_places/place_categer.cpp b/src/place/recognition/user_places/place_categer.cpp index 685f138..f71fe2c 100644 --- a/src/place/recognition/user_places/place_categer.cpp +++ b/src/place/recognition/user_places/place_categer.cpp @@ -22,74 +22,74 @@ #include #include -void ctx::PlaceCateger::reduceOutliers(ctx::visits_t &visits) +void ctx::PlaceCateger::reduceOutliers(ctx::Visits &visits) { int size = visits.size(); visits.erase(std::remove_if( visits.begin(), visits.end(), - [](Visit v) { + [](Visit v)->bool { return v.categs[PLACE_CATEG_ID_HOME] < PLACES_CATEGER_MIN_VISITS_SCORE && v.categs[PLACE_CATEG_ID_WORK] < PLACES_CATEGER_MIN_VISITS_SCORE && v.categs[PLACE_CATEG_ID_OTHER] < PLACES_CATEGER_MIN_VISITS_SCORE; }), visits.end()); - int new_size = visits.size(); - if (size != new_size) { - _D("Visits number from %d to %d (visits min scores checking)", size, new_size); + int newSize = visits.size(); + if (size != newSize) { + _D("Visits number from %d to %d (visits min scores checking)", size, newSize); } } /* * Change category if home or work has to few visits */ -bool ctx::PlaceCateger::__reduceCategory(const PlaceCategId &categ, const ctx::visits_t &visits) +bool ctx::PlaceCateger::__reduceCategory(const PlaceCategId &categId, const ctx::Visits &visits) { - return (categ == PLACE_CATEG_ID_HOME && visits.size() < PLACES_CATEGER_MIN_VISITS_PER_HOME) - || (categ == PLACE_CATEG_ID_WORK && visits.size() < PLACES_CATEGER_MIN_VISITS_PER_WORK); + return (categId == PLACE_CATEG_ID_HOME && visits.size() < PLACES_CATEGER_MIN_VISITS_PER_HOME) + || (categId == PLACE_CATEG_ID_WORK && visits.size() < PLACES_CATEGER_MIN_VISITS_PER_WORK); } -void ctx::PlaceCateger::categorize(ctx::visits_t &visits, ctx::Place &place) +void ctx::PlaceCateger::categorize(ctx::Visits &visits, ctx::Place &place) { reduceOutliers(visits); - place.categ_id = PLACE_CATEG_ID_NONE; - place.categ_confidence = 0.0; + place.categId = PLACE_CATEG_ID_NONE; + place.categConfidence = 0.0; if (!visits.empty()) { - const std::vector categ_ids = { + const std::vector categIds = { PLACE_CATEG_ID_HOME, PLACE_CATEG_ID_WORK, PLACE_CATEG_ID_OTHER }; - num_t sum_score = 0.0; - num_t max_score = 0.0; - for (PlaceCategId categ_id : categ_ids) { - std::vector categ_vector = categVectorFromVisits(visits, categ_id); - num_t score = median(categ_vector); - sum_score += score; - if (score > max_score) { - max_score = score; - place.categ_id = categ_id; + num_t sumScore = 0.0; + num_t maxScore = 0.0; + for (PlaceCategId categId : categIds) { + std::vector categVector = categVectorFromVisits(visits, categId); + num_t score = median(categVector); + sumScore += score; + if (score > maxScore) { + maxScore = score; + place.categId = categId; } } - if (sum_score > 0) { - place.categ_confidence = max_score / sum_score; + if (sumScore > 0) { + place.categConfidence = maxScore / sumScore; } - if (__reduceCategory(place.categ_id, visits)) { - place.categ_id = PLACE_CATEG_ID_OTHER; - place.categ_confidence = 0.0; + if (__reduceCategory(place.categId, visits)) { + place.categId = PLACE_CATEG_ID_OTHER; + place.categConfidence = 0.0; } } - place.name = categId2Name(place.categ_id); + place.name = categId2Name(place.categId); } -std::vector ctx::PlaceCateger::categVectorFromVisits(const ctx::visits_t &visits, PlaceCategId categ_id) +std::vector ctx::PlaceCateger::categVectorFromVisits(const ctx::Visits &visits, PlaceCategId categId) { std::vector vec; for (auto &visit : visits) { - auto search = visit.categs.find(categ_id); + auto search = visit.categs.find(categId); if (search != visit.categs.end()) { vec.push_back(search->second); } @@ -97,12 +97,17 @@ std::vector ctx::PlaceCateger::categVectorFromVisits(const ctx::visi return vec; } -std::string ctx::PlaceCateger::categId2Name(PlaceCategId categ_id) { - switch (categ_id) { - case PLACE_CATEG_ID_HOME: return "home"; - case PLACE_CATEG_ID_WORK: return "work"; - case PLACE_CATEG_ID_OTHER: return "other"; - case PLACE_CATEG_ID_NONE: return "none"; - default: return ""; +std::string ctx::PlaceCateger::categId2Name(PlaceCategId categId) { + switch (categId) { + case PLACE_CATEG_ID_HOME: + return "home"; + case PLACE_CATEG_ID_WORK: + return "work"; + case PLACE_CATEG_ID_OTHER: + return "other"; + case PLACE_CATEG_ID_NONE: + return "none"; + default: + return ""; } } diff --git a/src/place/recognition/user_places/place_categer.h b/src/place/recognition/user_places/place_categer.h index 05612f3..0d127b1 100644 --- a/src/place/recognition/user_places/place_categer.h +++ b/src/place/recognition/user_places/place_categer.h @@ -28,13 +28,13 @@ namespace ctx { class PlaceCateger { private: - static bool __reduceCategory(const PlaceCategId &categ, const ctx::visits_t &visits); + static bool __reduceCategory(const PlaceCategId &categId, const ctx::Visits &visits); public: - static void reduceOutliers(visits_t &visits); // TODO: move to private - static std::vector categVectorFromVisits(const ctx::visits_t &visits, PlaceCategId categ_id); // TODO: move to private - static void categorize(ctx::visits_t &visits, ctx::Place &place); - static std::string categId2Name(PlaceCategId categ_id); // TODO: move to private + static void reduceOutliers(Visits &visits); // TODO: move to private + static std::vector categVectorFromVisits(const ctx::Visits &visits, PlaceCategId categId); // TODO: move to private + static void categorize(ctx::Visits &visits, ctx::Place &place); + static std::string categId2Name(PlaceCategId categId); // TODO: move to private }; /* class PlaceCateger */ diff --git a/src/place/recognition/user_places/places_detector.cpp b/src/place/recognition/user_places/places_detector.cpp index 40faf67..88281cf 100644 --- a/src/place/recognition/user_places/places_detector.cpp +++ b/src/place/recognition/user_places/places_detector.cpp @@ -31,13 +31,13 @@ #include #include "user_places_params.h" -#define DELETE_PLACES_QUERY "DELETE FROM " PLACE_TABLE +#define __DELETE_PLACES_QUERY "DELETE FROM " PLACE_TABLE #ifdef TIZEN_ENGINEER_MODE -#define USER_PLACES_FILE "/opt/usr/media/Others/user_places.txt" // TODO: Only for debug purposes -> Remove in final solution +#define __USER_PLACES_FILE "/opt/usr/media/Others/user_places.txt" // TODO: Only for debug purposes -> Remove in final solution #endif /* TIZEN_ENGINEER_MODE */ -#define GET_VISITS_QUERY "SELECT "\ +#define __GET_VISITS_QUERY "SELECT "\ VISIT_COLUMN_END_TIME ", "\ VISIT_COLUMN_START_TIME ", "\ VISIT_COLUMN_WIFI_APS ", "\ @@ -49,7 +49,7 @@ VISIT_COLUMN_CATEG_OTHER \ " FROM " VISIT_TABLE -#define GET_PLACES_QUERY "SELECT "\ +#define __GET_PLACES_QUERY "SELECT "\ PLACE_COLUMN_CATEG_ID ", "\ PLACE_COLUMN_CATEG_CONFIDENCE ", "\ PLACE_COLUMN_NAME ", "\ @@ -60,7 +60,7 @@ PLACE_COLUMN_CREATE_DATE \ " FROM " PLACE_TABLE -#define PLACE_TABLE_COLUMNS \ +#define __PLACE_TABLE_COLUMNS \ PLACE_COLUMN_CATEG_ID " INTEGER, "\ PLACE_COLUMN_CATEG_CONFIDENCE " REAL, "\ PLACE_COLUMN_NAME " TEXT, "\ @@ -76,7 +76,7 @@ bool ctx::PlacesDetector::onTimerExpired(int timerId) __dbDeletePlaces(); __dbDeleteOldVisits(); std::vector records = __dbGetVisits(); - visits_t visits = __visitsFromJsons(records); + Visits visits = __visitsFromJsons(records); __processVisits(visits); return true; } @@ -84,7 +84,7 @@ bool ctx::PlacesDetector::onTimerExpired(int timerId) std::vector ctx::PlacesDetector::__dbGetVisits() { std::vector records; - bool ret = db_manager::execute_sync(GET_VISITS_QUERY, &records); + bool ret = db_manager::execute_sync(__GET_VISITS_QUERY, &records); _D("load visits execute query result: %s", ret ? "SUCCESS" : "FAIL"); return records; } @@ -92,7 +92,7 @@ std::vector ctx::PlacesDetector::__dbGetVisits() std::vector ctx::PlacesDetector::__dbGetPlaces() { std::vector records; - bool ret = db_manager::execute_sync(GET_PLACES_QUERY, &records); + bool ret = db_manager::execute_sync(__GET_PLACES_QUERY, &records); _D("load places execute query result: %s", ret ? "SUCCESS" : "FAIL"); return records; } @@ -105,9 +105,9 @@ double ctx::PlacesDetector::__doubleValueFromJson(Json &row, const char* key) return value; } -ctx::categs_t ctx::PlacesDetector::__visitCategsFromJson(Json &row) +ctx::Categs ctx::PlacesDetector::__visitCategsFromJson(Json &row) { - categs_t categs; + Categs categs; categs[PLACE_CATEG_ID_HOME] = __doubleValueFromJson(row, VISIT_COLUMN_CATEG_HOME); categs[PLACE_CATEG_ID_WORK] = __doubleValueFromJson(row, VISIT_COLUMN_CATEG_WORK); categs[PLACE_CATEG_ID_OTHER] = __doubleValueFromJson(row, VISIT_COLUMN_CATEG_OTHER); @@ -116,27 +116,27 @@ ctx::categs_t ctx::PlacesDetector::__visitCategsFromJson(Json &row) ctx::Visit ctx::PlacesDetector::__visitFromJson(Json &row) { - int start_time; - int end_time; - std::string mac_set_string; - row.get(NULL, VISIT_COLUMN_START_TIME, &start_time); - row.get(NULL, VISIT_COLUMN_END_TIME, &end_time); - row.get(NULL, VISIT_COLUMN_WIFI_APS, &mac_set_string); + int startTime; + int endTime; + std::string str; + row.get(NULL, VISIT_COLUMN_START_TIME, &startTime); + row.get(NULL, VISIT_COLUMN_END_TIME, &endTime); + row.get(NULL, VISIT_COLUMN_WIFI_APS, &str); - std::stringstream mac_set_ss; - mac_set_ss << mac_set_string; - std::shared_ptr macSet = std::make_shared(); - mac_set_ss >> *macSet; + std::stringstream ss; + ss << str; + std::shared_ptr macSet = std::make_shared(); + ss >> *macSet; - Interval interval(start_time, end_time); - categs_t categs = __visitCategsFromJson(row); + Interval interval(startTime, endTime); + Categs categs = __visitCategsFromJson(row); Visit visit(interval, macSet, categs); { // location - int location_valid_int; - row.get(NULL, VISIT_COLUMN_LOCATION_VALID, &location_valid_int); - visit.location_valid = (bool) location_valid_int; + int locationValidInt; + row.get(NULL, VISIT_COLUMN_LOCATION_VALID, &locationValidInt); + visit.locationValid = (bool) locationValidInt; row.get(NULL, VISIT_COLUMN_LOCATION_LATITUDE, &(visit.location.latitude)); row.get(NULL, VISIT_COLUMN_LOCATION_LONGITUDE, &(visit.location.longitude)); } @@ -144,9 +144,9 @@ ctx::Visit ctx::PlacesDetector::__visitFromJson(Json &row) return visit; } -ctx::visits_t ctx::PlacesDetector::__visitsFromJsons(std::vector& records) +ctx::Visits ctx::PlacesDetector::__visitsFromJsons(std::vector& records) { - visits_t visits; + Visits visits; _D("db_result: number of all visits: %d", records.size()); for (Json &row : records) { @@ -161,27 +161,27 @@ std::shared_ptr ctx::PlacesDetector::__placeFromJson(Json &row) { std::shared_ptr place = std::make_shared(); { // category - int categ_id; - row.get(NULL, PLACE_COLUMN_CATEG_ID, &categ_id); + int categId; + row.get(NULL, PLACE_COLUMN_CATEG_ID, &categId); // This is due to the fact the JSON module API interface doesn't handle enum - place->categ_id = static_cast(categ_id); + place->categId = static_cast(categId); } row.get(NULL, PLACE_COLUMN_NAME, &(place->name)); - row.get(NULL, PLACE_COLUMN_WIFI_APS, &(place->wifi_aps)); + row.get(NULL, PLACE_COLUMN_WIFI_APS, &(place->wifiAps)); { // location - int location_valid_int; - row.get(NULL, PLACE_COLUMN_LOCATION_VALID, &location_valid_int); - place->location_valid = (bool) location_valid_int; + int locationValidInt; + row.get(NULL, PLACE_COLUMN_LOCATION_VALID, &locationValidInt); + place->locationValid = (bool) locationValidInt; row.get(NULL, PLACE_COLUMN_LOCATION_LATITUDE, &(place->location.latitude)); row.get(NULL, PLACE_COLUMN_LOCATION_LONGITUDE, &(place->location.longitude)); } - { // create_date - int create_date; - row.get(NULL, PLACE_COLUMN_CREATE_DATE, &(create_date)); + { // createDate + int createDate; + row.get(NULL, PLACE_COLUMN_CREATE_DATE, &(createDate)); // This is due to the fact the JSON module API interface doesn't handle time_t - place->create_date = static_cast(create_date); + place->createDate = static_cast(createDate); } - _D("db_result: categ_id: %d; place: name: %s; wifi_aps: %s; location_valid: %d; latitude: %lf, longitude: %lf, create_date: %d", place->categ_id, place->name.c_str(), place->wifi_aps.c_str(), place->location_valid, place->location.latitude, place->location.longitude, place->create_date); + _D("db_result: categId: %d; place: name: %s; wifiAps: %s; locationValid: %d; latitude: %lf, longitude: %lf, createDate: %d", place->categId, place->name.c_str(), place->wifiAps.c_str(), place->locationValid, place->location.latitude, place->location.longitude, place->createDate); return place; } @@ -198,25 +198,25 @@ std::vector> ctx::PlacesDetector::__placesFromJsons( return places; } -void ctx::PlacesDetector::reduceOutliers(ctx::visits_t &visits) +void ctx::PlacesDetector::reduceOutliers(ctx::Visits &visits) { int size = visits.size(); visits.erase(std::remove_if( visits.begin(), visits.end(), - [](Visit v) { + [](Visit v)->bool { int minutes = (v.interval.end - v.interval.start) / 60; return (minutes < PLACES_DETECTOR_MIN_VISIT_DURATION_MINUTES) || (minutes > PLACES_DETECTOR_MAX_VISIT_DURATION_MINUTES); }), visits.end()); - int new_size = visits.size(); - if (size != new_size) { - _D("Visits number from %d to %d (to short and to long reduction)", size, new_size); + int newSize = visits.size(); + if (size != newSize) { + _D("Visits number from %d to %d (to short and to long reduction)", size, newSize); } } -void ctx::PlacesDetector::__processVisits(ctx::visits_t &visits) +void ctx::PlacesDetector::__processVisits(ctx::Visits &visits) { reduceOutliers(visits); @@ -224,7 +224,7 @@ void ctx::PlacesDetector::__processVisits(ctx::visits_t &visits) auto components = __mergeVisits(visits); std::vector> newDetectedPlaces; #ifdef TIZEN_ENGINEER_MODE - std::vector places_visits; // TODO: remove from final solution. + std::vector placesVisits; // TODO: remove from final solution. #endif /* TIZEN_ENGINEER_MODE */ for (std::shared_ptr component : *components) { // Small places outliers reduction @@ -232,12 +232,12 @@ void ctx::PlacesDetector::__processVisits(ctx::visits_t &visits) continue; } - std::shared_ptr merged = std::make_shared(); + std::shared_ptr merged = std::make_shared(); for (graph::Node i : *component) { merged->push_back(visits[i]); } std::shared_ptr place = __placeFromMergedVisits(*merged); - if (place->categ_id == PLACE_CATEG_ID_NONE) { + if (place->categId == PLACE_CATEG_ID_NONE) { continue; } newDetectedPlaces.push_back(place); @@ -247,11 +247,11 @@ void ctx::PlacesDetector::__processVisits(ctx::visits_t &visits) #ifdef TIZEN_ENGINEER_MODE { // TODO: Only for debug -> remove in final solution - visits_t place_visits; + Visits placeVisits; for (graph::Node i : *component) { - place_visits.push_back(visits[i]); + placeVisits.push_back(visits[i]); } - places_visits.push_back(place_visits); + placesVisits.push_back(placeVisits); } #endif /* TIZEN_ENGINEER_MODE */ } @@ -260,12 +260,12 @@ void ctx::PlacesDetector::__processVisits(ctx::visits_t &visits) #ifdef TIZEN_ENGINEER_MODE { // Print to file TODO: Only for debug -> remove in final solution - std::ofstream out(USER_PLACES_FILE); + std::ofstream out(__USER_PLACES_FILE); for (size_t i = 0; i < newDetectedPlaces.size(); i++) { - newDetectedPlaces[i]->print_to_stream(out); - visits_t place_visits = places_visits[i]; - for (Visit visit : place_visits) { - visit.print_short_to_stream(out); + newDetectedPlaces[i]->print2Stream(out); + Visits placeVisits = placesVisits[i]; + for (Visit visit : placeVisits) { + visit.printShort2Stream(out); } } out.close(); @@ -277,47 +277,47 @@ void ctx::PlacesDetector::__processVisits(ctx::visits_t &visits) /* * Replace old places by new ones. */ -void ctx::PlacesDetector::__detectedPlacesUpdate(std::vector> &new_places) +void ctx::PlacesDetector::__detectedPlacesUpdate(std::vector> &newPlaces) { _D(""); // XXX: In case of thread safety issues use std::mutex to protect places list. - __detectedPlaces = new_places; + __detectedPlaces = newPlaces; } -void ctx::PlacesDetector::__mergeLocation(const visits_t &visits, Place &place) +void ctx::PlacesDetector::__mergeLocation(const Visits &visits, Place &place) { - place.location_valid = false; + place.locationValid = false; std::vector latitudes; std::vector longitudes; for (const Visit& visit : visits) { - if (visit.location_valid) { + if (visit.locationValid) { latitudes.push_back(visit.location.latitude); longitudes.push_back(visit.location.longitude); - place.location_valid = true; + place.locationValid = true; } } - if (place.location_valid) { + if (place.locationValid) { place.location.latitude = median(latitudes); place.location.longitude = median(longitudes); } } -std::shared_ptr ctx::PlacesDetector::__placeFromMergedVisits(visits_t &merged_visits) +std::shared_ptr ctx::PlacesDetector::__placeFromMergedVisits(Visits &mergedVisits) { std::shared_ptr place = std::make_shared(); - place->create_date = std::time(nullptr); - std::vector> macSets; - for (const Visit &visit : merged_visits) { + place->createDate = std::time(nullptr); + std::vector> macSets; + for (const Visit &visit : mergedVisits) { macSets.push_back(visit.macSet); } - std::shared_ptr all_macs = mac_sets_union(macSets); - std::stringstream all_macs_ss; - all_macs_ss << *all_macs; - place->wifi_aps = all_macs_ss.str(); + std::shared_ptr allMacs = macSetsUnion(macSets); + std::stringstream ss; + ss << *allMacs; + place->wifiAps = ss.str(); - __mergeLocation(merged_visits, *place); + __mergeLocation(mergedVisits, *place); - PlaceCateger::categorize(merged_visits, *place); + PlaceCateger::categorize(mergedVisits, *place); return place; } @@ -327,13 +327,13 @@ void ctx::PlacesDetector::reduceOutliers(std::shared_ptr int size = cc->size(); cc->erase(std::remove_if(cc->begin(), cc->end(), - [](std::shared_ptr &c) { + [](std::shared_ptr &c)->bool { return c->size() < PLACES_DETECTOR_MIN_VISITS_PER_PLACE; }), cc->end()); - int new_size = cc->size(); - if (size != new_size) { - _D("Connected components from %d to %d (min visit per place)", size, new_size); + int newSize = cc->size(); + if (size != newSize) { + _D("Connected components from %d to %d (min visit per place)", size, newSize); } } @@ -364,16 +364,16 @@ std::shared_ptr ctx::PlacesDetector::__graphFromVisits(const void ctx::PlacesDetector::__dbDeletePlaces() { std::vector records; - bool ret = db_manager::execute_sync(DELETE_PLACES_QUERY, &records); + bool ret = db_manager::execute_sync(__DELETE_PLACES_QUERY, &records); _D("delete places execute query result: %s", ret ? "SUCCESS" : "FAIL"); } void ctx::PlacesDetector::__dbDeleteOldVisits() { - time_t current_time; - time(¤t_time); - time_t threshold_time = current_time - PLACES_DETECTOR_RETENTION_SECONDS; - __dbDeleteOlderVisitsThan(threshold_time); + time_t currentTime; + time(¤tTime); + time_t thresholdTime = currentTime - PLACES_DETECTOR_RETENTION_SECONDS; + __dbDeleteOlderVisitsThan(thresholdTime); } void ctx::PlacesDetector::__dbDeleteOlderVisitsThan(time_t threshold) @@ -396,32 +396,32 @@ ctx::PlacesDetector::PlacesDetector(bool testMode) : } __dbCreateTable(); std::vector records = __dbGetPlaces(); - std::vector> db_places = __placesFromJsons(records); - __detectedPlacesUpdate(db_places); + std::vector> dbPlaces = __placesFromJsons(records); + __detectedPlacesUpdate(dbPlaces); } void ctx::PlacesDetector::__dbCreateTable() { - bool ret = db_manager::create_table(0, PLACE_TABLE, PLACE_TABLE_COLUMNS); + bool ret = db_manager::create_table(0, PLACE_TABLE, __PLACE_TABLE_COLUMNS); _D("db: place Table Creation Result: %s", ret ? "SUCCESS" : "FAIL"); } void ctx::PlacesDetector::__dbInsertPlace(const Place &place) { Json data; - data.set(NULL, PLACE_COLUMN_CATEG_ID, place.categ_id); - data.set(NULL, PLACE_COLUMN_CATEG_CONFIDENCE, place.categ_confidence); + data.set(NULL, PLACE_COLUMN_CATEG_ID, place.categId); + data.set(NULL, PLACE_COLUMN_CATEG_CONFIDENCE, place.categConfidence); data.set(NULL, PLACE_COLUMN_NAME, place.name); - data.set(NULL, PLACE_COLUMN_LOCATION_VALID, place.location_valid); + data.set(NULL, PLACE_COLUMN_LOCATION_VALID, place.locationValid); data.set(NULL, PLACE_COLUMN_LOCATION_LATITUDE, place.location.latitude); data.set(NULL, PLACE_COLUMN_LOCATION_LONGITUDE, place.location.longitude); - data.set(NULL, PLACE_COLUMN_WIFI_APS, place.wifi_aps); - data.set(NULL, PLACE_COLUMN_CREATE_DATE, static_cast(place.create_date)); + data.set(NULL, PLACE_COLUMN_WIFI_APS, place.wifiAps); + data.set(NULL, PLACE_COLUMN_CREATE_DATE, static_cast(place.createDate)); - int64_t row_id; - bool ret = db_manager::insert_sync(PLACE_TABLE, data, &row_id); + int64_t rowId; + bool ret = db_manager::insert_sync(PLACE_TABLE, data, &rowId); _D("insert place execute query result: %s", ret ? "SUCCESS" : "FAIL"); } diff --git a/src/place/recognition/user_places/places_detector.h b/src/place/recognition/user_places/places_detector.h index 7ad43fb..510aebe 100644 --- a/src/place/recognition/user_places/places_detector.h +++ b/src/place/recognition/user_places/places_detector.h @@ -32,9 +32,9 @@ namespace ctx { bool __testMode; double __doubleValueFromJson(Json &row, const char* key); - categs_t __visitCategsFromJson(Json &row); + Categs __visitCategsFromJson(Json &row); Visit __visitFromJson(Json &row); - visits_t __visitsFromJsons(std::vector& records); + Visits __visitsFromJsons(std::vector& records); std::shared_ptr __placeFromJson(Json &row); std::vector> __placesFromJsons(std::vector& records); @@ -48,18 +48,18 @@ namespace ctx { std::vector __dbGetPlaces(); void __dbInsertPlace(const Place &place); - std::shared_ptr __placeFromMergedVisits(visits_t &merged_visits); + std::shared_ptr __placeFromMergedVisits(Visits &mergedVisits); std::vector> __detectedPlaces; - void __detectedPlacesUpdate(std::vector> &new_places); - void __processVisits(visits_t &visits); - static void __mergeLocation(const visits_t &merged_visits, Place &place); + void __detectedPlacesUpdate(std::vector> &newPlaces); + void __processVisits(Visits &visits); + static void __mergeLocation(const Visits &mergedVisits, Place &place); std::shared_ptr __mergeVisits(const std::vector &visits); bool onTimerExpired(int timerId); public: PlacesDetector(bool testMode = false); - static void reduceOutliers(visits_t &visits); // TODO: move to private + static void reduceOutliers(Visits &visits); // TODO: move to private static void reduceOutliers(std::shared_ptr &cc); // TODO: move to private std::vector> getPlaces(); diff --git a/src/place/recognition/user_places/user_places.cpp b/src/place/recognition/user_places/user_places.cpp index c61cb2a..5357fa9 100644 --- a/src/place/recognition/user_places/user_places.cpp +++ b/src/place/recognition/user_places/user_places.cpp @@ -22,7 +22,7 @@ #include "../place_recognition_types.h" #include "db_mgr.h" -ctx::UserPlaces::UserPlaces(place_recog_mode_e energyMode): +ctx::UserPlaces::UserPlaces(PlaceRecogMode energyMode): __visitDetector(nullptr), __placesDetector(nullptr), __placesDetectorTimerId(-1) @@ -114,22 +114,22 @@ ctx::Json ctx::UserPlaces::composeJson(std::vector> place { ctx::Json data; for (std::shared_ptr place : places) { - ctx::Json place_j; - place_j.set(NULL, PLACE_CATEG_ID, place->categ_id); - place_j.set(NULL, PLACE_CATEG_CONFIDENCE, place->categ_confidence); - place_j.set(NULL, PLACE_NAME, place->name); - if (place->location_valid) { - place_j.set(NULL, PLACE_GEO_LATITUDE, place->location.latitude); - place_j.set(NULL, PLACE_GEO_LONGITUDE, place->location.longitude); + ctx::Json placeJson; + placeJson.set(NULL, PLACE_CATEG_ID, place->categId); + placeJson.set(NULL, PLACE_CATEG_CONFIDENCE, place->categConfidence); + placeJson.set(NULL, PLACE_NAME, place->name); + if (place->locationValid) { + placeJson.set(NULL, PLACE_GEO_LATITUDE, place->location.latitude); + placeJson.set(NULL, PLACE_GEO_LONGITUDE, place->location.longitude); } - place_j.set(NULL, PLACE_WIFI_APS, place->wifi_aps); - place_j.set(NULL, PLACE_CREATE_DATE, static_cast(place->create_date)); - data.append(NULL, DATA_READ, place_j); + placeJson.set(NULL, PLACE_WIFI_APS, place->wifiAps); + placeJson.set(NULL, PLACE_CREATE_DATE, static_cast(place->createDate)); + data.append(NULL, DATA_READ, placeJson); } return data; } -void ctx::UserPlaces::setMode(place_recog_mode_e energyMode) +void ctx::UserPlaces::setMode(PlaceRecogMode energyMode) { if (__visitDetector) { __visitDetector->setMode(energyMode); diff --git a/src/place/recognition/user_places/user_places.h b/src/place/recognition/user_places/user_places.h index d4275cb..1df6388 100644 --- a/src/place/recognition/user_places/user_places.h +++ b/src/place/recognition/user_places/user_places.h @@ -35,10 +35,10 @@ namespace ctx { TimerManager __timerManager; public: - UserPlaces(place_recog_mode_e energyMode = PLACE_RECOG_HIGH_ACCURACY_MODE); + UserPlaces(PlaceRecogMode energyMode = PLACE_RECOG_HIGH_ACCURACY_MODE); ~UserPlaces(); - void setMode(place_recog_mode_e energyMode); + void setMode(PlaceRecogMode energyMode); std::vector> getPlaces(); static Json composeJson(std::vector> places); diff --git a/src/place/recognition/user_places/user_places_types.cpp b/src/place/recognition/user_places/user_places_types.cpp index 9fafbc4..7efd948 100644 --- a/src/place/recognition/user_places/user_places_types.cpp +++ b/src/place/recognition/user_places/user_places_types.cpp @@ -24,8 +24,8 @@ #include "user_places_params.h" #include "debug_utils.h" -#define MAC_STRING_COMPONENTS_SEPARATOR ':' -#define MAC_SET_STRING_DELIMITER ',' +#define __MAC_STRING_COMPONENTS_SEPARATOR ':' +#define __MAC_SET_STRING_DELIMITER ',' ctx::Mac::Mac(const std::string& str) { @@ -59,7 +59,7 @@ std::istream& ctx::operator>>(std::istream &input, ctx::Mac &mac) break; } input >> colon; - if (colon != MAC_STRING_COMPONENTS_SEPARATOR) { + if (colon != __MAC_STRING_COMPONENTS_SEPARATOR) { throw std::runtime_error("Invalid MAC format"); } } @@ -77,7 +77,7 @@ std::ostream& ctx::operator<<(std::ostream &output, const ctx::Mac &mac) if (i >= Mac::MAC_SIZE) { break; } - output << MAC_STRING_COMPONENTS_SEPARATOR; + output << __MAC_STRING_COMPONENTS_SEPARATOR; } output << std::dec; return output; @@ -121,7 +121,7 @@ bool ctx::operator<(const Mac &m1, const Mac &m2) return false; // they are equal } -std::istream& ctx::operator>>(std::istream &input, ctx::mac_set_t &macSet) +std::istream& ctx::operator>>(std::istream &input, ctx::MacSet &macSet) { Mac mac; char delimeter; @@ -137,7 +137,7 @@ std::istream& ctx::operator>>(std::istream &input, ctx::mac_set_t &macSet) break; } delimeter = input.get(); - if (delimeter != MAC_SET_STRING_DELIMITER) { + if (delimeter != __MAC_SET_STRING_DELIMITER) { input.unget(); break; } @@ -145,18 +145,18 @@ std::istream& ctx::operator>>(std::istream &input, ctx::mac_set_t &macSet) return input; } -std::ostream& ctx::operator<<(std::ostream &output, const ctx::mac_set_t &macSet) +std::ostream& ctx::operator<<(std::ostream &output, const ctx::MacSet &macSet) { - std::vector mac_vec(macSet.size()); - std::copy(macSet.begin(), macSet.end(), mac_vec.begin()); - std::sort(mac_vec.begin(), mac_vec.end()); + std::vector macVec(macSet.size()); + std::copy(macSet.begin(), macSet.end(), macVec.begin()); + std::sort(macVec.begin(), macVec.end()); bool first = true; - for (auto &mac: mac_vec) { + for (auto &mac: macVec) { if (first) { first = false; } else { - output << MAC_SET_STRING_DELIMITER; + output << __MAC_SET_STRING_DELIMITER; } output << mac; } @@ -182,13 +182,13 @@ void ctx::LocationEvent::log() #endif /* TIZEN_ENGINEER_MODE */ } -void ctx::Visit::set_location(Location location_) +void ctx::Visit::setLocation(Location location_) { - location_valid = true; + locationValid = true; location = location_; } -void ctx::Visit::print_short_to_stream(std::ostream &out) const +void ctx::Visit::printShort2Stream(std::ostream &out) const { // print only valid visits if (interval.end != 0) { @@ -207,13 +207,13 @@ bool ctx::operator==(const ctx::Visit &v1, const ctx::Visit &v2) && v1.location.latitude == v2.location.latitude && v1.location.longitude == v2.location.longitude && v1.location.accuracy == v2.location.accuracy - && v1.location_valid == v2.location_valid + && v1.locationValid == v2.locationValid && v1.macSet == v2.macSet; } -ctx::mac_set_t ctx::mac_set_from_string(const std::string &str) +ctx::MacSet ctx::macSetFromString(const std::string &str) { - mac_set_t macSet; + MacSet macSet; std::stringstream ss; ss << str; ss >> macSet; @@ -225,22 +225,22 @@ bool ctx::operator>(const Mac &m1, const Mac &m2) return m2 < m1; } -std::shared_ptr ctx::mac_set_from_mac_counts(const mac_counts_t &mac_counts) +std::shared_ptr ctx::macSetFromMacs2Counts(const Macs2Counts &macs2Counts) { - std::shared_ptr macSet(std::make_shared()); - for (auto &c: mac_counts) { - macSet->insert(c.first); + std::shared_ptr macSet(std::make_shared()); + for (auto &macCount: macs2Counts) { + macSet->insert(macCount.first); } return macSet; } -std::shared_ptr ctx::mac_sets_union(const std::vector> &macSets) +std::shared_ptr ctx::macSetsUnion(const std::vector> &macSets) { - std::shared_ptr union_set = std::make_shared(); - for (std::shared_ptr macSet : macSets) { - union_set->insert(macSet->begin(), macSet->end()); + std::shared_ptr unionSet = std::make_shared(); + for (std::shared_ptr macSet : macSets) { + unionSet->insert(macSet->begin(), macSet->end()); } - return union_set; + return unionSet; } ctx::Interval::Interval(time_t start_, time_t end_) : start(start_), end(end_) { @@ -249,14 +249,14 @@ ctx::Interval::Interval(time_t start_, time_t end_) : start(start_), end(end_) { } } -void ctx::Place::print_to_stream(std::ostream &out) const +void ctx::Place::print2Stream(std::ostream &out) const { out << "PLACE:" << std::endl; out << "__CATEGORY: " << name << std::endl; - if (location_valid) { + if (locationValid) { out << "__LOCATION: lat=" << std::setprecision(GEO_LOCATION_PRECISION + 2) << location.latitude; out << ", lon=" << location.longitude << std::setprecision(5) << std::endl; } - out << "__WIFI:" << wifi_aps << std::endl; - out << "__CREATE_DATE: " << DebugUtils::humanReadableDateTime(create_date, "%F %T", 80) << std::endl; + out << "__WIFI:" << wifiAps << std::endl; + out << "__CREATE_DATE: " << DebugUtils::humanReadableDateTime(createDate, "%F %T", 80) << std::endl; } diff --git a/src/place/recognition/user_places/user_places_types.h b/src/place/recognition/user_places/user_places_types.h index a19c015..cdf7be4 100644 --- a/src/place/recognition/user_places/user_places_types.h +++ b/src/place/recognition/user_places/user_places_types.h @@ -78,22 +78,22 @@ namespace ctx { typedef float share_t; typedef int count_t; - typedef std::unordered_map mac_counts_t; - typedef std::unordered_map mac_shares_t; + typedef std::unordered_map Macs2Counts; + typedef std::unordered_map Macs2Shares; - typedef std::unordered_set mac_set_t; + typedef std::unordered_set MacSet; - std::istream &operator>>(std::istream &input, ctx::mac_set_t &macSet); - std::ostream &operator<<(std::ostream &output, const ctx::mac_set_t &macSet); - ctx::mac_set_t mac_set_from_string(const std::string &str); + std::istream &operator>>(std::istream &input, ctx::MacSet &macSet); + std::ostream &operator<<(std::ostream &output, const ctx::MacSet &macSet); + ctx::MacSet macSetFromString(const std::string &str); - std::shared_ptr mac_sets_union(const std::vector> &macSets); + std::shared_ptr macSetsUnion(const std::vector> &macSets); struct Interval { time_t start; time_t end; - Interval(time_t start_, time_t end_); + Interval(time_t start, time_t end); }; } /* namespace ctx */ @@ -116,7 +116,7 @@ namespace ctx { struct Frame { Interval interval; count_t numberOfTimestamps; - mac_counts_t macCountsMap; + Macs2Counts macs2Counts; Frame(Interval interval_) : interval(interval_), numberOfTimestamps(0) {}; }; @@ -131,7 +131,7 @@ namespace ctx { MacEvent(time_t timestamp_, Mac mac_) : timestamp(timestamp_), mac(mac_) {} }; - typedef std::map categs_t; // scores of categories + typedef std::map Categs; // scores of categories struct Location { double latitude; @@ -161,11 +161,13 @@ namespace ctx { #ifdef TIZEN_ENGINEER_MODE LocationSource method; - LocationEvent(double latitude_, double longitude_, double accuracy_, time_t timestamp_, LocationSource method_) - : coordinates(latitude_, longitude_, accuracy_), timestamp(timestamp_), method(method_) {} + LocationEvent(double latitude_, double longitude_, double accuracy_, time_t timestamp_, LocationSource method_) : + coordinates(latitude_, longitude_, accuracy_), + timestamp(timestamp_), method(method_) {} #else /* TIZEN_ENGINEER_MODE */ - LocationEvent(double latitude_, double longitude_, double accuracy_, time_t timestamp_) - : coordinates(latitude_, longitude_, accuracy_), timestamp(timestamp_) {} + LocationEvent(double latitude_, double longitude_, double accuracy_, time_t timestamp_) : + coordinates(latitude_, longitude_, accuracy_), + timestamp(timestamp_) {} #endif /* TIZEN_ENGINEER_MODE */ void log(); @@ -174,41 +176,41 @@ namespace ctx { struct Visit { Interval interval; - std::shared_ptr macSet; - categs_t categs; - bool location_valid; - Location location; // makes sense if location_valid == true; + std::shared_ptr macSet; + Categs categs; + bool locationValid; + Location location; // makes sense if locationValid == true; - Visit(Interval interval_, std::shared_ptr macSet_ = std::make_shared(), categs_t categs_ = categs_t()) : + Visit(Interval interval_, std::shared_ptr macSet_ = std::make_shared(), Categs categs_ = Categs()) : interval(interval_), macSet(macSet_), categs(categs_), - location_valid(false) {} - void set_location(Location location); - void print_short_to_stream(std::ostream &out) const; + locationValid(false) {} + void setLocation(Location location); + void printShort2Stream(std::ostream &out) const; }; /* struct Visit */ bool operator==(const Visit &v1, const Visit &v2); - typedef std::vector visits_t; - typedef std::vector mac_events; // used to store current interval logs + typedef std::vector Visits; + typedef std::vector MacEvents; // used to store current interval logs - std::shared_ptr mac_set_from_mac_counts(const mac_counts_t &macCountsMap); + std::shared_ptr macSetFromMacs2Counts(const Macs2Counts &macs2Counts); typedef float confidence_t; class Place { public: - PlaceCategId categ_id; // category of a place (work/home/other) - confidence_t categ_confidence; // confidence of the above category - between [0,1] + PlaceCategId categId; // category of a place (work/home/other) + confidence_t categConfidence; // confidence of the above category - between [0,1] std::string name; // for now: "work"/"home"/"other" - bool location_valid; - Location location; // makes sense if location_valid == true; - std::string wifi_aps; // WiFi APs MAC addresses separated by "," - time_t create_date; // The last update time of this place + bool locationValid; + Location location; // makes sense if locationValid == true; + std::string wifiAps; // WiFi APs MAC addresses separated by "," + time_t createDate; // The last update time of this place - void print_to_stream(std::ostream &out) const; + void print2Stream(std::ostream &out) const; }; /* class Place */ diff --git a/src/place/recognition/user_places/visit_categer.cpp b/src/place/recognition/user_places/visit_categer.cpp index c09dd01..7c6ab7d 100644 --- a/src/place/recognition/user_places/visit_categer.cpp +++ b/src/place/recognition/user_places/visit_categer.cpp @@ -314,12 +314,12 @@ ctx::TimeFeatures ctx::VisitCateger::timeFeatures(const time_t &time) }; } -int ctx::VisitCateger::weeksScope(const TimeFeatures &start_f, const Interval &interval) +int ctx::VisitCateger::weeksScope(const TimeFeatures &startF, const Interval &interval) { - int duration_minutes = (interval.end - interval.start) / 60; - int scope_minutes = start_f.minutesSinceBeginingOfTheWeek + duration_minutes; - int weeksScope = scope_minutes / MINUTES_IN_WEEK; - if (scope_minutes % MINUTES_IN_WEEK > 0) { + int durationMinutes = (interval.end - interval.start) / 60; + int scopeMinutes = startF.minutesSinceBeginingOfTheWeek + durationMinutes; + int weeksScope = scopeMinutes / __MINUTES_IN_WEEK; + if (scopeMinutes % __MINUTES_IN_WEEK > 0) { weeksScope++; } return weeksScope; @@ -327,10 +327,10 @@ int ctx::VisitCateger::weeksScope(const TimeFeatures &start_f, const Interval &i ctx::num_t ctx::VisitCateger::__sum(const std::vector model, const size_t &from, const size_t &to) { - size_t to_secure = to; + size_t toSecure = to; if (to >= model.size()) { _E("'to' exceeds model size"); - to_secure = model.size() - 1; + toSecure = model.size() - 1; } if (from > to) { @@ -338,7 +338,7 @@ ctx::num_t ctx::VisitCateger::__sum(const std::vector model, const size_t } num_t result = 0.0; - for (size_t i = from; i <= to_secure; i++) { + for (size_t i = from; i <= toSecure; i++) { result += model[i]; } @@ -346,20 +346,20 @@ ctx::num_t ctx::VisitCateger::__sum(const std::vector model, const size_t } ctx::num_t ctx::VisitCateger::__weekModelMeanValue(PlaceCategId categ, const Interval &interval, - const TimeFeatures &start_f, const TimeFeatures &end_f) + const TimeFeatures &startF, const TimeFeatures &endF) { num_t ret = 0.0; int minutes = 0; - int ws = weeksScope(start_f, interval); + int ws = weeksScope(startF, interval); for (int week = 1; week <= ws; week++) { - size_t start_index = (week == 1) - ? start_f.minutesSinceBeginingOfTheWeek + size_t startIndex = (week == 1) + ? startF.minutesSinceBeginingOfTheWeek : 0; - size_t end_index = (week == ws) - ? end_f.minutesSinceBeginingOfTheWeek - : MINUTES_IN_WEEK - 1; - ret += __sum(prob_features::weekModel[categ], start_index, end_index); - minutes += end_index - start_index + 1; + size_t endIndex = (week == ws) + ? endF.minutesSinceBeginingOfTheWeek + : __MINUTES_IN_WEEK - 1; + ret += __sum(prob_features::weekModel[categ], startIndex, endIndex); + minutes += endIndex - startIndex + 1; } if (minutes > 0) { return ret / minutes; @@ -367,12 +367,11 @@ ctx::num_t ctx::VisitCateger::__weekModelMeanValue(PlaceCategId categ, const Int return ret; } -ctx::categs_t ctx::VisitCateger::weekModelFeatures(const Interval &interval, const TimeFeatures &start_f, - const TimeFeatures &end_f) +ctx::Categs ctx::VisitCateger::weekModelFeatures(const Interval &interval, const TimeFeatures &startF, const TimeFeatures &endF) { - ctx::categs_t categs; + ctx::Categs categs; for (const auto &item : prob_features::weekModel) { - categs[item.first] = __weekModelMeanValue(item.first, interval, start_f, end_f); + categs[item.first] = __weekModelMeanValue(item.first, interval, startF, endF); } _D("categs: H=%.12f, W=%.12f, O=%.12f", categs[PLACE_CATEG_ID_HOME], @@ -381,20 +380,20 @@ ctx::categs_t ctx::VisitCateger::weekModelFeatures(const Interval &interval, con return categs; } -std::vector ctx::VisitCateger::intervalFeatures(const Interval &interval) +ctx::IntervalFeatures ctx::VisitCateger::intervalFeatures(const Interval &interval) { - num_t duration_minutes = 1.0 * (interval.end - interval.start) / 60; - TimeFeatures start_features = timeFeatures(interval.start); - TimeFeatures end_features = timeFeatures(interval.end); - categs_t week_features = weekModelFeatures(interval, start_features, end_features); + num_t durationMinutes = 1.0 * (interval.end - interval.start) / 60; + TimeFeatures startFeatures = timeFeatures(interval.start); + TimeFeatures endFeatures = timeFeatures(interval.end); + Categs weekFeatures = weekModelFeatures(interval, startFeatures, endFeatures); return { - duration_minutes, - (num_t) start_features.minutesSinceMidnight, - (num_t) end_features.minutesSinceMidnight, - (num_t) start_features.weekday, - week_features[PLACE_CATEG_ID_HOME], - week_features[PLACE_CATEG_ID_WORK], - week_features[PLACE_CATEG_ID_OTHER] + durationMinutes, + (num_t) startFeatures.minutesSinceMidnight, + (num_t) endFeatures.minutesSinceMidnight, + (num_t) startFeatures.weekday, + weekFeatures[PLACE_CATEG_ID_HOME], + weekFeatures[PLACE_CATEG_ID_WORK], + weekFeatures[PLACE_CATEG_ID_OTHER] }; } @@ -409,15 +408,15 @@ void ctx::VisitCateger::__normalize(std::vector &features) void ctx::VisitCateger::categorize(ctx::Visit &visit) { - std::vector features = intervalFeatures(visit.interval); + IntervalFeatures features = intervalFeatures(visit.interval); __normalize(features); - for (auto &model_pair : __models) { - int categ_i = model_pair.first; - MahalModel model = model_pair.second; + for (auto &modelPair : __models) { + int categId = modelPair.first; + MahalModel model = modelPair.second; - num_t mahal_dist = model.dist(features); - num_t prob = 1 - __chiApprox.value(mahal_dist); // sth like probability but not exactly - visit.categs[categ_i] = prob; + num_t distance = model.distance(features); + num_t probability = 1 - __chiApprox.value(distance); // sth like probability but not exactly + visit.categs[categId] = probability; } } diff --git a/src/place/recognition/user_places/visit_categer.h b/src/place/recognition/user_places/visit_categer.h index d7888bb..b9d4940 100644 --- a/src/place/recognition/user_places/visit_categer.h +++ b/src/place/recognition/user_places/visit_categer.h @@ -31,19 +31,21 @@ namespace ctx { bool weekend; }; + typedef std::vector IntervalFeatures; + /* * visit categorizer class */ class VisitCateger { private: - const static int MINUTES_IN_WEEK = 60 * 24 * 7; - const static std::map __models; - const static std::vector __featuresMean; - const static std::vector __featuresStd; + static const int __MINUTES_IN_WEEK = 60 * 24 * 7; + static const std::map __models; + static const std::vector __featuresMean; + static const std::vector __featuresStd; static num_t __sum(const std::vector model, const size_t &from, const size_t &to); static num_t __weekModelMeanValue(PlaceCategId categ, const Interval &interval, - const TimeFeatures &start_f, const TimeFeatures &end_f); + const TimeFeatures &startF, const TimeFeatures &endF); static void __normalize(std::vector &features); static PiecewiseLin __chiApprox; // tabled chi function approximator @@ -56,27 +58,27 @@ namespace ctx { */ static TimeFeatures timeFeatures(const time_t &time); - static int weeksScope(const TimeFeatures &start_f, const Interval &interval); + static int weeksScope(const TimeFeatures &startF, const Interval &interval); /** * Function interpret time interval input argument and calculates scores * that argument interval is home, work or other based on whole week model. * * @param interval time interval - * @param start_f start time features - * @param end_f end time features - * @return categs_t score that argument interval is home, work or other + * @param startF start time features + * @param endF end time features + * @return Categs score that argument interval is home, work or other */ - static categs_t weekModelFeatures(const Interval &interval, const TimeFeatures &start_f, - const TimeFeatures &end_f); + static Categs weekModelFeatures(const Interval &interval, const TimeFeatures &startF, + const TimeFeatures &endF); /** * Function interpret time interval input argument, * - * @param interval time interval - * @return std::vector vector with interpretations of input time interval + * @param interval time interval + * @return IntervalFeatures vector with interpretations of input time interval */ - static std::vector intervalFeatures(const Interval &interval); + static IntervalFeatures intervalFeatures(const Interval &interval); /** * Function categorize visit based on visits time interval and fill its categories values. diff --git a/src/place/recognition/user_places/visit_detector.cpp b/src/place/recognition/user_places/visit_detector.cpp index d0ee631..57383ca 100644 --- a/src/place/recognition/user_places/visit_detector.cpp +++ b/src/place/recognition/user_places/visit_detector.cpp @@ -30,7 +30,7 @@ #include "debug_utils.h" #ifdef TIZEN_ENGINEER_MODE -#define VISIT_TABLE_COLUMNS \ +#define __VISIT_TABLE_COLUMNS \ VISIT_COLUMN_WIFI_APS " TEXT, "\ VISIT_COLUMN_START_TIME " timestamp, "\ VISIT_COLUMN_END_TIME " timestamp, "\ @@ -43,7 +43,7 @@ VISIT_COLUMN_CATEG_WORK " REAL, "\ VISIT_COLUMN_CATEG_OTHER " REAL" #else /* TIZEN_ENGINEER_MODE */ -#define VISIT_TABLE_COLUMNS \ +#define __VISIT_TABLE_COLUMNS \ VISIT_COLUMN_WIFI_APS " TEXT, "\ VISIT_COLUMN_START_TIME " timestamp, "\ VISIT_COLUMN_END_TIME " timestamp, "\ @@ -55,11 +55,11 @@ VISIT_COLUMN_CATEG_OTHER " REAL" #endif /* TIZEN_ENGINEER_MODE */ -ctx::VisitDetector::VisitDetector(time_t t_start_scan, place_recog_mode_e energyMode, bool testMode) : +ctx::VisitDetector::VisitDetector(time_t startScan, PlaceRecogMode energyMode, bool testMode) : __testMode(testMode), __locationLogger(this, testMode), __wifiLogger(this, energyMode, testMode), - __currentInterval(t_start_scan, t_start_scan + VISIT_DETECTOR_PERIOD_SECONDS_HIGH_ACCURACY), + __currentInterval(startScan, startScan + VISIT_DETECTOR_PERIOD_SECONDS_HIGH_ACCURACY), __stableCounter(0), __tolerance(VISIT_DETECTOR_TOLERANCE_DEPTH), __entranceToPlace(false), @@ -68,12 +68,12 @@ ctx::VisitDetector::VisitDetector(time_t t_start_scan, place_recog_mode_e energy __departureTime(0) { __setPeriod(energyMode); - __currentInterval = Interval(t_start_scan, t_start_scan + __periodSeconds); - __currentLogger = std::make_shared(); - __stayMacs = std::make_shared(); + __currentInterval = Interval(startScan, startScan + __periodSeconds); + __currentMacEvents = std::make_shared(); + __stayMacs = std::make_shared(); if (__testMode) { - __detectedVisits = std::make_shared(); + __detectedVisits = std::make_shared(); return; } @@ -100,28 +100,28 @@ void ctx::VisitDetector::onWifiScan(ctx::MacEvent e) __processCurrentLogger(); __shiftCurrentInterval(); } - __currentLogger->push_back(e); + __currentMacEvents->push_back(e); } } void ctx::VisitDetector::__processCurrentLogger() { _D(""); - std::shared_ptr frame = __makeFrame(__currentLogger, __currentInterval); + std::shared_ptr frame = __makeFrame(__currentMacEvents, __currentInterval); __detectEntranceOrDeparture(frame); - __currentLogger->clear(); + __currentMacEvents->clear(); } -std::shared_ptr ctx::VisitDetector::__makeFrame(std::shared_ptr logger, ctx::Interval interval) +std::shared_ptr ctx::VisitDetector::__makeFrame(std::shared_ptr logger, ctx::Interval interval) { std::set timestamps; std::shared_ptr frame = std::make_shared(interval); for (auto log : *logger) { timestamps.insert(log.timestamp); - if (frame->macCountsMap.find(log.mac) == frame->macCountsMap.end()) { - frame->macCountsMap[log.mac] = 1; + if (frame->macs2Counts.find(log.mac) == frame->macs2Counts.end()) { + frame->macs2Counts[log.mac] = 1; } else { - frame->macCountsMap[log.mac] += 1; + frame->macs2Counts[log.mac] += 1; } } frame->numberOfTimestamps = timestamps.size(); @@ -139,20 +139,20 @@ void ctx::VisitDetector::__detectEntranceOrDeparture(std::shared_ptr __entranceToPlace ? __detectDeparture(frame) : __detectEntrance(frame); } -bool ctx::VisitDetector::__isDisjoint(const ctx::mac_counts_t &macCountsMap, const ctx::mac_set_t &macSet) +bool ctx::VisitDetector::__isDisjoint(const ctx::Macs2Counts &macs2Counts, const ctx::MacSet &macSet) { for (auto &mac : macSet) { - if (macCountsMap.find(mac) != macCountsMap.end()) { + if (macs2Counts.find(mac) != macs2Counts.end()) { return false; } } return true; } -bool ctx::VisitDetector::__protrudesFrom(const ctx::mac_counts_t &macCountsMap, const ctx::mac_set_t &macSet) +bool ctx::VisitDetector::__protrudesFrom(const ctx::Macs2Counts &macs2Counts, const ctx::MacSet &macSet) { - for (auto &m : macCountsMap) { - if (macSet.find(m.first) == macSet.end()) { + for (auto &macCount : macs2Counts) { + if (macSet.find(macCount.first) == macSet.end()) { return true; } } @@ -167,8 +167,8 @@ void ctx::VisitDetector::__detectDeparture(std::shared_ptr frame) } else { // __tolerance < VISIT_DETECTOR_TOLERANCE_DEPTH __bufferedFrames.push_back(frame); } - if (__isDisjoint(frame->macCountsMap, *__representativesMacs)) { - if (frame->macCountsMap.empty() || __protrudesFrom(frame->macCountsMap, *__stayMacs)) { + if (__isDisjoint(frame->macs2Counts, *__representativesMacs)) { + if (frame->macs2Counts.empty() || __protrudesFrom(frame->macs2Counts, *__stayMacs)) { __tolerance--; } else { // no new macs __bufferedFrames.clear(); @@ -230,15 +230,15 @@ void ctx::VisitDetector::__putLocationToVisit(ctx::Visit &visit) // TODO: remove small accuracy locations from vectors? std::vector latitudes; std::vector longitudes; - visit.location_valid = false; + visit.locationValid = false; for (LocationEvent location : __locationEvents) { if (location.timestamp >= __entranceTime && location.timestamp <= __departureTime) { latitudes.push_back(location.coordinates.latitude); longitudes.push_back(location.coordinates.longitude); - visit.location_valid = true; + visit.locationValid = true; } } - if (visit.location_valid) { + if (visit.locationValid) { visit.location.latitude = median(latitudes); visit.location.longitude = median(longitudes); _D("visit location set: lat=%.8f, lon=%.8f", visit.location.latitude, visit.location.longitude); @@ -262,29 +262,29 @@ void ctx::VisitDetector::__processBuffer(std::shared_ptr frame) } } -void ctx::VisitDetector::__detectEntrance(std::shared_ptr current_frame) +void ctx::VisitDetector::__detectEntrance(std::shared_ptr currentFrame) { - if (current_frame->macCountsMap.empty() || __historyFrames.empty()) { - __resetHistory(current_frame); + if (currentFrame->macs2Counts.empty() || __historyFrames.empty()) { + __resetHistory(currentFrame); return; } if (__stableCounter == 0) { - std::shared_ptr oldest_history_frame = __historyFrames[0]; - __stayMacs = mac_set_from_mac_counts(oldest_history_frame->macCountsMap); + std::shared_ptr oldestHistoryFrame = __historyFrames[0]; + __stayMacs = macSetFromMacs2Counts(oldestHistoryFrame->macs2Counts); } - std::shared_ptr current_beacons = mac_set_from_mac_counts(current_frame->macCountsMap); + std::shared_ptr currentBeacons = macSetFromMacs2Counts(currentFrame->macs2Counts); - if (similarity::overlapBiggerOverSmaller(*current_beacons, *__stayMacs) > VISIT_DETECTOR_OVERLAP) { + if (similarity::overlapBiggerOverSmaller(*currentBeacons, *__stayMacs) > VISIT_DETECTOR_OVERLAP) { __stableCounter++; - __historyFrames.push_back(current_frame); + __historyFrames.push_back(currentFrame); if (__stableCounter == VISIT_DETECTOR_STABLE_DEPTH) { // entrance detected __visitStartDetected(); } } else { - __resetHistory(current_frame); + __resetHistory(currentFrame); } return; } @@ -301,82 +301,81 @@ void ctx::VisitDetector::__resetHistory(std::shared_ptr frame) __historyFrames.push_back(frame); } -std::shared_ptr ctx::VisitDetector::__selectRepresentatives(const std::vector> &frames) +std::shared_ptr ctx::VisitDetector::__selectRepresentatives(const std::vector> &frames) { - mac_counts_t repr_counts; - count_t all_count = 0; + Macs2Counts reprs2Counts; + count_t allCount = 0; for (auto frame : frames) { - all_count += frame->numberOfTimestamps; - for (auto &c : frame->macCountsMap) { - repr_counts[c.first] += c.second; + allCount += frame->numberOfTimestamps; + for (auto &c : frame->macs2Counts) { + reprs2Counts[c.first] += c.second; } } - std::shared_ptr repr_shares = __macSharesFromCounts(repr_counts, all_count); + std::shared_ptr reprs2Shares = __macSharesFromCounts(reprs2Counts, allCount); - share_t max_share = __calcMaxShare(*repr_shares); - share_t threshold = max_share < VISIT_DETECTOR_REP_THRESHOLD ? - max_share : VISIT_DETECTOR_REP_THRESHOLD; + share_t maxShare = __calcMaxShare(*reprs2Shares); + share_t threshold = maxShare < VISIT_DETECTOR_REP_THRESHOLD ? maxShare : VISIT_DETECTOR_REP_THRESHOLD; - std::shared_ptr repr_mac_set = __macSetOfGreaterOrEqualShare(*repr_shares, threshold); + std::shared_ptr reprsMacSet = __macSetOfGreaterOrEqualShare(*reprs2Shares, threshold); - return repr_mac_set; + return reprsMacSet; } -ctx::share_t ctx::VisitDetector::__calcMaxShare(const ctx::mac_shares_t &mac_shares) +ctx::share_t ctx::VisitDetector::__calcMaxShare(const ctx::Macs2Shares &macs2Shares) { - ctx::share_t max_value = 0.0; - for (auto &ms : mac_shares) { - if (ms.second > max_value) { - max_value = ms.second; + ctx::share_t maxShare = 0.0; + for (auto &macShare : macs2Shares) { + if (macShare.second > maxShare) { + maxShare = macShare.second; } } - return max_value; + return maxShare; } -std::shared_ptr ctx::VisitDetector::__macSetOfGreaterOrEqualShare(const ctx::mac_shares_t &mac_shares, ctx::share_t threshold) +std::shared_ptr ctx::VisitDetector::__macSetOfGreaterOrEqualShare(const ctx::Macs2Shares &macs2Shares, ctx::share_t threshold) { - std::shared_ptr macSet = std::make_shared(); - for (auto &ms : mac_shares) { - if (ms.second >= threshold) { - macSet->insert(ms.first); + std::shared_ptr macSet = std::make_shared(); + for (auto &macShare : macs2Shares) { + if (macShare.second >= threshold) { + macSet->insert(macShare.first); } } return macSet; } -std::shared_ptr ctx::VisitDetector::__macSharesFromCounts(ctx::mac_counts_t const &macCountsMap, ctx::count_t denominator) +std::shared_ptr ctx::VisitDetector::__macSharesFromCounts(ctx::Macs2Counts const &macs2Counts, ctx::count_t denominator) { - std::shared_ptr mac_shares(std::make_shared()); - for (auto mac_count : macCountsMap) { - (*mac_shares)[mac_count.first] = (share_t) mac_count.second / denominator; + std::shared_ptr macs2Shares(std::make_shared()); + for (auto macCount : macs2Counts) { + (*macs2Shares)[macCount.first] = (share_t) macCount.second / denominator; } - return mac_shares; + return macs2Shares; } -std::shared_ptr ctx::VisitDetector::getVisits() +std::shared_ptr ctx::VisitDetector::getVisits() { return __detectedVisits; } void ctx::VisitDetector::__dbCreateTable() { - bool ret = db_manager::create_table(0, VISIT_TABLE, VISIT_TABLE_COLUMNS); + bool ret = db_manager::create_table(0, VISIT_TABLE, __VISIT_TABLE_COLUMNS); _D("db: visit Table Creation Result: %s", ret ? "SUCCESS" : "FAIL"); } -void ctx::VisitDetector::__putVisitCategToJson(const char* key, const categs_t &categs, int categ_type, Json &data) +void ctx::VisitDetector::__putVisitCategToJson(const char* key, const Categs &categs, int categType, Json &data) { - auto categ_p = categs.find(categ_type); - if (categ_p == categs.end()) { - _E("json_put_visit no type %d in categs", categ_type); + auto categ = categs.find(categType); + if (categ == categs.end()) { + _E("json_put_visit no type %d in categs", categType); } else { - data.set(NULL, key, categ_p->second); + data.set(NULL, key, categ->second); } } -void ctx::VisitDetector::__putVisitCategsToJson(const categs_t &categs, Json &data) +void ctx::VisitDetector::__putVisitCategsToJson(const Categs &categs, Json &data) { __putVisitCategToJson(VISIT_COLUMN_CATEG_HOME, categs, PLACE_CATEG_ID_HOME, data); __putVisitCategToJson(VISIT_COLUMN_CATEG_WORK, categs, PLACE_CATEG_ID_WORK, data); @@ -385,13 +384,13 @@ void ctx::VisitDetector::__putVisitCategsToJson(const categs_t &categs, Json &da int ctx::VisitDetector::__dbInsertVisit(Visit visit) { - std::stringstream macs_ss; - macs_ss << *visit.macSet; + std::stringstream ss; + ss << *visit.macSet; Json data; - data.set(NULL, VISIT_COLUMN_WIFI_APS, macs_ss.str().c_str()); + data.set(NULL, VISIT_COLUMN_WIFI_APS, ss.str().c_str()); - data.set(NULL, VISIT_COLUMN_LOCATION_VALID, visit.location_valid); + data.set(NULL, VISIT_COLUMN_LOCATION_VALID, visit.locationValid); data.set(NULL, VISIT_COLUMN_LOCATION_LATITUDE, visit.location.latitude); data.set(NULL, VISIT_COLUMN_LOCATION_LONGITUDE, visit.location.longitude); @@ -399,32 +398,32 @@ int ctx::VisitDetector::__dbInsertVisit(Visit visit) data.set(NULL, VISIT_COLUMN_END_TIME, static_cast(visit.interval.end)); #ifdef TIZEN_ENGINEER_MODE - std::string start_time_human = DebugUtils::humanReadableDateTime(visit.interval.start, "%F %T", 80); - std::string end_time_human = DebugUtils::humanReadableDateTime(visit.interval.end, "%F %T", 80); - data.set(NULL, VISIT_COLUMN_START_TIME_HUMAN, start_time_human.c_str()); - data.set(NULL, VISIT_COLUMN_END_TIME_HUMAN, end_time_human.c_str()); + std::string startTimeHuman = DebugUtils::humanReadableDateTime(visit.interval.start, "%F %T", 80); + std::string endTimeHuman = DebugUtils::humanReadableDateTime(visit.interval.end, "%F %T", 80); + data.set(NULL, VISIT_COLUMN_START_TIME_HUMAN, startTimeHuman.c_str()); + data.set(NULL, VISIT_COLUMN_END_TIME_HUMAN, endTimeHuman.c_str()); _D("db: visit table insert interval: (%d, %d): (%s, %s)", - visit.interval.start, visit.interval.end, start_time_human.c_str(), end_time_human.c_str()); + visit.interval.start, visit.interval.end, startTimeHuman.c_str(), endTimeHuman.c_str()); #else _D("db: visit table insert interval: (%d, %d)", visit.interval.start, visit.interval.end); #endif /* TIZEN_ENGINEER_MODE */ __putVisitCategsToJson(visit.categs, data); - int64_t row_id; - bool ret = db_manager::insert_sync(VISIT_TABLE, data, &row_id); + int64_t rowId; + bool ret = db_manager::insert_sync(VISIT_TABLE, data, &rowId); _D("db: visit table insert result: %s", ret ? "SUCCESS" : "FAIL"); return ret; } -void ctx::VisitDetector::onNewLocation(LocationEvent location_event) +void ctx::VisitDetector::onNewLocation(LocationEvent locationEvent) { _D(""); - location_event.log(); - __locationEvents.push_back(location_event); + locationEvent.log(); + __locationEvents.push_back(locationEvent); }; -void ctx::VisitDetector::__setPeriod(place_recog_mode_e energyMode) +void ctx::VisitDetector::__setPeriod(PlaceRecogMode energyMode) { switch (energyMode) { case PLACE_RECOG_LOW_POWER_MODE: @@ -438,7 +437,7 @@ void ctx::VisitDetector::__setPeriod(place_recog_mode_e energyMode) } } -void ctx::VisitDetector::setMode(place_recog_mode_e energyMode) +void ctx::VisitDetector::setMode(PlaceRecogMode energyMode) { _D(""); __setPeriod(energyMode); diff --git a/src/place/recognition/user_places/visit_detector.h b/src/place/recognition/user_places/visit_detector.h index a4c9b34..757774e 100644 --- a/src/place/recognition/user_places/visit_detector.h +++ b/src/place/recognition/user_places/visit_detector.h @@ -36,11 +36,11 @@ namespace ctx { private: bool __testMode; - std::shared_ptr __detectedVisits; // only used in test mode + std::shared_ptr __detectedVisits; // only used in test mode LocationLogger __locationLogger; WifiLogger __wifiLogger; std::vector __listeners; - std::shared_ptr __currentLogger; + std::shared_ptr __currentMacEvents; Interval __currentInterval; std::vector __locationEvents; std::vector> __historyFrames; // python: history_scans + history_times @@ -51,8 +51,8 @@ namespace ctx { int __periodSeconds; // fields that are used only in case of entrance detection - std::shared_ptr __representativesMacs; // macs that represent the current place - std::shared_ptr __stayMacs; // macs that can appear in the current place + std::shared_ptr __representativesMacs; // macs that represent the current place + std::shared_ptr __stayMacs; // macs that can appear in the current place time_t __entranceTime; time_t __departureTime; @@ -62,37 +62,37 @@ namespace ctx { void __detectEntrance(std::shared_ptr frame); void __detectDeparture(std::shared_ptr frame); void __processBuffer(std::shared_ptr frame); // python: buffer_analysing - std::shared_ptr __makeFrame(std::shared_ptr mac_events, Interval interval); // python: scans2fingerprint + std::shared_ptr __makeFrame(std::shared_ptr macEvents, Interval interval); // python: scans2fingerprint void __resetHistory(); void __resetHistory(std::shared_ptr frame); void __visitStartDetected(); void __visitEndDetected(); void __putLocationToVisit(Visit &visit); - std::shared_ptr __selectRepresentatives(const std::vector> &frames); - std::shared_ptr __macSetOfGreaterOrEqualShare(const mac_shares_t &mac_shares, share_t threshold); - std::shared_ptr __macSharesFromCounts(mac_counts_t const &mac_counts, count_t denominator); // python: response_rate - share_t __calcMaxShare(const mac_shares_t &mac_shares); - bool __isDisjoint(const mac_counts_t &mac_counts, const mac_set_t &macSet); - bool __protrudesFrom(const mac_counts_t &mac_counts, const mac_set_t &macSet); - void __setPeriod(place_recog_mode_e mode); + std::shared_ptr __selectRepresentatives(const std::vector> &frames); + std::shared_ptr __macSetOfGreaterOrEqualShare(const Macs2Shares &macs2Shares, share_t threshold); + std::shared_ptr __macSharesFromCounts(Macs2Counts const &macs2Counts, count_t denominator); // python: response_rate + share_t __calcMaxShare(const Macs2Shares &macs2Shares); + bool __isDisjoint(const Macs2Counts &macs2Counts, const MacSet &macSet); + bool __protrudesFrom(const Macs2Counts &macs2Counts, const MacSet &macSet); + void __setPeriod(PlaceRecogMode mode); void __processCurrentLogger(); /* DATABASE */ void __dbCreateTable(); int __dbInsertVisit(Visit visit); - void __putVisitCategToJson(const char* key, const categs_t &categs, int categ_type, Json &data); - void __putVisitCategsToJson(const categs_t &categs, Json &data); + void __putVisitCategToJson(const char* key, const Categs &categs, int categType, Json &data); + void __putVisitCategsToJson(const Categs &categs, Json &data); /* INPUT */ void onWifiScan(MacEvent event); void onNewLocation(LocationEvent location); public: - VisitDetector(time_t t_start_scan, place_recog_mode_e energyMode = PLACE_RECOG_HIGH_ACCURACY_MODE, bool testMode = false); + VisitDetector(time_t startScan, PlaceRecogMode energyMode = PLACE_RECOG_HIGH_ACCURACY_MODE, bool testMode = false); ~VisitDetector(); - std::shared_ptr getVisits(); // only used in test mode - void setMode(place_recog_mode_e energyMode); + std::shared_ptr getVisits(); // only used in test mode + void setMode(PlaceRecogMode energyMode); }; /* class VisitDetector */ diff --git a/src/place/recognition/user_places/wifi_listener_iface.h b/src/place/recognition/user_places/wifi_listener_iface.h index 8f91c22..3b883d3 100644 --- a/src/place/recognition/user_places/wifi_listener_iface.h +++ b/src/place/recognition/user_places/wifi_listener_iface.h @@ -25,7 +25,7 @@ namespace ctx { public: virtual ~IWifiListener() {}; - virtual void onWifiScan(ctx::MacEvent e) = 0; + virtual void onWifiScan(ctx::MacEvent macEvent) = 0; }; /* IWifiListener */ diff --git a/src/place/recognition/user_places/wifi_logger.cpp b/src/place/recognition/user_places/wifi_logger.cpp index 29dabd4..4c3742a 100644 --- a/src/place/recognition/user_places/wifi_logger.cpp +++ b/src/place/recognition/user_places/wifi_logger.cpp @@ -21,11 +21,11 @@ #include #include "debug_utils.h" -#define WIFI_CREATE_TABLE_COLUMNS \ +#define __WIFI_CREATE_TABLE_COLUMNS \ WIFI_COLUMN_TIMESTAMP " timestamp NOT NULL, "\ WIFI_COLUMN_BSSID " TEXT NOT NULL" -#define _WIFI_ERROR_LOG(error) { \ +#define __WIFI_ERROR_LOG(error) { \ if (error != WIFI_ERROR_NONE) { \ _E("ERROR == %s", __wifiError2Str(error)); \ } else { \ @@ -35,7 +35,7 @@ int ctx::WifiLogger::__dbCreateTable() { - bool ret = db_manager::create_table(0, WIFI_TABLE_NAME, WIFI_CREATE_TABLE_COLUMNS, NULL, NULL); + bool ret = db_manager::create_table(0, WIFI_TABLE_NAME, __WIFI_CREATE_TABLE_COLUMNS, NULL, NULL); _D("Table Creation Request: %s", ret ? "SUCCESS" : "FAIL"); return ret; } @@ -64,7 +64,7 @@ int ctx::WifiLogger::__dbInsertLogs() return 0; } -ctx::WifiLogger::WifiLogger(IWifiListener * listener, place_recog_mode_e energyMode, bool testMode) : +ctx::WifiLogger::WifiLogger(IWifiListener * listener, PlaceRecogMode energyMode, bool testMode) : __timerOn(false), __intervalMinutes(WIFI_LOGGER_INTERVAL_MINUTES_HIGH_ACCURACY), __testMode(testMode), @@ -107,9 +107,9 @@ ctx::WifiLogger::~WifiLogger() __wifiDeinitializeRequest(); } -void ctx::WifiLogger::__wifiDeviceStateChangedCb(wifi_device_state_e state, void *user_data) +void ctx::WifiLogger::__wifiDeviceStateChangedCb(wifi_device_state_e state, void *userData) { - ctx::WifiLogger* wifiLogger = (ctx::WifiLogger *)user_data; + ctx::WifiLogger* wifiLogger = (ctx::WifiLogger *)userData; switch (state) { case WIFI_DEVICE_STATE_DEACTIVATED: _D("WIFI setting OFF"); @@ -128,9 +128,9 @@ void ctx::WifiLogger::__wifiDeviceStateChangedCb(wifi_device_state_e state, void } } -void ctx::WifiLogger::__wifiConnectionStateChangedCb(wifi_connection_state_e state, wifi_ap_h ap, void *user_data) +void ctx::WifiLogger::__wifiConnectionStateChangedCb(wifi_connection_state_e state, wifi_ap_h ap, void *userData) { - ctx::WifiLogger* wifiLogger = (ctx::WifiLogger *)user_data; + ctx::WifiLogger* wifiLogger = (ctx::WifiLogger *)userData; switch (state) { case WIFI_CONNECTION_STATE_CONNECTED: _D("connected to AP"); @@ -145,9 +145,9 @@ void ctx::WifiLogger::__wifiConnectionStateChangedCb(wifi_connection_state_e sta // TODO: Check if AP bssid (MAC Address) will be helpful somehow in LOW_POWER mode } -bool ctx::WifiLogger::__wifiFoundApCb(wifi_ap_h ap, void *user_data) +bool ctx::WifiLogger::__wifiFoundApCb(wifi_ap_h ap, void *userData) { - ctx::WifiLogger* wifiLogger = (ctx::WifiLogger *)user_data; + ctx::WifiLogger* wifiLogger = (ctx::WifiLogger *)userData; char *bssid = NULL; int ret = __wifiApGetBssidRequest(ap, &bssid); @@ -215,9 +215,9 @@ const char* ctx::WifiLogger::__wifiError2Str(int error) } } -void ctx::WifiLogger::__wifiScanFinishedCb(wifi_error_e error_code, void *user_data) +void ctx::WifiLogger::__wifiScanFinishedCb(wifi_error_e errorCode, void *userData) { - ctx::WifiLogger* wifiLogger = (ctx::WifiLogger *)user_data; + ctx::WifiLogger* wifiLogger = (ctx::WifiLogger *)userData; time_t now = time(nullptr); #ifdef TIZEN_ENGINEER_MODE @@ -225,17 +225,17 @@ void ctx::WifiLogger::__wifiScanFinishedCb(wifi_error_e error_code, void *user_d if (wifiLogger->__lastScanTime > 0) { seconds = difftime(now, wifiLogger->__lastScanTime); } - std::string time_str = DebugUtils::humanReadableDateTime(now, "%T", 9); + std::string timeStr = DebugUtils::humanReadableDateTime(now, "%T", 9); _D("__connectedToWifiAp = %d, __duringVisit = %d, __lastScansPool.size() = %d -> scan %s (from last : %.1fs)", static_cast(wifiLogger->__connectedToWifiAp), static_cast(wifiLogger->__duringVisit), wifiLogger->__lastScansPool.size(), - time_str.c_str(), + timeStr.c_str(), seconds); #endif /* TIZEN_ENGINEER_MODE */ wifiLogger->__lastScanTime = now; - int ret = __wifiForeachFoundApsRequest(user_data); + int ret = __wifiForeachFoundApsRequest(userData); if (ret != WIFI_ERROR_NONE) { return; } @@ -246,69 +246,69 @@ void ctx::WifiLogger::__wifiScanFinishedCb(wifi_error_e error_code, void *user_d bool ctx::WifiLogger::__checkWifiIsActivated() { - bool wifi_activated = true; - int ret = wifi_is_activated(&wifi_activated); - _WIFI_ERROR_LOG(ret); - _D("Wi-Fi is %s", wifi_activated ? "ON" : "OFF"); - return wifi_activated; + bool wifiActivated = true; + int ret = wifi_is_activated(&wifiActivated); + __WIFI_ERROR_LOG(ret); + _D("Wi-Fi is %s", wifiActivated ? "ON" : "OFF"); + return wifiActivated; } void ctx::WifiLogger::__wifiScanRequest() { int ret = wifi_scan(__wifiScanFinishedCb, this); - _WIFI_ERROR_LOG(ret); + __WIFI_ERROR_LOG(ret); } -int ctx::WifiLogger::__wifiForeachFoundApsRequest(void *user_data) +int ctx::WifiLogger::__wifiForeachFoundApsRequest(void *userData) { - int ret = wifi_foreach_found_aps(__wifiFoundApCb, user_data); - _WIFI_ERROR_LOG(ret); + int ret = wifi_foreach_found_aps(__wifiFoundApCb, userData); + __WIFI_ERROR_LOG(ret); return ret; } wifi_connection_state_e ctx::WifiLogger::__wifiGetConnectionStateRequest() { - wifi_connection_state_e connection_state; - int ret = wifi_get_connection_state(&connection_state); - _WIFI_ERROR_LOG(ret); - return connection_state; + wifi_connection_state_e connectionState; + int ret = wifi_get_connection_state(&connectionState); + __WIFI_ERROR_LOG(ret); + return connectionState; } void ctx::WifiLogger::__wifiSetBackgroundScanCbRequest() { int ret = wifi_set_background_scan_cb(__wifiScanFinishedCb, this); - _WIFI_ERROR_LOG(ret); + __WIFI_ERROR_LOG(ret); } void ctx::WifiLogger::__wifiSetDeviceStateChangedCbRequest() { int ret = wifi_set_device_state_changed_cb(__wifiDeviceStateChangedCb, this); - _WIFI_ERROR_LOG(ret); + __WIFI_ERROR_LOG(ret); } void ctx::WifiLogger::__wifiSetConnectionStateChangedCbRequest() { int ret = wifi_set_connection_state_changed_cb(__wifiConnectionStateChangedCb, this); - _WIFI_ERROR_LOG(ret); + __WIFI_ERROR_LOG(ret); } int ctx::WifiLogger::__wifiApGetBssidRequest(wifi_ap_h ap, char **bssid) { int ret = wifi_ap_get_bssid(ap, bssid); - _WIFI_ERROR_LOG(ret); + __WIFI_ERROR_LOG(ret); return ret; } void ctx::WifiLogger::__wifiInitializeRequest() { int ret = wifi_initialize(); - _WIFI_ERROR_LOG(ret); + __WIFI_ERROR_LOG(ret); } void ctx::WifiLogger::__wifiDeinitializeRequest() { int ret = wifi_deinitialize(); - _WIFI_ERROR_LOG(ret); + __WIFI_ERROR_LOG(ret); } bool ctx::WifiLogger::__checkTimerId(int id) @@ -443,7 +443,7 @@ void ctx::WifiLogger::onVisitEnd() __lastScansPool.clear(); } -void ctx::WifiLogger::__setInterval(place_recog_mode_e energyMode) +void ctx::WifiLogger::__setInterval(PlaceRecogMode energyMode) { switch (energyMode) { case PLACE_RECOG_LOW_POWER_MODE: @@ -463,7 +463,7 @@ void ctx::WifiLogger::__timerRestart() __timerStart(__intervalMinutes); } -void ctx::WifiLogger::setMode(place_recog_mode_e energyMode) +void ctx::WifiLogger::setMode(PlaceRecogMode energyMode) { _D(""); __setInterval(energyMode); diff --git a/src/place/recognition/user_places/wifi_logger.h b/src/place/recognition/user_places/wifi_logger.h index 029eee1..9938a2c 100644 --- a/src/place/recognition/user_places/wifi_logger.h +++ b/src/place/recognition/user_places/wifi_logger.h @@ -51,13 +51,13 @@ namespace ctx { public: WifiLogger(IWifiListener * listener = nullptr, - place_recog_mode_e mode = PLACE_RECOG_HIGH_ACCURACY_MODE, + PlaceRecogMode energyMode = PLACE_RECOG_HIGH_ACCURACY_MODE, bool testMode = false); ~WifiLogger(); void startLogging(); void stopLogging(); - void setMode(place_recog_mode_e energyMode); + void setMode(PlaceRecogMode energyMode); private: /* INPUT */ @@ -71,7 +71,7 @@ namespace ctx { int __timerId; int __intervalMinutes; TimerManager __timerManager; - void __setInterval(place_recog_mode_e energyMode); + void __setInterval(PlaceRecogMode energyMode); bool __checkTimerId(int id); bool __checkTimerTime(time_t now); void __timerStart(time_t minutes); @@ -87,17 +87,17 @@ namespace ctx { void __wifiSetConnectionStateChangedCbRequest(); static bool __checkWifiIsActivated(); void __wifiScanRequest(); - static int __wifiForeachFoundApsRequest(void *user_data); + static int __wifiForeachFoundApsRequest(void *userData); static wifi_connection_state_e __wifiGetConnectionStateRequest(); static int __wifiApGetBssidRequest(wifi_ap_h ap, char **bssid); void __wifiInitializeRequest(); void __wifiDeinitializeRequest(); /* SYSTEM CAPI CALLBACKS */ - static void __wifiDeviceStateChangedCb(wifi_device_state_e state, void *user_data); - static void __wifiConnectionStateChangedCb(wifi_connection_state_e state, wifi_ap_h ap, void *user_data); - static bool __wifiFoundApCb(wifi_ap_h ap, void *user_data); - static void __wifiScanFinishedCb(wifi_error_e error_code, void *user_data); + static void __wifiDeviceStateChangedCb(wifi_device_state_e state, void *userData); + static void __wifiConnectionStateChangedCb(wifi_connection_state_e state, wifi_ap_h ap, void *userData); + static bool __wifiFoundApCb(wifi_ap_h ap, void *userData); + static void __wifiScanFinishedCb(wifi_error_e errorCode, void *userData); bool __testMode; IWifiListener * const __listener; -- 2.34.1