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 #define VISIT_COLUMN_LOCATION_VALID "location_valid"
36 #define VISIT_COLUMN_LOCATION_LATITUDE "location_latitude"
37 #define VISIT_COLUMN_LOCATION_LONGITUDE "location_longitude"
38 #define VISIT_COLUMN_LOCATION_ACCURACY "location_accuracy"
39 #define VISIT_COLUMN_CATEG_HOME "categ_home"
40 #define VISIT_COLUMN_CATEG_WORK "categ_work"
41 #define VISIT_COLUMN_CATEG_OTHER "categ_other"
43 #define WIFI_APS_MAP_TABLE "Log_Myplace_WifiAPsMap"
44 #define WIFI_APS_MAP_COLUMN_MAC "mac"
45 #define WIFI_APS_MAP_COLUMN_NETWORK_NAME "network_name"
46 #define WIFI_APS_MAP_COLUMN_INSERT_TIME "insert_time"
48 #define PLACE_TABLE "Log_Myplace_Place"
49 #define PLACE_COLUMN_CATEG_ID "categ_id"
50 #define PLACE_COLUMN_CATEG_CONFIDENCE "categ_confidence"
51 #define PLACE_COLUMN_NAME "name"
52 #define PLACE_COLUMN_LOCATION_VALID "location_valid"
53 #define PLACE_COLUMN_LOCATION_LATITUDE "location_latitude"
54 #define PLACE_COLUMN_LOCATION_LONGITUDE "location_longitude"
55 #define PLACE_COLUMN_LOCATION_ACCURACY "location_accuracy"
56 #define PLACE_COLUMN_WIFI_APS "wifi_aps"
57 #define PLACE_COLUMN_CREATE_DATE "create_date"
59 #define WIFI_TABLE "Log_Myplace_Wifi"
60 #define WIFI_COLUMN_TIMESTAMP "timestamp"
61 #define WIFI_COLUMN_BSSID "bssid"
62 #define WIFI_COLUMN_ESSID "essid"
64 #define LOCATION_TABLE "Log_Myplace_Location"
65 #define LOCATION_COLUMN_LATITUDE "latitude"
66 #define LOCATION_COLUMN_LONGITUDE "longitude"
67 #define LOCATION_COLUMN_ACCURACY "accuracy"
68 #define LOCATION_COLUMN_TIMESTAMP "timestamp"
70 #define MYPLACE_SETTINGS_TABLE "Myplace_Settings"
71 #define MYPLACE_SETTINGS_COLUMN_KEY "key"
72 #define MYPLACE_SETTINGS_COLUMN_VALUE "value"
73 #define MYPLACE_SETTING_KEY_USER_CONSENT PLACE_DETECTION_REQUEST_CONSENT
76 PLACE_RECOG_HIGH_ACCURACY_MODE = 0,
77 PLACE_RECOG_LOW_POWER_MODE = 1
83 * type for numerical computations
93 const static size_t MAC_SIZE = 6; // number of bytes for mac address.
94 unsigned char c[MAC_SIZE];
97 Mac(const std::string &str);
99 operator std::string() const;
103 std::istream &operator>>(std::istream &input, ctx::Mac &mac);
104 std::ostream &operator<<(std::ostream &output, const ctx::Mac &mac);
105 bool operator==(const ctx::Mac &m1, const ctx::Mac &m2);
106 bool operator!=(const ctx::Mac &m1, const ctx::Mac &m2);
107 bool operator<(const ctx::Mac &m1, const ctx::Mac &m2);
108 bool operator>(const ctx::Mac &m1, const ctx::Mac &m2);
110 } /* namespace ctx */
114 template <> struct hash<ctx::Mac> {
115 size_t operator()(const ctx::Mac & m) const {
117 for (size_t i = 0; i < ctx::Mac::MAC_SIZE; i++) {
124 } /* namespace std */
128 typedef float share_t;
131 typedef std::unordered_map<ctx::Mac, ctx::count_t> Macs2Counts;
132 typedef std::unordered_map<ctx::Mac, ctx::share_t> Macs2Shares;
134 typedef std::unordered_set<ctx::Mac> MacSet;
136 std::istream &operator>>(std::istream &input, ctx::MacSet &macSet);
137 std::ostream &operator<<(std::ostream &output, const ctx::MacSet &macSet);
138 ctx::MacSet macSetFromString(const std::string &str);
140 std::shared_ptr<MacSet> macSetsUnion(const std::vector<std::shared_ptr<MacSet>> &macSets);
146 Interval(time_t start, time_t end);
149 } /* namespace ctx */
153 template <> struct hash<ctx::Interval> {
154 size_t operator()(const ctx::Interval & interval) const {
155 return interval.end * interval.start;
159 } /* namespace std */
164 * fully describes interval data after the interval is finished
168 count_t numberOfTimestamps;
169 Macs2Counts macs2Counts;
171 Frame(Interval interval_) : interval(interval_), numberOfTimestamps(0) {};
175 * mac address + its timestamp
180 std::string networkName;
182 MacEvent(time_t timestamp_, Mac mac_, std::string networkName_ = "")
183 : timestamp(timestamp_)
185 , networkName(networkName_) {}
188 typedef std::map<int, num_t> Categs; // scores of categories
191 * location + timestamp + method
193 struct LocationEvent {
194 Location coordinates;
197 LocationEvent(double latitude_, double longitude_, double accuracy_, time_t timestamp_) :
198 coordinates(latitude_, longitude_, accuracy_),
199 timestamp(timestamp_) {}
203 }; /* struct LocationEvent */
207 std::shared_ptr<MacSet> macSet;
210 Location location; // makes sense if locationValid == true;
212 Visit(Interval interval_, std::shared_ptr<MacSet> macSet_ = std::make_shared<MacSet>(), Categs categs_ = Categs()) :
216 locationValid(false) {}
217 void setLocation(Location location);
218 void printShort2Stream(std::ostream &out) const;
220 }; /* struct Visit */
222 bool operator==(const Visit &v1, const Visit &v2);
223 typedef std::vector<Visit> Visits;
224 typedef std::vector<MacEvent> MacEvents; // used to store current interval logs
226 std::shared_ptr<MacSet> macSetFromMacs2Counts(const Macs2Counts &macs2Counts);
228 } /* namespace ctx */
230 #endif /* End of _CONTEXT_PLACE_RECOGNITION_USER_PLACES_TYPES_H_ */