[caciviclab/disclosure-backend-static] Always serialize OaklandCandidate with contribution calculations (#19)

0 views
Skip to first unread message

Tom Dooner

unread,
Sep 17, 2016, 6:05:28 PM9/17/16
to caciviclab/disclosure-backend-static
Always serialize OaklandCandidate with contribution calculations

By adding a `supporting_contribution_data` and
`opposing_contribution_data` to the candidate object's serialization, we
will make sure that we have top-line contribution numbers for any screen
we could need it. Plus it's not good API design to return two different
versions of the same object depending on the endpoint requested.

Fixes #17

cc @adborden @jnmarcus @kylew because of the backwards incompatibility

You can view, comment on, or merge this pull request online at:

  https://github.com/caciviclab/disclosure-backend-static/pull/19

Commit Summary

  • Always serialize OaklandCandidate with contribution calculations
  • Add build artifacts from commit fixing #17

File Changes

Patch Links:


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

Tom Dooner

unread,
Sep 17, 2016, 6:07:17 PM9/17/16
to caciviclab/disclosure-backend-static

Oops, messed up the JSON shenanigans.

Aaron D Borden

unread,
Sep 17, 2016, 7:51:47 PM9/17/16
to caciviclab/disclosure-backend-static

@adborden commented on this pull request.


In models/oakland_candidate.rb:

> @@ -30,6 +30,29 @@ def as_json(options = nil)
       last_name: last_name,
       ballot_item: office_election.id,
       office_election: office_election.id,
+
+      # contribution data
+      supporting_contribution_data: {

nitpick, I prefer to leave off the _data, since all of this is data and feels redundant. I think having an entity named supporting_contributions or supporting_money is totally cool and very descriptive of the domain we're working in.

Aaron D Borden

unread,
Sep 17, 2016, 7:52:25 PM9/17/16
to caciviclab/disclosure-backend-static

Sweeet, thanks for getting to this so fast! I talked to Tom briefly and this was the high-level comments I had:

  • I love the idea of maintaining backwards compatibility for the API, at least for the next few weeks until we're out of the crunch and can start cleaning up.
  • #17 is really about the data for the office view, which only has the total_contributions per candidate

sm-desktop-candidate-4-local_list-all-candidates

  • @KyleW pointed out for the next screen, the candidate screen, this is exactly the data you need and otherwise would have to make 3 API calls for it, so 🎉
  • This will bloat the ballot endpoint (/locality/:id/current_ballot) because this extra support/opposing data would also be included for all candidates. Not a huge deal, but might consider maybe we don't need candidates at all in that endpoint.

👍

Aaron D Borden

unread,
Sep 17, 2016, 8:02:44 PM9/17/16
to caciviclab/disclosure-backend-static

@adborden commented on this pull request.


In models/oakland_candidate.rb:

> @@ -30,6 +30,29 @@ def as_json(options = nil)
       last_name: last_name,
       ballot_item: office_election.id,
       office_election: office_election.id
,
+
+      # contribution data
+      supporting_contribution_data: {
+        contributions_received: calculation(:total_contributions).try(:to_f),
+        total_contributions: calculation(:total_contributions).try(:to_f),
+        total_expenditures: calculation(:total_expenditures).try(:to_f),
+        total_loans_received: calculation(:total_loans_received).try(:to_f),
+        contributions_by_type: calculation(:contributions_by_type) || {},
+        expenditures_by_type: calculation(:expenditures_by_type) || {},
+      },
+      opposing_contribution_data: {

Oh, I'm trying to get clarification from Suzanne, but I'm not sure that there is anyway for money opposing a candidate to be filed... like it would just show up as expenditures from another committee, but not actually tied in anyway to the candidate through filings... Do you know how that works?

Aaron D Borden

unread,
Sep 17, 2016, 9:08:37 PM9/17/16
to caciviclab/disclosure-backend-static

@adborden commented on this pull request.


In models/oakland_candidate.rb:

> @@ -30,6 +30,29 @@ def as_json(options = nil)
       last_name: last_name,
       ballot_item: office_election.id,
       office_election: office_election.id,
+
+      # contribution data
+      supporting_contribution_data: {
+        contributions_received: calculation(:total_contributions).try(:to_f),
+        total_contributions: calculation(:total_contributions).try(:to_f),
+        total_expenditures: calculation(:total_expenditures).try(:to_f),
+        total_loans_received: calculation(:total_loans_received).try(:to_f),
+        contributions_by_type: calculation(:contributions_by_type) || {},
+        expenditures_by_type: calculation(:expenditures_by_type) || {},
+      },
+      opposing_contribution_data: {

Ah, I got an answer, it does get reported. A committee can exist for the purpose of defeating a candidate and will report expenditures as opposing the candidate. Carry on.

Tom Dooner

unread,
Sep 17, 2016, 10:22:59 PM9/17/16
to caciviclab/disclosure-backend-static

@tdooner commented on this pull request.


In models/oakland_candidate.rb:

> @@ -30,6 +30,29 @@ def as_json(options = nil)
       last_name: last_name,
       ballot_item: office_election.id,
       office_election: office_election.id,
+
+      # contribution data
+      supporting_contribution_data: {

Hm, okay, I'll do that before merging.

Tom Dooner

unread,
Sep 17, 2016, 10:23:50 PM9/17/16
to caciviclab/disclosure-backend-static

@tdooner commented on this pull request.


In models/oakland_candidate.rb:

> @@ -30,6 +30,29 @@ def as_json(options = nil)
       last_name: last_name,
       ballot_item: office_election.id,
       office_election: office_election.id
,
+
+      # contribution data
+      supporting_contribution_data: {
+        contributions_received: calculation(:total_contributions).try(:to_f),
+        total_contributions: calculation(:total_contributions).try(:to_f),
+        total_expenditures: calculation(:total_expenditures).try(:to_f),
+        total_loans_received: calculation(:total_loans_received).try(:to_f),
+        contributions_by_type: calculation(:contributions_by_type) || {},
+        expenditures_by_type: calculation(:expenditures_by_type) || {},
+      },
+      opposing_contribution_data: {

Yeah, I'd be surprised if we have any data for this, but I guess we want to at least start theoretically tracking this.

Tom Dooner

unread,
Sep 17, 2016, 10:29:30 PM9/17/16
to caciviclab/disclosure-backend-static, Push

@tdooner pushed 1 commit.

  • 5ea93fe Rename "contribution_data" -> "money"


You are receiving this because you are subscribed to this thread.

View it on GitHub or mute the thread.

Tom Dooner

unread,
Sep 17, 2016, 10:30:08 PM9/17/16
to caciviclab/disclosure-backend-static

Merged #19.

Reply all
Reply to author
Forward
0 new messages