Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ Refactor the user stats into pipeline dependent and pipeline indep…
…endent buckets - The pipeline dependent stage is based on analysed data and only changes when the pipeline has finished running. Since it is infrequent, it can be more complicated and lower performance. - The pipeline independent stage is read from the raw data, so it has to be run every time the pipeline is run, roughly every hour. So it should make sure to run quick and fast queries. This change splits the existing function to pipeline dependent and independent stages and then invokes both of them properly from the pipeline. Testing done: - Launched a server with these changes - Connected an emulator to it - Faked a trip using the location simulation ``` START 2025-01-23 00:30:20.575034 POST /usercache/put START 2025-01-23 00:30:20.597320 POST /usercache/get END 2025-01-23 00:30:20.600963 POST /usercache/get 414ee37a-732e-4751-a6f6-0d83b41b27f0 0.002919912338256836 END 2025-01-23 00:30:21.948563 POST /usercache/put 414ee37a-732e-4751-a6f6-0d83b41b27f0 1.373345136642456 ``` There was only one profile ``` >>> edb.get_profile_db().count_documents({}) 1 ``` Before running the pipeline, it did not have any of these user stats ``` >>> edb.get_profile_db().find_one() {'_id': ObjectId('6791fc13b4b3fa6db902c42b'), 'user_id': UUID('414ee37a-732e-4751-a6f6-0d83b41b27f0'), 'mode': {}, 'mpg_array': [32.044384997811726], 'purpose': {}, 'source': 'Shankari', 'update_ts': datetime.datetime(2025, 1, 23, 0, 21, 39, 712000), 'client_app_version': '1.9.6', 'client_os_version': '18.1', 'curr_platform': 'ios', 'manufacturer': 'Apple', 'phone_lang': 'en'} ``` - and after the pipeline ran, it did ``` >>> edb.get_profile_db().find_one() {'_id': ObjectId('6791fc13b4b3fa6db902c42b'), 'user_id': UUID('414ee37a-732e-4751-a6f6-0d83b41b27f0'), 'mode': {}, 'mpg_array': [32.044384997811726], 'purpose': {}, 'source': 'Shankari', 'update_ts': datetime.datetime(2025, 1, 23, 0, 21, 39, 712000), 'client_app_version': '1.9.6', 'client_os_version': '18.1', 'curr_platform': 'ios', 'manufacturer': 'Apple', 'phone_lang': 'en', 'labeled_trips': 0, 'pipeline_range': {'start_ts': 1737620409.0311022, 'end_ts': 1737621020.497178}, 'total_trips': 1, 'last_call_ts': 1737621021.948551} ```
- Loading branch information