-
Notifications
You must be signed in to change notification settings - Fork 10
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
Conversation
Three columns were added to the user screen on the data page: -confirmed_trips -first_trip -last_trip
utils/db_utils.py
Outdated
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 |
There was a problem hiding this comment.
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
utils/db_utils.py
Outdated
user_id = user['user_id'] | ||
if user_id in trip_grouped.groups: | ||
trips = trip_grouped.get_group(user_id) | ||
user['confirmed_trips'] = len(trips) |
There was a problem hiding this comment.
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.
@AlirezaRa94 |
- 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.
@shankari |
- Refactor the assignment of user profile data by replacing empty brackets [] with the dictionary get method to prevent errors.
This pull request is going to address this issue: #48