Skip to content

Commit

Permalink
♻️ Minor fixes to the survey metrics
Browse files Browse the repository at this point in the history
- use `.get` to check whether this is an enketo survey so that it works for
  older deployments that predate the `survey_info` functionality as well. This
  has no functional difference since, if there is no `survey_info`, this is not
  a survey. But we get a better exception and avoid confusion later.
- improve error handling for survey_responses, by splitting the attribute and
  name errors from the more complex errors
  • Loading branch information
shankari committed May 8, 2024
1 parent ef4786e commit 91cc8e7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion viz_scripts/survey_metrics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"outputs": [],
"source": [
"# Do not run this notebook at all unless it is for a survey configuration; nbclient will run up through this cell\n",
"if not survey_info['trip-labels'] == 'ENKETO':\n",
"if not survey_info.get('trip-labels', None) == 'ENKETO':\n",
" ipython = get_ipython()\n",
" ipython._showtraceback = scaffolding.no_traceback_handler\n",
" raise Exception(\"The plots in this notebook are only relevant to deployments with trip-level surveys\")"
Expand Down
12 changes: 8 additions & 4 deletions viz_scripts/survey_responses.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"outputs": [],
"source": [
"# Do not run this notebook at all unless it is for a survey configuration; nbclient will run up through this cell\n",
"if not survey_info['trip-labels'] == 'ENKETO':\n",
"if not survey_info.get('trip-labels', None) == 'ENKETO':\n",
" ipython = get_ipython()\n",
" ipython._showtraceback = scaffolding.no_traceback_handler\n",
" raise Exception(\"The plots in this notebook are only relevant to deployments with trip-level surveys\")"
Expand Down Expand Up @@ -372,10 +372,14 @@
" \n",
" plot_and_text_stacked_bar_chart(plot_df, \"Responses\", ax, text_results, get_survey_colors(list(plot_df.index.values) ,color_map), debug_df)\n",
" set_title_and_save(fig, text_results, plot_title, filename)\n",
"\n",
" except:\n",
" except (AttributeError, KeyError, pd.errors.UndefinedVariableError) as e:\n",
" plt.clf()\n",
" generate_missing_plot(plot_title_no_quality, debug_df, filename)\n",
" alt_text = store_alt_text_missing(debug_df, filename, plot_title_no_quality)"
" alt_text = store_alt_text_missing(debug_df, filename, plot_title_no_quality) \n",
" alt_html = store_alt_html_missing(debug_df, filename, plot_title_no_quality)\n",
" except Exception as e:\n",
" fig, ax = plt.subplots()\n",
" plot_and_text_error(e, ax, filename)"
]
}
],
Expand Down

0 comments on commit 91cc8e7

Please sign in to comment.