Skip to content

Commit

Permalink
Fix display for static version to last known datapoint
Browse files Browse the repository at this point in the history
  • Loading branch information
hamogu committed Oct 30, 2023
1 parent 9b7dbcf commit f6985b9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/MA_energy_codes_town_future.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/plain.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

<div id='map'></div>

<script type="text/javascript" src="MA_energy_codes_town.js"></script>
<script type="text/javascript" src="MA_energy_codes_town_future.js"></script>

<script type="text/javascript">

Expand Down
17 changes: 13 additions & 4 deletions make_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ def USdate_to_ISO(datestr, subtractdays=0):
return (datetime.strptime(datestr, '%m/%d/%Y') -
timedelta(days=subtractdays)).isoformat()

# Now we build up the geojson file with the data we want to display
featurelist = []
# Now we build up the geojson files with the data we want to display
featurelist = [] # for timeline
featurelist_future = [] # for plain version, capture last known date

for town in data['features']:
name = town['properties']['town'].title()
Expand All @@ -59,7 +60,7 @@ def USdate_to_ISO(datestr, subtractdays=0):
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 ''

# Special case for the town of Essex, the only one that unadopted the code
# Special case for towns that left the stretch code program
if name == 'Essex':
feature['properties']['stretchcode'] = '1/1/2015 - 5/8/2023'
dates = [('01/01/2009', 0), ('01/01/2015', 1), ('05/08/2023', -1), ('01/02/2025', None)]
Expand Down Expand Up @@ -87,14 +88,22 @@ def USdate_to_ISO(datestr, subtractdays=0):
code['properties']['end'] = USdate_to_ISO(dates[i + 1][0], subtractdays=1)
featurelist.append(code)

outdata = {'type': 'FeatureCollection', 'features': featurelist}
# Add last known data point - the one most in the future
# i.e. the last thing the town has adopted so far
featurelist_future.append(code)


# And write it into docs/MA_energy_codes_town.js such that it's read directly as a javascript file
# That way, we get a file very similar to https://leafletjs.com/examples/choropleth/
outdata = {'type': 'FeatureCollection', 'features': featurelist}
with open('docs/MA_energy_codes_town.js', 'w') as f:
f.write('var townsData = ' + json.dumps(outdata) + ';')

outdata = {'type': 'FeatureCollection', 'features': featurelist_future}
with open('docs/MA_energy_codes_town_future.js', 'w') as f:
f.write('var townsData = ' + json.dumps(outdata) + ';')


base_code = []
for town in data['features']:
name = town['properties']['town'].title()
Expand Down

0 comments on commit f6985b9

Please sign in to comment.