-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix totals for off-year special candidates on /candidates/totals endpoint #3198
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #3198 +/- ##
==========================================
- Coverage 88.15% 88.1% -0.05%
==========================================
Files 77 77
Lines 6145 6129 -16
==========================================
- Hits 5417 5400 -17
- Misses 728 729 +1
Continue to review full report at Codecov.
|
98e66f7
to
b0b6b2b
Compare
I updated the data tracking sheet with the new data using the temporary MV's on |
Data looks good. One thing I noticed though is when running this query, each ID returns two rows, the only difference is is_election column. So one candidate has both False and True for is_election column in 2018. I am not sure if that conforms to business rule. select * |
select * |
@fecjjeng and @hcaofec thanks for taking a look. @jwchumley is going to spend some time investigating the data because Jon Ossoff is missing (see outstanding item in PR). I don't follow the |
@hcaofec @fecjjeng - Pat and I looked into |
1bfabcb
to
1a3990b
Compare
1a3990b
to
1991c37
Compare
- Drop MV: ofec_candidate_history_latest_mv - Remove MV from refresh management task - Remove factories for CandidateHistoryLatest
f237541
to
faa1e69
Compare
By following the testing steps written in this PR, here are the results:
The data comparison looks good. But the creation sql script can be refactored to simply the logic. ( see comment above ) |
AND totals.cycle <= election.cand_election_year | ||
AND totals.cycle > election.prev_election_year | ||
GROUP BY link.cand_id, election.cand_election_year, totals.cycle | ||
), election_aggregates AS ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The left join here ( line 66 - 69 ) may not be necessary here because of the distinct logic used in link subquery. And because ofec_candidate_election_mv is used on the right side of the left join, it will not have any effect on the result of cycle_totals subquery.
@vrajmohan @lbeaufort
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tested on local by running py.test. No errors.
Summary (required)
1) #3196: Fixes incorrect totals for /candidates/totals/ for off-year special election candidates
Change to
ofec_candidate_totals_mv
:Add a
SELECT DISTINCT
:Performance
Before: 87037 rows, cost=(22821.52..22840.34)
After: 87037 rows, cost=(17454.39..17462.67)
Example: Doug Jones, Raised
Incorrect totals in API call:
https://api.open.fec.gov/v1/candidates/totals/?api_key=DEMO_KEY&per_page=20&page=1&candidate_id=S0AL00156&cycle=2018
2) #3200 : Fixes missing off-year special candidates
Change to
ofec_candidate_totals_with_0s_mv
: Remove restrictive join on totals (ofec_candidate_totals_mv
) that was preventing odd-year special candidates who didn't run again (H8GA06195 is an example) from showing up:AND cand.candidate_election_year = totals.election_year
Missing candidate in API call (top raising candidate in 2018)
https://api.open.fec.gov/v1/candidates/totals/?api_key=DEMO_KEY&sort_hide_null=true&q=H8GA06195&cycle=2018&sort=-receipts&per_page=30&page=1&office=H
Data tracking: https://docs.google.com/spreadsheets/d/1NUlhWZ6aHvNNSugPk3BWemDQSZn3pimjbqW_4IC_cnw/edit#gid=1784243483
Background
TotalsCandidateView
ofec_candidate_totals_with_0s_mv
which relies onofec_candidate_totals_mv
ofec_candidate_totals_mv
has incorrect totals for Doug Jones (S0AL00156)ofec_cand_cmte_linkage_mv
- off-year special election candidates will have two entries for 2018 in there.Impacted areas:
How to test locally
cfdm_test
db, theninvoke create_sample_db
Testing real data:
SQLA_CONN
to thedev
database.(There is an
ofec_candidate_totals_mv_tmp
andofec_candidate_totals_with_0s_mv_tmp
based off it for data testing.)CandidateTotal(db.Model)
inwebservices/common/models/candidates.py
to point toofec_candidate_totals_with_0s_mv_tmp
Outstanding items
rename_indexes
works <- I think this might be case sensitive? Will test if I can_tmp
for testing data