@@ -437,57 +437,35 @@ def add_user_stats(user_data, batch_size=5):
437
437
def process_user (user ):
438
438
with ect .Timer () as process_user_timer :
439
439
user_uuid = UUID (user ['user_id' ])
440
-
441
- # Fetch aggregated data for all users once and cache it
442
- ts_aggregate = esta .TimeSeries .get_aggregate_time_series ()
443
-
444
- # Fetch data for the user, cached for repeated queries
445
440
profile_data = edb .get_profile_db ().find_one ({'user_id' : user_uuid })
441
+ # Fetch data for the user, cached for repeated queries
442
+ logging .info (f'keyspr: { profile_data } ' )
443
+ if not profile_data :
444
+ profile_data = {}
445
+ # Assign existing profile attributes to the user dictionary
446
+ user ['platform' ] = profile_data .get ('curr_platform' )
447
+ user ['manufacturer' ] = profile_data .get ('manufacturer' )
448
+ user ['app_version' ] = profile_data .get ('client_app_version' )
449
+ user ['os_version' ] = profile_data .get ('client_os_version' )
450
+ user ['phone_lang' ] = profile_data .get ('phone_lang' )
446
451
447
- total_trips = ts_aggregate .find_entries_count (
448
- key_list = ["analysis/confirmed_trip" ],
449
- extra_query_list = [{'user_id' : user_uuid }]
450
- )
451
- labeled_trips = ts_aggregate .find_entries_count (
452
- key_list = ["analysis/confirmed_trip" ],
453
- extra_query_list = [{'user_id' : user_uuid }, {'data.user_input' : {'$ne' : {}}}]
454
- )
452
+ # Assign newly stored statistics to the user dictionary
453
+ user ['total_trips' ] = profile_data .get ('total_trips' )
454
+ user ['labeled_trips' ] = profile_data .get ('labeled_trips' )
455
455
456
- user ['total_trips' ] = total_trips
457
- user ['labeled_trips' ] = labeled_trips
458
-
459
- if profile_data :
460
- user ['platform' ] = profile_data .get ('curr_platform' )
461
- user ['manufacturer' ] = profile_data .get ('manufacturer' )
462
- user ['app_version' ] = profile_data .get ('client_app_version' )
463
- user ['os_version' ] = profile_data .get ('client_os_version' )
464
- user ['phone_lang' ] = profile_data .get ('phone_lang' )
465
-
466
- if total_trips > 0 :
467
- ts = esta .TimeSeries .get_time_series (user_uuid )
468
- first_trip_ts = ts .get_first_value_for_field (
469
- key = 'analysis/confirmed_trip' ,
470
- field = 'data.end_ts' ,
471
- sort_order = pymongo .ASCENDING
472
- )
473
- if first_trip_ts != - 1 :
474
- user ['first_trip' ] = arrow .get (first_trip_ts ).format (time_format )
475
-
476
- last_trip_ts = ts .get_first_value_for_field (
477
- key = 'analysis/confirmed_trip' ,
478
- field = 'data.end_ts' ,
479
- sort_order = pymongo .DESCENDING
480
- )
481
- if last_trip_ts != - 1 :
482
- user ['last_trip' ] = arrow .get (last_trip_ts ).format (time_format )
483
-
484
- last_call_ts = ts .get_first_value_for_field (
485
- key = 'stats/server_api_time' ,
486
- field = 'data.ts' ,
487
- sort_order = pymongo .DESCENDING
488
- )
489
- if last_call_ts != - 1 :
490
- user ['last_call' ] = arrow .get (last_call_ts ).format (time_format )
456
+ # Retrieve and assign pipeline range
457
+ pipeline_range = profile_data .get ('pipeline_range' , {})
458
+ start_ts = pipeline_range .get ('start_ts' )
459
+ end_ts = pipeline_range .get ('end_ts' )
460
+ if start_ts :
461
+ user ['first_trip' ] = arrow .get (start_ts ).format (time_format )
462
+ if end_ts :
463
+ user ['last_trip' ] = arrow .get (end_ts ).format (time_format )
464
+
465
+ # Retrieve and assign last API call timestamp
466
+ last_call_ts = profile_data .get ('last_call_ts' )
467
+ if last_call_ts :
468
+ user ['last_call' ] = arrow .get (last_call_ts ).format ('YYYY-MM-DD' )
491
469
492
470
esdsq .store_dashboard_time (
493
471
"admin/db_utils/add_user_stats/process_user" ,
0 commit comments