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

Add server-side support for storing trip and place additions #895

Merged
merged 108 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
655b53b
Add server-side support for storing trip and place additions
shankari Jan 5, 2023
2129075
Change the input matcher to support multiple matches for a single trip
shankari Jan 5, 2023
28a3b75
Fix field addition to confirmed trip
shankari Jan 5, 2023
bdcf629
Add additional unit tests for the incoming matching
shankari Jan 5, 2023
34d78fc
Start adding unit tests for finding the final candiate
shankari Jan 15, 2023
ae4983e
Merge branch 'master' of https://github.com/e-mission/e-mission-serve…
shankari Jan 18, 2023
a7ee02c
Handle the matching of user inputs that came in before the confirmed …
shankari Jan 18, 2023
bad2d69
Fix syntax errors in `get_additions_for_trip_object`
shankari Jan 18, 2023
d534ed0
Match by `match_id` instead of `_id`
shankari Jan 18, 2023
fcf5a9c
Fix regression in the input matching for new entries
shankari Jan 19, 2023
ef2ce21
Pass in the `continue_on_error` flag to cache series insertion from t…
shankari Jan 19, 2023
8abd2ef
Create confirmedplace.py
sebastianbarry Feb 3, 2023
743eca0
Added confirmedplace in entry.py and builtin_timeseries.py
sebastianbarry Feb 13, 2023
64cab33
Removed expectedplace.py and inferredplace.py
sebastianbarry Feb 13, 2023
9220dd2
Added confirmedplace into the pipeline
sebastianbarry Feb 15, 2023
e8a910d
First draft
sebastianbarry Feb 15, 2023
286f233
create confirmed_places during CREATE_CONFIRMED_OBJECTS
JGreenlee Feb 15, 2023
9eb812d
implement CREATE_COMPOSITE_OBJECTS
JGreenlee Feb 16, 2023
5cdbdeb
Change confirmed_trip variable to confirmed_object for consistency
sebastianbarry Feb 20, 2023
64f1f51
Remove unnecessary confirmed_place properties
sebastianbarry Feb 20, 2023
3fbc72d
Remove info log spew by replacing Logging.info changes back to Loggin…
sebastianbarry Feb 20, 2023
d016b3d
update confirmed_place properties
JGreenlee Feb 20, 2023
3d62c81
add a `locations` property to composite trip
JGreenlee Feb 22, 2023
34baef6
correct confirmed_place generation
JGreenlee Feb 22, 2023
d90de7f
use enter_ts to query places and mark stage done
JGreenlee Feb 22, 2023
b690b0c
revise input matching functions
JGreenlee Feb 23, 2023
01e0bb3
Remove weird overwrite of start and end timestamps on android
shankari Mar 9, 2023
9aed65d
:bug: Read the match ID from 'data' instead of directly from the entry
shankari Mar 10, 2023
763a3cb
add keys for place user input
JGreenlee Mar 10, 2023
6bc5f84
revise input matching
JGreenlee Mar 10, 2023
1cc481e
modify user input tests
JGreenlee Mar 10, 2023
73841ab
Merge branch 'add_trip_place_additions' into add-composite-trip
JGreenlee Mar 10, 2023
9b75391
unify tripuserinput and placeuserinput
JGreenlee Mar 11, 2023
c51aee9
add logic to check places for inputs
JGreenlee Mar 11, 2023
8bcacc3
revise unit tests to work with places matching
JGreenlee Mar 11, 2023
2573ced
fix matching on last place
JGreenlee Mar 11, 2023
d0c46f6
expand tests to check trip&place additions
JGreenlee Mar 11, 2023
52ecab2
Merge pull request #4 from sebastianbarry/add-composite-trip
shankari Mar 22, 2023
1c3f128
fix missing confirmed_places on existing confirmed_trips
JGreenlee Mar 22, 2023
180a979
insert confirmed_place_entry to ts
JGreenlee Mar 22, 2023
7fa3aa7
receive confirmed place id from ts.insert()
JGreenlee Mar 22, 2023
8709243
Merge pull request #5 from sebastianbarry/update-missing-confirmed-pl…
shankari Mar 22, 2023
0c5d1a5
comments explaining unit test changes
JGreenlee Mar 24, 2023
e4265d5
refactor composite trip creation into composite_trip_creation.py
JGreenlee Mar 24, 2023
8f0bf45
optimize get_confirmed_obj_for_user_input_obj
JGreenlee Mar 24, 2023
e34c463
tidy/refactor functions in trip_queries.py
JGreenlee Mar 25, 2023
3ea7b67
allow other keys than trip_user_input for trips
JGreenlee Mar 25, 2023
a62fa09
comment describing use of getattr
JGreenlee Mar 25, 2023
54fd12e
import composite_trip_creation with alias eapcc
JGreenlee Mar 26, 2023
f56bd3c
Merge pull request #6 from sebastianbarry/additions-and-composite-cle…
shankari Mar 27, 2023
7d544f3
allow timeline to support IDing trips by a key
JGreenlee Mar 28, 2023
9ea47e0
add real_examples that demonstrate untracked time
JGreenlee Mar 28, 2023
0aa7c83
refactor confirmed object creation to use Timeline
JGreenlee Mar 28, 2023
9d41f1d
include untracked time in composite trip creation
JGreenlee Mar 28, 2023
df93a93
don't return early from create_composite_objects
JGreenlee Mar 28, 2023
c307647
Don't break the composite trip creation pipeline stage if there are n…
shankari Mar 28, 2023
02c910a
Use the composite trip for the pipeline timestamps
shankari Mar 28, 2023
2de4b4a
Merge pull request #8 from shankari/minor_pipeline_fixes
shankari Mar 28, 2023
77f5db1
Merge branch 'add_trip_place_additions' into untracked-composite-trip
JGreenlee Mar 29, 2023
9c51961
include origin_key in composite trip
JGreenlee Mar 29, 2023
9bf0352
Merge branch 'add_trip_place_additions' into untracked-composite-trip
JGreenlee Mar 29, 2023
8ac11d9
declare composite trip origin_key before key
JGreenlee Mar 29, 2023
5e885f1
if using trip_id_key in Timeline, fallback to _id
JGreenlee Mar 29, 2023
5586b2c
include empty locations list in untracked composite
JGreenlee Mar 29, 2023
1c24095
reword comments in create_confirmed_objects
JGreenlee Mar 30, 2023
e81eede
create testJackUntrackedTimeMar12
JGreenlee Mar 30, 2023
e50f88d
Tweak the threshold for detecting untracked time to account for backg…
shankari Mar 27, 2023
8cbdf43
add more unit tests for untracked time
JGreenlee Mar 30, 2023
8330b72
add comment explaining places after untracked time
JGreenlee Mar 30, 2023
1bb8a3e
update expected test result: shankariUntrackedTimeJul20
JGreenlee Apr 4, 2023
9a43a07
Merge pull request #7 from sebastianbarry/untracked-composite-trip
shankari Apr 4, 2023
93039ce
fix first composite trip of batch not being created
JGreenlee Apr 5, 2023
bad6126
make log statements clearer
JGreenlee Apr 5, 2023
c816632
Rename confirmed_place in compositetrip to end_confirmed_place
sebastianbarry Apr 5, 2023
418cffc
Ensure that the composite trip metadata reflects the time that it was…
shankari Apr 5, 2023
e769c6b
Fix broken test case
shankari Apr 5, 2023
73149e9
Merge pull request #9 from sebastianbarry/fix_first_composite_of_batc…
shankari Apr 5, 2023
6a26c54
Merge pull request #10 from sebastianbarry/add_trip_place_additions_e…
shankari Apr 5, 2023
3527525
Merge branch 'add_trip_place_additions' of https://github.com/shankar…
shankari Apr 5, 2023
014a611
Merge pull request #11 from shankari/composite_metadata_fix
shankari Apr 5, 2023
b3d06ba
update expected composite trips for test JackMar12
JGreenlee Apr 5, 2023
9f0de13
Merge pull request #12 from sebastianbarry/update-expected-composite-…
shankari Apr 5, 2023
157e6f9
Create and link the timeline properly, similar to the `CLEAN_AND_RESA…
shankari Apr 11, 2023
0729b41
Fix the backwards compat to generate correct confirmed object timelines
shankari Apr 11, 2023
149025b
Update composite trips when confirmed objects are updated
shankari Apr 12, 2023
33af6dd
Add unit tests to check the new functions in composite trip creation
shankari Apr 12, 2023
5410d56
Expand the `save_ground_truth` script to also support saving a compos…
shankari Apr 13, 2023
57abb97
Fix population of start place additions when grafting timeline
shankari Apr 13, 2023
fb6a982
Check in a new unit test to test incremental updates of the composite…
shankari Apr 13, 2023
c97b49c
Multiple fixes to the hack code
shankari Apr 13, 2023
b768571
Change deprecated `remove` to `delete_many`
shankari Apr 13, 2023
d3bbe37
Merge pull request #13 from shankari/fix_incremental_confirmed_obj_cr…
shankari Apr 13, 2023
34dd104
Ensure that object <-> input matching code works properly
shankari Apr 16, 2023
94ffc9e
Fix new issue uncovered in existing incremental test
shankari Apr 16, 2023
2d9ee58
Set a flag to prevent the test data from being torn down
shankari Apr 16, 2023
cf48989
Final changes from cleaned_untracked -> confirmed_untracked
shankari Apr 16, 2023
61d6e5c
Merge pull request #15 from shankari/fix_object_to_addition_matching
shankari Apr 16, 2023
afd11c7
Remove the ubuntu 18 environment + run manual tests on both OSX and u…
shankari Apr 17, 2023
f2647b9
Merge branch 'add_trip_place_additions' of https://github.com/shankar…
shankari Apr 17, 2023
28ad00d
Remove the teardown step from the docker tests
shankari Apr 17, 2023
1e67cd6
Remove manual install test on OSX
shankari Apr 17, 2023
0ad1c10
Use EPOCH_MININUM when the start timestamp is None
shankari Apr 17, 2023
564a9b5
Fix format of transition distance logging
shankari Apr 17, 2023
6045174
Merge branch 'master' into add_trip_place_additions
shankari Apr 17, 2023
b74198d
Try setting the random seed for the test
shankari Apr 17, 2023
0b272d6
Merge branch 'add_trip_place_additions' of https://github.com/shankar…
shankari Apr 17, 2023
90a3d92
Temporarily commenting out the start timestamp checks
shankari Apr 17, 2023
09de165
Expand the set of valid responses for the script tests
shankari Apr 17, 2023
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
2 changes: 1 addition & 1 deletion bin/debug/load_timeline_for_day_and_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@
print("About to save %s" % entry)
munged_entries.append(entry)

(tsdb_count, ucdb_count) = estcs.insert_entries(override_uuid, munged_entries)
(tsdb_count, ucdb_count) = estcs.insert_entries(override_uuid, munged_entries, continue_on_error=False)
print("Finished loading %d entries into the usercache and %d entries into the timeseries" %
(ucdb_count, tsdb_count))
40 changes: 33 additions & 7 deletions emission/analysis/userinput/matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import emission.storage.decorations.trip_queries as esdt
import emission.storage.pipeline_queries as epq
import emission.core.wrapper.entry as ecwe
import emission.core.wrapper.tripuserinput as ecwtui

obj_to_dict_key = lambda key: key.split("/")[1]

Expand All @@ -27,29 +28,52 @@ def match_incoming_user_inputs(user_id):

def match_incoming_inputs(user_id, timerange):
ts = esta.TimeSeries.get_time_series(user_id)
input_key_list = eac.get_config()["userinput.keylist"]
single_most_recent_match_key_list = eac.get_config()["userinput.keylist"]
multi_non_deleted_key_list = ["manual/trip_addition_input"]
input_key_list = single_most_recent_match_key_list + multi_non_deleted_key_list
toMatchInputs = [ecwe.Entry(e) for e in ts.find_entries(input_key_list, time_query=timerange)]
logging.debug("Matching %d inputs to trips" % len(toMatchInputs))
logging.debug("Matching %d single inputs to trips" % len(toMatchInputs))
lastInputProcessed = None
if len(toMatchInputs) == 0:
logging.debug("len(toMatchInputs) == 0, early return")
return None
for ui in toMatchInputs:
Copy link
Contributor

@JGreenlee JGreenlee Jan 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have been having a hard time understanding how input matching works on phone vs server. I now understand why:

I see here that input matching on the server works by iterating through each user input (ui), and then ui is matched to the appropriate trip by esdt.get_trip_for_user_input_obj()

This is fundamentally different on the phone: input matching works by iterating through each trip, and then finds the user inputs that correspond to that trip (with the functions getUserInputForTrip() and getTripAdditionsForTrip() in input-matcher.js)

If we want to unify the matching functions, and improve interoperability and maintainability, we would have to reconcile that fundamental difference

Copy link
Contributor Author

@shankari shankari Jan 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JGreenlee the server actually does both:

  • in the common case, in which the user labels processed trips, we do indeed match the inputs to the trips
  • however, for the uncommon case, in which the user labels draft trips, and we process both the trip information and the inputs at the same time, we match the trip to the inputs. Please see a7ee02c

That is of the complexity of the system, especially around handling user inputs. You can probably tell that I am a distributed systems person at heart 😄

confirmed_trip = esdt.get_trip_for_user_input_obj(ts, ui)
if confirmed_trip is not None:
input_name = obj_to_dict_key(ui.metadata.key)
if input_name == "trip_user_input":
confirmed_trip["data"]["user_input"][input_name] = ui
if ui.metadata.key in single_most_recent_match_key_list:
handle_single_most_recent_match(confirmed_trip, ui)
elif ui.metadata.key in multi_non_deleted_key_list:
handle_multi_non_deleted_match(confirmed_trip, ui)
else:
confirmed_trip["data"]["user_input"][input_name] = ui.data.label
assert False, "Found weird key {ui.metadata.key} that was not in the search list"
import emission.storage.timeseries.builtin_timeseries as estbt
estbt.BuiltinTimeSeries.update(confirmed_trip)
else:
logging.warn("No match found for user input %s, moving forward anyway" % ui)
logging.warn("No match found for single user input %s, moving forward anyway" % ui)
lastInputProcessed = ui

return lastInputProcessed

def handle_single_most_recent_match(confirmed_trip, ui):
input_name = obj_to_dict_key(ui.metadata.key)
if input_name == "trip_user_input":
confirmed_trip["data"]["user_input"][input_name] = ui
else:
confirmed_trip["data"]["user_input"][input_name] = ui.data.label

def handle_multi_non_deleted_match(confirmed_trip, ui):
logging.debug(f"handling user input {ui} for {confirmed_trip}")
if "trip_addition" not in confirmed_trip["data"] or \
confirmed_trip["data"]["trip_addition"] is None:
confirmed_trip["data"]["trip_addition"] = []
if "status" not in ui.data or ui.data.status == ecwtui.InputStatus.ACTIVE:
confirmed_trip["data"]["trip_addition"].append(ui)
elif ui.data.status == ecwtui.InputStatus.DELETED:
after_del_list = [ta for ta in confirmed_trip["data"]["trip_addition"] if ta["match_id"] != ui["match_id"]]
confirmed_trip["data"]["trip_addition"] = after_del_list
else:
# TODO: Decide whether to error or to warn here
logging.warn("Invalid status found in user input %s, moving forward anyway" % ui)

def create_confirmed_objects(user_id):
time_query = epq.get_time_range_for_confirmed_object_creation(user_id)
Expand Down Expand Up @@ -82,6 +106,8 @@ def create_confirmed_trips(user_id, timerange):
confirmed_trip_dict["data"]["expected_trip"] = tct.get_id()
confirmed_trip_dict["data"]["user_input"] = \
get_user_input_dict(ts, tct, input_key_list)
confirmed_trip_dict["data"]["trip_addition"] = \
esdt.get_additions_for_trip_object(ts, tct)
confirmed_trip_entry = ecwe.Entry(confirmed_trip_dict)
# save the entry
ts.insert(confirmed_trip_entry)
Expand Down
3 changes: 2 additions & 1 deletion emission/core/wrapper/confirmedtrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class Confirmedtrip(ecwt.Trip):
"inferred_primary_mode": ecwb.WrapperBase.Access.WORM,
# the user input will have all `manual/*` entries
# let's make that be somewhat flexible instead of hardcoding into the data model
"user_input": ecwb.WrapperBase.Access.WORM
"user_input": ecwb.WrapperBase.Access.WORM,
"trip_addition": ecwb.WrapperBase.Access.WORM
})

def _populateDependencies(self):
Expand Down
5 changes: 5 additions & 0 deletions emission/core/wrapper/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ def _getData2Wrapper():
"manual/replaced_mode": "userlabel",
# user input for the trip; in one entry instead of being split up
"manual/trip_user_input": "tripuserinput",
# trip-level additions/splits: currently only used for the time-use survey
"manual/trip_addition_input": "tripuserinput",
# place-level additions/splits: currently only used for the
# time-use survey, and potentially
"manual/place_addition_input": "placeuserinput",
# user confirmation of the destination (unsure how this will
# interact with purpose
"manual/destination_confirm": "userlabel",
Expand Down
31 changes: 31 additions & 0 deletions emission/core/wrapper/placeuserinput.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import *
import logging
import emission.core.wrapper.wrapperbase as ecwb

class Placeuserinput(ecwb.WrapperBase):
props = {"enter_ts": ecwb.WrapperBase.Access.RO, # geojson representation of the point
"enter_local_dt": ecwb.WrapperBase.Access.RO, # start datetime in local time
"enter_fmt_time": ecwb.WrapperBase.Access.RO, # start formatted time (in timezone of point)
"exit_ts": ecwb.WrapperBase.Access.WORM, # end UTC timestamp (in secs)
"exit_local_dt": ecwb.WrapperBase.Access.RO, # end datetime in local time
"exit_fmt_time": ecwb.WrapperBase.Access.RO, # end formatted time (in timezone of point)
"label": ecwb.WrapperBase.Access.RO, # string summary of the survey
"version": ecwb.WrapperBase.Access.RO, # the survey version
"name": ecwb.WrapperBase.Access.RO, # the survey name
"xmlResponse": ecwb.WrapperBase.Access.RO, # the XML string representation of the survey response
"jsonDocResponse": ecwb.WrapperBase.Access.RO # the JSON representation of the survey response
}

enums = {}
geojson = []
nullable = []
local_dates = ["enter_local_dt", "exit_local_dt"]

def _populateDependencies(self):
pass
8 changes: 7 additions & 1 deletion emission/core/wrapper/tripuserinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,29 @@
standard_library.install_aliases()
from builtins import *
import logging
import enum
import emission.core.wrapper.wrapperbase as ecwb

class InputStatus(str, enum.Enum):
ACTIVE = "ACTIVE"
DELETED = "DELETED"

class Tripuserinput(ecwb.WrapperBase):
props = {"start_ts": ecwb.WrapperBase.Access.RO, # geojson representation of the point
"start_local_dt": ecwb.WrapperBase.Access.RO, # start datetime in local time
"start_fmt_time": ecwb.WrapperBase.Access.RO, # start formatted time (in timezone of point)
"end_ts": ecwb.WrapperBase.Access.WORM, # end UTC timestamp (in secs)
"end_local_dt": ecwb.WrapperBase.Access.RO, # end datetime in local time
"end_fmt_time": ecwb.WrapperBase.Access.RO, # end formatted time (in timezone of point)
"status": ecwb.WrapperBase.Access.RO, # ACTIVE or DELETED
"label": ecwb.WrapperBase.Access.RO, # string summary of the survey
"version": ecwb.WrapperBase.Access.RO, # the survey version
"name": ecwb.WrapperBase.Access.RO, # the survey name
"xmlResponse": ecwb.WrapperBase.Access.RO, # the XML string representation of the survey response
"jsonDocResponse": ecwb.WrapperBase.Access.RO # the JSON representation of the survey response
}

enums = {}
enums = {"status": InputStatus}
geojson = []
nullable = []
local_dates = ["start_local_dt", "end_local_dt"]
Expand Down
12 changes: 12 additions & 0 deletions emission/net/usercache/formatters/android/place_addition_input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import *
import logging
import emission.net.usercache.formatters.generic.userlabel as fgl

def format(entry):
return fgl.format(entry)
16 changes: 16 additions & 0 deletions emission/net/usercache/formatters/android/trip_addition_input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import *
import logging
import emission.net.usercache.formatters.generic.userlabel as fgl

def format(entry):
import arrow

entry["data"]["start_ts"] = 0
entry["data"]["end_ts"] = arrow.get()
return fgl.format(entry)
12 changes: 12 additions & 0 deletions emission/net/usercache/formatters/ios/place_addition_input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import *
import logging
import emission.net.usercache.formatters.generic.userlabel as fgl

def format(entry):
return fgl.format(entry)
12 changes: 12 additions & 0 deletions emission/net/usercache/formatters/ios/trip_addition_input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import *
import logging
import emission.net.usercache.formatters.generic.userlabel as fgl

def format(entry):
return fgl.format(entry)
21 changes: 21 additions & 0 deletions emission/storage/decorations/trip_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import emission.core.get_database as edb
import emission.core.wrapper.rawtrip as ecwrt
import emission.core.wrapper.entry as ecwe
import emission.core.wrapper.tripuserinput as ecwtui

import emission.storage.timeseries.abstract_timeseries as esta
import emission.storage.timeseries.cache_series as estsc
Expand Down Expand Up @@ -153,6 +154,21 @@ def final_candidate(filter_fn, potential_candidates):
(most_recent_entry.metadata.write_fmt_time, entry_detail(most_recent_entry)))
return most_recent_entry

def get_not_deleted_candidates(filter_fn, potential_candidates):
potential_candidate_objects = [ecwe.Entry(c) for c in potential_candidates]
extra_filtered_potential_candidates = list(filter(filter_fn, potential_candidate_objects))
if len(extra_filtered_potential_candidates) == 0:
logging.debug(f"in get_not_deleted_candidates, no candidates, returning []")
return []

# We want to retain all ACTIVE entries that have not been DELETED
all_active_list = [efpc for efpc in extra_filtered_potential_candidates if "status" not in efpc.data or efpc.data.status == ecwtui.InputStatus.ACTIVE]
all_deleted_id = [efpc["match_id"] for efpc in extra_filtered_potential_candidates if "status" in efpc.data and efpc.data.status == ecwtui.InputStatus.DELETED]
# TODO: Replace this with filter and a lambda if we decide not to match by ID after all
not_deleted_active = [efpc for efpc in all_active_list if efpc["match_id"] not in all_deleted_id]
logging.info(f"Found {len(all_active_list)} active entries, {len(all_deleted_id)} deleted entries -> {len(not_deleted_active)} non deleted active entries")
return not_deleted_active

def get_user_input_for_trip_object(ts, trip_obj, user_input_key):
tq = estt.TimeQuery("data.start_ts", trip_obj.data.start_ts, trip_obj.data.end_ts)
potential_candidates = ts.find_entries([user_input_key], tq)
Expand All @@ -169,6 +185,11 @@ def get_user_input_from_cache_series(user_id, trip_obj, user_input_key):
potential_candidates = estsc.find_entries(user_id, [user_input_key], tq)
return final_candidate(valid_user_input(ts, trip_obj), potential_candidates)

def get_additions_for_trip_object(ts, trip_obj):
tq = estt.TimeQuery("data.start_ts", trip_obj.data.start_ts, trip_obj.data.end_ts)
potential_candidates = ts.find_entries(["manual/trip_addition_input"], tq)
return get_not_deleted_candidates(valid_user_input(ts, trip_obj), potential_candidates)

def valid_trip(ts, user_input):
def curried(trip_obj):
return valid_user_input_for_trip(ts, trip_obj, user_input)
Expand Down
3 changes: 2 additions & 1 deletion emission/storage/timeseries/builtin_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def __init__(self, user_id):
"manual/purpose_confirm": self.timeseries_db,
"manual/replaced_mode": self.timeseries_db,
"manual/trip_user_input": self.timeseries_db,
"manual/destination_confirm": self.timeseries_db,
"manual/trip_addition_input": self.timeseries_db,
"manual/place_addition_input": self.timeseries_db,
"manual/demographic_survey": self.timeseries_db,
"segmentation/raw_trip": self.analysis_timeseries_db,
"segmentation/raw_place": self.analysis_timeseries_db,
Expand Down
Loading