@sentiance-react-native/user-context 6.1.2 → 6.2.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5,13 +5,12 @@ import com.facebook.react.bridge.WritableArray;
|
|
|
5
5
|
import com.facebook.react.bridge.WritableMap;
|
|
6
6
|
import com.sentiance.sdk.ondevice.api.Attribute;
|
|
7
7
|
import com.sentiance.sdk.ondevice.api.GeoLocation;
|
|
8
|
+
import com.sentiance.sdk.ondevice.api.Waypoint;
|
|
8
9
|
import com.sentiance.sdk.ondevice.api.event.Event;
|
|
9
10
|
import com.sentiance.sdk.ondevice.api.event.StationaryEvent;
|
|
10
11
|
import com.sentiance.sdk.ondevice.api.event.TransportEvent;
|
|
11
12
|
import com.sentiance.sdk.ondevice.api.segment.Segment;
|
|
12
13
|
import com.sentiance.sdk.ondevice.api.venue.Venue;
|
|
13
|
-
import com.sentiance.sdk.ondevice.api.venue.VenueCandidate;
|
|
14
|
-
import com.sentiance.sdk.ondevice.api.venue.Visit;
|
|
15
14
|
import com.sentiance.sdk.usercontext.api.RequestUserContextError;
|
|
16
15
|
import com.sentiance.sdk.usercontext.api.RequestUserContextFailureReason;
|
|
17
16
|
import com.sentiance.sdk.usercontext.api.UserContext;
|
|
@@ -19,16 +18,15 @@ import com.sentiance.sdk.usercontext.api.UserContextUpdateCriteria;
|
|
|
19
18
|
import com.sentiance.sdk.util.DateTime;
|
|
20
19
|
|
|
21
20
|
import java.util.List;
|
|
22
|
-
import java.util.Map;
|
|
23
21
|
|
|
24
22
|
public class SentianceUserContextConverter {
|
|
25
23
|
|
|
26
24
|
public static WritableMap convertGeoLocation(GeoLocation location) {
|
|
27
25
|
WritableMap locationMap = Arguments.createMap();
|
|
28
26
|
|
|
29
|
-
locationMap.
|
|
30
|
-
locationMap.
|
|
31
|
-
locationMap.
|
|
27
|
+
locationMap.putDouble("latitude", location.getLatitude());
|
|
28
|
+
locationMap.putDouble("longitude", location.getLongitude());
|
|
29
|
+
locationMap.putInt("accuracy", location.getAccuracyInMeters());
|
|
32
30
|
|
|
33
31
|
return locationMap;
|
|
34
32
|
}
|
|
@@ -41,12 +39,12 @@ public class SentianceUserContextConverter {
|
|
|
41
39
|
map.putString("type", segment.getType().name());
|
|
42
40
|
map.putInt("id", segment.getType().getUniqueId());
|
|
43
41
|
map.putString("startTime", segment.getStartTime().toString());
|
|
44
|
-
map.
|
|
42
|
+
map.putDouble("startTimeEpoch", segment.getStartTime().getEpochTime());
|
|
45
43
|
|
|
46
44
|
DateTime endTime = segment.getEndTime();
|
|
47
45
|
if (endTime != null) {
|
|
48
46
|
map.putString("endTime", endTime.toString());
|
|
49
|
-
map.
|
|
47
|
+
map.putDouble("endTimeEpoch", segment.getEndTime().getEpochTime());
|
|
50
48
|
}
|
|
51
49
|
|
|
52
50
|
WritableArray attributes = Arguments.createArray();
|
|
@@ -65,8 +63,10 @@ public class SentianceUserContextConverter {
|
|
|
65
63
|
WritableMap map = Arguments.createMap();
|
|
66
64
|
|
|
67
65
|
map.putString("startTime", event.getStartTime().toString());
|
|
66
|
+
map.putDouble("startTimeEpoch", event.getStartTime().getEpochTime());
|
|
68
67
|
if (event.getEndTime() != null) {
|
|
69
68
|
map.putString("endTime", event.getEndTime().toString());
|
|
69
|
+
map.putDouble("endTimeEpoch", event.getEndTime().getEpochTime());
|
|
70
70
|
|
|
71
71
|
Long durationInSeconds = event.getDurationInSeconds();
|
|
72
72
|
if (durationInSeconds != null) {
|
|
@@ -125,6 +125,9 @@ public class SentianceUserContextConverter {
|
|
|
125
125
|
userContextMap.putMap("work", convertVenue(userContext.getWork()));
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
+
// Semantic time
|
|
129
|
+
userContextMap.putString("semanticTime", userContext.getSemanticTime().name());
|
|
130
|
+
|
|
128
131
|
return userContextMap;
|
|
129
132
|
}
|
|
130
133
|
|
|
@@ -149,62 +152,47 @@ public class SentianceUserContextConverter {
|
|
|
149
152
|
if (event.getLocation() != null) {
|
|
150
153
|
map.putMap("location", convertGeoLocation(event.getLocation()));
|
|
151
154
|
}
|
|
152
|
-
|
|
153
|
-
map.putString("venueSignificance", event.getVenueSignificance().toString());
|
|
154
|
-
|
|
155
|
-
WritableArray venueCandidatesArray = Arguments.createArray();
|
|
156
|
-
for (VenueCandidate candidate : event.getVenueCandidates()) {
|
|
157
|
-
venueCandidatesArray.pushMap(convertVenueCandidate(candidate));
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
map.putArray("venueCandidates", venueCandidatesArray);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
private static WritableMap convertVenueCandidate(VenueCandidate candidate) {
|
|
164
|
-
WritableMap venueCandidateMap = Arguments.createMap();
|
|
165
|
-
venueCandidateMap.putMap("venue", convertVenue(candidate.getVenue()));
|
|
166
|
-
venueCandidateMap.putDouble("likelihood", candidate.getLikelihood());
|
|
167
|
-
|
|
168
|
-
WritableArray visitsArray = Arguments.createArray();
|
|
169
|
-
for (Visit visit : candidate.getVisits()) {
|
|
170
|
-
visitsArray.pushMap(convertVisit(visit));
|
|
171
|
-
}
|
|
172
|
-
venueCandidateMap.putArray("visits", visitsArray);
|
|
173
|
-
return venueCandidateMap;
|
|
155
|
+
map.putMap("venue", convertVenue(event.getVenue()));
|
|
174
156
|
}
|
|
175
157
|
|
|
176
158
|
private static WritableMap convertVenue(Venue venue) {
|
|
177
159
|
WritableMap venueMap = Arguments.createMap();
|
|
178
160
|
|
|
179
|
-
if (venue.
|
|
180
|
-
venueMap.
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
venueMap.putMap("location", convertGeoLocation(venue.getLocation()));
|
|
184
|
-
|
|
185
|
-
WritableMap venueLabelsMap = Arguments.createMap();
|
|
186
|
-
for (Map.Entry<String, String> entry : venue.getLabels().entrySet()) {
|
|
187
|
-
venueLabelsMap.putString(entry.getKey(), entry.getValue());
|
|
161
|
+
if (venue.getLocation() != null) {
|
|
162
|
+
venueMap.putMap("location", convertGeoLocation(venue.getLocation()));
|
|
188
163
|
}
|
|
189
|
-
venueMap.
|
|
164
|
+
venueMap.putString("significance", venue.getSignificance().name());
|
|
165
|
+
venueMap.putString("type", venue.getType().name());
|
|
190
166
|
|
|
191
167
|
return venueMap;
|
|
192
168
|
}
|
|
193
169
|
|
|
194
|
-
private static
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
170
|
+
private static void addTransportEventInfo(WritableMap map, TransportEvent event) {
|
|
171
|
+
map.putString("transportMode", event.getTransportMode().toString());
|
|
172
|
+
map.putArray("waypoints", convertWaypointList(event.getWaypoints()));
|
|
173
|
+
|
|
174
|
+
if (event.getDistanceInMeters() != null) {
|
|
175
|
+
map.putInt("distance", event.getDistanceInMeters());
|
|
176
|
+
}
|
|
177
|
+
}
|
|
198
178
|
|
|
199
|
-
|
|
200
|
-
|
|
179
|
+
public static WritableMap convertWaypoint(Waypoint waypoint) {
|
|
180
|
+
WritableMap waypointMap = Arguments.createMap();
|
|
201
181
|
|
|
202
|
-
|
|
182
|
+
waypointMap.putDouble("latitude", waypoint.getLatitude());
|
|
183
|
+
waypointMap.putDouble("longitude", waypoint.getLongitude());
|
|
184
|
+
waypointMap.putInt("accuracy", waypoint.getAccuracyInMeters());
|
|
185
|
+
waypointMap.putDouble("timestamp", waypoint.getTimestamp());
|
|
203
186
|
|
|
204
|
-
return
|
|
187
|
+
return waypointMap;
|
|
205
188
|
}
|
|
206
189
|
|
|
207
|
-
private static
|
|
208
|
-
|
|
190
|
+
private static WritableArray convertWaypointList(List<Waypoint> waypointList) {
|
|
191
|
+
WritableArray array = Arguments.createArray();
|
|
192
|
+
for (Waypoint waypoint : waypointList) {
|
|
193
|
+
array.pushMap(convertWaypoint(waypoint));
|
|
194
|
+
}
|
|
195
|
+
return array;
|
|
209
196
|
}
|
|
197
|
+
|
|
210
198
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -108,9 +108,9 @@ declare module "@sentiance-react-native/user-context" {
|
|
|
108
108
|
| "WORK_TRAVELLER"
|
|
109
109
|
| "WORKAHOLIC";
|
|
110
110
|
|
|
111
|
-
type TransportMode =
|
|
111
|
+
export type TransportMode =
|
|
112
112
|
| "UNKNOWN"
|
|
113
|
-
| "
|
|
113
|
+
| "BICYCLE"
|
|
114
114
|
| "WALKING"
|
|
115
115
|
| "RUNNING"
|
|
116
116
|
| "TRAM"
|
|
@@ -119,45 +119,118 @@ declare module "@sentiance-react-native/user-context" {
|
|
|
119
119
|
| "BUS"
|
|
120
120
|
| "MOTORCYCLE";
|
|
121
121
|
|
|
122
|
+
export type VenueSignificance =
|
|
123
|
+
| "UNKNOWN"
|
|
124
|
+
| "HOME"
|
|
125
|
+
| "WORK"
|
|
126
|
+
| "POINT_OF_INTEREST"
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* The list of venue types that are currently supported by the venue-type mapping model:
|
|
130
|
+
*
|
|
131
|
+
* <ul>
|
|
132
|
+
* <li><b>DRINK_DAY</b> - Cafes, coffee bars, tea rooms, etc</li>
|
|
133
|
+
* <li><b>DRINK_EVENING</b> - Bars, pubs and in general places where one goes for drinks in evenings.</li>
|
|
134
|
+
* <li><b>EDUCATION_INDEPENDENT</b> - Educational institutions visited by the user on his own for their own studies. High schools, universities, colleges, etc.</li>
|
|
135
|
+
* <li><b>EDUCATION_PARENTS</b> - Schools and kindergartens visited by parents.</li>
|
|
136
|
+
* <li><b>HEALTH</b> - Hospitals, clinics, emergency rooms.</li>
|
|
137
|
+
* <li><b>INDUSTRIAL</b> - Buildings tagged as “industrial” on OSM, built for some manufacturing process.</li>
|
|
138
|
+
* <li><b>LEISURE_BEACH</b> - Beaches, resorts and swimming areas.</li>
|
|
139
|
+
* <li><b>LEISURE_DAY</b> - Bowling, billiards and other entertainment places.</li>
|
|
140
|
+
* <li><b>LEISURE_EVENING</b> - Cinemas, theatres and music halls.</li>
|
|
141
|
+
* <li><b>LEISURE_MUSEUM</b> - Museums.</li>
|
|
142
|
+
* <li><b>LEISURE_NATURE</b> - Forests, lakes, national parks, etc.</li>
|
|
143
|
+
* <li><b>LEISURE_PARK</b> - City parks, gardens, zoos.</li>
|
|
144
|
+
* <li><b>OFFICE</b> - Office buildings. For example, of private lawyers, notaries or company representatives.</li>
|
|
145
|
+
* <li><b>RELIGION</b> - Churches, mosques and other religion related buildings.</li>
|
|
146
|
+
* <li><b>RESIDENTIAL</b> - Apartment blocks, houses.</li>
|
|
147
|
+
* <li><b>RESTO_MID</b> - Food courts, restaurants, snack bars.</li>
|
|
148
|
+
* <li><b>RESTO_SHORT</b> - Ice cream, fast food, donut stores.</li>
|
|
149
|
+
* <li><b>SHOP_LONG</b> - Supermarkets, malls, wholesales, shopping centres.</li>
|
|
150
|
+
* <li><b>SHOP_SHORT</b> - Small grocery stores, butchers, bakers.</li>
|
|
151
|
+
* <li><b>SPORT</b> - Gyms, sport centres. Venues visited to exercise.</li>
|
|
152
|
+
* <li><b>SPORT_ATTEND</b> - Stadiums. Venues visited to attend a sport event.</li>
|
|
153
|
+
* <li><b>TRAVEL_BUS</b> - Bus stops.</li>
|
|
154
|
+
* <li><b>TRAVEL_CONFERENCE</b> - Conference, convention, exhibition centres.</li>
|
|
155
|
+
* <li><b>TRAVEL_FILL</b> - Gas stations.</li>
|
|
156
|
+
* <li><b>TRAVEL_HOTEL</b> - Hotels, motels, guest rooms, etc.</li>
|
|
157
|
+
* <li><b>TRAVEL_LONG</b> - Airports</li>
|
|
158
|
+
* <li><b>TRAVEL_SHORT</b> - Public transport stations, railway stations.</li>
|
|
159
|
+
* </ul>
|
|
160
|
+
*/
|
|
161
|
+
export type VenueType =
|
|
162
|
+
| "UNKNOWN"
|
|
163
|
+
| "DRINK_DAY"
|
|
164
|
+
| "DRINK_EVENING"
|
|
165
|
+
| "EDUCATION_INDEPENDENT"
|
|
166
|
+
| "EDUCATION_PARENTS"
|
|
167
|
+
| "HEALTH"
|
|
168
|
+
| "INDUSTRIAL"
|
|
169
|
+
| "LEISURE_BEACH"
|
|
170
|
+
| "LEISURE_DAY"
|
|
171
|
+
| "LEISURE_EVENING"
|
|
172
|
+
| "LEISURE_MUSEUM"
|
|
173
|
+
| "LEISURE_NATURE"
|
|
174
|
+
| "LEISURE_PARK"
|
|
175
|
+
| "OFFICE"
|
|
176
|
+
| "RELIGION"
|
|
177
|
+
| "RESIDENTIAL"
|
|
178
|
+
| "RESTO_MID"
|
|
179
|
+
| "RESTO_SHORT"
|
|
180
|
+
| "SHOP_LONG"
|
|
181
|
+
| "SHOP_SHORT"
|
|
182
|
+
| "SPORT"
|
|
183
|
+
| "SPORT_ATTEND"
|
|
184
|
+
| "TRAVEL_BUS"
|
|
185
|
+
| "TRAVEL_CONFERENCE"
|
|
186
|
+
| "TRAVEL_FILL"
|
|
187
|
+
| "TRAVEL_HOTEL"
|
|
188
|
+
| "TRAVEL_LONG"
|
|
189
|
+
| "TRAVEL_SHORT"
|
|
190
|
+
|
|
191
|
+
export type SemanticTime =
|
|
192
|
+
| "UNKNOWN"
|
|
193
|
+
| "MORNING"
|
|
194
|
+
| "LATE_MORNING"
|
|
195
|
+
| "LUNCH"
|
|
196
|
+
| "AFTERNOON"
|
|
197
|
+
| "EARLY_EVENING"
|
|
198
|
+
| "EVENING"
|
|
199
|
+
| "NIGHT";
|
|
200
|
+
|
|
122
201
|
export interface Event {
|
|
123
202
|
startTime: string;
|
|
203
|
+
startTimeEpoch: number; // in milliseconds
|
|
124
204
|
endTime: string | null;
|
|
205
|
+
endTimeEpoch: number | null; // in milliseconds
|
|
125
206
|
durationInSeconds: number | null;
|
|
126
207
|
type: string;
|
|
127
208
|
// stationary event fields
|
|
128
|
-
location:
|
|
129
|
-
|
|
130
|
-
venueCandidates: VenueCandidate[] | null;
|
|
209
|
+
location: GeoLocation | null;
|
|
210
|
+
venue: Venue | null;
|
|
131
211
|
// transport event fields
|
|
132
212
|
transportMode: TransportMode | null;
|
|
213
|
+
waypoints: Waypoint[];
|
|
214
|
+
distance?: number; // in meters
|
|
133
215
|
}
|
|
134
216
|
|
|
135
|
-
export interface
|
|
136
|
-
latitude:
|
|
137
|
-
longitude:
|
|
138
|
-
accuracy:
|
|
217
|
+
export interface GeoLocation {
|
|
218
|
+
latitude: number;
|
|
219
|
+
longitude: number;
|
|
220
|
+
accuracy: number;
|
|
139
221
|
}
|
|
140
222
|
|
|
141
|
-
export interface
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
223
|
+
export interface Waypoint {
|
|
224
|
+
latitude: number;
|
|
225
|
+
longitude: number;
|
|
226
|
+
accuracy: number; // in meters
|
|
227
|
+
timestamp: number; // UTC epoch time in milliseconds
|
|
145
228
|
}
|
|
146
229
|
|
|
147
230
|
export interface Venue {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export interface VenueLabels {
|
|
154
|
-
[label: string]: string;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export interface Visit {
|
|
158
|
-
startTime: string;
|
|
159
|
-
endTime: string;
|
|
160
|
-
durationInSeconds: number;
|
|
231
|
+
location: GeoLocation | null;
|
|
232
|
+
significance: VenueSignificance;
|
|
233
|
+
type: VenueType;
|
|
161
234
|
}
|
|
162
235
|
|
|
163
236
|
export interface Segment {
|
|
@@ -166,7 +239,9 @@ declare module "@sentiance-react-native/user-context" {
|
|
|
166
239
|
type: SegmentType;
|
|
167
240
|
id: number;
|
|
168
241
|
startTime: string;
|
|
242
|
+
startTimeEpoch: number; // in milliseconds
|
|
169
243
|
endTime: string | null;
|
|
244
|
+
endTimeEpoch: number | null; // in milliseconds
|
|
170
245
|
attributes: SegmentAttribute[];
|
|
171
246
|
}
|
|
172
247
|
|
|
@@ -178,9 +253,10 @@ declare module "@sentiance-react-native/user-context" {
|
|
|
178
253
|
export interface UserContext {
|
|
179
254
|
events: Event[];
|
|
180
255
|
activeSegments: Segment[];
|
|
181
|
-
lastKnownLocation:
|
|
256
|
+
lastKnownLocation: GeoLocation | null;
|
|
182
257
|
home: Venue | null;
|
|
183
258
|
work: Venue | null;
|
|
259
|
+
semanticTime: SemanticTime;
|
|
184
260
|
}
|
|
185
261
|
|
|
186
262
|
export interface SentianceUserContext {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentiance-react-native/user-context",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.2.0-rc.2",
|
|
4
4
|
"description": "React Native Sentiance - This module provides an easy API to add user context awareness into your apps.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"sentiance"
|
|
15
15
|
],
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"@sentiance-react-native/core": "6.
|
|
17
|
+
"@sentiance-react-native/core": "6.2.0-rc.2"
|
|
18
18
|
},
|
|
19
19
|
"author": "",
|
|
20
20
|
"license": "",
|