Skip to content

Commit 0e128d4

Browse files
authored
Ian/add data dictionary (#26)
* add datadictionary, readme, zip for csv download * add geojson zip download * add favicon
1 parent c77bd66 commit 0e128d4

File tree

5 files changed

+86
-24
lines changed

5 files changed

+86
-24
lines changed

layouts/index.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
77
<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" />
88
<link rel="stylesheet" href="{{ "css/style.css" | absURL }}">
9+
<link rel="icon" href="{{ "images/favicon.png" | absURL }}" type="image/x-icon">
910
</head>
1011
<body>
1112
<div id="sidebar">
@@ -145,8 +146,10 @@ <h2>Funding</h2>
145146
</div>
146147
<div id="map"></div>
147148

148-
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
149-
<script src="https://cdn.jsdelivr.net/npm/papaparse@5.4.1/papaparse.min.js"></script>
149+
<!-- <script src="https://unpkg.com/leaflet/dist/leaflet.js"></script> -->
150+
<script src="https://cdn.jsdelivr.net/npm/leaflet@1.9/dist/leaflet.min.js"></script>
151+
<script src="https://cdn.jsdelivr.net/npm/papaparse@5.5/papaparse.min.js"></script>
152+
<script src="https://cdn.jsdelivr.net/npm/jszip@3.10/dist/jszip.min.js"></script>
150153
<script src="{{ "js/script.js" | absURL }}"></script>
151154
</body>
152155
</html>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
ColumnName, Description, MeasurementUnit,
2+
TractLong,Census tract identifier,NA,
3+
CensusTractName, Name of tract as defined by US Census, NA,
4+
MedianYearBuilt, Median year of construction of the residential housing stock in the census tract, Year,
5+
MedianBuildingSqft, Median square footage of the residential housing stock in the census tract including garages, Square Feet,
6+
AverageHouseholdElectricityMmbtu,Average energy used to electrify a household in the census tract,MMBTU,
7+
AverageHouseholdSpaceHeatingMmbtu,Average energy used to heat a household in the census tract,MMBTU,
8+
AverageHouseholdElectricityCost,Average financial cost to electrify a household in the census tract,USD,
9+
AverageHouseholdSpaceHeatingCost,Average financial cost to heat a household in the census tract,USD,
10+
MedianHouseholdIncome, Median household income of residents in the census tract,USD,
11+
EnergyBurden, Share of gross household income spend on residential energy services such as space heating and electricity,Percent,
12+
ElectricityPriceInput, Retail residential price of electricity input value in web app when download button pushed (may be user defined),USD/kWh,
13+
HeatingFuelOilPriceInput, Retail residential price of heating fuel oil input value in web app when download button pushed (may be user defined),USD/gallon,
14+
CordWoodPriceInput, Retail residential price of cordwood input value in web app when download button pushed (may be user defined),USD/cord,
15+
NaturalGasPriceInput, Retail residential price of natural gas input value in web app when download button pushed (may be user defined),USD/centum cubic foot,
16+
PelletPriceInput, Retail residential price of pellets input value in web app when download button pushed (may be user defined),USD/ton,
17+
CoalPriceInput, Retail residential price of coal input value in web app when download button pushed (may be user defined),USD/ton,
18+
DistrictHeatPriceInput, Retail residential price of district heating input value in web app when download button pushed (may be user defined),USD/1000 lbs steam,

static/data/zipReadme.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This ZIP contains:
2+
- fairbanksEnergyBurden(.csv/.geojson), a data file containing both source data and user-inputs from the app at the moment of download.
3+
- fairbanksEnergyBurdenDataDictionary.csv, a data dictionary of columns and their respective descriptions

static/images/favicon.png

28.8 KB
Loading

static/js/script.js

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ document.addEventListener("DOMContentLoaded", async () => {
182182
});
183183

184184

185-
document.getElementById("download-csv").addEventListener("click", (e) => {
185+
document.getElementById("download-csv").addEventListener("click", async (e) => {
186186
const prices = getUserPrices();
187187
const { result: dataWithResults } = processData(rawData, prices);
188188

@@ -238,19 +238,34 @@ document.addEventListener("DOMContentLoaded", async () => {
238238
]);
239239
}
240240

241-
const csvContent = csvRows.map(r => r.join(",")).join("\n");
242-
const blob = new Blob([csvContent], { type: "text/csv" });
243-
const url = URL.createObjectURL(blob);
244-
245-
const a = document.createElement("a");
246-
a.href = url;
247-
a.download = "fairbanksEnergyBurden.csv";
248-
a.click();
241+
const zip = new JSZip();
242+
243+
// compile dynamically-generated CSV
244+
const csvData = csvRows.map(r => r.join(",")).join("\n");
245+
zip.file("fairbanksEnergyBurden.csv", csvData)
246+
247+
// pull static CSV
248+
const dataDictionaryResponse = await fetch("data/fairbanksEnergyBurdenDataDictionary.csv");
249+
if (!dataDictionaryResponse.ok) throw new Error("Failed to fetch data dictionary");
250+
const dataDictionaryCsv = await dataDictionaryResponse.text();
251+
zip.file("fairbanksEnergyBurdenDataDictionary.csv", dataDictionaryCsv);
252+
253+
// pull static CSV
254+
const readMeResponse = await fetch("data/zipReadme.txt");
255+
if (!readMeResponse.ok) throw new Error("Failed to fetch data/README");
256+
const readmeTxt = await readMeResponse.text();
257+
zip.file("README.txt", readmeTxt);
258+
259+
// zip it all together
260+
const blob = await zip.generateAsync({ type: "blob" });
261+
const link = document.createElement("a");
262+
link.href = URL.createObjectURL(blob);
263+
link.download = "fairbanksEnergyBurden.zip";
264+
link.click();
249265

250-
setTimeout(() => URL.revokeObjectURL(url), 1000);
251266
});
252267

253-
document.getElementById("download-geojson").addEventListener("click", () => {
268+
document.getElementById("download-geojson").addEventListener("click", async (e) => {
254269
const prices = getUserPrices();
255270
const { result: dataWithResults } = processData(rawData, prices);
256271

@@ -296,17 +311,40 @@ document.addEventListener("DOMContentLoaded", async () => {
296311
};
297312
})
298313
};
299-
300-
// Download the GeoJSON
301-
const blob = new Blob([JSON.stringify(geojson, null, 2)], { type: "application/geo+json" });
302-
const url = URL.createObjectURL(blob);
303-
304-
const a = document.createElement("a");
305-
a.href = url;
306-
a.download = "fairbanksEnergyBurden.geojson";
307-
a.click();
308-
309-
setTimeout(() => URL.revokeObjectURL(url), 1000);
314+
315+
const zip = JSZip();
316+
317+
// compile dynamically-generated geojson
318+
const jsonData = JSON.stringify(geojson, null, 2)
319+
zip.file("fairbanksEnergyBurden.geojson", jsonData)
320+
321+
// pull static CSV
322+
const dataDictionaryResponse = await fetch("data/fairbanksEnergyBurdenDataDictionary.csv");
323+
if (!dataDictionaryResponse.ok) throw new Error("Failed to fetch data dictionary");
324+
const dataDictionaryCsv = await dataDictionaryResponse.text();
325+
zip.file("fairbanksEnergyBurdenDataDictionary.csv", dataDictionaryCsv);
326+
327+
// pull static CSV
328+
const readMeResponse = await fetch("data/zipReadme.txt");
329+
if (!readMeResponse.ok) throw new Error("Failed to fetch data/README");
330+
const readmeTxt = await readMeResponse.text();
331+
zip.file("README.txt", readmeTxt);
332+
333+
// zip it all together
334+
const blob = await zip.generateAsync({ type: "blob" });
335+
const link = document.createElement("a");
336+
link.href = URL.createObjectURL(blob);
337+
link.download = "fairbanksEnergyBurden.zip";
338+
link.click();
339+
340+
// // Download the GeoJSON
341+
// const blob = new Blob([JSON.stringify(geojson, null, 2)], { type: "application/geo+json" });
342+
// const url = URL.createObjectURL(blob);
343+
// const a = document.createElement("a");
344+
// a.href = url;
345+
// a.download = "fairbanksEnergyBurden.geojson";
346+
// a.click();
347+
// setTimeout(() => URL.revokeObjectURL(url), 1000);
310348
});
311349

312350
}

0 commit comments

Comments
 (0)