Skip to content

Commit 8a90c14

Browse files
author
Eric Tsai
committed
bar chart uses most recent election for jurisdiction
1 parent 9c44544 commit 8a90c14

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

src/election_anomaly/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,15 +1050,15 @@ def bar(
10501050
hierarchy = db.get_jurisdiction_hierarchy(
10511051
self.session, jurisdiction_id, most_granular_id
10521052
)
1053-
results_info = db.get_datafile_info(self.session, self.d["results_file_short"])
1053+
election_id = db.most_recent_election(self.session, jurisdiction_id)
10541054
# bar chart always at one level below top reporting unit
10551055
agg_results = a.create_bar(
10561056
self.session,
10571057
jurisdiction_id,
10581058
hierarchy[1],
10591059
contest_type,
10601060
contest,
1061-
results_info[1],
1061+
election_id,
10621062
False,
10631063
)
10641064
if fig_type:

src/election_anomaly/database/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,3 +1207,17 @@ def get_candidate_votecounts(session, election_id, top_ru_id, subdivision_type_i
12071207
result_df = pd.DataFrame(result)
12081208
result_df.columns = result.keys()
12091209
return result_df
1210+
1211+
1212+
def most_recent_election(session, jurisdiction_id):
1213+
q = session.execute(
1214+
f"""
1215+
SELECT "Election_Id"
1216+
FROM _datafile d
1217+
JOIN "Election" e on d."Election_Id" = e."Id"
1218+
WHERE "ReportingUnit_Id" = 274
1219+
ORDER BY "Name" desc
1220+
LIMIT 1
1221+
"""
1222+
).fetchall()
1223+
return q[0][0]

0 commit comments

Comments
 (0)