Public
HTTP
tmcw-nychargingstations.web.val.run
October 23, 2023
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { fetch } from "https://esm.town/v/std/fetch";
export const nyChargingStations = (async () => {
const { csvParse } = await import("npm:d3-dsv");
const { group } = await import("npm:d3-array");
const { micromark } = await import("npm:micromark");
const rows = await fetch(
"https://data.ny.gov/api/views/7rrd-248n/rows.csv?accessType=DOWNLOAD&sorting=true",
)
.then((r) => r.text())
.then(csvParse);
const facets = ["Groups With Access Code", "Access Days Time", "ZIP"];
let output = `# New York City Charging Station Analytics
From: [NYC Open Data](https://data.ny.gov/Energy-Environment/Electric-Vehicle-Charging-Stations-in-New-York/7rrd-248n) \n\n`;
for (let facet of facets) {
const groups = group(rows, (r) => r[facet]);
output += `# ${facet}\n` +
Array.from(groups.entries(), ([k, v]) => [k, v.length]).sort((
[a, b],
[a1, b1],
) => b1 - b)
.map(([a, b]) => `- ${a}: ${b}`)
.join("\n") +
"\n\n";
}
return new Response(
`<link rel="stylesheet" href="https://unpkg.com/missing.css@1.1.1"><main>` +
micromark(output),
{
headers: {
"Content-Type": "text/html",
},
},
);
});
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023