Skip to content

Commit 467196c

Browse files
author
msj
committed
Remove code blocks for challenge
1 parent d9aac78 commit 467196c

2 files changed

Lines changed: 39 additions & 36 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: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,18 @@ export default function RestaurantPermitMap() {
4242
const [currentYearData, setCurrentYearData] = useState([])
4343
const [year, setYear] = useState(2026)
4444

45-
const currentUrl = `/map-data/?year=${year}`
45+
const yearlyDataEndpoint = `/map-data/?year=${year}`
4646

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

6458
function getColor(pcntPermits) {
6559
if (pcntPermits > .5)
@@ -73,21 +67,14 @@ export default function RestaurantPermitMap() {
7367
}
7468

7569
function setAreaInteraction(feature, layer) {
76-
const thisAreaData = communityAreaDict[feature.properties.community],
77-
numPermits = thisAreaData.num_permits,
78-
pcntPermits = numPermits / maxNumPermits
79-
layer.setStyle({
80-
color: "#000000",
81-
weight: 1,
82-
fillOpacity: 0.7,
83-
fillColor: getColor(pcntPermits)
84-
})
85-
layer.on("mouseover", () => {
86-
layer.bindPopup(`
87-
<strong>${feature.properties.community}</strong><br />
88-
Year: ${year}<br />
89-
Restaurant permits: ${thisAreaData.num_permits}
90-
`)
70+
/**
71+
* TODO: use the methods below to:
72+
* 1) shade each area according to how many permits it had in a year
73+
* 2) display a popup with area details during user interaction
74+
*/
75+
layer.setStyle()
76+
layer.on("", () => {
77+
layer.bindPopup("")
9178
layer.openPopup()
9279
})
9380
}
@@ -96,11 +83,11 @@ export default function RestaurantPermitMap() {
9683
<>
9784
<YearSelect filterVal={year} setFilterVal={setYear} />
9885
<p className="fs-4">
99-
Restaurant permits issued this year: {totalPermits || "0"}
86+
Restaurant permits issued this year: {/* TODO: display this value */}
10087
</p>
10188
<p className="fs-4">
10289
Maximum number of restaurant permits in a single area:
103-
{" " + (maxNumPermits || "0")}
90+
{/* TODO: display this value */}
10491
</p>
10592
<MapContainer
10693
id="restaurant-map"

0 commit comments

Comments
 (0)