Skip to content

Commit e59057d

Browse files
committed
document code
1 parent fcfb792 commit e59057d

2 files changed

Lines changed: 28 additions & 11 deletions

File tree

src/electiondata/__init__.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2830,12 +2830,29 @@ def scatter(
28302830
v_category: str,
28312831
v_count: str, # vertical axis params
28322832
fig_type: str = None,
2833-
) -> Optional[list]:
2834-
"""Used to create a scatter plot based on selected inputs. The fig_type parameter
2835-
is used when the user wants to actually create the visualization; this uses plotly
2836-
so any image extension that is supported by plotly is usable here. Currently supports
2837-
html, png, jpeg, webp, svg, pdf, and eps. Note that some filetypes may need plotly-orca
2838-
installed as well."""
2833+
) -> Optional[dict]:
2834+
"""
2835+
Required inputs:
2836+
jurisdiction: str,
2837+
for horizontal axis of scatter plot:
2838+
h_election: str, election parameter
2839+
h_category: str, category parameter (e.g., Population by Race or Candidate total)
2840+
h_count: str, count label parameter (e.g., "Black" or "Joseph R. Biden", depending on category)
2841+
for vertical axis of scatter plot (same definitions as for horizontal):
2842+
v_election: str,
2843+
v_category: str,
2844+
v_count: str,
2845+
Optional input:
2846+
fig_type: str = None, an image format string from plotly - as of 8/2021, includes
2847+
html, png, jpeg, webp, svg, pdf, and eps. Note that some filetypes may need
2848+
plotly-orca installed as well.
2849+
2850+
If <fig_type> is given and points for scatter are found, creates a scatter plot
2851+
in the self.reports_and_plots_dir directory with file extension and format determined by fig_type.
2852+
2853+
Returns:
2854+
dict, dictionary of data for creating the scatter plot (including title, axis titles, etc.)
2855+
"""
28392856
jurisdiction_id = db.name_to_id(self.session, "ReportingUnit", jurisdiction)
28402857
subdivision_type = self.major_subdivision_type[jurisdiction]
28412858
h_election_id = db.name_to_id(self.session, "Election", h_election)
@@ -2874,7 +2891,7 @@ def bar(
28742891
contest_type: str = None,
28752892
contest: str = None,
28762893
fig_type: str = None,
2877-
) -> list:
2894+
) -> List[dict]:
28782895
"""contest_type is an election district type, e.g.,
28792896
state, congressional, state-senate, state-house, territory, etc.
28802897
Complete list is given by the keys of <db.contest_type_mapping>"""
@@ -2917,7 +2934,7 @@ def export_outlier_data(
29172934
election: str,
29182935
jurisdiction: str,
29192936
contest: str = None,
2920-
) -> list:
2937+
) -> List[dict]:
29212938
"""contest_type is one of state, congressional, state-senate, state-house"""
29222939
election_id = db.name_to_id(self.session, "Election", election)
29232940
jurisdiction_id = db.name_to_id(self.session, "ReportingUnit", jurisdiction)

src/electiondata/analyze/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def create_scatter(
145145
v_count,
146146
v_type,
147147
v_runoff,
148-
):
148+
) -> Optional[dict]:
149149
connection = session.bind.raw_connection()
150150
cursor = connection.cursor()
151151

@@ -259,7 +259,7 @@ def create_scatter(
259259
return results
260260

261261

262-
def package_results(data, jurisdiction, x, y, restrict=None):
262+
def package_results(data, jurisdiction, x, y, restrict=None) -> dict:
263263
results = {"jurisdiction": jurisdiction, "x": x, "y": y, "counts": []}
264264
if restrict and len(data.index) > restrict:
265265
data = get_remaining_averages(data, restrict)
@@ -452,7 +452,7 @@ def create_bar(
452452
contest: Optional[str],
453453
election_id: int,
454454
for_export: bool,
455-
):
455+
) -> List[dict]:
456456

457457
connection = session.bind.raw_connection()
458458
cursor = connection.cursor()

0 commit comments

Comments
 (0)