@sentiance-react-native/user-context 6.1.2 → 6.2.0-rc.1

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.putString("latitude", String.valueOf(location.getLatitude()));
30
- locationMap.putString("longitude", String.valueOf(location.getLongitude()));
31
- locationMap.putString("accuracy", String.valueOf(location.getAccuracyInMeters()));
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.putString("startTimeEpoch", "" + segment.getStartTime().getEpochTime() / 1000);
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.putString("endTimeEpoch", "" + segment.getEndTime().getEpochTime() / 1000);
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) {
@@ -149,62 +149,47 @@ public class SentianceUserContextConverter {
149
149
  if (event.getLocation() != null) {
150
150
  map.putMap("location", convertGeoLocation(event.getLocation()));
151
151
  }
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;
152
+ map.putMap("venue", convertVenue(event.getVenue()));
174
153
  }
175
154
 
176
155
  private static WritableMap convertVenue(Venue venue) {
177
156
  WritableMap venueMap = Arguments.createMap();
178
157
 
179
- if (venue.getName() != null) {
180
- venueMap.putString("name", venue.getName());
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());
158
+ if (venue.getLocation() != null) {
159
+ venueMap.putMap("location", convertGeoLocation(venue.getLocation()));
188
160
  }
189
- venueMap.putMap("venueLabels", venueLabelsMap);
161
+ venueMap.putString("significance", venue.getSignificance().name());
162
+ venueMap.putString("type", venue.getType().name());
190
163
 
191
164
  return venueMap;
192
165
  }
193
166
 
194
- private static WritableMap convertVisit(Visit visit) {
195
- WritableMap visitMap = Arguments.createMap();
196
- visitMap.putString("startTime", visit.getStartTime().toString());
197
- visitMap.putString("startTimeEpoch", "" + visit.getStartTime().getEpochTime());
167
+ private static void addTransportEventInfo(WritableMap map, TransportEvent event) {
168
+ map.putString("transportMode", event.getTransportMode().toString());
169
+ map.putArray("waypoints", convertWaypointList(event.getWaypoints()));
170
+
171
+ if (event.getDistanceInMeters() != null) {
172
+ map.putInt("distance", event.getDistanceInMeters());
173
+ }
174
+ }
198
175
 
199
- visitMap.putString("endTime", visit.getEndTime().toString());
200
- visitMap.putString("endTimeEpoch", "" + visit.getEndTime().getEpochTime());
176
+ public static WritableMap convertWaypoint(Waypoint waypoint) {
177
+ WritableMap waypointMap = Arguments.createMap();
201
178
 
202
- visitMap.putInt("durationInSeconds", (int) visit.getDurationInSeconds());
179
+ waypointMap.putDouble("latitude", waypoint.getLatitude());
180
+ waypointMap.putDouble("longitude", waypoint.getLongitude());
181
+ waypointMap.putInt("accuracy", waypoint.getAccuracyInMeters());
182
+ waypointMap.putDouble("timestamp", waypoint.getTimestamp());
203
183
 
204
- return visitMap;
184
+ return waypointMap;
205
185
  }
206
186
 
207
- private static void addTransportEventInfo(WritableMap map, TransportEvent event) {
208
- map.putString("transportMode", event.getTransportMode().toString());
187
+ private static WritableArray convertWaypointList(List<Waypoint> waypointList) {
188
+ WritableArray array = Arguments.createArray();
189
+ for (Waypoint waypoint : waypointList) {
190
+ array.pushMap(convertWaypoint(waypoint));
191
+ }
192
+ return array;
209
193
  }
194
+
210
195
  }
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
- | "BYCICLE"
113
+ | "BICYCLE"
114
114
  | "WALKING"
115
115
  | "RUNNING"
116
116
  | "TRAM"
@@ -119,45 +119,108 @@ 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
+
122
191
  export interface Event {
123
192
  startTime: string;
193
+ startTimeEpoch: number; // in milliseconds
124
194
  endTime: string | null;
195
+ endTimeEpoch: number | null; // in milliseconds
125
196
  durationInSeconds: number | null;
126
197
  type: string;
127
198
  // stationary event fields
128
- location: EventLocation | null;
129
- venueSignificance: string | null;
130
- venueCandidates: VenueCandidate[] | null;
199
+ location: GeoLocation | null;
200
+ venue: Venue | null;
131
201
  // transport event fields
132
202
  transportMode: TransportMode | null;
203
+ waypoints: Waypoint[];
204
+ distance?: number; // in meters
133
205
  }
134
206
 
135
- export interface EventLocation {
136
- latitude: string;
137
- longitude: string;
138
- accuracy: string;
207
+ export interface GeoLocation {
208
+ latitude: number;
209
+ longitude: number;
210
+ accuracy: number;
139
211
  }
140
212
 
141
- export interface VenueCandidate {
142
- venue: Venue;
143
- likelihood: number;
144
- visits: Visit[];
213
+ export interface Waypoint {
214
+ latitude: number;
215
+ longitude: number;
216
+ accuracy: number; // in meters
217
+ timestamp: number; // UTC epoch time in milliseconds
145
218
  }
146
219
 
147
220
  export interface Venue {
148
- name: string | null;
149
- location: EventLocation | null;
150
- venueLabels: VenueLabels;
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;
221
+ location: GeoLocation | null;
222
+ significance: VenueSignificance;
223
+ type: VenueType;
161
224
  }
162
225
 
163
226
  export interface Segment {
@@ -166,7 +229,9 @@ declare module "@sentiance-react-native/user-context" {
166
229
  type: SegmentType;
167
230
  id: number;
168
231
  startTime: string;
232
+ startTimeEpoch: number; // in milliseconds
169
233
  endTime: string | null;
234
+ endTimeEpoch: number | null; // in milliseconds
170
235
  attributes: SegmentAttribute[];
171
236
  }
172
237
 
@@ -178,7 +243,7 @@ declare module "@sentiance-react-native/user-context" {
178
243
  export interface UserContext {
179
244
  events: Event[];
180
245
  activeSegments: Segment[];
181
- lastKnownLocation: EventLocation | null;
246
+ lastKnownLocation: GeoLocation | null;
182
247
  home: Venue | null;
183
248
  work: Venue | null;
184
249
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentiance-react-native/user-context",
3
- "version": "6.1.2",
3
+ "version": "6.2.0-rc.1",
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.1.2"
17
+ "@sentiance-react-native/core": "6.2.0-rc.1"
18
18
  },
19
19
  "author": "",
20
20
  "license": "",