Skip to content
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

Process Form 497 Page 2 (Late Expenditures) #31

Merged
merged 5 commits into from
Sep 21, 2016
Merged

Process Form 497 Page 2 (Late Expenditures) #31

merged 5 commits into from
Sep 21, 2016

Conversation

tdooner
Copy link
Member

@tdooner tdooner commented Sep 19, 2016

This adds Late Expenditures to:

  1. referendum supporters/opponents calculator
  2. total expenditures calculator
  3. expenditures by type calculator

The first one is somewhat difficult since Form 497 has no "Sup_Opp_Cd" field, so we must infer it based on the Schedule E (Payments Made). (We could instead use Schedule D, but it seems like the data is more complete for E).

Not much changed for candidates, since there is only one candidate entry on the 497 and it is a contribution, not an expenditure.

[Fixes #27]

This is a somewhat complicated implementation, but out of necessity:
Form 497 rows do not contain the "Sup_Opp_Cd" column needed to bucket an
expenditure into either supporting or opposing a ballot measure. So we
must guess.

Also, I suspect this will double-count in some cases like Just Cause --
they gave money to a committee that is basically themselves. I don't
think we should count this money twice. I opened #29 to track this.
This changes nothing, yet. Form 497 doesn't have an Expn_Code column so
I've bucketed them all in "Not Stated".
This changes nothing, yet, because no candidates have data here.
end
elsif sup_opp_cd == 'O'
opposing_by_measure_name[row['Bal_Name']] ||= []
opposing_by_measure_name[row['Bal_Name']] << row
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right, aren't you appending the row twice?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, good catch.

@@ -29,6 +39,37 @@ def fetch
end
end

late_expenditures.each do |row|
sup_opp_cd = guess_whether_committee_supports_measure(row['Filer_ID'], row['Bal_Name'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this ever come up empty? In that case, we just don't count the money?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like if we can't guess then we drop it. Its not likely to happen too often.
On a related note, I think I saw the same ballot measure referred by two different names.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, we drop it. I created #35 as a issue to track our tracking of how many records / how much money we skip because we can't find a match. We can keep adding more to that issue as we introduce more fuzzy matching into our processing.

# Stated".
late_expenditures = ActiveRecord::Base.connection.execute(<<-SQL)
SELECT DISTINCT ON ("Filer_ID")
"Filer_ID", '' AS "Expn_Code", SUM("Amount") AS "Total"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should '' be 'Not stated'? Or maybe null so it's easier to handle on the frontend?

@adborden
Copy link
Member

Not sure I'm reading the Ruby right, hopefully my comments are helpful :)

* origin/master:
  Update build artifacts for 9e5b9b8
  Update contributions_received stub to zero
  Limit Form 497 results to contributions only
  Add Form 497 to candidate total contributions
  Add Form 497 to candidate contributions by type
Copy link
Collaborator

@mikeubell mikeubell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise 👍

@_guess_cache ||=
begin
guesses = ActiveRecord::Base.connection.execute(<<-SQL)
SELECT "Filer_ID", "Bal_Name", "Sup_Opp_Cd"
Copy link
Collaborator

@mikeubell mikeubell Sep 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use SELECT DISTINCT rather than GROUP BY, its probably its processed about the same but I think it is clearer that is what you are doing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I didn't use the Report_Num here because it seemed unlikely to me that the Sup_Opp_Cd would change between amendments.

@@ -29,6 +39,37 @@ def fetch
end
end

late_expenditures.each do |row|
sup_opp_cd = guess_whether_committee_supports_measure(row['Filer_ID'], row['Bal_Name'])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like if we can't guess then we drop it. Its not likely to happen too often.
On a related note, I think I saw the same ballot measure referred by two different names.

@tdooner tdooner merged commit 69e44e9 into master Sep 21, 2016
@tdooner tdooner deleted the issue_27 branch September 27, 2018 01:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants