Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-picked from location history #738

Merged
merged 3 commits into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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