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 PLACE_PRIV_RECOGNITION "location" // TODO: unused?
33 #define VISIT_TABLE "place_status_user_place_visit"
34 #define VISIT_COLUMN_START_TIME "start_time"
35 #define VISIT_COLUMN_END_TIME "end_time"
36 #define VISIT_COLUMN_WIFI_APS "wifi_aps"
37 #define VISIT_COLUMN_CATEGORY "category"
38 #ifdef TIZEN_ENGINEER_MODE
39 #define VISIT_COLUMN_START_TIME_HUMAN "start_time_human" // only for debug: human readable time data:
40 #define VISIT_COLUMN_END_TIME_HUMAN "end_time_human" // only for debug: human readable time data:
41 #endif /* TIZEN_ENGINEER_MODE */
42 #define VISIT_COLUMN_LOCATION_VALID "location_valid"
43 #define VISIT_COLUMN_LOCATION_LATITUDE "location_latitude"
44 #define VISIT_COLUMN_LOCATION_LONGITUDE "location_longitude"
45 #define VISIT_COLUMN_LOCATION_ACCURACY "location_accuracy"
46 #define VISIT_COLUMN_CATEG_HOME "categ_home"
47 #define VISIT_COLUMN_CATEG_WORK "categ_work"
48 #define VISIT_COLUMN_CATEG_OTHER "categ_other"
50 #define WIFI_APS_MAP_TABLE "place_status_user_place_wifi_aps_map"
51 #define WIFI_APS_MAP_COLUMN_MAC "mac"
52 #define WIFI_APS_MAP_COLUMN_NETWORK_NAME "network_name"
53 #define WIFI_APS_MAP_COLUMN_INSERT_TIME "insert_time"
55 #define PLACE_TABLE "place_status_user_place"
56 #define PLACE_COLUMN_CATEG_ID "categ_id"
57 #define PLACE_COLUMN_CATEG_CONFIDENCE "categ_confidence"
58 #define PLACE_COLUMN_NAME "name"
59 #define PLACE_COLUMN_LOCATION_VALID "location_valid"
60 #define PLACE_COLUMN_LOCATION_LATITUDE "location_latitude"
61 #define PLACE_COLUMN_LOCATION_LONGITUDE "location_longitude"
62 #define PLACE_COLUMN_LOCATION_ACCURACY "location_accuracy"
63 #define PLACE_COLUMN_WIFI_APS "wifi_aps"
64 #define PLACE_COLUMN_CREATE_DATE "create_date"
66 #define WIFI_TABLE_NAME "place_status_user_place_wifi"
67 #define WIFI_COLUMN_TIMESTAMP "timestamp"
68 #define WIFI_COLUMN_BSSID "bssid"
69 #define WIFI_COLUMN_ESSID "essid"
71 #define LOCATION_TABLE_NAME "place_status_user_place_location"
72 #define LOCATION_COLUMN_LATITUDE "geo_latitude"
73 #define LOCATION_COLUMN_LONGITUDE "geo_longitude"
74 #define LOCATION_COLUMN_ACCURACY "accuracy"
75 #define LOCATION_COLUMN_TIMESTAMP "timestamp"
76 #ifdef TIZEN_ENGINEER_MODE
77 #define LOCATION_COLUMN_TIMESTAMP_HUMAN "time_human" // only for debug: human readable time data:
78 #define LOCATION_COLUMN_METHOD "method"
79 #endif /* TIZEN_ENGINEER_MODE */
82 PLACE_RECOG_HIGH_ACCURACY_MODE = 0,
83 PLACE_RECOG_LOW_POWER_MODE = 1
89 * type for numerical computations
99 const static size_t MAC_SIZE = 6; // number of bytes for mac address.
100 unsigned char c[MAC_SIZE];
103 Mac(const std::string &str);
104 Mac(const char *str);
105 operator std::string() const;
109 std::istream &operator>>(std::istream &input, ctx::Mac &mac);
110 std::ostream &operator<<(std::ostream &output, const ctx::Mac &mac);
111 bool operator==(const ctx::Mac &m1, const ctx::Mac &m2);
112 bool operator!=(const ctx::Mac &m1, const ctx::Mac &m2);
113 bool operator<(const ctx::Mac &m1, const ctx::Mac &m2);
114 bool operator>(const ctx::Mac &m1, const ctx::Mac &m2);
116 } /* namespace ctx */
120 template <> struct hash<ctx::Mac> {
121 size_t operator()(const ctx::Mac & m) const {
123 for (size_t i = 0; i < ctx::Mac::MAC_SIZE; i++) {
130 } /* namespace std */
134 typedef float share_t;
137 typedef std::unordered_map<ctx::Mac, ctx::count_t> Macs2Counts;
138 typedef std::unordered_map<ctx::Mac, ctx::share_t> Macs2Shares;
140 typedef std::unordered_set<ctx::Mac> MacSet;
142 std::istream &operator>>(std::istream &input, ctx::MacSet &macSet);
143 std::ostream &operator<<(std::ostream &output, const ctx::MacSet &macSet);
144 ctx::MacSet macSetFromString(const std::string &str);
146 std::shared_ptr<MacSet> macSetsUnion(const std::vector<std::shared_ptr<MacSet>> &macSets);
152 Interval(time_t start, time_t end);
155 } /* namespace ctx */
159 template <> struct hash<ctx::Interval> {
160 size_t operator()(const ctx::Interval & interval) const {
161 return interval.end * interval.start;
165 } /* namespace std */
170 * fully describes interval data after the interval is finished
174 count_t numberOfTimestamps;
175 Macs2Counts macs2Counts;
177 Frame(Interval interval_) : interval(interval_), numberOfTimestamps(0) {};
181 * mac address + its timestamp
186 std::string networkName;
188 MacEvent(time_t timestamp_, Mac mac_, std::string networkName_ = "")
189 : timestamp(timestamp_)
191 , networkName(networkName_) {}
194 typedef std::map<int, num_t> Categs; // scores of categories
196 #ifdef TIZEN_ENGINEER_MODE
197 enum LocationSource {
198 LOCATION_METHOD_REQUEST = 0,
199 LOCATION_METHOD_GET_LOCATION = 1,
200 LOCATION_METHOD_GET_LAST_LOCATION = 2
202 #endif /* TIZEN_ENGINEER_MODE */
205 * location + timestamp + method
207 struct LocationEvent {
208 Location coordinates;
211 #ifdef TIZEN_ENGINEER_MODE
212 LocationSource method;
214 LocationEvent(double latitude_, double longitude_, double accuracy_, time_t timestamp_, LocationSource method_) :
215 coordinates(latitude_, longitude_, accuracy_),
216 timestamp(timestamp_), method(method_) {}
217 #else /* TIZEN_ENGINEER_MODE */
218 LocationEvent(double latitude_, double longitude_, double accuracy_, time_t timestamp_) :
219 coordinates(latitude_, longitude_, accuracy_),
220 timestamp(timestamp_) {}
221 #endif /* TIZEN_ENGINEER_MODE */
225 }; /* struct LocationEvent */
229 std::shared_ptr<MacSet> macSet;
232 Location location; // makes sense if locationValid == true;
234 Visit(Interval interval_, std::shared_ptr<MacSet> macSet_ = std::make_shared<MacSet>(), Categs categs_ = Categs()) :
238 locationValid(false) {}
239 void setLocation(Location location);
240 void printShort2Stream(std::ostream &out) const;
242 }; /* struct Visit */
244 bool operator==(const Visit &v1, const Visit &v2);
245 typedef std::vector<Visit> Visits;
246 typedef std::vector<MacEvent> MacEvents; // used to store current interval logs
248 std::shared_ptr<MacSet> macSetFromMacs2Counts(const Macs2Counts &macs2Counts);
250 } /* namespace ctx */
252 #endif /* End of _CONTEXT_PLACE_RECOGNITION_USER_PLACES_TYPES_H_ */