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 some trip stats to the user screen #57

Merged
merged 5 commits into from
Jul 11, 2023

Conversation

AlirezaRa94
Copy link
Contributor

@AlirezaRa94 AlirezaRa94 commented Jun 19, 2023

This pull request is going to address this issue: #48

Three columns were added to the user screen on the data page:
-confirmed_trips
-first_trip
-last_trip
Comment on lines 100 to 111
trip_df = pd.DataFrame(trip_data)
trip_grouped = trip_df.groupby('user_id')
for user in user_data:
user_id = user['user_id']
if user_id in trip_grouped.groups:
trips = trip_grouped.get_group(user_id)
user['confirmed_trips'] = len(trips)
user['first_trip'] = trips['trip_start_time_str'].min()
user['last_trip'] = trips['trip_start_time_str'].max()
# logging.debug(f"{trip_grouped.get_group(user_id).columns}")
# number_of_answered = len(df[df['user_input'] != {}].index) if 'user_input' in df.columns else 0
return user_data
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure that this is the desired implementation.

This may have the desired behavior at this point, but I believe it will no longer do so once #51 is implemented

@asiripanich can confirm, but I believe that the goal is for the user table to include the summary of the entire trip history for the user. If we only load a week at a time, this will not have enough information.

Please use get_first_value_for_field to get the first and last trips instead - there should be examples of how it is used in the codebase

user_id = user['user_id']
if user_id in trip_grouped.groups:
trips = trip_grouped.get_group(user_id)
user['confirmed_trips'] = len(trips)
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to be total_trips.
confirmed_trips aka labeled_trips should be the number of trips that have labels.
I have existing script that essentially generates that this table needs
https://github.com/e-mission/e-mission-server/blob/master/bin/monitor/check_participant_status.py

Unfortunately, it uses edb directly, so please import edb in this function only (so you are not tempted to use it elsewhere) and file a new issue to add timeseries support for the functionality needed here.

- Refactor the code to retrieve and update user information.
- Use MongoDB's count_documents method to count the total trips and labeled trips for each user.
- Update the user dictionary with the total trips and labeled trips counts.
- If the user has at least one trip, retrieve the first and last trip timestamps using the TimeSeries module.
- Update the user dictionary with the first and last trip timestamps if available.
- Retrieve the last call timestamp from the TimeSeries object using the get_first_value_for_field() method.
- Check if the last call timestamp exists and is valid.
- If valid, convert the timestamp to a formatted string using the Arrow library and store it as 'last_call' in the user dictionary.
@shankari
Copy link
Contributor

@AlirezaRa94
This is good as a first step and I am fine with merging as an incremental improvement if you mark it as "ready for review".
However, to fully fix #48, we still need to add the profile information on the platform, app version, os version, etc.

- Retrieve the profile data of the user from the profile database using the find_one method.
- Extract specific fields from the profile data and assign them to corresponding fields in the user dictionary.
@AlirezaRa94
Copy link
Contributor Author

@shankari
For now, I've used edb to get profile information, and we can change it later when needed queries are added.

@AlirezaRa94 AlirezaRa94 marked this pull request as ready for review July 11, 2023 04:51
- Refactor the assignment of user profile data by replacing empty brackets [] with the dictionary get method to prevent errors.
@shankari shankari merged commit 6f0c381 into e-mission:master Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants