Skip to content

Commit

Permalink
Updated COLS to be uniform like the other constants. Updated ADD USER…
Browse files Browse the repository at this point in the history
… STATS
  • Loading branch information
TeachMeTW committed Dec 10, 2024
1 parent 3da0f4d commit fd32ba1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"inferred_section_summary",
]

valid_uuids_columns = [
VALID_UUIDS_COLS = [
'user_token',
'user_id',
'update_ts',
Expand Down
24 changes: 12 additions & 12 deletions utils/db_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ def process_user(user):
user_uuid = UUID(user['user_id'])
profile_data = edb.get_profile_db().find_one({'user_id': user_uuid})
# Fetch data for the user, cached for repeated queries
logging.info(f'keyspr: {profile_data}')
if not profile_data:
profile_data = {}
# Assign existing profile attributes to the user dictionary
Expand All @@ -447,25 +448,24 @@ def process_user(user):
user['app_version'] = profile_data.get('client_app_version')
user['os_version'] = profile_data.get('client_os_version')
user['phone_lang'] = profile_data.get('phone_lang')


# Assign newly stored statistics to the user dictionary
user['total_trips'] = profile_data.get('total_trips', 0)
user['labeled_trips'] = profile_data.get('labeled_trips', 0)
user['total_trips'] = profile_data.get('total_trips')
user['labeled_trips'] = profile_data.get('labeled_trips')

# Retrieve and assign pipeline range
pipeline_range = profile_data.get('pipeline_range', {})
user['pipeline_start_ts'] = pipeline_range.get('start_ts')
user['pipeline_end_ts'] = pipeline_range.get('end_ts')
start_ts = pipeline_range.get('start_ts')
end_ts = pipeline_range.get('end_ts')
if start_ts:
user['first_trip'] = arrow.get(start_ts).format(time_format)
if end_ts:
user['last_trip'] = arrow.get(end_ts).format(time_format)

# Retrieve and assign last API call timestamp
user['last_call'] = profile_data.get('last_call')

# Optional: Format the last_call timestamp for readability
if user['last_call']:
user['formatted_last_call'] = arrow.get(user['last_call']).format('YYYY-MM-DD HH:mm:ss')
else:
user['formatted_last_call'] = None
last_call_ts = profile_data.get('last_call_ts')
if last_call_ts:
user['last_call'] = arrow.get(last_call_ts).format('YYYY-MM-DD')

esdsq.store_dashboard_time(
"admin/db_utils/add_user_stats/process_user",
Expand Down
2 changes: 1 addition & 1 deletion utils/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def get_allowed_trip_columns():


def get_uuids_columns():
columns = set(constants.valid_uuids_columns)
columns = set(constants.VALID_UUIDS_COLS)
for column in permissions.get("data_uuids_columns_exclude", []):
columns.discard(column)
return columns
Expand Down

0 comments on commit fd32ba1

Please sign in to comment.