2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef _CONTEXT_PLACE_RECOGNITION_USER_PLACES_TYPES_H_
18 #define _CONTEXT_PLACE_RECOGNITION_USER_PLACES_TYPES_H_
23 #include <unordered_map>
24 #include <unordered_set>
27 #include <MyPlaceTypes.h>
30 #define VISIT_TABLE "Log_Myplace_Visit"
31 #define VISIT_COLUMN_START_TIME "start_time"
32 #define VISIT_COLUMN_END_TIME "end_time"
33 #define VISIT_COLUMN_WIFI_APS "wifi_aps"
34 #define VISIT_COLUMN_CATEGORY "category"
35 #ifdef TIZEN_ENGINEER_MODE
36 #define VISIT_COLUMN_START_TIME_HUMAN "start_time_human" // only for debug: human readable time data:
37 #define VISIT_COLUMN_END_TIME_HUMAN "end_time_human" // only for debug: human readable time data:
38 #endif /* TIZEN_ENGINEER_MODE */
39 #define VISIT_COLUMN_LOCATION_VALID "location_valid"
40 #define VISIT_COLUMN_LOCATION_LATITUDE "location_latitude"
41 #define VISIT_COLUMN_LOCATION_LONGITUDE "location_longitude"
42 #define VISIT_COLUMN_LOCATION_ACCURACY "location_accuracy"
43 #define VISIT_COLUMN_CATEG_HOME "categ_home"
44 #define VISIT_COLUMN_CATEG_WORK "categ_work"
45 #define VISIT_COLUMN_CATEG_OTHER "categ_other"
47 #define WIFI_APS_MAP_TABLE "Log_Myplace_WifiAPsMap"
48 #define WIFI_APS_MAP_COLUMN_MAC "mac"
49 #define WIFI_APS_MAP_COLUMN_NETWORK_NAME "network_name"
50 #define WIFI_APS_MAP_COLUMN_INSERT_TIME "insert_time"
52 #define PLACE_TABLE "Log_Myplace_Place"
53 #define PLACE_COLUMN_CATEG_ID "categ_id"
54 #define PLACE_COLUMN_CATEG_CONFIDENCE "categ_confidence"
55 #define PLACE_COLUMN_NAME "name"
56 #define PLACE_COLUMN_LOCATION_VALID "location_valid"
57 #define PLACE_COLUMN_LOCATION_LATITUDE "location_latitude"
58 #define PLACE_COLUMN_LOCATION_LONGITUDE "location_longitude"
59 #define PLACE_COLUMN_LOCATION_ACCURACY "location_accuracy"
60 #define PLACE_COLUMN_WIFI_APS "wifi_aps"
61 #define PLACE_COLUMN_CREATE_DATE "create_date"
63 #define WIFI_TABLE "Log_Myplace_Wifi"
64 #define WIFI_COLUMN_TIMESTAMP "timestamp"
65 #define WIFI_COLUMN_BSSID "bssid"
66 #define WIFI_COLUMN_ESSID "essid"
68 #define LOCATION_TABLE "Log_Myplace_Location"
69 #define LOCATION_COLUMN_LATITUDE "latitude"
70 #define LOCATION_COLUMN_LONGITUDE "longitude"
71 #define LOCATION_COLUMN_ACCURACY "accuracy"
72 #define LOCATION_COLUMN_TIMESTAMP "timestamp"
73 #ifdef TIZEN_ENGINEER_MODE
74 #define LOCATION_COLUMN_TIMESTAMP_HUMAN "time_human" // only for debug: human readable time data:
75 #define LOCATION_COLUMN_METHOD "method"
76 #endif /* TIZEN_ENGINEER_MODE */
78 #define MYPLACE_SETTINGS_TABLE "Myplace_Settings"
79 #define MYPLACE_SETTINGS_COLUMN_KEY "key"
80 #define MYPLACE_SETTINGS_COLUMN_VALUE "value"
81 #define MYPLACE_SETTING_KEY_USER_CONSENT PLACE_DETECTION_REQUEST_CONSENT
84 PLACE_RECOG_HIGH_ACCURACY_MODE = 0,
85 PLACE_RECOG_LOW_POWER_MODE = 1
91 * type for numerical computations
101 const static size_t MAC_SIZE = 6; // number of bytes for mac address.
102 unsigned char c[MAC_SIZE];
105 Mac(const std::string &str);
106 Mac(const char *str);
107 operator std::string() const;
111 std::istream &operator>>(std::istream &input, ctx::Mac &mac);
112 std::ostream &operator<<(std::ostream &output, const ctx::Mac &mac);
113 bool operator==(const ctx::Mac &m1, const ctx::Mac &m2);
114 bool operator!=(const ctx::Mac &m1, const ctx::Mac &m2);
115 bool operator<(const ctx::Mac &m1, const ctx::Mac &m2);
116 bool operator>(const ctx::Mac &m1, const ctx::Mac &m2);
118 } /* namespace ctx */
122 template <> struct hash<ctx::Mac> {
123 size_t operator()(const ctx::Mac & m) const {
125 for (size_t i = 0; i < ctx::Mac::MAC_SIZE; i++) {
132 } /* namespace std */
136 typedef float share_t;
139 typedef std::unordered_map<ctx::Mac, ctx::count_t> Macs2Counts;
140 typedef std::unordered_map<ctx::Mac, ctx::share_t> Macs2Shares;
142 typedef std::unordered_set<ctx::Mac> MacSet;
144 std::istream &operator>>(std::istream &input, ctx::MacSet &macSet);
145 std::ostream &operator<<(std::ostream &output, const ctx::MacSet &macSet);
146 ctx::MacSet macSetFromString(const std::string &str);
148 std::shared_ptr<MacSet> macSetsUnion(const std::vector<std::shared_ptr<MacSet>> &macSets);
154 Interval(time_t start, time_t end);
157 } /* namespace ctx */
161 template <> struct hash<ctx::Interval> {
162 size_t operator()(const ctx::Interval & interval) const {
163 return interval.end * interval.start;
167 } /* namespace std */
172 * fully describes interval data after the interval is finished
176 count_t numberOfTimestamps;
177 Macs2Counts macs2Counts;
179 Frame(Interval interval_) : interval(interval_), numberOfTimestamps(0) {};
183 * mac address + its timestamp
188 std::string networkName;
190 MacEvent(time_t timestamp_, Mac mac_, std::string networkName_ = "")
191 : timestamp(timestamp_)
193 , networkName(networkName_) {}
196 typedef std::map<int, num_t> Categs; // scores of categories
198 #ifdef TIZEN_ENGINEER_MODE
199 enum LocationSource {
200 LOCATION_METHOD_REQUEST = 0,
201 LOCATION_METHOD_GET_LOCATION = 1,
202 LOCATION_METHOD_GET_LAST_LOCATION = 2
204 #endif /* TIZEN_ENGINEER_MODE */
207 * location + timestamp + method
209 struct LocationEvent {
210 Location coordinates;
213 #ifdef TIZEN_ENGINEER_MODE
214 LocationSource method;
216 LocationEvent(double latitude_, double longitude_, double accuracy_, time_t timestamp_, LocationSource method_) :
217 coordinates(latitude_, longitude_, accuracy_),
218 timestamp(timestamp_), method(method_) {}
219 #else /* TIZEN_ENGINEER_MODE */
220 LocationEvent(double latitude_, double longitude_, double accuracy_, time_t timestamp_) :
221 coordinates(latitude_, longitude_, accuracy_),
222 timestamp(timestamp_) {}
223 #endif /* TIZEN_ENGINEER_MODE */
227 }; /* struct LocationEvent */
231 std::shared_ptr<MacSet> macSet;
234 Location location; // makes sense if locationValid == true;
236 Visit(Interval interval_, std::shared_ptr<MacSet> macSet_ = std::make_shared<MacSet>(), Categs categs_ = Categs()) :
240 locationValid(false) {}
241 void setLocation(Location location);
242 void printShort2Stream(std::ostream &out) const;
244 }; /* struct Visit */
246 bool operator==(const Visit &v1, const Visit &v2);
247 typedef std::vector<Visit> Visits;
248 typedef std::vector<MacEvent> MacEvents; // used to store current interval logs
250 std::shared_ptr<MacSet> macSetFromMacs2Counts(const Macs2Counts &macs2Counts);
252 } /* namespace ctx */
254 #endif /* End of _CONTEXT_PLACE_RECOGNITION_USER_PLACES_TYPES_H_ */