the-blue-alliance/the-blue-alliance — pull request #1052 by fangeugene (2014-06-21 22:20:57+00:00)
Title: Districts!

Discussion in #917

I'm not a huge fan of the top-level "Districts" page because it a) feels kind of redundant since we already have "Events" (even more redundant once we implement district filtering on the Events page) and b) it requires too much scrolling/clicking to see rankings for some of the lower districts. Ideas welcome.

Implementation:
-----
District points are calculated for each event, and stored under the Event model as district_points_json. This stores the points breakdown (qual, elim, alliance, and award) scores for each team as well as any information required for tiebreakers (# qual wins, top 3 highest qual scores). This is data is displayed on event details pages (see second screenshot).

On the Rankings page, we fetch the Event model for all events for a district for a year and aggregate all of the point breakdowns for the first 2 events for each team + the district championship if they attend. Aggregation isn't to computationally intensive, but the only way to access rookie year is to fetch all teams, which is on the order of 250 teams per district. We might offload this to a cron job later, but for now, we'll just rely on caching to help us. This data is displayed on the new Rankings page (see third screenshot).

Screenshots:
-----
(Rookie bonus is incorrect because my local machine doesn't have a full copy of data.)
![first robotics districts the blue alliance](https://cloud.githubusercontent.com/assets/1421884/3350135/2b7e68dc-f991-11e3-9c99-2738249f0a34.png)

![center line first robotics district competition 2014 the blue alliance](https://cloud.githubusercontent.com/assets/1421884/3350145/752c2456-f991-11e3-90b8-28437d87fdff.png)

![2014 first robotics district rankings the blue alliance](https://cloud.githubusercontent.com/assets/1421884/3350133/2b5a308e-f991-11e3-9de8-9f6209551e19.png)