[my-place] Submodules dynamic loading bug fix (utils static library). 16/94016/1
authorMarcin Masternak <m.masternak@samsung.com>
Wed, 26 Oct 2016 17:13:53 +0000 (19:13 +0200)
committerMarcin Masternak <m.masternak@samsung.com>
Wed, 26 Oct 2016 17:13:53 +0000 (19:13 +0200)
Change-Id: I872e137d3f44c4093ee0a0cecb0448e636601f79
Signed-off-by: Marcin Masternak <m.masternak@samsung.com>
28 files changed:
src/my-place/CMakeLists.txt
src/my-place/facade/UserPlaces.h
src/my-place/facade/UserPlacesParams.h [deleted file]
src/my-place/facade/UserPlacesTypes.cpp [deleted file]
src/my-place/facade/UserPlacesTypes.h [deleted file]
src/my-place/place/CMakeLists.txt
src/my-place/place/PlaceCateger.cpp
src/my-place/place/PlaceCateger.h
src/my-place/place/PlacesDetector.cpp
src/my-place/place/PlacesDetector.h
src/my-place/utils/CMakeLists.txt [new file with mode: 0644]
src/my-place/utils/Gmap.h
src/my-place/utils/Median.h
src/my-place/utils/Similarity.h
src/my-place/utils/UserPlacesParams.h [new file with mode: 0644]
src/my-place/utils/UserPlacesTypes.cpp [new file with mode: 0644]
src/my-place/utils/UserPlacesTypes.h [new file with mode: 0644]
src/my-place/visit-categer/CMakeLists.txt
src/my-place/visit-categer/Mahal.h
src/my-place/visit-categer/PiecewiseLin.h
src/my-place/visit-categer/VisitCateger.h
src/my-place/visit-detector/LocationListenerIface.h
src/my-place/visit-detector/LocationLogger.cpp
src/my-place/visit-detector/VisitDetector.cpp
src/my-place/visit-detector/VisitDetector.h
src/my-place/visit-detector/WifiListenerIface.h
src/my-place/visit-detector/WifiLogger.cpp
src/my-place/visit-detector/WifiLogger.h

index 7ea03eec59cdba85740b4212ddf2dda2ee7d49f0..cc19619fd131973528ff052d8e25fdfcf68305aa 100644 (file)
@@ -1,4 +1,7 @@
 SET(target "${target_prefix}-my-place")
