Skip to content

Commit

Permalink
Cherry-picked from location history (#738)
Browse files Browse the repository at this point in the history
* Improve the matching of user inputs to cleaned trips

While matching user inputs on the server, found that user input matching was
broken for some cleaned trips on the phone.
e-mission/e-mission-docs#476 (comment)

Expanded the user input end check to fix.
e-mission/e-mission-docs#476 (comment)

Will merge into master after additional testing on the branch.

+ bump up the allowed delta to 15 minutes since the time threshold default for
the distance filter is 10 minutes.

* Fix regression in enhanced trip matching

The enhanced trip matching (75129db) caused a
regression in which a spurious trip (not a trip) that occurred after the real
trip fit the criteria for a match.

And since it was confirmed after the real trip, as you would expect while going
down the trip list, it was matched preferentially.
e-mission/e-mission-docs#476 (comment)

Fixed by checking the degree over overlap and rejecting too short matches

* Fix the infinite scroll user input matching

to be consistent with the refactor in
21ab3fa
and
6bd731a
  • Loading branch information
shankari authored Feb 18, 2021
1 parent 6a2deb3 commit 189a5ee
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 16 deletions.
7 changes: 4 additions & 3 deletions www/js/diary/infinite_scroll_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ angular.module('emission.main.diary.infscrolllist',['ui-leaflet',
Logger.log("Received batch of size "+ctList.length);
ctList.reverse();
ctList.forEach($scope.populateBasicClasses);
ctList.forEach((trip) => {
ctList.forEach((trip, tIndex) => {
trip.userInput = {};
ConfirmHelper.INPUTS.forEach(function(item, index) {
$scope.populateManualInputs(trip, item, $scope.data.manualResultMap[item]);
$scope.populateManualInputs(trip, ctList[tIndex+1], item, $scope.data.manualResultMap[item]);
});
});
ctList.forEach(function(trip, index) {
Expand Down Expand Up @@ -252,11 +252,12 @@ angular.module('emission.main.diary.infscrolllist',['ui-leaflet',
/**
* Embed 'inputType' to the trip
*/
$scope.populateManualInputs = function (tripgj, inputType, inputList) {
$scope.populateManualInputs = function (tripgj, nextTripgj, inputType, inputList) {
// Check unprocessed labels first since they are more recent
// Massage the input to meet getUserInputForTrip expectations
const unprocessedLabelEntry = DiaryHelper.getUserInputForTrip(
{data: {properties: tripgj, features: [{}, {}, {}]}},
{data: {properties: nextTripgj, features: [{}, {}, {}]}},
inputList);
var userInputLabel = unprocessedLabelEntry? unprocessedLabelEntry.data.label : undefined;
if (!angular.isDefined(userInputLabel)) {
Expand Down
8 changes: 4 additions & 4 deletions www/js/diary/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ angular.module('emission.main.diary.list',['ui-leaflet',
/**
* Embed 'inputType' to the trip
*/
$scope.populateInputFromTimeline = function (tripgj, inputType, inputList) {
var userInput = DiaryHelper.getUserInputForTrip(tripgj, inputList);
$scope.populateInputFromTimeline = function (tripgj, nextTripgj, inputType, inputList) {
var userInput = DiaryHelper.getUserInputForTrip(tripgj, nextTripgj, inputList);
if (angular.isDefined(userInput)) {
// userInput is an object with data + metadata
// the label is the "value" from the options
Expand Down Expand Up @@ -237,10 +237,10 @@ angular.module('emission.main.diary.list',['ui-leaflet',
DiaryHelper.directiveForTrip);
Timeline.setTripWrappers(currDayTripWrappers);

$scope.data.currDayTripWrappers.forEach(function(tripgj, index, array) {
$scope.data.currDayTripWrappers.forEach(function(tripgj, tripIndex, array) {
tripgj.userInput = {};
ConfirmHelper.INPUTS.forEach(function(item, index) {
$scope.populateInputFromTimeline(tripgj, item, $scope.data.unifiedConfirmsResults[item]);
$scope.populateInputFromTimeline(tripgj, array[tripIndex+1], item, $scope.data.unifiedConfirmsResults[item]);
});
$scope.populateBasicClasses(tripgj);
$scope.populateCommonInfo(tripgj);
Expand Down
43 changes: 34 additions & 9 deletions www/js/diary/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger',
" " + ui.data.label + " logged at "+ ui.metadata.write_ts;
}

dh.getUserInputForTrip = function(tripgj, userInputList) {
dh.getUserInputForTrip = function(tripgj, nextTripgj, userInputList) {
if (userInputList.length < 20) {
console.log("Input list = "+userInputList.map(printUserInput));
}
Expand All @@ -431,13 +431,15 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger',
+" trip = "+fmtTs(tripProp.start_ts, userInput.metadata.time_zone)
+" -> "+fmtTs(tripProp.end_ts, userInput.metadata.time_zone)
+" checks are ("+(userInput.data.start_ts >= tripProp.start_ts)
+" || "+(-(userInput.data.start_ts - tripProp.start_ts) <= 5 * 60)
+" && "+(userInput.data.start_ts <= tripProp.end_ts)
+" || "+(-(userInput.data.start_ts - tripProp.start_ts) <= 15 * 60)
+") && "+(userInput.data.end_ts <= tripProp.end_ts);
console.log(logStr);
// Logger.log(logStr);
}
return (userInput.data.start_ts >= tripProp.start_ts
|| -(userInput.data.start_ts - tripProp.start_ts) <= 5 * 60)
&& userInput.data.start_ts <= tripProp.end_ts
|| -(userInput.data.start_ts - tripProp.start_ts) <= 15 * 60)
&& userInput.data.end_ts <= tripProp.end_ts;
} else {
// we know that the trip is cleaned so we can use the fmt_time
Expand All @@ -448,14 +450,37 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger',
+" -> "+fmtTs(userInput.data.end_ts, userInput.metadata.time_zone)
+" trip = "+tripProp.start_fmt_time
+" -> "+tripProp.end_fmt_time
+" checks are "+(userInput.data.start_ts >= tripProp.start_ts)
+" && ("+(userInput.data.end_ts <= tripProp.end_ts)
+" || "+((userInput.data.end_ts - tripProp.end_ts) <= 5 * 60)+")";
+" start checks are "+(userInput.data.start_ts >= tripProp.start_ts)
+" && "+(userInput.data.start_ts <= tripProp.end_ts)
+" end checks are "+(userInput.data.end_ts <= tripProp.end_ts)
+" || "+((userInput.data.end_ts - tripProp.end_ts) <= 15 * 60)+")";
Logger.log(logStr);
}
return userInput.data.start_ts >= tripProp.start_ts
&& (userInput.data.end_ts <= tripProp.end_ts ||
(userInput.data.end_ts - tripProp.end_ts) <= 5 * 60);
// https://github.com/e-mission/e-mission-docs/issues/476#issuecomment-747222181
const startChecks = userInput.data.start_ts >= tripProp.start_ts &&
userInput.data.start_ts <= tripProp.end_ts;
var endChecks = (userInput.data.end_ts <= tripProp.end_ts ||
(userInput.data.end_ts - tripProp.end_ts) <= 15 * 60);
if (startChecks && !endChecks) {
if (angular.isDefined(nextTripgj)) {
endChecks = userInput.data.end_ts <= nextTripgj.data.properties.start_ts;
Logger.log("Second level of end checks when the next trip is defined("+userInput.data.end_ts+" <= "+ nextTripgj.data.properties.start_ts+") = "+endChecks);
} else {
// next trip is not defined, last trip
endChecks = (userInput.data.end_local_dt.day == userInput.data.start_local_dt.day)
Logger.log("Second level of end checks for the last trip of the day");
Logger.log("compare "+userInput.data.end_local_dt.day + " with " + userInput.data.start_local_dt.day + " = " + endChecks);
}
if (endChecks) {
// If we have flipped the values, check to see that there
// is sufficient overlap
const overlapDuration = Math.min(userInput.data.end_ts, tripProp.end_ts) - Math.max(userInput.data.start_ts, tripProp.start_ts)
Logger.log("Flipped endCheck, overlap("+overlapDuration+
")/trip("+tripProp.duration+") = "+ (overlapDuration / tripProp.duration));
endChecks = (overlapDuration/tripProp.duration) > 0.5;
}
}
return startChecks && endChecks;
}
});
if (potentialCandidates.length === 0) {
Expand Down

0 comments on commit 189a5ee

Please sign in to comment.