Code Reference

Note

These modules include the Python documentation for creating the Bokeh plots used in the application. Javascript adjustments may be necessary to extend the application. See the javascript file in the application for guidance.

views.views.get_counties(request)

Provides the counties of a state.

Parameters

request – The HTML request which is provided by Django when the route is called. A ‘state’ value is required to identify the state for which counties are returned.

Returns

A JSON formatted list of counties in the provided state.

views.views.index_view(request)

Default Index route which shows the initial page. A call to this route will attempt to refresh the Git status of the repo. :param request: The HTML request which is provided by Django when the route is called. :return: Renders an HTML home page with ‘states’ and ‘political_affiliation’ values available to Jinja.

views.views.refresh_git(request)

Triggers a pull of the Git repository that hold the data used in plots.

Parameters

request – The HTML request which is provided by Django when the route is called. No values of the request are used in this function.

Returns

A Json formatted text response that includes the git activity of the request to pull data.

views.plot_state_totals.plot_state_chart(request, state='United States', county='All', frequency='daily', data_type='infections', rolling_window=14)

Plots the values for a selected state, county or the entire United States.

Parameters
  • request – The HTML request that should include values for ‘state’, ‘county’, ‘frequency’, ‘data_type’ and ‘rolling_window’. See the parameter descriptions below for contraints and defaults for each parameter.

  • state – (optional) Default ‘Massachusetts’. The name of the state to plot.

  • county – (optional) Default ‘All’. The county to plot or ‘All’ counties of a state of value is ‘All’.

  • frequency – (optional) Default ‘daily’. Whether to plot daily or cumulative values.

  • data_type – (optional) Default ‘infections’. Plot ‘infections’ data or ‘deaths’ data.

  • rolling_window – (optional) Default 14. The number of days to use when drawing the daily average line in the plot.

Returns

A Bokeh JSON formatted plot that can be handled by JavaScript for HTML presentation.

views.plot_state_by_county.plot_state_by_county_chart(request, state='Massachusetts', exclude_counties=False, top_n_counties=15, data_type='infections')

Plots a line chart of values by date for the counties in a provided state. Not all counties are shown to avoid visual confusion. The top_n counties defaults to 15 but can be set. Infections are plotted by default, but ‘deaths’ can be plotted as well. Counties can be excluded from the plot. The function can be called with parameters in a request object or with specific parameters. If a request object is supplied, other variables supplied are ignored.

Parameters
  • request – The HTML request that should include values for ‘state’, ‘exclude_counties’, ‘top_n_counties’ and ‘data_type’. See the parameter descriptions below for contraints and defaults for each parameter.

  • state – (optional) Default ‘Massachusetts’. The name of the state to plot.

  • exclude_counties – (optional) Default is None. A list of counties that should be excluded from the plot.

  • top_n_counties – (optional) Defaults to 15. The top n counties plotted.

  • data_type – (optional) Defaults to ‘infections’. Can also be ‘deaths’.

Returns

A Bokeh JSON formatted plot that can be handled by JavaScript for HTML presentation.

views.political_affiliation.plot_affiliation(request, frequency='daily', rolling_window=14, exclude_states=[], data_type='infections')

Plots data based on ‘red’ and ‘blue’ affiliation of states. Relies on global variable from helpers.py that lists the political affiliation per state.

Parameters
  • request – The HTML request that should include values for ‘frequency’, ‘rolling_window’, ‘data_type’ and ‘exclude_states’. See the parameter descriptions below for contraints and defaults for each parameter.

  • frequency – (optional) Default is ‘daily’. Plot ‘daily’ or ‘cumulative’ values.

  • rolling_window – (optional) Default 14. The number of days to use when drawing the daily average line in the plot.

  • exclude_states – (optional) Default is None. A list of states to exclude from the plotted values.

  • data_type – (optional) Default is ‘infections. Plot ‘infections’ data or ‘deaths’ data.

Returns

A Bokeh JSON formatted plot that can be handled by JavaScript for HTML presentation.

views.plot_top_states.plot_top_states(request, states=None, top_n_states=15, data_type='infections', exclude_states: Optional[list] = None)

Plot a line chart of values for the top n states in the US. Can plot based on infections or deaths. A list of states canbe provided which are exluded from the list.

Parameters
  • request – The HTML request that should include values for ‘states’, ‘top_n_states’, ‘data_type’ and ‘exclude_states’. See the parameter descriptions below for contraints and defaults for each parameter.

  • states – (optional) Default is None. A specific list of states that should be included in the plot. When None is the value, the top_n states are plotted.

  • top_n_states – (optional) Default 15. The top n number of states to plot.

  • data_type – (optional) Default is ‘infections’. Plot ‘infections’ or ‘deaths’.

  • exclude_states – (optional) Default is None. A list of the states to exclude from the plot.

Returns

A Bokeh JSON formatted plot that can be handled by JavaScript for HTML presentation.