Skip to content

Commit

Permalink
Merge pull request #157 from iantei/patch_fixes
Browse files Browse the repository at this point in the history
Patch fixes: Eliminate plot_title for Replaced mode stacked bar charts
  • Loading branch information
shankari authored Jan 5, 2025
2 parents f927f36 + 6833854 commit 1fb4b24
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
4 changes: 2 additions & 2 deletions viz_scripts/generic_metrics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,8 @@
" expanded_ct_sensed_u80 = expanded_ct_sensed.loc[(expanded_ct_sensed['distance'] <= cutoff)]\n",
"\n",
" sensed_u80_quality_text = f\"{len(expanded_ct_sensed_u80)} trips ({round(len(expanded_ct_sensed_u80)/len(expanded_ct_sensed)*100)}% of all trips)\\nfrom {scaffolding.unique_users(expanded_ct_sensed_u80)} {sensed_match.group(3)}\"\n",
" labeled_u80_quality_text = f\"{len(expanded_ct_u80)} trips ({round(len(expanded_ct_u80)/len(expanded_ct)*100)}% of all labeled,\\n{round(len(expanded_ct_u80)/len(expanded_ct_sensed)*100)}% of all trips)\\nfrom {scaffolding.unique_users(expanded_ct_u80)} {sensed_match.group(3)}\" if \"Mode_confirm\" in expanded_ct.columns else \"0 labeled trips\"\n",
" inferred_u80_quality_text = f\"{len(expanded_ct_inferred_u80)} trips ({round(len(expanded_ct_inferred_u80)/len(expanded_ct_inferred)*100)}% of all inferred,\\n{round(len(expanded_ct_inferred_u80)/len(expanded_ct_sensed)*100)}% of all trips)\\nfrom {scaffolding.unique_users(expanded_ct_inferred_u80)} {sensed_match.group(3)}\" if \"Mode_confirm\" in expanded_ct_inferred.columns else \"0 inferred trips\"\n",
" labeled_u80_quality_text = f\"{len(expanded_ct_u80)} trips ({round(len(expanded_ct_u80)/len(expanded_ct)*100)}% of all labeled,\\n{round(len(expanded_ct_u80)/len(expanded_ct_sensed)*100)}% of all trips)\\nfrom {scaffolding.unique_users(expanded_ct_u80)} {sensed_match.group(3)}\" if \"mode_confirm_w_other\" in expanded_ct.columns else \"0 labeled trips\"\n",
" inferred_u80_quality_text = f\"{len(expanded_ct_inferred_u80)} trips ({round(len(expanded_ct_inferred_u80)/len(expanded_ct_inferred)*100)}% of all inferred,\\n{round(len(expanded_ct_inferred_u80)/len(expanded_ct_sensed)*100)}% of all trips)\\nfrom {scaffolding.unique_users(expanded_ct_inferred_u80)} {sensed_match.group(3)}\" if \"mode_confirm_w_other\" in expanded_ct_inferred.columns else \"0 inferred trips\"\n",
"\n",
" # Plot entries\n",
" fig, ax = plt.subplots(nrows=3, ncols=1, figsize=(15,3*2), sharex=True)\n",
Expand Down
9 changes: 3 additions & 6 deletions viz_scripts/mode_specific_metrics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,7 @@
" f\"Labeled `{mode_of_interest}` by user\\n\"+stacked_bar_quality_text, ax[0], text_results[0], colors_purpose, debug_df, value_to_translations_purpose)\n",
" plot_and_text_stacked_bar_chart(data_eb_inferred, lambda df: df.groupby(\"purpose_confirm_w_other\").agg({distance_col: 'count'}).sort_values(by=distance_col, ascending=False),\n",
" f\"Labeled and Inferred `{mode_of_interest}` by OpenPATH\\n\"+stacked_bar_quality_text_inferred, ax[1], text_results[1], colors_purpose, debug_df_inferred, value_to_translations_purpose)\n",
" plot_title = plot_title_no_quality + \"\\n\" + f\"For {mode_of_interest}: \" + quality_text\n",
" set_title_and_save(fig, text_results, plot_title, file_name)\n",
" set_title_and_save(fig, text_results, plot_title_no_quality, file_name)\n",
"except (AttributeError, KeyError, pd.errors.UndefinedVariableError) as e:\n",
" plt.clf()\n",
" generate_missing_plot(plot_title_no_quality, debug_df, file_name)\n",
Expand Down Expand Up @@ -302,8 +301,7 @@
" \"Labeled by user\\n (Trip distance)\\n\"+stacked_bar_quality_text, ax[0], text_results[0], colors_replaced, debug_df, value_to_translations_replaced)\n",
" plot_and_text_stacked_bar_chart(data_eb_inferred, lambda df: df.groupby(\"replaced_mode_w_other\").agg({distance_col: 'sum'}).sort_values(by=distance_col, ascending=False), \n",
" \"Labeled and Inferred by OpenPATH\\n (Trip distance)\\n\"+stacked_bar_quality_text_inferred, ax[1], text_results[1], colors_replaced, debug_df_inferred, value_to_translations_replaced)\n",
" plot_title = plot_title_no_quality\n",
" set_title_and_save(fig, text_results, plot_title, file_name)\n",
" set_title_and_save(fig, text_results, plot_title_no_quality, file_name)\n",
"except (AttributeError, KeyError, pd.errors.UndefinedVariableError) as e:\n",
" plt.clf()\n",
" generate_missing_plot(plot_title_no_quality, debug_df, file_name)\n",
Expand Down Expand Up @@ -339,8 +337,7 @@
" f\"Labeled `{mode_of_interest}` by user\\n\"+stacked_bar_quality_text, ax[0], text_results[0], colors_replaced, debug_df, value_to_translations_replaced)\n",
" plot_and_text_stacked_bar_chart(data_eb_inferred, lambda df: df.groupby(\"replaced_mode_w_other\").agg({distance_col: 'count'}).sort_values(by=distance_col, ascending=False), \n",
" f\"Labeled and Inferred `{mode_of_interest}` by OpenPATH\\n\"+stacked_bar_quality_text_inferred, ax[1], text_results[1], colors_replaced, debug_df_inferred, value_to_translations_replaced)\n",
" plot_title = plot_title_no_quality + \"\\n\" + f\"For {mode_of_interest}: \" + quality_text\n",
" set_title_and_save(fig, text_results, plot_title, file_name)\n",
" set_title_and_save(fig, text_results, plot_title_no_quality, file_name)\n",
"except (AttributeError, KeyError, pd.errors.UndefinedVariableError) as e:\n",
" plt.clf()\n",
" generate_missing_plot(plot_title_no_quality, debug_df, file_name)\n",
Expand Down
8 changes: 4 additions & 4 deletions viz_scripts/scaffolding.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ async def load_viz_notebook_data(year, month, program, study_type, dynamic_label
"Participants_with_at_least_one_trip": unique_users(participant_ct_df),
"Participant_with_at_least_one_labeled_trip": unique_users(labeled_ct),
"Trips_with_at_least_one_label": len(labeled_ct),
"Trips_with_mode_confirm_label": trip_label_count("Mode_confirm", expanded_ct),
"Trips_with_trip_purpose_label": trip_label_count("Trip_purpose", expanded_ct)
"Trips_with_mode_confirm_label": trip_label_count("mode_confirm_w_other", expanded_ct),
"Trips_with_trip_purpose_label": trip_label_count("purpose_confirm_w_other", expanded_ct)
},
orient='index', columns=["value"])

Expand Down Expand Up @@ -279,8 +279,8 @@ async def load_viz_notebook_inferred_data(year, month, program, study_type, dyna
"Participants_with_at_least_one_trip": unique_users(participant_ct_df),
"Participant_with_at_least_one_inferred_trip": unique_users(inferred_ct),
"Trips_with_at_least_one_inferred_label": len(inferred_ct),
"Trips_with_mode_confirm_inferred_label": trip_label_count("Mode_confirm", expanded_it),
"Trips_with_trip_purpose_inferred_label": trip_label_count("Trip_purpose", expanded_it)
"Trips_with_mode_confirm_inferred_label": trip_label_count("mode_confirm_w_other", expanded_it),
"Trips_with_trip_purpose_inferred_label": trip_label_count("purpose_confirm_w_other", expanded_it)
},
orient='index', columns=["value"])

Expand Down

0 comments on commit 1fb4b24

Please sign in to comment.