Batch Trend takes into account batches that have votes but a batch breakdown of N/A
drimgere opened this issue · comments
Describe the bug
The Batch Trend column counts against all votes that come in, even if there is an update where there was a vote change but no breakdown of the batch re: Trump vs Biden
To Reproduce
Steps to reproduce the behavior:
- Go to https://alex.github.io/nyt-2020-election-scraper/battleground-state-changes.html#
- Scroll down to the North Carolina entries
- 3 of the bottom 5 entries for North Carolina have data in the "Change" column, but in the "Batch Breakdown" column the entry is "N/A". The three entries read 220, 1,989 and 2,233 respectively.
- Since there is no "Batch Breakdown", the "Batch Trend" column entry is empty, which is correct.
- On the very next update with a breakdown. (6th from the bottom) There is a "Change" of 390 and a "Batch Breakdown" of Trump 46.7% / 53.3% Biden. However in the "Batch Trend" column the entry reads "Biden is averaging 4.3%" instead of lining up with the "Batch Breakdown" entry.
- I think what's happening is that the calculation is taking the sum of all the votes in the "Changes" column and treats a value of N/A in the "Batch Breakdown" column as 0.
EDIT: I see in https://github.com/alex/nyt-2020-election-scraper/blob/master/print-battleground-state-changes that it is only the last 5 or the last 30k votes that is counted, so my calculation below has one extra row, however that row is 0 so it does not invalidate the issue brought up.
Calculation:
Votes from the "Changes" column for the bottom 6 entries that have:
0+ 220 + 0 + 1989 + 2233 + 390 = 4832
Votes for Biden calculated from the "Batch Breakdown" entry for the bottom 6 entries:
00 + 2200 + 00 + 19890 + 22330 + 39053.3% = 207
Biden Votes / Total Votes from "Changes"
207/4832 = 4.3% (4.2839%)
Expected behavior
A batch of votes shouldn't be counted towards the Batch Trend if it doesn't have a valid Batch Breakdown (i.e. not "N/A") value.
e.g. the Batch Trend for the row sixth from the bottom should read "Biden is averaging 53.3%" as the first entry that has a valid Batch Breakown
EDIT: I believe the issue is at https://github.com/alex/nyt-2020-election-scraper/blob/master/print-battleground-state-changes#L146
Screenshots
Desktop (please complete the following information):
- OS: Windows 10
- Browser Firefox/Chrome/IE
- Latest
Additional context
North Carolina has the easiest/clearest example of this error. This problem occurs in the Batch Trend for other states as well so it's a systemic calculation issue.
Thanks for your hard work!