Skip to content

Commit 7e088b8

Browse files
author
msj
committed
Remove code blocks for challenge
1 parent 6759816 commit 7e088b8

2 files changed

Lines changed: 38 additions & 32 deletions

File tree

map/serializers.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,24 @@ class Meta:
1111
num_permits = serializers.SerializerMethodField()
1212

1313
def get_num_permits(self, obj):
14-
year = self.context.get("year", 2026)
14+
"""
15+
TODO: supplement each community area object with the number
16+
of permits issued in the given year.
1517
16-
return RestaurantPermit.objects.filter(
17-
community_area_id=str(obj.area_id), issue_date__year=year
18-
).count()
18+
e.g. The endpoint /map-data/?year=2017 should return something like:
19+
[
20+
{
21+
"ROGERS PARK": {
22+
area_id: 17,
23+
num_permits: 2
24+
},
25+
"BEVERLY": {
26+
area_id: 72,
27+
num_permits: 2
28+
},
29+
...
30+
}
31+
]
32+
"""
33+
34+
pass

map/static/js/RestaurantPermitMap.js

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -40,37 +40,27 @@ export default function RestaurantPermitMap() {
4040
const [currentYearData, setCurrentYearData] = useState([])
4141
const [year, setYear] = useState(2026)
4242

43-
const currentUrl = `/map-data/?year=${year}`
43+
const yearlyDataEndpoint = `/map-data/?year=${year}`
4444

45-
const totalPermits = currentYearData.reduce(
46-
(acc, curr) => acc + curr.num_permits,
47-
0
48-
)
49-
const maxNumPermits = Math.max(...currentYearData.map((c) => c.num_permits))
50-
51-
const communityAreaDict = Object.fromEntries(
52-
currentYearData.map((d) => [d.name, d])
53-
)
54-
55-
// Get values for community areas
5645
useEffect(() => {
57-
fetch(currentUrl)
46+
fetch()
5847
.then((res) => res.json())
59-
.then((data) => setCurrentYearData(data))
60-
}, [currentUrl])
48+
.then((data) => {
49+
/**
50+
* TODO: Fetch the data needed to supply to map with data
51+
*/
52+
})
53+
}, [yearlyDataEndpoint])
6154

6255
function setAreaInteraction(feature, layer) {
63-
const thisAreaData = communityAreaDict[feature.properties.community],
64-
numPermits = thisAreaData.num_permits,
65-
pcntPermits = numPermits / maxNumPermits
66-
layer.setStyle({
67-
fillOpacity: pcntPermits,
68-
})
69-
layer.on("mouseover", () => {
70-
layer.bindPopup(`
71-
<h3>${feature.properties.community}</h3>
72-
<p>Restaurant permits issued during ${year}: ${thisAreaData.num_permits}</p>
73-
`)
56+
/**
57+
* TODO: use the methods below to:
58+
* 1) shade each area according to how many permits it had in a year
59+
* 2) display a popup with area details during user interaction
60+
*/
61+
layer.setStyle()
62+
layer.on("", () => {
63+
layer.bindPopup("")
7464
layer.openPopup()
7565
})
7666
}
@@ -79,11 +69,11 @@ export default function RestaurantPermitMap() {
7969
<>
8070
<YearSelect filterVal={year} setFilterVal={setYear} />
8171
<p className="fs-4">
82-
Restaurant permits issued this year: {totalPermits || "0"}
72+
Restaurant permits issued this year: {/* TODO: display this value */}
8373
</p>
8474
<p className="fs-4">
8575
Maximum number of restaurant permits in a single area:
86-
{" " + (maxNumPermits || "0")}
76+
{/* TODO: display this value */}
8777
</p>
8878
<MapContainer
8979
id="restaurant-map"

0 commit comments

Comments
 (0)