Skip to content

Commit

Permalink
Set date for first fossil-fuel free community
Browse files Browse the repository at this point in the history
  • Loading branch information
hamogu committed Feb 27, 2024
1 parent 71af480 commit 47011a1
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/MA_energy_codes_town.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/MA_energy_codes_town_future.js

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
info.addTo(map);


// get color depending on population density value
// get color depending building code status
function getColor(d) {
return d == 0 ? '#c5dbd0' :
d == 1 ? '#6fa58a' :
Expand Down Expand Up @@ -150,7 +150,6 @@
const labels = [`<i style="background:${getColor(0)}"></i> Base Energy Code`,
`<i style="background:${getColor(1)}"></i> Stretch Code`,
`<i style="background:${getColor(2)}"></i> Specialized Opt-in Code`,
`<i style="background:${getColor(11)}"></i> Stretch Code &plus; Fossil Fuel Free (draft)`,
`<i style="background:${getColor(12)}"></i> Specialized Opt-in Code &plus; Fossil Fuel Free (draft)`,
];

Expand Down
2 changes: 1 addition & 1 deletion fossil_fuel_free.dat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Arlington
Lexington
Brookline
Brookline 2/20/2024
Acton
Concord
Cambridge
Expand Down
27 changes: 22 additions & 5 deletions make_maps.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
import json
import copy
from datetime import date, timedelta, datetime
from datetime import timedelta, datetime

# Data is downloaded from https://maps.massgis.digital.mass.gov/MassMapper/MassMapper.html
# Using layer: Massachusetts Municipalities Multipar Polygons
Expand All @@ -16,6 +16,7 @@
f['id'] = f['properties']['town']

# Parse input data in three files
fossil_fuel_free_table = re.compile("(?P<name>[a-zA-Z\ ]+)\ (?P<date>[0-9/]+)")
stretch_code_table = re.compile("(?P<name>[a-zA-Z\ ]+)\ [0-9\,]+ (?P<date>[0-9/]+)")
specialized_code_table = re.compile("(?P<name>[a-zA-Z\ ]+)\ [0-9\,]+ (?P<date>[0-9/]+) (?P<specialdate>[0-9/]*)")

Expand All @@ -32,10 +33,18 @@
specialized_opt_in[out.group('name')] = out.group('specialdate')

# Approved list of fossil-fuel free pilot towns
fossil_fuel_free = []
fossil_fuel_free = {}
with open('fossil_fuel_free.dat') as f:
for line in f:
fossil_fuel_free.append(line.strip())
out = fossil_fuel_free_table.search(line)
if out is None:
# Just the name of the town, no date
fossil_fuel_free[line.strip()] = "draft"
else:
# Name and date
fossil_fuel_free[out.group("name")] = out.group("date")

print(fossil_fuel_free)

print(f'Number of municipalities in geojson file: {len(data["features"])}')
print(f'Number of municipalities with base code: {len(data["features"]) - len(stretch_code)}')
Expand All @@ -58,7 +67,12 @@ def USdate_to_ISO(datestr, subtractdays=0):
'properties': town['properties']}
feature['properties']['stretchcode'] = stretch_code.get(name, 'not yet')
feature['properties']['optinstretchcode'] = specialized_opt_in.get(name, 'not yet')
feature['properties']['fossilfuel'] = 'Fossil Fuel Free prioritized community (draft)' if name in fossil_fuel_free else ''
if name in fossil_fuel_free:
feature["properties"][
"fossilfuel"
] = f"Fossil Fuel Free prioritized community: {fossil_fuel_free[name]}"
else:
feature["properties"]["fossilfuel"] = ""

# Special case for towns that left the stretch code program
if name == 'Essex':
Expand All @@ -75,7 +89,10 @@ def USdate_to_ISO(datestr, subtractdays=0):
if name in specialized_opt_in:
dates.append((specialized_opt_in.get(name), 1))
if name in fossil_fuel_free:
dates.append(('07/01/2024', 10))
if fossil_fuel_free[name] == "draft":
dates.append(("07/01/2024", 10))
else:
dates.append((fossil_fuel_free[name], 10))

dates.sort(key=lambda x: datetime.strptime(x[0], '%m/%d/%Y'))

Expand Down

0 comments on commit 47011a1

Please sign in to comment.