+SET(target_myplace_utils_static "${target}-utils_static")
+
+INCLUDE_DIRECTORIES(utils)
 
 SET(DEPS ${DEPS}
        gmodule-2.0
@@ -6,7 +9,7 @@ SET(DEPS ${DEPS}
        capi-network-wifi
 )
 
-FILE(GLOB SRCS *.cpp facade/*.cpp utils/*.cpp visit-detector/*.cpp)
+FILE(GLOB SRCS *.cpp facade/*.cpp visit-detector/*.cpp)
 
 INCLUDE(FindPkgConfig)
 PKG_CHECK_MODULES(PKG_MYPLACE REQUIRED ${DEPS})
@@ -16,9 +19,10 @@ FOREACH(flag ${PKG_MYPLACE_CFLAGS})
 ENDFOREACH(flag)
 
 ADD_LIBRARY(${target} SHARED ${SRCS})
-TARGET_LINK_LIBRARIES(${target} ${PKG_MYPLACE_LDFLAGS} ${target_shared})
+TARGET_LINK_LIBRARIES(${target} ${PKG_MYPLACE_LDFLAGS} ${target_shared} ${target_myplace_utils_static})
 
 INSTALL(TARGETS ${target} DESTINATION ${CMAKE_INSTALL_LIBDIR}/${target_dir})
 
+ADD_SUBDIRECTORY(utils)
 ADD_SUBDIRECTORY(place)
 ADD_SUBDIRECTORY(visit-categer)
\ No newline at end of file
index 31bac72f770c195b27d24b86bf724ded65f5bdac..bc552cc6bafb3c26b04c3a4c84d719fa822acc71 100644 (file)
@@ -24,8 +24,7 @@
 #include <TimerManager.h>
 #include <ITimerListener.h>
 #include "../visit-detector/VisitDetector.h"
-#include "../place/PlacesDetector.h"
-#include "UserPlacesTypes.h"
+#include <UserPlacesTypes.h>
 
 namespace ctx {
 
diff --git a/src/my-place/facade/UserPlacesParams.h b/src/my-place/facade/UserPlacesParams.h
deleted file mode 100644 (file)
index ccb136b..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _CONTEXT_PLACE_RECOGNITION_USER_PLACES_PARAMS_H_
-#define _CONTEXT_PLACE_RECOGNITION_USER_PLACES_PARAMS_H_
-
-/*
- * WiFi scanning frequency (in minutes) in PLACE_RECOG_HIGH_ACCURACY_MODE.
- */
-#define WIFI_LOGGER_INTERVAL_MINUTES_HIGH_ACCURACY 3
-
-/*
- * WiFi scanning frequency (in minutes) in PLACE_RECOG_LOW_POWER_MODE.
- */
-#define WIFI_LOGGER_INTERVAL_MINUTES_LOW_POWER 60
-
-/*
- * Time window taken into consideration (in seconds) in PLACE_RECOG_HIGH_ACCURACY_MODE.
- */
-#define VISIT_DETECTOR_PERIOD_SECONDS_HIGH_ACCURACY 360
-
-/*
- * Time window taken into consideration (in seconds) in PLACE_RECOG_LOW_POWER_MODE.
- */
-#define VISIT_DETECTOR_PERIOD_SECONDS_LOW_POWER 3600
-
-/*
- * Overlap threshold between two sets of mac addresses (overlap
- * coefficient for two sets should be higher than this threshold
- * in order to detect stable radio environment); =< 1.0
- * New parameter in algorithm compared to original version of PlaceSense!
- */
-#define VISIT_DETECTOR_OVERLAP 0.8f
-
-/*
- * Specifies how many stable intervals must be seen to
- * indicate an entrance to a place; >= 1
- */
-#define VISIT_DETECTOR_STABLE_DEPTH 1
-
-/*
- * Representatives threshold (representatnive beacon
- * response rate should be higher than this threshold); =< 1.0
- */
-#define VISIT_DETECTOR_REP_THRESHOLD 0.9f
-
-/*
- * Specifies how long scans must be unstable to indicate a leave form a place; >= 1
- */
-#define VISIT_DETECTOR_TOLERANCE_DEPTH 3
-
-#define PLACES_DETECTOR_TASK_START_HOUR 3
-#define PLACES_DETECTOR_TASK_START_MINUTE 11
-#define PLACES_DETECTOR_RETENTION_DAYS 30
-#define PLACES_DETECTOR_RETENTION_SECONDS 24 * 60 * 60 * PLACES_DETECTOR_RETENTION_DAYS
-
-/*
- * Minimal duration of visit (in minutes) taking into account for place detection
- */
-#define PLACES_DETECTOR_MIN_VISIT_DURATION_MINUTES 15
-
-/*
- * Maximum duration of visit (in minutes) taking into account for place detection
- */
-#define PLACES_DETECTOR_MAX_VISIT_DURATION_MINUTES 5 * 24 * 60
-
-/*
- * Minimum visits number per place
- */
-#define PLACES_DETECTOR_MIN_VISITS_PER_PLACE 1
-
-/*
- * Minimum visits number per big place
- */
-#define PLACES_DETECTOR_MIN_VISITS_PER_BIG_PLACE 4
-
-/*
- * Minimal visit category score for taking this visit into consideration during
- * place categorization
- */
-#define PLACES_CATEGER_MIN_VISITS_SCORE 0.1
-
-/*
- * Minimum visits number per home
- */
-#define PLACES_CATEGER_MIN_VISITS_PER_HOME 3
-
-/*
- * Minimum visits number per work
- */
-#define PLACES_CATEGER_MIN_VISITS_PER_WORK 2
-
-/*
- * Default user consent value for place detection
- */
-#define MYPLACE_SETTING_USER_CONSENT_DEFAULT false
-
-#endif /* End of _CONTEXT_PLACE_RECOGNITION_USER_PLACES_PARAMS_H_ */
diff --git a/src/my-place/facade/UserPlacesTypes.cpp b/src/my-place/facade/UserPlacesTypes.cpp
deleted file mode 100644 (file)
index bf00798..0000000
+++ /dev/null
@@ -1,242 +0,0 @@
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <set>
-#include <iostream>
-#include <iomanip>
-#include <sstream>
-#include <algorithm>
-#include <Types.h>
-#include "UserPlacesTypes.h"
-#include "UserPlacesParams.h"
-#include "../utils/DebugUtils.h"
-
-#define __MAC_STRING_COMPONENTS_SEPARATOR ':'
-#define __MAC_SET_STRING_DELIMITER ','
-
-ctx::Mac::Mac(const std::string& str)
-{
-       std::stringstream ss(str);
-       try {
-               ss >> *this;
-       } catch (std::runtime_error &e) {
-               _E("%s", e.what());
-       }
-}
-
-ctx::Mac::Mac(const char *str)
-{
-       std::stringstream ss(str);
-       try {
-               ss >> *this;
-       } catch (std::runtime_error &e) {
-               _E("%s", e.what());
-       }
-}
-
-std::istream& ctx::operator>>(std::istream &input, ctx::Mac &mac)
-{
-       int h;
-       char colon;
-       for (size_t i = 0; i < ctx::Mac::MAC_SIZE; i++) {
-               input >> std::hex;
-               input >> h;
-               mac.c[i] = h;
-               if (i + 1 >= ctx::Mac::MAC_SIZE)
-                       break;
-               input >> colon;
-               if (colon != __MAC_STRING_COMPONENTS_SEPARATOR)
-                       throw std::runtime_error("Invalid MAC format");
-       }
-       input >> std::dec;
-       return input;
-}
-
-std::ostream& ctx::operator<<(std::ostream &output, const ctx::Mac &mac)
-{
-       size_t i = 0;
-       while (true) {
-               output << std::hex << std::setfill('0') << std::setw(2);
-               output << static_cast<int>(mac.c[i]);
-               i++;
-               if (i >= Mac::MAC_SIZE)
-                       break;
-               output << __MAC_STRING_COMPONENTS_SEPARATOR;
-       }
-       output << std::dec;
-       return output;
-}
-
-ctx::Mac::operator std::string() const
-{
-       std::stringstream ss;
-       ss << *this;
-       return ss.str();
-}
-
-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])
-                       return false;
-       }
-       return true;
-}
-
-bool ctx::operator!=(const Mac &m1, const Mac &m2)
-{
-       return !(m1 == m2);
-}
-
-bool ctx::operator<(const Mac &m1, const Mac &m2)
-{
-       unsigned char c1, c2;
-       for (size_t i = 0; i < Mac::MAC_SIZE; i++) {
-               c1 = m1.c[i];
-               c2 = m2.c[i];
-               if (c1 < c2)
-                       return true;
-               if (c1 > c2)
-                       return false;
-       }
-       return false; // they are equal
-}
-
-std::istream& ctx::operator>>(std::istream &input, ctx::MacSet &macSet)
-{
-       Mac mac;
-       char delimeter;
-       while (!input.eof()) {
-               try {
-                       input >> mac;
-               } catch (std::runtime_error &e) {
-                       _E("Cannot read macSet. Exception: %s", e.what());
-                       break;
-               }
-               macSet.insert(mac);
-               if (input.eof())
-                       break;
-               delimeter = input.get();
-               if (delimeter != __MAC_SET_STRING_DELIMITER) {
-                       input.unget();
-                       break;
-               }
-       }
-       return input;
-}
-
-std::ostream& ctx::operator<<(std::ostream &output, const ctx::MacSet &macSet)
-{
-       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: macVec) {
-               if (first) {
-                       first = false;
-               } else {
-                       output << __MAC_SET_STRING_DELIMITER;
-               }
-               output << mac;
-       }
-       return output;
-}
-
-void ctx::LocationEvent::log()
-{
-       std::string time_str = DebugUtils::humanReadableDateTime(timestamp, "%T", 9);
-#ifdef TIZEN_ENGINEER_MODE
-       _D("location lat=%.8f, lon=%.8f, acc=%.2f[m], time=%s, method=%d",
-                       coordinates.latitude,
-                       coordinates.longitude,
-                       coordinates.accuracy,
-                       time_str.c_str(),
-                       method);
-#else /* TIZEN_ENGINEER_MODE */
-       _D("location lat=%.8f, lon=%.8f, acc=%.2f[m], time=%s",
-                       coordinates.latitude,
-                       coordinates.longitude,
-                       coordinates.accuracy,
-                       time_str.c_str());
-#endif /* TIZEN_ENGINEER_MODE */
-}
-
-void ctx::Visit::setLocation(Location location_)
-{
-       locationValid = true;
-       location = location_;
-}
-
-void ctx::Visit::printShort2Stream(std::ostream &out) const
-{
-       // print only valid visits
-       if (interval.end != 0) {
-               float duration = ((float) (interval.end - interval.start)) / 3600; // [h]
-               out << "__VISIT " << duration << "h: ";
-                       out << DebugUtils::humanReadableDateTime(interval.start, "%m/%d %H:%M", 15) << " Ã· ";
-                       out << DebugUtils::humanReadableDateTime(interval.end, "%m/%d %H:%M", 15) << std::endl;
-       }
-}
-
-bool ctx::operator==(const ctx::Visit &v1, const ctx::Visit &v2)
-{
-       return v1.interval.start == v2.interval.start
-                       && v1.interval.end == v2.interval.end
-                       && v1.categs == v2.categs
-                       && v1.location.latitude == v2.location.latitude
-                       && v1.location.longitude == v2.location.longitude
-                       && v1.location.accuracy == v2.location.accuracy
-                       && v1.locationValid == v2.locationValid
-                       && v1.macSet == v2.macSet;
-}
-
-ctx::MacSet ctx::macSetFromString(const std::string &str)
-{
-       MacSet macSet;
-       std::stringstream ss;
-       ss << str;
-       ss >> macSet;
-       return macSet;
-}
-
-bool ctx::operator>(const Mac &m1, const Mac &m2)
-{
-       return m2 < m1;
-}
-
-std::shared_ptr<ctx::MacSet> ctx::macSetFromMacs2Counts(const Macs2Counts &macs2Counts)
-{
-       std::shared_ptr<MacSet> macSet(std::make_shared<MacSet>());
-       for (auto &macCount: macs2Counts) {
-               macSet->insert(macCount.first);
-       }
-       return macSet;
-}
-
-std::shared_ptr<ctx::MacSet> ctx::macSetsUnion(const std::vector<std::shared_ptr<MacSet>> &macSets)
-{
-       std::shared_ptr<MacSet> unionSet = std::make_shared<MacSet>();
-       for (std::shared_ptr<MacSet> macSet : macSets) {
-               unionSet->insert(macSet->begin(), macSet->end());
-       }
-       return unionSet;
-}
-
-ctx::Interval::Interval(time_t start_, time_t end_) : start(start_), end(end_) {
-       if (end_ < start_)
-               _E("Negative interval, start=%d, end=%d", start_, end_);
-}
diff --git a/src/my-place/facade/UserPlacesTypes.h b/src/my-place/facade/UserPlacesTypes.h
deleted file mode 100644 (file)
index 9365beb..0000000
+++ /dev/null
@@ -1,254 +0,0 @@
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _CONTEXT_PLACE_RECOGNITION_USER_PLACES_TYPES_H_
-#define _CONTEXT_PLACE_RECOGNITION_USER_PLACES_TYPES_H_
-
-#include <memory>
-#include <vector>
-#include <map>
-#include <unordered_map>
-#include <unordered_set>
-#include <string>
-#include <ctime>
-#include <MyPlaceTypes.h>
-
-// Database
-#define VISIT_TABLE                            "Log_Myplace_Visit"
-#define VISIT_COLUMN_START_TIME                "start_time"
-#define VISIT_COLUMN_END_TIME                  "end_time"
-#define VISIT_COLUMN_WIFI_APS                  "wifi_aps"
-#define VISIT_COLUMN_CATEGORY                  "category"
-#ifdef TIZEN_ENGINEER_MODE
-#define VISIT_COLUMN_START_TIME_HUMAN          "start_time_human" // only for debug: human readable time data:
-#define VISIT_COLUMN_END_TIME_HUMAN            "end_time_human" // only for debug: human readable time data:
-#endif /* TIZEN_ENGINEER_MODE */
-#define VISIT_COLUMN_LOCATION_VALID            "location_valid"
-#define VISIT_COLUMN_LOCATION_LATITUDE         "location_latitude"
-#define VISIT_COLUMN_LOCATION_LONGITUDE        "location_longitude"
-#define VISIT_COLUMN_LOCATION_ACCURACY         "location_accuracy"
-#define VISIT_COLUMN_CATEG_HOME                "categ_home"
-#define VISIT_COLUMN_CATEG_WORK                "categ_work"
-#define VISIT_COLUMN_CATEG_OTHER               "categ_other"
-
-#define WIFI_APS_MAP_TABLE                     "Log_Myplace_WifiAPsMap"
-#define WIFI_APS_MAP_COLUMN_MAC                "mac"
-#define WIFI_APS_MAP_COLUMN_NETWORK_NAME       "network_name"
-#define WIFI_APS_MAP_COLUMN_INSERT_TIME        "insert_time"
-
-#define PLACE_TABLE                            "Log_Myplace_Place"
-#define PLACE_COLUMN_CATEG_ID                  "categ_id"
-#define PLACE_COLUMN_CATEG_CONFIDENCE          "categ_confidence"
-#define PLACE_COLUMN_NAME                      "name"
-#define PLACE_COLUMN_LOCATION_VALID            "location_valid"
-#define PLACE_COLUMN_LOCATION_LATITUDE         "location_latitude"
-#define PLACE_COLUMN_LOCATION_LONGITUDE        "location_longitude"
-#define PLACE_COLUMN_LOCATION_ACCURACY         "location_accuracy"
-#define PLACE_COLUMN_WIFI_APS                  "wifi_aps"
-#define PLACE_COLUMN_CREATE_DATE               "create_date"
-
-#define WIFI_TABLE                             "Log_Myplace_Wifi"
-#define WIFI_COLUMN_TIMESTAMP                  "timestamp"
-#define WIFI_COLUMN_BSSID                      "bssid"
-#define WIFI_COLUMN_ESSID                      "essid"
-
-#define LOCATION_TABLE                         "Log_Myplace_Location"
-#define LOCATION_COLUMN_LATITUDE               "latitude"
-#define LOCATION_COLUMN_LONGITUDE              "longitude"
-#define LOCATION_COLUMN_ACCURACY               "accuracy"
-#define LOCATION_COLUMN_TIMESTAMP              "timestamp"
-#ifdef TIZEN_ENGINEER_MODE
-#define LOCATION_COLUMN_TIMESTAMP_HUMAN        "time_human" // only for debug: human readable time data:
-#define LOCATION_COLUMN_METHOD                 "method"
-#endif /* TIZEN_ENGINEER_MODE */
-
-#define MYPLACE_SETTINGS_TABLE                 "Myplace_Settings"
-#define MYPLACE_SETTINGS_COLUMN_KEY            "key"
-#define MYPLACE_SETTINGS_COLUMN_VALUE          "value"
-#define MYPLACE_SETTING_KEY_USER_CONSENT       PLACE_DETECTION_REQUEST_CONSENT
-
-enum PlaceRecogMode {
-       PLACE_RECOG_HIGH_ACCURACY_MODE = 0,
-       PLACE_RECOG_LOW_POWER_MODE = 1
-};
-
-namespace ctx {
-
-       /*
-        * type for numerical computations
-        */
-       typedef double num_t;
-
-       /*
-        * mac address
-        */
-       class Mac {
-
-       public:
-               const static size_t MAC_SIZE = 6;  // number of bytes for mac address.
-               unsigned char c[MAC_SIZE];
-
-               Mac() {};
-               Mac(const std::string &str);
-               Mac(const char *str);
-               operator std::string() const;
-
-       };      /* class Mac */
-
-       std::istream &operator>>(std::istream &input, ctx::Mac &mac);
-       std::ostream &operator<<(std::ostream &output, const ctx::Mac &mac);
-       bool operator==(const ctx::Mac &m1, const ctx::Mac &m2);
-       bool operator!=(const ctx::Mac &m1, const ctx::Mac &m2);
-       bool operator<(const ctx::Mac &m1, const ctx::Mac &m2);
-       bool operator>(const ctx::Mac &m1, const ctx::Mac &m2);
-
-}      /* namespace ctx */
-
-namespace std {
-
-       template <> struct hash<ctx::Mac> {
-               size_t operator()(const ctx::Mac & m) const {
-                       size_t h = 1;
-                       for (size_t i = 0; i < ctx::Mac::MAC_SIZE; i++) {
-                               h = h * 37 + m.c[i];
-                       }
-                       return h;
-               }
-       };
-
-}      /* namespace std */
-
-namespace ctx {
-
-       typedef float share_t;
-       typedef int count_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> MacSet;
-
-       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<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);
-       };
-
-}      /* namespace ctx */
-
-namespace std {
-
-       template <> struct hash<ctx::Interval> {
-               size_t operator()(const ctx::Interval & interval) const {
-                       return interval.end * interval.start;
-               }
-       };
-
-}      /* namespace std */
-
-namespace ctx {
-
-       /*
-        * fully describes interval data after the interval is finished
-        */
-       struct Frame {
-               Interval interval;
-               count_t numberOfTimestamps;
-               Macs2Counts macs2Counts;
-
-               Frame(Interval interval_) : interval(interval_), numberOfTimestamps(0) {};
-       };
-
-       /*
-        * mac address + its timestamp
-        */
-       struct MacEvent {
-               time_t timestamp;
-               Mac mac;
-               std::string networkName;
-
-               MacEvent(time_t timestamp_, Mac mac_, std::string networkName_ = "")
-                       : timestamp(timestamp_)
-                       , mac(mac_)
-                       , networkName(networkName_) {}
-       };
-
-       typedef std::map<int, num_t> Categs; // scores of categories
-
-#ifdef TIZEN_ENGINEER_MODE
-       enum LocationSource {
-               LOCATION_METHOD_REQUEST = 0,
-               LOCATION_METHOD_GET_LOCATION = 1,
-               LOCATION_METHOD_GET_LAST_LOCATION = 2
-       };
-#endif /* TIZEN_ENGINEER_MODE */
-
-       /*
-        * location + timestamp + method
-        */
-       struct LocationEvent {
-               Location coordinates;
-               time_t timestamp;
-
-#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_) {}
-#else /* TIZEN_ENGINEER_MODE */
-               LocationEvent(double latitude_, double longitude_, double accuracy_, time_t timestamp_) :
-                       coordinates(latitude_, longitude_, accuracy_),
-                       timestamp(timestamp_) {}
-#endif /* TIZEN_ENGINEER_MODE */
-
-               void log();
-
-       };      /* struct LocationEvent */
-
-       struct Visit {
-               Interval interval;
-               std::shared_ptr<MacSet> macSet;
-               Categs categs;
-               bool locationValid;
-               Location location; // makes sense if locationValid == true;
-
-               Visit(Interval interval_, std::shared_ptr<MacSet> macSet_ = std::make_shared<MacSet>(), Categs categs_ = Categs()) :
-                       interval(interval_),
-                       macSet(macSet_),
-                       categs(categs_),
-                       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;
-       typedef std::vector<MacEvent> MacEvents; // used to store current interval logs
-
-       std::shared_ptr<MacSet> macSetFromMacs2Counts(const Macs2Counts &macs2Counts);
-
-}      /* namespace ctx */
-
-#endif /* End of _CONTEXT_PLACE_RECOGNITION_USER_PLACES_TYPES_H_ */
index fc2c120a38b86c7b5f8de4236e6b0d9d0d38cb72..7ac705fbe2074c142b92d8a430c0d31f334cc612 100644 (file)
@@ -1,7 +1,10 @@
 SET(target "${target_prefix}-my-place-places-detector")
 
+INCLUDE_DIRECTORIES(../utils)
+
 FILE(GLOB SRCS *.cpp)
 
 ADD_LIBRARY(${target} SHARED ${SRCS})
+TARGET_LINK_LIBRARIES(${target} ${target_myplace_utils_static})
 
 INSTALL(TARGETS ${target} DESTINATION ${CMAKE_INSTALL_LIBDIR}/${target_dir})
\ No newline at end of file
index 1b956a890f430423bcc47974e63b4aba40ada980..603e857c6ab83d9675a85c3b989ad564e7388101 100644 (file)
@@ -15,9 +15,9 @@
  */
 
 #include "PlaceCateger.h"
-#include "../utils/Median.h"
-#include "../facade/UserPlacesParams.h"
-#include "../facade/UserPlacesTypes.h"
+#include <Median.h>
+#include <UserPlacesParams.h>
+#include <UserPlacesTypes.h>
 #include <algorithm>
 #include <Types.h>
 
index 44927b30c0e7332803d560835df9c46b74b9a623..dd6943ff786e158234639831be7026650efd6710 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef _CONTEXT_PLACE_RECOGNITION_PLACE_CATEGER_
 #define _CONTEXT_PLACE_RECOGNITION_PLACE_CATEGER_
 
-#include "../facade/UserPlacesTypes.h"
+#include <UserPlacesTypes.h>
 #include <utility>
 #include <vector>
 #include <string>
index e66c5eea8c9c475d0f3cfcad5d891f7c812f1547..115a44b791c472c43c66f9b6c80efacd45ab9aeb 100644 (file)
 #include <sstream>
 #include <Types.h>
 #include <Json.h>
-#include "../utils/Similarity.h"
+#include <Similarity.h>
 #include "PlacesDetector.h"
 #include "PlaceCateger.h"
-#include "../utils/Median.h"
+#include <Median.h>
 #ifdef TIZEN_ENGINEER_MODE
-#include "../utils/Gmap.h"
+#include <Gmap.h>
 #endif /* TIZEN_ENGINEER_MODE */
-#include "../facade/UserPlacesTypes.h"
+#include <UserPlacesTypes.h>
 #include <fstream>
 #include <algorithm>
-#include "../facade/UserPlacesParams.h"
-#include "../utils/DebugUtils.h"
+#include <UserPlacesParams.h>
+#include <DebugUtils.h>
 #include <DatabaseManager.h>
 
 #define __DELETE_PLACES_QUERY "DELETE FROM " PLACE_TABLE
@@ -89,7 +89,7 @@ double ctx::PlacesDetector::__doubleValueFromJson(Json &row, const char* key)
 {
        double value;
        row.get(NULL, key, &value);
-       _D("__doubleValueFromJson, key:%s, value: %lf", key, value);
+       _D("key: %s, value: %lf", key, value);
        return value;
 }
 
index d9c47cb1d289853687533f4aa7b58b0e7a58ee04..81c6a448a8bbe1ecae07e26e701083d2c5f61d37 100644 (file)
@@ -20,7 +20,7 @@
 #include <vector>
 #include <cstdint>
 #include <ITimerListener.h>
-#include "../facade/UserPlacesTypes.h"
+#include <UserPlacesTypes.h>
 #include <MyPlaceTypes.h>
 #include "Graph.h"
 
diff --git a/src/my-place/utils/CMakeLists.txt b/src/my-place/utils/CMakeLists.txt
new file mode 100644 (file)
index 0000000..2ecc5e4
--- /dev/null
@@ -0,0 +1,5 @@
+SET(target ${target_myplace_utils_static})
+
+FILE(GLOB SRCS *.cpp)
+
+ADD_LIBRARY(${target} STATIC ${SRCS})
\ No newline at end of file
index 891b8517b73c46a276b232ad9f39890512096f5e..c6a54828780b0f447b0bc3eb5fe0d63cb4be8e76 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef _CONTEXT_PLACE_RECOGNITION_GMAP_H_
 #define _CONTEXT_PLACE_RECOGNITION_GMAP_H_
 
-#include "../facade/UserPlacesTypes.h"
+#include "UserPlacesTypes.h"
 
 #define GMAP_FILE "/tmp/user_places_map.html"
 
index b33e7b22101c10e17dc707695e7a5f6dc7ff0ad7..275fa1303751d3573c3924d4c4fef8ebaaf0e345 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef _CONTEXT_PLACE_RECOGNITION_MEDIAN_
 #define _CONTEXT_PLACE_RECOGNITION_MEDIAN_
 
-#include "../facade/UserPlacesTypes.h"
+#include "UserPlacesTypes.h"
 #include <vector>
 
 namespace ctx {
index e0061645151e08cdd7e788194153bead0814178a..f78b675242aab598ea0e6d32ec08be6b9d6fbad6 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef _CONTEXT_PLACE_RECOGNITION_SIMILAR_H_
 #define _CONTEXT_PLACE_RECOGNITION_SIMILAR_H_
 
-#include "../facade/UserPlacesTypes.h"
+#include "UserPlacesTypes.h"
 
 namespace ctx {
 
diff --git a/src/my-place/utils/UserPlacesParams.h b/src/my-place/utils/UserPlacesParams.h
new file mode 100644 (file)
index 0000000..ccb136b
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _CONTEXT_PLACE_RECOGNITION_USER_PLACES_PARAMS_H_
+#define _CONTEXT_PLACE_RECOGNITION_USER_PLACES_PARAMS_H_
+
+/*
+ * WiFi scanning frequency (in minutes) in PLACE_RECOG_HIGH_ACCURACY_MODE.
+ */
+#define WIFI_LOGGER_INTERVAL_MINUTES_HIGH_ACCURACY 3
+
+/*
+ * WiFi scanning frequency (in minutes) in PLACE_RECOG_LOW_POWER_MODE.
+ */
+#define WIFI_LOGGER_INTERVAL_MINUTES_LOW_POWER 60
+
+/*
+ * Time window taken into consideration (in seconds) in PLACE_RECOG_HIGH_ACCURACY_MODE.
+ */
+#define VISIT_DETECTOR_PERIOD_SECONDS_HIGH_ACCURACY 360
+
+/*
+ * Time window taken into consideration (in seconds) in PLACE_RECOG_LOW_POWER_MODE.
+ */
+#define VISIT_DETECTOR_PERIOD_SECONDS_LOW_POWER 3600
+
+/*
+ * Overlap threshold between two sets of mac addresses (overlap
+ * coefficient for two sets should be higher than this threshold
+ * in order to detect stable radio environment); =< 1.0
+ * New parameter in algorithm compared to original version of PlaceSense!
+ */
+#define VISIT_DETECTOR_OVERLAP 0.8f
+
+/*
+ * Specifies how many stable intervals must be seen to
+ * indicate an entrance to a place; >= 1
+ */
+#define VISIT_DETECTOR_STABLE_DEPTH 1
+
+/*
+ * Representatives threshold (representatnive beacon
+ * response rate should be higher than this threshold); =< 1.0
+ */
+#define VISIT_DETECTOR_REP_THRESHOLD 0.9f
+
+/*
+ * Specifies how long scans must be unstable to indicate a leave form a place; >= 1
+ */
+#define VISIT_DETECTOR_TOLERANCE_DEPTH 3
+
+#define PLACES_DETECTOR_TASK_START_HOUR 3
+#define PLACES_DETECTOR_TASK_START_MINUTE 11
+#define PLACES_DETECTOR_RETENTION_DAYS 30
+#define PLACES_DETECTOR_RETENTION_SECONDS 24 * 60 * 60 * PLACES_DETECTOR_RETENTION_DAYS
+
+/*
+ * Minimal duration of visit (in minutes) taking into account for place detection
+ */
+#define PLACES_DETECTOR_MIN_VISIT_DURATION_MINUTES 15
+
+/*
+ * Maximum duration of visit (in minutes) taking into account for place detection
+ */
+#define PLACES_DETECTOR_MAX_VISIT_DURATION_MINUTES 5 * 24 * 60
+
+/*
+ * Minimum visits number per place
+ */
+#define PLACES_DETECTOR_MIN_VISITS_PER_PLACE 1
+
+/*
+ * Minimum visits number per big place
+ */
+#define PLACES_DETECTOR_MIN_VISITS_PER_BIG_PLACE 4
+
+/*
+ * Minimal visit category score for taking this visit into consideration during
+ * place categorization
+ */
+#define PLACES_CATEGER_MIN_VISITS_SCORE 0.1
+
+/*
+ * Minimum visits number per home
+ */
+#define PLACES_CATEGER_MIN_VISITS_PER_HOME 3
+
+/*
+ * Minimum visits number per work
+ */
+#define PLACES_CATEGER_MIN_VISITS_PER_WORK 2
+
+/*
+ * Default user consent value for place detection
+ */
+#define MYPLACE_SETTING_USER_CONSENT_DEFAULT false
+
+#endif /* End of _CONTEXT_PLACE_RECOGNITION_USER_PLACES_PARAMS_H_ */
diff --git a/src/my-place/utils/UserPlacesTypes.cpp b/src/my-place/utils/UserPlacesTypes.cpp
new file mode 100644 (file)
index 0000000..c5ed30c
--- /dev/null
@@ -0,0 +1,242 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <set>
+#include <iostream>
+#include <iomanip>
+#include <sstream>
+#include <algorithm>
+#include <Types.h>
+#include "UserPlacesTypes.h"
+#include "UserPlacesParams.h"
+#include "DebugUtils.h"
+
+#define __MAC_STRING_COMPONENTS_SEPARATOR ':'
+#define __MAC_SET_STRING_DELIMITER ','
+
+ctx::Mac::Mac(const std::string& str)
+{
+       std::stringstream ss(str);
+       try {
+               ss >> *this;
+       } catch (std::runtime_error &e) {
+               _E("%s", e.what());
+       }
+}
+
+ctx::Mac::Mac(const char *str)
+{
+       std::stringstream ss(str);
+       try {
+               ss >> *this;
+       } catch (std::runtime_error &e) {
+               _E("%s", e.what());
+       }
+}
+
+std::istream& ctx::operator>>(std::istream &input, ctx::Mac &mac)
+{
+       int h;
+       char colon;
+       for (size_t i = 0; i < ctx::Mac::MAC_SIZE; i++) {
+               input >> std::hex;
+               input >> h;
+               mac.c[i] = h;
+               if (i + 1 >= ctx::Mac::MAC_SIZE)
+                       break;
+               input >> colon;
+               if (colon != __MAC_STRING_COMPONENTS_SEPARATOR)
+                       throw std::runtime_error("Invalid MAC format");
+       }
+       input >> std::dec;
+       return input;
+}
+
+std::ostream& ctx::operator<<(std::ostream &output, const ctx::Mac &mac)
+{
+       size_t i = 0;
+       while (true) {
+               output << std::hex << std::setfill('0') << std::setw(2);
+               output << static_cast<int>(mac.c[i]);
+               i++;
+               if (i >= Mac::MAC_SIZE)
+                       break;
+               output << __MAC_STRING_COMPONENTS_SEPARATOR;
+       }
+       output << std::dec;
+       return output;
+}
+
+ctx::Mac::operator std::string() const
+{
+       std::stringstream ss;
+       ss << *this;
+       return ss.str();
+}
+
+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])
+                       return false;
+       }
+       return true;
+}
+
+bool ctx::operator!=(const Mac &m1, const Mac &m2)
+{
+       return !(m1 == m2);
+}
+
+bool ctx::operator<(const Mac &m1, const Mac &m2)
+{
+       unsigned char c1, c2;
+       for (size_t i = 0; i < Mac::MAC_SIZE; i++) {
+               c1 = m1.c[i];
+               c2 = m2.c[i];
+               if (c1 < c2)
+                       return true;
+               if (c1 > c2)
+                       return false;
+       }
+       return false; // they are equal
+}
+
+std::istream& ctx::operator>>(std::istream &input, ctx::MacSet &macSet)
+{
+       Mac mac;
+       char delimeter;
+       while (!input.eof()) {
+               try {
+                       input >> mac;
+               } catch (std::runtime_error &e) {
+                       _E("Cannot read macSet. Exception: %s", e.what());
+                       break;
+               }
+               macSet.insert(mac);
+               if (input.eof())
+                       break;
+               delimeter = input.get();
+               if (delimeter != __MAC_SET_STRING_DELIMITER) {
+                       input.unget();
+                       break;
+               }
+       }
+       return input;
+}
+
+std::ostream& ctx::operator<<(std::ostream &output, const ctx::MacSet &macSet)
+{
+       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: macVec) {
+               if (first) {
+                       first = false;
+               } else {
+                       output << __MAC_SET_STRING_DELIMITER;
+               }
+               output << mac;
+       }
+       return output;
+}
+
+void ctx::LocationEvent::log()
+{
+       std::string time_str = DebugUtils::humanReadableDateTime(timestamp, "%T", 9);
+#ifdef TIZEN_ENGINEER_MODE
+       _D("location lat=%.8f, lon=%.8f, acc=%.2f[m], time=%s, method=%d",
+                       coordinates.latitude,
+                       coordinates.longitude,
+                       coordinates.accuracy,
+                       time_str.c_str(),
+                       method);
+#else /* TIZEN_ENGINEER_MODE */
+       _D("location lat=%.8f, lon=%.8f, acc=%.2f[m], time=%s",
+                       coordinates.latitude,
+                       coordinates.longitude,
+                       coordinates.accuracy,
+                       time_str.c_str());
+#endif /* TIZEN_ENGINEER_MODE */
+}
+
+void ctx::Visit::setLocation(Location location_)
+{
+       locationValid = true;
+       location = location_;
+}
+
+void ctx::Visit::printShort2Stream(std::ostream &out) const
+{
+       // print only valid visits
+       if (interval.end != 0) {
+               float duration = ((float) (interval.end - interval.start)) / 3600; // [h]
+               out << "__VISIT " << duration << "h: ";
+                       out << DebugUtils::humanReadableDateTime(interval.start, "%m/%d %H:%M", 15) << " Ã· ";
+                       out << DebugUtils::humanReadableDateTime(interval.end, "%m/%d %H:%M", 15) << std::endl;
+       }
+}
+
+bool ctx::operator==(const ctx::Visit &v1, const ctx::Visit &v2)
+{
+       return v1.interval.start == v2.interval.start
+                       && v1.interval.end == v2.interval.end
+                       && v1.categs == v2.categs
+                       && v1.location.latitude == v2.location.latitude
+                       && v1.location.longitude == v2.location.longitude
+                       && v1.location.accuracy == v2.location.accuracy
+                       && v1.locationValid == v2.locationValid
+                       && v1.macSet == v2.macSet;
+}
+
+ctx::MacSet ctx::macSetFromString(const std::string &str)
+{
+       MacSet macSet;
+       std::stringstream ss;
+       ss << str;
+       ss >> macSet;
+       return macSet;
+}
+
+bool ctx::operator>(const Mac &m1, const Mac &m2)
+{
+       return m2 < m1;
+}
+
+std::shared_ptr<ctx::MacSet> ctx::macSetFromMacs2Counts(const Macs2Counts &macs2Counts)
+{
+       std::shared_ptr<MacSet> macSet(std::make_shared<MacSet>());
+       for (auto &macCount: macs2Counts) {
+               macSet->insert(macCount.first);
+       }
+       return macSet;
+}
+
+std::shared_ptr<ctx::MacSet> ctx::macSetsUnion(const std::vector<std::shared_ptr<MacSet>> &macSets)
+{
+       std::shared_ptr<MacSet> unionSet = std::make_shared<MacSet>();
+       for (std::shared_ptr<MacSet> macSet : macSets) {
+               unionSet->insert(macSet->begin(), macSet->end());
+       }
+       return unionSet;
+}
+
+ctx::Interval::Interval(time_t start_, time_t end_) : start(start_), end(end_) {
+       if (end_ < start_)
+               _E("Negative interval, start=%d, end=%d", start_, end_);
+}
diff --git a/src/my-place/utils/UserPlacesTypes.h b/src/my-place/utils/UserPlacesTypes.h
new file mode 100644 (file)
index 0000000..9365beb
--- /dev/null
@@ -0,0 +1,254 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _CONTEXT_PLACE_RECOGNITION_USER_PLACES_TYPES_H_
+#define _CONTEXT_PLACE_RECOGNITION_USER_PLACES_TYPES_H_
+
+#include <memory>
+#include <vector>
+#include <map>
+#include <unordered_map>
+#include <unordered_set>
+#include <string>
+#include <ctime>
+#include <MyPlaceTypes.h>
+
+// Database
+#define VISIT_TABLE                            "Log_Myplace_Visit"
+#define VISIT_COLUMN_START_TIME                "start_time"
+#define VISIT_COLUMN_END_TIME                  "end_time"
+#define VISIT_COLUMN_WIFI_APS                  "wifi_aps"
+#define VISIT_COLUMN_CATEGORY                  "category"
+#ifdef TIZEN_ENGINEER_MODE
+#define VISIT_COLUMN_START_TIME_HUMAN          "start_time_human" // only for debug: human readable time data:
+#define VISIT_COLUMN_END_TIME_HUMAN            "end_time_human" // only for debug: human readable time data:
+#endif /* TIZEN_ENGINEER_MODE */
+#define VISIT_COLUMN_LOCATION_VALID            "location_valid"
+#define VISIT_COLUMN_LOCATION_LATITUDE         "location_latitude"
+#define VISIT_COLUMN_LOCATION_LONGITUDE        "location_longitude"
+#define VISIT_COLUMN_LOCATION_ACCURACY         "location_accuracy"
+#define VISIT_COLUMN_CATEG_HOME                "categ_home"
+#define VISIT_COLUMN_CATEG_WORK                "categ_work"
+#define VISIT_COLUMN_CATEG_OTHER               "categ_other"
+
+#define WIFI_APS_MAP_TABLE                     "Log_Myplace_WifiAPsMap"
+#define WIFI_APS_MAP_COLUMN_MAC                "mac"
+#define WIFI_APS_MAP_COLUMN_NETWORK_NAME       "network_name"
+#define WIFI_APS_MAP_COLUMN_INSERT_TIME        "insert_time"
+
+#define PLACE_TABLE                            "Log_Myplace_Place"
+#define PLACE_COLUMN_CATEG_ID                  "categ_id"
+#define PLACE_COLUMN_CATEG_CONFIDENCE          "categ_confidence"
+#define PLACE_COLUMN_NAME                      "name"
+#define PLACE_COLUMN_LOCATION_VALID            "location_valid"
+#define PLACE_COLUMN_LOCATION_LATITUDE         "location_latitude"
+#define PLACE_COLUMN_LOCATION_LONGITUDE        "location_longitude"
+#define PLACE_COLUMN_LOCATION_ACCURACY         "location_accuracy"
+#define PLACE_COLUMN_WIFI_APS                  "wifi_aps"
+#define PLACE_COLUMN_CREATE_DATE               "create_date"
+
+#define WIFI_TABLE                             "Log_Myplace_Wifi"
+#define WIFI_COLUMN_TIMESTAMP                  "timestamp"
+#define WIFI_COLUMN_BSSID                      "bssid"
+#define WIFI_COLUMN_ESSID                      "essid"
+
+#define LOCATION_TABLE                         "Log_Myplace_Location"
+#define LOCATION_COLUMN_LATITUDE               "latitude"
+#define LOCATION_COLUMN_LONGITUDE              "longitude"
+#define LOCATION_COLUMN_ACCURACY               "accuracy"
+#define LOCATION_COLUMN_TIMESTAMP              "timestamp"
+#ifdef TIZEN_ENGINEER_MODE
+#define LOCATION_COLUMN_TIMESTAMP_HUMAN        "time_human" // only for debug: human readable time data:
+#define LOCATION_COLUMN_METHOD                 "method"
+#endif /* TIZEN_ENGINEER_MODE */
+
+#define MYPLACE_SETTINGS_TABLE                 "Myplace_Settings"
+#define MYPLACE_SETTINGS_COLUMN_KEY            "key"
+#define MYPLACE_SETTINGS_COLUMN_VALUE          "value"
+#define MYPLACE_SETTING_KEY_USER_CONSENT       PLACE_DETECTION_REQUEST_CONSENT
+
+enum PlaceRecogMode {
+       PLACE_RECOG_HIGH_ACCURACY_MODE = 0,
+       PLACE_RECOG_LOW_POWER_MODE = 1
+};
+
+namespace ctx {
+
+       /*
+        * type for numerical computations
+        */
+       typedef double num_t;
+
+       /*
+        * mac address
+        */
+       class Mac {
+
+       public:
+               const static size_t MAC_SIZE = 6;  // number of bytes for mac address.
+               unsigned char c[MAC_SIZE];
+
+               Mac() {};
+               Mac(const std::string &str);
+               Mac(const char *str);
+               operator std::string() const;
+
+       };      /* class Mac */
+
+       std::istream &operator>>(std::istream &input, ctx::Mac &mac);
+       std::ostream &operator<<(std::ostream &output, const ctx::Mac &mac);
+       bool operator==(const ctx::Mac &m1, const ctx::Mac &m2);
+       bool operator!=(const ctx::Mac &m1, const ctx::Mac &m2);
+       bool operator<(const ctx::Mac &m1, const ctx::Mac &m2);
+       bool operator>(const ctx::Mac &m1, const ctx::Mac &m2);
+
+}      /* namespace ctx */
+
+namespace std {
+
+       template <> struct hash<ctx::Mac> {
+               size_t operator()(const ctx::Mac & m) const {
+                       size_t h = 1;
+                       for (size_t i = 0; i < ctx::Mac::MAC_SIZE; i++) {
+                               h = h * 37 + m.c[i];
+                       }
+                       return h;
+               }
+       };
+
+}      /* namespace std */
+
+namespace ctx {
+
+       typedef float share_t;
+       typedef int count_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> MacSet;
+
+       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<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);
+       };
+
+}      /* namespace ctx */
+
+namespace std {
+
+       template <> struct hash<ctx::Interval> {
+               size_t operator()(const ctx::Interval & interval) const {
+                       return interval.end * interval.start;
+               }
+       };
+
+}      /* namespace std */
+
+namespace ctx {
+
+       /*
+        * fully describes interval data after the interval is finished
+        */
+       struct Frame {
+               Interval interval;
+               count_t numberOfTimestamps;
+               Macs2Counts macs2Counts;
+
+               Frame(Interval interval_) : interval(interval_), numberOfTimestamps(0) {};
+       };
+
+       /*
+        * mac address + its timestamp
+        */
+       struct MacEvent {
+               time_t timestamp;
+               Mac mac;
+               std::string networkName;
+
+               MacEvent(time_t timestamp_, Mac mac_, std::string networkName_ = "")
+                       : timestamp(timestamp_)
+                       , mac(mac_)
+                       , networkName(networkName_) {}
+       };
+
+       typedef std::map<int, num_t> Categs; // scores of categories
+
+#ifdef TIZEN_ENGINEER_MODE
+       enum LocationSource {
+               LOCATION_METHOD_REQUEST = 0,
+               LOCATION_METHOD_GET_LOCATION = 1,
+               LOCATION_METHOD_GET_LAST_LOCATION = 2
+       };
+#endif /* TIZEN_ENGINEER_MODE */
+
+       /*
+        * location + timestamp + method
+        */
+       struct LocationEvent {
+               Location coordinates;
+               time_t timestamp;
+
+#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_) {}
+#else /* TIZEN_ENGINEER_MODE */
+               LocationEvent(double latitude_, double longitude_, double accuracy_, time_t timestamp_) :
+                       coordinates(latitude_, longitude_, accuracy_),
+                       timestamp(timestamp_) {}
+#endif /* TIZEN_ENGINEER_MODE */
+
+               void log();
+
+       };      /* struct LocationEvent */
+
+       struct Visit {
+               Interval interval;
+               std::shared_ptr<MacSet> macSet;
+               Categs categs;
+               bool locationValid;
+               Location location; // makes sense if locationValid == true;
+
+               Visit(Interval interval_, std::shared_ptr<MacSet> macSet_ = std::make_shared<MacSet>(), Categs categs_ = Categs()) :
+                       interval(interval_),
+                       macSet(macSet_),
+                       categs(categs_),
+                       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;
+       typedef std::vector<MacEvent> MacEvents; // used to store current interval logs
+
+       std::shared_ptr<MacSet> macSetFromMacs2Counts(const Macs2Counts &macs2Counts);
+
+}      /* namespace ctx */
+
+#endif /* End of _CONTEXT_PLACE_RECOGNITION_USER_PLACES_TYPES_H_ */
index 93fb055e3a2ade986a43418b94f0a4a4924b580e..f127d6163be75d428c44ca1cf5b1fecdfbe0b5d6 100644 (file)
@@ -1,7 +1,10 @@
 SET(target "${target_prefix}-my-place-visit-categer")
 
+INCLUDE_DIRECTORIES(../utils)
+
 FILE(GLOB SRCS *.cpp)
 
 ADD_LIBRARY(${target} SHARED ${SRCS})
+TARGET_LINK_LIBRARIES(${target} ${target_myplace_utils_static})
 
 INSTALL(TARGETS ${target} DESTINATION ${CMAKE_INSTALL_LIBDIR}/${target_dir})
\ No newline at end of file
index 54ec7f3252b785f6d23d6438fb21283227b00ba1..26e623521538a385a5190e16e5cc38dda25ae81a 100644 (file)
@@ -18,7 +18,7 @@
 #define _CONTEXT_PLACE_RECOGNITION_MAHAL_H_
 
 #include <vector>
-#include "../facade/UserPlacesTypes.h"
+#include <UserPlacesTypes.h>
 
 namespace ctx {
 
index a0e92d76256adabfa93d08950256555eadabc490..4ff497bf5b081c7a3504d659239345da1b5f2d0e 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef _CONTEXT_PLACE_RECOGNITION_PIECEWISE_LIN_
 #define _CONTEXT_PLACE_RECOGNITION_PIECEWISE_LIN_
 
-#include "../facade/UserPlacesTypes.h"
+#include <UserPlacesTypes.h>
 
 namespace ctx {
 
index f1c5456fc97b4ca07f85cdaaf66eb02f52ba3acc..3edfb93804e561d73a930fcbcf1dea319bab6c3a 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef _CONTEXT_PLACE_RECOGNITION_VISIT_CATEGER_H_
 #define _CONTEXT_PLACE_RECOGNITION_VISIT_CATEGER_H_
 
-#include "../facade/UserPlacesTypes.h"
+#include <UserPlacesTypes.h>
 #include "Mahal.h"
 #include "PiecewiseLin.h"
 #include <map>
index 46f2b3f7f1971dbf572d69e90e6643b091734ee7..7d2aef24657810548ef197220666d7e3df134f2f 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef _CONTEXT_PLACE_RECOGNITION_LOCATION_LISTENER_IFACE_H_
 #define _CONTEXT_PLACE_RECOGNITION_LOCATION_LISTENER_IFACE_H_
 
-#include "../facade/UserPlacesTypes.h"
+#include <UserPlacesTypes.h>
 
 namespace ctx {
 
index 4b95eed173f0beaa2236850ecd5968f8c13072b9..372ee746be48c1c4b20a26c48c000ce2364908db 100644 (file)
@@ -18,9 +18,9 @@
 #include <Types.h>
 #include <Json.h>
 #include <DatabaseManager.h>
-#include "../facade/UserPlacesTypes.h"
-#include "../facade/UserPlacesParams.h"
-#include "../utils/DebugUtils.h"
+#include <UserPlacesTypes.h>
+#include <UserPlacesParams.h>
+#include <DebugUtils.h>
 #include "LocationLogger.h"
 
 #ifdef TIZEN_ENGINEER_MODE
index 0aa53c5dde3b44095afcd59ee36a188cf654be10..98460c2af3cd854bcffe13e5329d7359da6c2458 100644 (file)
 #include <sstream>
 #include <Types.h>
 #include <Json.h>
-#include "../facade/UserPlacesTypes.h"
+#include <UserPlacesTypes.h>
 #include "VisitDetector.h"
-#include "../facade/UserPlacesParams.h"
-#include "../utils/Similarity.h"
-#include "../utils/Median.h"
-#include "../utils/DebugUtils.h"
+#include <UserPlacesParams.h>
+#include <Similarity.h>
+#include <Median.h>
+#include <DebugUtils.h>
 #include <gmodule.h>
 #include <DatabaseManager.h>
 
index 98bbda3d02979cccf48c97cd316d6283a4359912..b4769420555f79c9f7647b24eb9ef216fd142054 100644 (file)
@@ -22,7 +22,7 @@
 #include <map>
 #include <unordered_map>
 #include <unordered_set>
-#include "../facade/UserPlacesTypes.h"
+#include <UserPlacesTypes.h>
 #include <Json.h>
 #include "VisitListenerIface.h"
 #include "LocationLogger.h"
index 56307d0b5f7b66ddac03d0ddb573c7eb5615b6e9..84ef489852a2481a60a9704dbe59c35972baa195 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef _CONTEXT_PLACE_RECOGNITION_WIFI_LISTENER_IFACE_H_
 #define _CONTEXT_PLACE_RECOGNITION_WIFI_LISTENER_IFACE_H_
 
-#include "../facade/UserPlacesTypes.h"
+#include <UserPlacesTypes.h>
 
 namespace ctx {
 
index 2baa24c0b201296e402fcb680b1346c3914d9b9c..874f4947210e93ee36de36136909afebd949673a 100644 (file)
@@ -17,8 +17,8 @@
 #include <sstream>
 #include <Types.h>
 #include <DatabaseManager.h>
-#include "../facade/UserPlacesTypes.h"
-#include "../utils/DebugUtils.h"
+#include <UserPlacesTypes.h>
+#include <DebugUtils.h>
 #include "WifiLogger.h"
 
 #define __WIFI_CREATE_TABLE_COLUMNS \
index 0134c2d79bfd4e99777994cc49ace3fd7bccb717..7c627a1d13a51b5a77898df0251c94093ebbb5b3 100644 (file)
@@ -24,7 +24,7 @@
 #include <TimerManager.h>
 #include "WifiListenerIface.h"
 #include "VisitListenerIface.h"
-#include "../facade/UserPlacesParams.h"
+#include <UserPlacesParams.h>
 
 /* Database usage flag */
 #define WIFI_LOGGER_DATABASE false