std::set<int> fringe;
for (Node i = 0; i < static_cast<Node>(graph.size()); i++) {
- if (!graph[i]) {
+ if (!graph[i])
continue;
- }
+
// neighbourhood of node i exists (was not removed)
std::shared_ptr<Component> c = std::make_shared<Component>();
ccs->push_back(c);
std::shared_ptr<NeighbourNodes> currNhood = graph[currNode];
for (Node nhoodNode : *currNhood) {
- if (graph[nhoodNode] && fringe.find(nhoodNode) == fringe.end()) {
+ if (graph[nhoodNode] && fringe.find(nhoodNode) == fringe.end())
fringe.insert(nhoodNode);
- }
}
graph[currNode].reset(); // removing current node
}
__locationManagerCreate();
- if (LOCATION_LOGGER_DATABASE) {
+ if (LOCATION_LOGGER_DATABASE)
__dbCreateTable();
- }
__locationManagerSetServiceStateChangedCb();
__locationManagerSetSettingChangedCb();
{
_D("");
__locationCount++;
- if (__listener) {
+ if (__listener)
__listener->onNewLocation(locationEvent);
- }
- if (LOCATION_LOGGER_DATABASE) {
+ if (LOCATION_LOGGER_DATABASE)
__dbInsertLog(locationEvent);
- }
}
bool ctx::LocationLogger::onTimerExpired(int id)
void ctx::LocationLogger::__activeRequestTimerStart()
{
int minutes = LOCATION_LOGGER_ACTIVE_REQUEST_TIMEOUT_SECONDS / 60;
- if (LOCATION_LOGGER_ACTIVE_REQUEST_TIMEOUT_SECONDS % 60) {
+ if (LOCATION_LOGGER_ACTIVE_REQUEST_TIMEOUT_SECONDS % 60)
minutes++;
- }
__timerPurpose = LOCATION_LOGGER_WAITING_FOR_ACTIVE_REQUEST;
_D("LOCATION_LOGGER_WAITING_FOR_ACTIVE_REQUEST (minutes=%d)", minutes);
__timerStart(minutes);
}),
visits.end());
int newSize = visits.size();
- if (size != newSize) {
+ if (size != newSize)
_D("Visits number from %d to %d (visits min scores checking)", size, newSize);
- }
}
/*
place.categId = categId;
}
}
- if (sumScore > 0) {
+ if (sumScore > 0)
place.categConfidence = maxScore / sumScore;
- }
if (__reduceCategory(place.categId, visits)) {
place.categId = PLACE_CATEG_ID_OTHER;
place.categConfidence = 0.0;
std::vector<ctx::num_t> vec;
for (auto &visit : visits) {
auto search = visit.categs.find(categId);
- if (search != visit.categs.end()) {
+ if (search != visit.categs.end())
vec.push_back(search->second);
- }
}
return vec;
}
}),
visits.end());
int newSize = visits.size();
- if (size != newSize) {
+ if (size != newSize)
_D("Visits number from %d to %d (to short and to long reduction)", size, newSize);
- }
}
void ctx::PlacesDetector::__processVisits(ctx::Visits &visits)
#endif /* TIZEN_ENGINEER_MODE */
for (std::shared_ptr<graph::Component> component : *components) {
// Small places outliers reduction
- if (!__testMode && component->size() < PLACES_DETECTOR_MIN_VISITS_PER_BIG_PLACE) {
+ if (!__testMode && component->size() < PLACES_DETECTOR_MIN_VISITS_PER_BIG_PLACE)
continue;
- }
-
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->categId == PLACE_CATEG_ID_NONE) {
+ if (place->categId == PLACE_CATEG_ID_NONE)
continue;
- }
newDetectedPlaces.push_back(place);
- if (!__testMode) {
+ if (!__testMode)
__dbInsertPlace(*place);
- }
#ifdef TIZEN_ENGINEER_MODE
{ // TODO: Only for debug -> remove in final solution
}),
cc->end());
int newSize = cc->size();
- if (size != newSize) {
+ if (size != newSize)
_D("Connected components from %d to %d (min visit per place)", size, newSize);
- }
}
std::shared_ptr<ctx::graph::Components> ctx::PlacesDetector::__mergeVisits(const std::vector<Visit> &visits)
__testMode(testMode),
__dbManager(testMode ? nullptr : new DatabaseManager())
{
- if (testMode) {
+ if (testMode)
return;
- }
__dbCreateTable();
std::vector<Json> records = __dbGetPlaces();
std::vector<std::shared_ptr<Place>> dbPlaces = __placesFromJsons(records);
template <class T> ctx::share_t overlap1stOver2nd(const T &s1, const T &s2)
{
- if (s2.empty()) {
+ if (s2.empty())
return 0;
- }
int count = 0;
for (auto e : s2) {
- if (s1.find(e) != s1.end()) {
+ if (s1.find(e) != s1.end())
count++;
- }
}
return (ctx::share_t) count / s2.size();
}
template <class T> bool isJoint(const T &s1, const T &s2)
{
for (auto e : s2) {
- if (s1.find(e) != s1.end()) {
+ if (s1.find(e) != s1.end())
return true;
- }
}
return false;
}
_D("PlacesDetector timer removed");
}
- if (__visitDetector) {
+ if (__visitDetector)
delete __visitDetector;
- }
-
- if (__placesDetector) {
+ if (__placesDetector)
delete __placesDetector;
- }
};
std::vector<std::shared_ptr<ctx::Place>> ctx::UserPlaces::__getPlaces()
void ctx::UserPlaces::setMode(PlaceRecogMode energyMode)
{
- if (__visitDetector) {
+ if (__visitDetector)
__visitDetector->setMode(energyMode);
- }
}
input >> std::hex;
input >> h;
mac.c[i] = h;
- if (i + 1 >= ctx::Mac::MAC_SIZE) {
+ if (i + 1 >= ctx::Mac::MAC_SIZE)
break;
- }
input >> colon;
- if (colon != __MAC_STRING_COMPONENTS_SEPARATOR) {
+ if (colon != __MAC_STRING_COMPONENTS_SEPARATOR)
throw std::runtime_error("Invalid MAC format");
- }
}
input >> std::dec;
return input;
output << std::hex << std::setfill('0') << std::setw(2);
output << static_cast<int>(mac.c[i]);
i++;
- if (i >= Mac::MAC_SIZE) {
+ if (i >= Mac::MAC_SIZE)
break;
- }
output << __MAC_STRING_COMPONENTS_SEPARATOR;
}
output << std::dec;
bool ctx::operator==(const Mac &m1, const Mac &m2)
{
for (size_t i = 0; i < Mac::MAC_SIZE; i++) {
- if (m1.c[i] != m2.c[i]) {
+ if (m1.c[i] != m2.c[i])
return false;
- }
}
return true;
}
for (size_t i = 0; i < Mac::MAC_SIZE; i++) {
c1 = m1.c[i];
c2 = m2.c[i];
- if (c1 < c2) {
+ if (c1 < c2)
return true;
- }
- if (c1 > c2) {
+ if (c1 > c2)
return false;
- }
}
return false; // they are equal
}
break;
}
macSet.insert(mac);
- if (input.eof()) {
+ if (input.eof())
break;
- }
delimeter = input.get();
if (delimeter != __MAC_SET_STRING_DELIMITER) {
input.unget();
}
ctx::Interval::Interval(time_t start_, time_t end_) : start(start_), end(end_) {
- if (end_ < start_) {
+ if (end_ < start_)
_E("Negative interval, start=%d, end=%d", start_, end_);
- }
}
struct tm *result;
tzset();
result = localtime_r(&time, &timeinfo);
- if (result == NULL) {
+ if (result == NULL)
return {0, 0, 0, false};
- }
int minutesSinceMidnight = 60 * timeinfo.tm_hour + timeinfo.tm_min;
int weekday = (timeinfo.tm_wday + 6) % 7; // Monday is 0, Sunday is 6
bool weekend = weekday > 4;
int durationMinutes = (interval.end - interval.start) / 60;
int scopeMinutes = startF.minutesSinceBeginingOfTheWeek + durationMinutes;
int weeksScope = scopeMinutes / __MINUTES_IN_WEEK;
- if (scopeMinutes % __MINUTES_IN_WEEK > 0) {
+ if (scopeMinutes % __MINUTES_IN_WEEK > 0)
weeksScope++;
- }
return weeksScope;
}
_E("'to' exceeds model size");
toSecure = model.size() - 1;
}
-
- if (from > to) {
+ if (from > to)
_E("'from' greater than 'to'");
- }
-
num_t result = 0.0;
for (size_t i = from; i <= toSecure; i++) {
result += model[i];
}
-
return result;
}
ret += __sum(prob_features::weekModel[categ], startIndex, endIndex);
minutes += endIndex - startIndex + 1;
}
- if (minutes > 0) {
+ if (minutes > 0)
return ret / minutes;
- }
return ret;
}
bool ctx::VisitDetector::__isDisjoint(const ctx::Macs2Counts &macs2Counts, const ctx::MacSet &macSet)
{
for (auto &mac : macSet) {
- if (macs2Counts.find(mac) != macs2Counts.end()) {
+ if (macs2Counts.find(mac) != macs2Counts.end())
return false;
- }
}
return true;
}
bool ctx::VisitDetector::__protrudesFrom(const ctx::Macs2Counts &macs2Counts, const ctx::MacSet &macSet)
{
for (auto &macCount : macs2Counts) {
- if (macSet.find(macCount.first) == macSet.end()) {
+ if (macSet.find(macCount.first) == macSet.end())
return true;
- }
}
return false;
}
__historyFrames.push_back(__bufferedFrames[0]);
for (size_t i = 1; i < __bufferedFrames.size(); i++) {
__detectEntrance(__bufferedFrames[i]);
- if (__entranceToPlace) {
+ if (__entranceToPlace)
break;
- }
}
}
}
if (similarity::overlapBiggerOverSmaller(*currentBeacons, *__stayMacs) > VISIT_DETECTOR_OVERLAP) {
__stableCounter++;
__historyFrames.push_back(currentFrame);
-
- if (__stableCounter == VISIT_DETECTOR_STABLE_DEPTH) { // entrance detected
+ if (__stableCounter == VISIT_DETECTOR_STABLE_DEPTH) // entrance detected
__visitStartDetected();
- }
} else {
__resetHistory(currentFrame);
}
{
ctx::share_t maxShare = 0.0;
for (auto &macShare : macs2Shares) {
- if (macShare.second > maxShare) {
+ if (macShare.second > maxShare)
maxShare = macShare.second;
- }
}
return maxShare;
}
{
std::shared_ptr<MacSet> macSet = std::make_shared<MacSet>();
for (auto &macShare : macs2Shares) {
- if (macShare.second >= threshold) {
+ if (macShare.second >= threshold)
macSet->insert(macShare.first);
- }
}
return macSet;
}
{
_D("");
__setPeriod(energyMode);
- if (__wifiLogger) {
+ if (__wifiLogger)
__wifiLogger->setMode(energyMode);
- }
}
__setInterval(energyMode);
- if (WIFI_LOGGER_DATABASE) {
+ if (WIFI_LOGGER_DATABASE)
__dbCreateTable();
- }
__logs = std::vector<MacEvent>();
__wifiSetDeviceStateChangedCbRequest();
- if (WIFI_LOGGER_LOW_POWER_MODE) {
+
+ if (WIFI_LOGGER_LOW_POWER_MODE)
__wifiSetConnectionStateChangedCbRequest();
- }
+
wifi_connection_state_e state = __wifiGetConnectionStateRequest();
__connectedToWifiAp = (state == WIFI_CONNECTION_STATE_CONNECTED);
_D("__connectedToWifiAp = %d, __duringVisit = %d IN CONSTRUCTOR",
switch (state) {
case WIFI_DEVICE_STATE_DEACTIVATED:
_D("WIFI setting OFF");
- if (wifiLogger->__started) {
+ if (wifiLogger->__started)
wifiLogger->__stopLogging();
- }
break;
case WIFI_DEVICE_STATE_ACTIVATED:
_D("WIFI setting ON");
- if (wifiLogger->__started) {
+ if (wifiLogger->__started)
wifiLogger->__startLogging();
- }
break;
default:
break;
char *bssid = NULL;
int ret = wifiLogger->__wifiApGetBssidRequest(ap, &bssid);
- if (ret != WIFI_ERROR_NONE) {
+ if (ret != WIFI_ERROR_NONE)
return false;
- }
char *essid = NULL;
ret = wifiLogger->__wifiApGetEssidRequest(ap, &essid);
- if (ret != WIFI_ERROR_NONE) {
+ if (ret != WIFI_ERROR_NONE)
return false;
- }
Mac mac;
try {
wifiLogger->__lastScansPool.insert(std::string(bssid));
}
}
- if (WIFI_LOGGER_DATABASE) {
+ if (WIFI_LOGGER_DATABASE)
wifiLogger->__logs.push_back(log);
- }
return true;
}
wifiLogger->__lastScanTime = now;
int ret = wifiLogger->__wifiForeachFoundApsRequest(userData);
- if (ret != WIFI_ERROR_NONE) {
+ if (ret != WIFI_ERROR_NONE)
return;
- }
- if (WIFI_LOGGER_DATABASE) {
+ if (WIFI_LOGGER_DATABASE)
wifiLogger->__dbInsertLogs();
- }
}
bool ctx::WifiLogger::__checkWifiIsActivated()
{
time_t now = time(nullptr);
_D("");
- if (__checkTimerId(id) == false) {
- // Incorrect callback call
+ if (__checkTimerId(id) == false) // Incorrect callback call
return false;
- }
- if (__checkTimerTime(now) == false) {
- // Prevention from double callback call bug
+ if (__checkTimerTime(now) == false) // Prevention from double callback call bug
return __timerOn;
- }
_D("__connectedToWifiAp = %d, __duringVisit = %d, __lastScansPool.size() = %d",
static_cast<int>(__connectedToWifiAp),
static_cast<int>(__duringVisit),
void ctx::WifiLogger::__startLogging()
{
_D("");
- if (!__checkWifiIsActivated() || __running) {
+ if (!__checkWifiIsActivated() || __running)
return;
- }
__running = true;
if (WIFI_LOGGER_ACTIVE_SCANNING) {
__timerStart(__intervalMinutes);
__wifiScanRequest();
}
- if (WIFI_LOGGER_PASSIVE_SCANNING) {
+ if (WIFI_LOGGER_PASSIVE_SCANNING)
__wifiSetBackgroundScanCbRequest();
- }
}
void ctx::WifiLogger::stopLogging()
void ctx::WifiLogger::__stopLogging()
{
_D("");
- if (!__running) {
+ if (!__running)
return;
- }
if (WIFI_LOGGER_ACTIVE_SCANNING) {
// Unset timer
__timerOn = false;
// Remove timer
__timerManager.remove(__timerId);
}
- if (WIFI_LOGGER_PASSIVE_SCANNING) {
+ if (WIFI_LOGGER_PASSIVE_SCANNING)
__wifiWrapper.unsetBackgroundScanCb();
- }
__running = false;
}
{
_D("");
__setInterval(energyMode);
- if (WIFI_LOGGER_ACTIVE_SCANNING && __timerOn) {
+ if (WIFI_LOGGER_ACTIVE_SCANNING && __timerOn)
__timerRestart();
- }
}