DataMade: Developer Position Coding Challenge by Grant Russell#12
DataMade: Developer Position Coding Challenge by Grant Russell#12grantongrant wants to merge 3 commits intodatamade:mainfrom
Conversation
| class Meta: | ||
| model = CommunityArea | ||
| fields = ["name", "num_permits"] | ||
| fields = ["name", "area_id", "num_permits"] |
There was a problem hiding this comment.
I veered slightly from the instructions, but I took inspiration from the TODO example object in get_num_permits. I would prefer to include the area_id for use on the frontend. I checked the raw data, and while it appears clean, it's just better practice to match on an id if one is present.
| const map = data.reduce((acc, area) => { | ||
| acc[area.area_id] = area | ||
| return acc | ||
| }, {}) | ||
| setAreaDataMap(map) |
There was a problem hiding this comment.
I veered slightly from the instructions here as well. I added a state variable to map the area data on the same fetch response as setting the current year data. I'm storing the fetched data in two shapes for convenience, as they serve two different purposes.
currentYearData is the array, used for computing totalNumPermits and maxNumPermits with .reduce()
areaDataMap is the same data keyed by area_id, used for fast lookups in setAreaInteraction where we need to find a specific area by its ID.
Branched from main
Overview
This PR completes the DataMade React Map code challenge. It implements a map of Chicago community areas shaded by the number of new restaurant permits issued in a given year, with interactive popups, a year filter, and summary stats.
Changes / Additions
map/serializers.py.area_idadded as a field toCommunityAreaSerializer. The frontend usesarea_idrather than name to key and look up community area data.map/static/js/RestaurantPermitMap.js.useEffectsets the current year's data and builds an area data map for O(1) lookup.getColor()to set community area shading (the darker the color, the more permits per area)setAreaInteraction().tests/test_views.py.Demo
Notes
See changed files for any notes / comments.
Testing Instructions
feature/grant/permit-map-challengeREADME.mdfor instructions)http://localhost:8000/and confirm:docker compose -f docker-compose.yml -f tests/docker-compose.yml run --rm app