PlaceGeofenceProvider::submitTriggerItem();
#ifndef _DISABLE_RECOG_ENGINE_
- place_recognition_provider::create(NULL);
- registerProvider<place_recognition_provider>(PLACE_SUBJ_RECOGNITION, PLACE_PRIV_RECOGNITION);
+ PlaceRecognitionProvider::create(NULL);
+ registerProvider<PlaceRecognitionProvider>(PLACE_SUBJ_RECOGNITION, PLACE_PRIV_RECOGNITION);
#endif /* _DISABLE_RECOG_ENGINE_ */
#endif /* _MOBILE_ */
#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;
_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<std::shared_ptr<ctx::Place>> places = engine.getPlaces();
+ std::vector<std::shared_ptr<ctx::Place>> 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;
}
namespace ctx {
- class place_recognition_provider : public ContextProviderBase {
+ class PlaceRecognitionProvider : public ContextProviderBase {
public:
static ContextProviderBase *create(void *data);
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 */
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_ */
#include <iostream>
#include <fstream>
-const std::string ctx::Gmap::__htmlHeader = R"(
+const std::string ctx::Gmap::__HTML_HEADER = R"(
<!DOCTYPE html>
<html>
<head>
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);
</html>
)";
-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";
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<std::shared_ptr<ctx::Place>>& places, std::ostream& out)
{
- out << __htmlHeader;
+ out << __HTML_HEADER;
for (std::shared_ptr<ctx::Place> place : places) {
__placeMarker2Stream(*place, out);
}
- out << __htmlFooter;
+ out << __HTML_FOOTER;
}
void ctx::Gmap::writeMap(const std::vector<std::shared_ptr<ctx::Place>>& places)
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<std::shared_ptr<Place>>& places, std::ostream& out);
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<NeighbourNodes> 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<NeighbourNodes> 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;
#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, "\
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 { \
} \
}
-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");
}
}
-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) {
}
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);
}
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)
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<int>(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<int>(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<int>(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<int>(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;
}
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;
}
{
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()
LOCATION_LOGGER_MAX_LOCATION_ATTEMPTS,
__locationCount,
LOCATION_LOGGER_MAX_LOCATION_COUNT);
- _LOCATION_ERROR_LOG(ret);
+ __LOCATION_ERROR_LOG(ret);
__activeRequestAttempts++;
__activeAttempts++;
__allAttempts++;
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) {
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
{
bool enable;
int ret = location_manager_is_enabled_method(method, &enable);
- _LOCATION_ERROR_LOG(ret);
+ __LOCATION_ERROR_LOG(ret);
return enable;
}
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();
}
__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);
}
}
}
}
-#undef _LOCATION_ERROR_LOG
+#undef __LOCATION_ERROR_LOG
class LocationLogger : public ITimerListener, public IVisitListener {
public:
- LocationLogger(ILocationListener *listener = nullptr,
- bool testMode = false);
+ LocationLogger(ILocationListener *listener = nullptr, bool testMode = false);
~LocationLogger();
private:
/* OUTPUT */
ILocationListener * const __listener;
- void __broadcast(LocationEvent location_event);
+ void __broadcast(LocationEvent locationEvent);
/* INTERNAL */
bool __testMode;
/* DATABASE */
static int __dbCreateTable();
- int __dbInsertLog(LocationEvent location_event);
+ int __dbInsertLog(LocationEvent locationEvent);
/* DEBUG */
static const char* __locationError2Str(int error);
/* 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();
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();
/* 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 */
#include <math.h>
#include <types_internal.h>
-ctx::num_t ctx::MahalModel::dist_s(const std::vector<num_t> &v1, const std::vector<num_t> &v2, const std::vector<num_t> &m)
+ctx::num_t ctx::MahalModel::distance(const std::vector<num_t> &v1, const std::vector<num_t> &v2, const std::vector<num_t> &m)
{
size_t n = v1.size();
if (m.size() != n * n) {
return sqrt(dist2);
}
-ctx::num_t ctx::MahalModel::dist(const std::vector<ctx::num_t> &v)
+ctx::num_t ctx::MahalModel::distance(const std::vector<ctx::num_t> &v)
{
- return dist_s(v, __mean, __sigma);
+ return distance(v, __mean, __sigma);
}
std::vector<num_t> __sigma; // represents square matrix row-wise
public:
- static num_t dist_s(const std::vector<num_t> &v1, const std::vector<num_t> &v2, const std::vector<num_t> &m);
+ static num_t distance(const std::vector<num_t> &v1, const std::vector<num_t> &v2, const std::vector<num_t> &m);
MahalModel(std::vector<num_t> mean, std::vector<num_t> sigma) :
__mean(mean),
__sigma(sigma) { }
- num_t dist(const std::vector<num_t> &v);
+ num_t distance(const std::vector<num_t> &v);
}; /* class MahalModel */
#include <algorithm>
#include <types_internal.h>
-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<PlaceCategId> categ_ids = {
+ const std::vector<PlaceCategId> 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<num_t> 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<num_t> 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::num_t> ctx::PlaceCateger::categVectorFromVisits(const ctx::visits_t &visits, PlaceCategId categ_id)
+std::vector<ctx::num_t> ctx::PlaceCateger::categVectorFromVisits(const ctx::Visits &visits, PlaceCategId categId)
{
std::vector<ctx::num_t> 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);
}
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 "";
}
}
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<ctx::num_t> 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<ctx::num_t> 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 */
#include <algorithm>
#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 ", "\
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 ", "\
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, "\
__dbDeletePlaces();
__dbDeleteOldVisits();
std::vector<Json> records = __dbGetVisits();
- visits_t visits = __visitsFromJsons(records);
+ Visits visits = __visitsFromJsons(records);
__processVisits(visits);
return true;
}
std::vector<ctx::Json> ctx::PlacesDetector::__dbGetVisits()
{
std::vector<Json> 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;
}
std::vector<ctx::Json> ctx::PlacesDetector::__dbGetPlaces()
{
std::vector<Json> 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;
}
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);
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<mac_set_t> macSet = std::make_shared<mac_set_t>();
- mac_set_ss >> *macSet;
+ std::stringstream ss;
+ ss << str;
+ std::shared_ptr<MacSet> macSet = std::make_shared<MacSet>();
+ 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));
}
return visit;
}
-ctx::visits_t ctx::PlacesDetector::__visitsFromJsons(std::vector<Json>& records)
+ctx::Visits ctx::PlacesDetector::__visitsFromJsons(std::vector<Json>& records)
{
- visits_t visits;
+ Visits visits;
_D("db_result: number of all visits: %d", records.size());
for (Json &row : records) {
{
std::shared_ptr<Place> place = std::make_shared<Place>();
{ // 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<PlaceCategId>(categ_id);
+ place->categId = static_cast<PlaceCategId>(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<time_t>(create_date);
+ place->createDate = static_cast<time_t>(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;
}
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);
auto components = __mergeVisits(visits);
std::vector<std::shared_ptr<Place>> newDetectedPlaces;
#ifdef TIZEN_ENGINEER_MODE
- std::vector<visits_t> places_visits; // TODO: remove from final solution.
+ std::vector<Visits> placesVisits; // TODO: remove from final solution.
#endif /* TIZEN_ENGINEER_MODE */
for (std::shared_ptr<graph::Component> component : *components) {
// Small places outliers reduction
continue;
}
- std::shared_ptr<visits_t> merged = std::make_shared<visits_t>();
+ std::shared_ptr<Visits> merged = std::make_shared<Visits>();
for (graph::Node i : *component) {
merged->push_back(visits[i]);
}
std::shared_ptr<Place> place = __placeFromMergedVisits(*merged);
- if (place->categ_id == PLACE_CATEG_ID_NONE) {
+ if (place->categId == PLACE_CATEG_ID_NONE) {
continue;
}
newDetectedPlaces.push_back(place);
#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 */
}
#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();
/*
* Replace old places by new ones.
*/
-void ctx::PlacesDetector::__detectedPlacesUpdate(std::vector<std::shared_ptr<Place>> &new_places)
+void ctx::PlacesDetector::__detectedPlacesUpdate(std::vector<std::shared_ptr<Place>> &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<double> latitudes;
std::vector<double> 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::Place> ctx::PlacesDetector::__placeFromMergedVisits(visits_t &merged_visits)
+std::shared_ptr<ctx::Place> ctx::PlacesDetector::__placeFromMergedVisits(Visits &mergedVisits)
{
std::shared_ptr<Place> place = std::make_shared<Place>();
- place->create_date = std::time(nullptr);
- std::vector<std::shared_ptr<mac_set_t>> macSets;
- for (const Visit &visit : merged_visits) {
+ place->createDate = std::time(nullptr);
+ std::vector<std::shared_ptr<MacSet>> macSets;
+ for (const Visit &visit : mergedVisits) {
macSets.push_back(visit.macSet);
}
- std::shared_ptr<mac_set_t> 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<MacSet> 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;
}
int size = cc->size();
cc->erase(std::remove_if(cc->begin(),
cc->end(),
- [](std::shared_ptr<graph::Component> &c) {
+ [](std::shared_ptr<graph::Component> &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);
}
}
void ctx::PlacesDetector::__dbDeletePlaces()
{
std::vector<Json> 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)
}
__dbCreateTable();
std::vector<Json> records = __dbGetPlaces();
- std::vector<std::shared_ptr<Place>> db_places = __placesFromJsons(records);
- __detectedPlacesUpdate(db_places);
+ std::vector<std::shared_ptr<Place>> 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<int>(place.create_date));
+ data.set(NULL, PLACE_COLUMN_WIFI_APS, place.wifiAps);
+ data.set(NULL, PLACE_COLUMN_CREATE_DATE, static_cast<int>(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");
}
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<Json>& records);
+ Visits __visitsFromJsons(std::vector<Json>& records);
std::shared_ptr<ctx::Place> __placeFromJson(Json &row);
std::vector<std::shared_ptr<Place>> __placesFromJsons(std::vector<Json>& records);
std::vector<Json> __dbGetPlaces();
void __dbInsertPlace(const Place &place);
- std::shared_ptr<Place> __placeFromMergedVisits(visits_t &merged_visits);
+ std::shared_ptr<Place> __placeFromMergedVisits(Visits &mergedVisits);
std::vector<std::shared_ptr<Place>> __detectedPlaces;
- void __detectedPlacesUpdate(std::vector<std::shared_ptr<Place>> &new_places);
- void __processVisits(visits_t &visits);
- static void __mergeLocation(const visits_t &merged_visits, Place &place);
+ void __detectedPlacesUpdate(std::vector<std::shared_ptr<Place>> &newPlaces);
+ void __processVisits(Visits &visits);
+ static void __mergeLocation(const Visits &mergedVisits, Place &place);
std::shared_ptr<graph::Components> __mergeVisits(const std::vector<Visit> &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<graph::Components> &cc); // TODO: move to private
std::vector<std::shared_ptr<Place>> getPlaces();
#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)
{
ctx::Json data;
for (std::shared_ptr<ctx::Place> 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<int>(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<int>(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);
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<std::shared_ptr<Place>> getPlaces();
static Json composeJson(std::vector<std::shared_ptr<Place>> places);
#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)
{
break;
}
input >> colon;
- if (colon != MAC_STRING_COMPONENTS_SEPARATOR) {
+ if (colon != __MAC_STRING_COMPONENTS_SEPARATOR) {
throw std::runtime_error("Invalid MAC format");
}
}
if (i >= Mac::MAC_SIZE) {
break;
}
- output << MAC_STRING_COMPONENTS_SEPARATOR;
+ output << __MAC_STRING_COMPONENTS_SEPARATOR;
}
output << std::dec;
return output;
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;
break;
}
delimeter = input.get();
- if (delimeter != MAC_SET_STRING_DELIMITER) {
+ if (delimeter != __MAC_SET_STRING_DELIMITER) {
input.unget();
break;
}
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> mac_vec(macSet.size());
- std::copy(macSet.begin(), macSet.end(), mac_vec.begin());
- std::sort(mac_vec.begin(), mac_vec.end());
+ std::vector<Mac> 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;
}
#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) {
&& 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;
return m2 < m1;
}
-std::shared_ptr<ctx::mac_set_t> ctx::mac_set_from_mac_counts(const mac_counts_t &mac_counts)
+std::shared_ptr<ctx::MacSet> ctx::macSetFromMacs2Counts(const Macs2Counts &macs2Counts)
{
- std::shared_ptr<mac_set_t> macSet(std::make_shared<mac_set_t>());
- for (auto &c: mac_counts) {
- macSet->insert(c.first);
+ std::shared_ptr<MacSet> macSet(std::make_shared<MacSet>());
+ for (auto &macCount: macs2Counts) {
+ macSet->insert(macCount.first);
}
return macSet;
}
-std::shared_ptr<ctx::mac_set_t> ctx::mac_sets_union(const std::vector<std::shared_ptr<mac_set_t>> &macSets)
+std::shared_ptr<ctx::MacSet> ctx::macSetsUnion(const std::vector<std::shared_ptr<MacSet>> &macSets)
{
- std::shared_ptr<mac_set_t> union_set = std::make_shared<mac_set_t>();
- for (std::shared_ptr<mac_set_t> macSet : macSets) {
- union_set->insert(macSet->begin(), macSet->end());
+ std::shared_ptr<MacSet> unionSet = std::make_shared<MacSet>();
+ for (std::shared_ptr<MacSet> 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_) {
}
}
-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;
}
typedef float share_t;
typedef int count_t;
- typedef std::unordered_map<ctx::Mac, ctx::count_t> mac_counts_t;
- typedef std::unordered_map<ctx::Mac, ctx::share_t> mac_shares_t;
+ typedef std::unordered_map<ctx::Mac, ctx::count_t> Macs2Counts;
+ typedef std::unordered_map<ctx::Mac, ctx::share_t> Macs2Shares;
- typedef std::unordered_set<ctx::Mac> mac_set_t;
+ typedef std::unordered_set<ctx::Mac> 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_set_t> mac_sets_union(const std::vector<std::shared_ptr<mac_set_t>> &macSets);
+ std::shared_ptr<MacSet> macSetsUnion(const std::vector<std::shared_ptr<MacSet>> &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 */
struct Frame {
Interval interval;
count_t numberOfTimestamps;
- mac_counts_t macCountsMap;
+ Macs2Counts macs2Counts;
Frame(Interval interval_) : interval(interval_), numberOfTimestamps(0) {};
};
MacEvent(time_t timestamp_, Mac mac_) : timestamp(timestamp_), mac(mac_) {}
};
- typedef std::map<int, num_t> categs_t; // scores of categories
+ typedef std::map<int, num_t> Categs; // scores of categories
struct Location {
double latitude;
#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();
struct Visit {
Interval interval;
- std::shared_ptr<mac_set_t> macSet;
- categs_t categs;
- bool location_valid;
- Location location; // makes sense if location_valid == true;
+ std::shared_ptr<MacSet> macSet;
+ Categs categs;
+ bool locationValid;
+ Location location; // makes sense if locationValid == true;
- Visit(Interval interval_, std::shared_ptr<mac_set_t> macSet_ = std::make_shared<mac_set_t>(), categs_t categs_ = categs_t()) :
+ Visit(Interval interval_, std::shared_ptr<MacSet> macSet_ = std::make_shared<MacSet>(), 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<Visit> visits_t;
- typedef std::vector<MacEvent> mac_events; // used to store current interval logs
+ typedef std::vector<Visit> Visits;
+ typedef std::vector<MacEvent> MacEvents; // used to store current interval logs
- std::shared_ptr<mac_set_t> mac_set_from_mac_counts(const mac_counts_t &macCountsMap);
+ std::shared_ptr<MacSet> 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 */
};
}
-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;
ctx::num_t ctx::VisitCateger::__sum(const std::vector<num_t> 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) {
}
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];
}
}
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;
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],
return categs;
}
-std::vector<ctx::num_t> 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]
};
}
void ctx::VisitCateger::categorize(ctx::Visit &visit)
{
- std::vector<ctx::num_t> 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;
}
}
bool weekend;
};
+ typedef std::vector<num_t> IntervalFeatures;
+
/*
* visit categorizer class
*/
class VisitCateger {
private:
- const static int MINUTES_IN_WEEK = 60 * 24 * 7;
- const static std::map<int, MahalModel> __models;
- const static std::vector<num_t> __featuresMean;
- const static std::vector<num_t> __featuresStd;
+ static const int __MINUTES_IN_WEEK = 60 * 24 * 7;
+ static const std::map<int, MahalModel> __models;
+ static const std::vector<num_t> __featuresMean;
+ static const std::vector<num_t> __featuresStd;
static num_t __sum(const std::vector<num_t> 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<num_t> &features);
static PiecewiseLin __chiApprox; // tabled chi function approximator
*/
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<num_t> vector with interpretations of input time interval
+ * @param interval time interval
+ * @return IntervalFeatures vector with interpretations of input time interval
*/
- static std::vector<num_t> intervalFeatures(const Interval &interval);
+ static IntervalFeatures intervalFeatures(const Interval &interval);
/**
* Function categorize visit based on visits time interval and fill its categories values.
#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, "\
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, "\
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),
__departureTime(0)
{
__setPeriod(energyMode);
- __currentInterval = Interval(t_start_scan, t_start_scan + __periodSeconds);
- __currentLogger = std::make_shared<mac_events>();
- __stayMacs = std::make_shared<mac_set_t>();
+ __currentInterval = Interval(startScan, startScan + __periodSeconds);
+ __currentMacEvents = std::make_shared<MacEvents>();
+ __stayMacs = std::make_shared<MacSet>();
if (__testMode) {
- __detectedVisits = std::make_shared<ctx::visits_t>();
+ __detectedVisits = std::make_shared<ctx::Visits>();
return;
}
__processCurrentLogger();
__shiftCurrentInterval();
}
- __currentLogger->push_back(e);
+ __currentMacEvents->push_back(e);
}
}
void ctx::VisitDetector::__processCurrentLogger()
{
_D("");
- std::shared_ptr<ctx::Frame> frame = __makeFrame(__currentLogger, __currentInterval);
+ std::shared_ptr<ctx::Frame> frame = __makeFrame(__currentMacEvents, __currentInterval);
__detectEntranceOrDeparture(frame);
- __currentLogger->clear();
+ __currentMacEvents->clear();
}
-std::shared_ptr<ctx::Frame> ctx::VisitDetector::__makeFrame(std::shared_ptr<ctx::mac_events> logger, ctx::Interval interval)
+std::shared_ptr<ctx::Frame> ctx::VisitDetector::__makeFrame(std::shared_ptr<ctx::MacEvents> logger, ctx::Interval interval)
{
std::set<time_t> timestamps;
std::shared_ptr<Frame> frame = std::make_shared<Frame>(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();
__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;
}
}
} 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();
// TODO: remove small accuracy locations from vectors?
std::vector<double> latitudes;
std::vector<double> 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);
}
}
-void ctx::VisitDetector::__detectEntrance(std::shared_ptr<ctx::Frame> current_frame)
+void ctx::VisitDetector::__detectEntrance(std::shared_ptr<ctx::Frame> 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<Frame> oldest_history_frame = __historyFrames[0];
- __stayMacs = mac_set_from_mac_counts(oldest_history_frame->macCountsMap);
+ std::shared_ptr<Frame> oldestHistoryFrame = __historyFrames[0];
+ __stayMacs = macSetFromMacs2Counts(oldestHistoryFrame->macs2Counts);
}
- std::shared_ptr<mac_set_t> current_beacons = mac_set_from_mac_counts(current_frame->macCountsMap);
+ std::shared_ptr<MacSet> 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;
}
__historyFrames.push_back(frame);
}
-std::shared_ptr<ctx::mac_set_t> ctx::VisitDetector::__selectRepresentatives(const std::vector<std::shared_ptr<Frame>> &frames)
+std::shared_ptr<ctx::MacSet> ctx::VisitDetector::__selectRepresentatives(const std::vector<std::shared_ptr<Frame>> &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<mac_shares_t> repr_shares = __macSharesFromCounts(repr_counts, all_count);
+ std::shared_ptr<Macs2Shares> 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<mac_set_t> repr_mac_set = __macSetOfGreaterOrEqualShare(*repr_shares, threshold);
+ std::shared_ptr<MacSet> 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::mac_set_t> ctx::VisitDetector::__macSetOfGreaterOrEqualShare(const ctx::mac_shares_t &mac_shares, ctx::share_t threshold)
+std::shared_ptr<ctx::MacSet> ctx::VisitDetector::__macSetOfGreaterOrEqualShare(const ctx::Macs2Shares &macs2Shares, ctx::share_t threshold)
{
- std::shared_ptr<mac_set_t> macSet = std::make_shared<mac_set_t>();
- for (auto &ms : mac_shares) {
- if (ms.second >= threshold) {
- macSet->insert(ms.first);
+ std::shared_ptr<MacSet> macSet = std::make_shared<MacSet>();
+ for (auto &macShare : macs2Shares) {
+ if (macShare.second >= threshold) {
+ macSet->insert(macShare.first);
}
}
return macSet;
}
-std::shared_ptr<ctx::mac_shares_t> ctx::VisitDetector::__macSharesFromCounts(ctx::mac_counts_t const &macCountsMap, ctx::count_t denominator)
+std::shared_ptr<ctx::Macs2Shares> ctx::VisitDetector::__macSharesFromCounts(ctx::Macs2Counts const &macs2Counts, ctx::count_t denominator)
{
- std::shared_ptr<mac_shares_t> mac_shares(std::make_shared<mac_shares_t>());
- for (auto mac_count : macCountsMap) {
- (*mac_shares)[mac_count.first] = (share_t) mac_count.second / denominator;
+ std::shared_ptr<Macs2Shares> macs2Shares(std::make_shared<Macs2Shares>());
+ for (auto macCount : macs2Counts) {
+ (*macs2Shares)[macCount.first] = (share_t) macCount.second / denominator;
}
- return mac_shares;
+ return macs2Shares;
}
-std::shared_ptr<ctx::visits_t> ctx::VisitDetector::getVisits()
+std::shared_ptr<ctx::Visits> 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);
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);
data.set(NULL, VISIT_COLUMN_END_TIME, static_cast<int>(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:
}
}
-void ctx::VisitDetector::setMode(place_recog_mode_e energyMode)
+void ctx::VisitDetector::setMode(PlaceRecogMode energyMode)
{
_D("");
__setPeriod(energyMode);
private:
bool __testMode;
- std::shared_ptr<visits_t> __detectedVisits; // only used in test mode
+ std::shared_ptr<Visits> __detectedVisits; // only used in test mode
LocationLogger __locationLogger;
WifiLogger __wifiLogger;
std::vector<IVisitListener*> __listeners;
- std::shared_ptr<mac_events> __currentLogger;
+ std::shared_ptr<MacEvents> __currentMacEvents;
Interval __currentInterval;
std::vector<LocationEvent> __locationEvents;
std::vector<std::shared_ptr<Frame>> __historyFrames; // python: history_scans + history_times
int __periodSeconds;
// fields that are used only in case of entrance detection
- std::shared_ptr<mac_set_t> __representativesMacs; // macs that represent the current place
- std::shared_ptr<mac_set_t> __stayMacs; // macs that can appear in the current place
+ std::shared_ptr<MacSet> __representativesMacs; // macs that represent the current place
+ std::shared_ptr<MacSet> __stayMacs; // macs that can appear in the current place
time_t __entranceTime;
time_t __departureTime;
void __detectEntrance(std::shared_ptr<Frame> frame);
void __detectDeparture(std::shared_ptr<Frame> frame);
void __processBuffer(std::shared_ptr<Frame> frame); // python: buffer_analysing
- std::shared_ptr<Frame> __makeFrame(std::shared_ptr<mac_events> mac_events, Interval interval); // python: scans2fingerprint
+ std::shared_ptr<Frame> __makeFrame(std::shared_ptr<MacEvents> macEvents, Interval interval); // python: scans2fingerprint
void __resetHistory();
void __resetHistory(std::shared_ptr<Frame> frame);
void __visitStartDetected();
void __visitEndDetected();
void __putLocationToVisit(Visit &visit);
- std::shared_ptr<mac_set_t> __selectRepresentatives(const std::vector<std::shared_ptr<Frame>> &frames);
- std::shared_ptr<mac_set_t> __macSetOfGreaterOrEqualShare(const mac_shares_t &mac_shares, share_t threshold);
- std::shared_ptr<mac_shares_t> __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<MacSet> __selectRepresentatives(const std::vector<std::shared_ptr<Frame>> &frames);
+ std::shared_ptr<MacSet> __macSetOfGreaterOrEqualShare(const Macs2Shares &macs2Shares, share_t threshold);
+ std::shared_ptr<Macs2Shares> __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<visits_t> getVisits(); // only used in test mode
- void setMode(place_recog_mode_e energyMode);
+ std::shared_ptr<Visits> getVisits(); // only used in test mode
+ void setMode(PlaceRecogMode energyMode);
}; /* class VisitDetector */
public:
virtual ~IWifiListener() {};
- virtual void onWifiScan(ctx::MacEvent e) = 0;
+ virtual void onWifiScan(ctx::MacEvent macEvent) = 0;
}; /* IWifiListener */
#include <sstream>
#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 { \
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;
}
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),
__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");
}
}
-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");
// 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);
}
}
-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
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<int>(wifiLogger->__connectedToWifiAp),
static_cast<int>(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;
}
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)
__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:
__timerStart(__intervalMinutes);
}
-void ctx::WifiLogger::setMode(place_recog_mode_e energyMode)
+void ctx::WifiLogger::setMode(PlaceRecogMode energyMode)
{
_D("");
__setInterval(energyMode);
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 */
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);
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;