Skip to content

Commit d31bfef

Browse files
allisonhorstAllison HorstmbostockFil
authored
Eia dashboard static version (#1218)
* update to EIA API v2, static CSVs alongside data loaders * minor index annotation & cleanup * Update examples/eia/docs/components/charts.js Co-authored-by: Mike Bostock <[email protected]> * Update examples/eia/docs/components/charts.js Co-authored-by: Mike Bostock <[email protected]> * Update examples/eia/docs/index.md Co-authored-by: Mike Bostock <[email protected]> * Update examples/eia/docs/index.md Co-authored-by: Mike Bostock <[email protected]> * Update examples/eia/docs/components/charts.js Co-authored-by: Mike Bostock <[email protected]> * data update * fix order in area chart * updated static data --------- Co-authored-by: Allison Horst <[email protected]> Co-authored-by: Mike Bostock <[email protected]> Co-authored-by: Philippe Rivière <[email protected]>
1 parent 1201c6c commit d31bfef

File tree

9 files changed

+2354
-78
lines changed

9 files changed

+2354
-78
lines changed

examples/eia/docs/components/charts.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export function usGenDemandForecastChart(width, height, data, currentHour) {
9797
export function countryInterchangeChart(width, height, usDemandGenForecast, countryInterchangeSeries, currentHour) {
9898
return Plot.plot({
9999
width,
100-
marginTop: 0,
100+
marginTop: 10,
101101
height: height - 50,
102102
color: {legend: true, range: ["#B6B5B1", "#848890"]},
103103
grid: true,
@@ -110,9 +110,15 @@ export function countryInterchangeChart(width, height, usDemandGenForecast, coun
110110
y: (d) => d.value / 1000,
111111
curve: "step",
112112
fill: "name",
113-
tip: true
114-
}),
115-
Plot.ruleY([0], {strokeOpacity: 0.3})
113+
order: "sum",
114+
tip: true,
115+
title: (d) =>
116+
`Country: ${d.name}\nDate: ${d.date.toLocaleString("en-US", {
117+
month: "short",
118+
day: "numeric",
119+
hour: "numeric"
120+
})}\nExported: ${(d.value / 1000).toLocaleString("en-US")} GWh`
121+
})
116122
]
117123
});
118124
}
Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
id,name,date,value
2+
CAN,Canada,2024-04-11T04:00Z,2412
3+
MEX,Mexico,2024-04-11T04:00Z,309
4+
CAN,Canada,2024-04-11T03:00Z,2065
5+
MEX,Mexico,2024-04-11T03:00Z,341
6+
MEX,Mexico,2024-04-11T02:00Z,245
7+
CAN,Canada,2024-04-11T02:00Z,1862
8+
CAN,Canada,2024-04-11T01:00Z,470
9+
MEX,Mexico,2024-04-11T01:00Z,258
10+
MEX,Mexico,2024-04-11,390
11+
CAN,Canada,2024-04-11,241
12+
CAN,Canada,2024-04-10T23:00Z,66
13+
MEX,Mexico,2024-04-10T23:00Z,472
14+
CAN,Canada,2024-04-10T22:00Z,1049
15+
MEX,Mexico,2024-04-10T22:00Z,429
16+
MEX,Mexico,2024-04-10T21:00Z,412
17+
CAN,Canada,2024-04-10T21:00Z,1317
18+
MEX,Mexico,2024-04-10T20:00Z,423
19+
CAN,Canada,2024-04-10T20:00Z,1837
20+
CAN,Canada,2024-04-10T19:00Z,1745
21+
MEX,Mexico,2024-04-10T19:00Z,436
22+
CAN,Canada,2024-04-10T18:00Z,1679
23+
MEX,Mexico,2024-04-10T18:00Z,392
24+
CAN,Canada,2024-04-10T17:00Z,1353
25+
MEX,Mexico,2024-04-10T17:00Z,321
26+
MEX,Mexico,2024-04-10T16:00Z,166
27+
CAN,Canada,2024-04-10T16:00Z,1685
28+
CAN,Canada,2024-04-10T15:00Z,1001
29+
MEX,Mexico,2024-04-10T15:00Z,130
30+
MEX,Mexico,2024-04-10T14:00Z,135
31+
CAN,Canada,2024-04-10T14:00Z,990
32+
MEX,Mexico,2024-04-10T13:00Z,67
33+
CAN,Canada,2024-04-10T13:00Z,1843
34+
CAN,Canada,2024-04-10T12:00Z,780
35+
MEX,Mexico,2024-04-10T12:00Z,64
36+
MEX,Mexico,2024-04-10T11:00Z,59
37+
CAN,Canada,2024-04-10T11:00Z,1844
38+
MEX,Mexico,2024-04-10T10:00Z,61
39+
CAN,Canada,2024-04-10T10:00Z,2216
40+
CAN,Canada,2024-04-10T09:00Z,1763
41+
MEX,Mexico,2024-04-10T09:00Z,58
42+
MEX,Mexico,2024-04-10T08:00Z,55
43+
CAN,Canada,2024-04-10T08:00Z,2193
44+
CAN,Canada,2024-04-10T07:00Z,2185
45+
MEX,Mexico,2024-04-10T07:00Z,94
46+
CAN,Canada,2024-04-10T06:00Z,2175
47+
MEX,Mexico,2024-04-10T06:00Z,106
48+
MEX,Mexico,2024-04-10T05:00Z,193
49+
CAN,Canada,2024-04-10T05:00Z,1724
50+
MEX,Mexico,2024-04-10T04:00Z,191
51+
CAN,Canada,2024-04-10T04:00Z,1500
52+
CAN,Canada,2024-04-10T03:00Z,1491
53+
MEX,Mexico,2024-04-10T03:00Z,223
54+
MEX,Mexico,2024-04-10T02:00Z,109
55+
CAN,Canada,2024-04-10T02:00Z,493
56+
MEX,Mexico,2024-04-10T01:00Z,198
57+
CAN,Canada,2024-04-10T01:00Z,-1110
58+
CAN,Canada,2024-04-10,-1100
59+
MEX,Mexico,2024-04-10,291
60+
MEX,Mexico,2024-04-09T23:00Z,322
61+
CAN,Canada,2024-04-09T23:00Z,87
62+
CAN,Canada,2024-04-09T22:00Z,825
63+
MEX,Mexico,2024-04-09T22:00Z,389
64+
CAN,Canada,2024-04-09T21:00Z,1233
65+
MEX,Mexico,2024-04-09T21:00Z,382
66+
MEX,Mexico,2024-04-09T20:00Z,384
67+
CAN,Canada,2024-04-09T20:00Z,896
68+
MEX,Mexico,2024-04-09T19:00Z,397
69+
CAN,Canada,2024-04-09T19:00Z,1401
70+
MEX,Mexico,2024-04-09T18:00Z,341
71+
CAN,Canada,2024-04-09T18:00Z,1277
72+
MEX,Mexico,2024-04-09T17:00Z,370
73+
CAN,Canada,2024-04-09T17:00Z,1679
74+
MEX,Mexico,2024-04-09T16:00Z,246
75+
CAN,Canada,2024-04-09T16:00Z,711
76+
MEX,Mexico,2024-04-09T15:00Z,151
77+
CAN,Canada,2024-04-09T15:00Z,777
78+
MEX,Mexico,2024-04-09T14:00Z,113
79+
CAN,Canada,2024-04-09T14:00Z,1144
80+
CAN,Canada,2024-04-09T13:00Z,1258
81+
MEX,Mexico,2024-04-09T13:00Z,64
82+
CAN,Canada,2024-04-09T12:00Z,-119
83+
MEX,Mexico,2024-04-09T12:00Z,67
84+
CAN,Canada,2024-04-09T11:00Z,740
85+
MEX,Mexico,2024-04-09T11:00Z,61
86+
MEX,Mexico,2024-04-09T10:00Z,66
87+
CAN,Canada,2024-04-09T10:00Z,1987
88+
MEX,Mexico,2024-04-09T09:00Z,152
89+
CAN,Canada,2024-04-09T09:00Z,1946
90+
CAN,Canada,2024-04-09T08:00Z,2240
91+
MEX,Mexico,2024-04-09T08:00Z,168
92+
CAN,Canada,2024-04-09T07:00Z,2336
93+
MEX,Mexico,2024-04-09T07:00Z,163
94+
MEX,Mexico,2024-04-09T06:00Z,65
95+
CAN,Canada,2024-04-09T06:00Z,2359
96+
CAN,Canada,2024-04-09T05:00Z,1994
97+
MEX,Mexico,2024-04-09T05:00Z,245
98+
MEX,Mexico,2024-04-09T04:00Z,252
99+
CAN,Canada,2024-04-09T04:00Z,2141
100+
CAN,Canada,2024-04-09T03:00Z,1616
101+
MEX,Mexico,2024-04-09T03:00Z,186
102+
CAN,Canada,2024-04-09T02:00Z,-322
103+
MEX,Mexico,2024-04-09T02:00Z,114
104+
MEX,Mexico,2024-04-09T01:00Z,157
105+
CAN,Canada,2024-04-09T01:00Z,-1071
106+
MEX,Mexico,2024-04-09,377
107+
CAN,Canada,2024-04-09,-785
108+
CAN,Canada,2024-04-08T23:00Z,556
109+
MEX,Mexico,2024-04-08T23:00Z,370
110+
MEX,Mexico,2024-04-08T22:00Z,399
111+
CAN,Canada,2024-04-08T22:00Z,1183
112+
MEX,Mexico,2024-04-08T21:00Z,412
113+
CAN,Canada,2024-04-08T21:00Z,1413
114+
CAN,Canada,2024-04-08T20:00Z,792
115+
MEX,Mexico,2024-04-08T20:00Z,330
116+
CAN,Canada,2024-04-08T19:00Z,1402
117+
MEX,Mexico,2024-04-08T19:00Z,167
118+
MEX,Mexico,2024-04-08T18:00Z,115
119+
CAN,Canada,2024-04-08T18:00Z,1378
120+
MEX,Mexico,2024-04-08T17:00Z,152
121+
CAN,Canada,2024-04-08T17:00Z,1425
122+
CAN,Canada,2024-04-08T16:00Z,1295
123+
MEX,Mexico,2024-04-08T16:00Z,111
124+
MEX,Mexico,2024-04-08T15:00Z,18
125+
CAN,Canada,2024-04-08T15:00Z,1192
126+
CAN,Canada,2024-04-08T14:00Z,923
127+
MEX,Mexico,2024-04-08T14:00Z,-16
128+
CAN,Canada,2024-04-08T13:00Z,814
129+
MEX,Mexico,2024-04-08T13:00Z,-27
130+
MEX,Mexico,2024-04-08T12:00Z,-18
131+
CAN,Canada,2024-04-08T12:00Z,-751
132+
MEX,Mexico,2024-04-08T11:00Z,-34
133+
CAN,Canada,2024-04-08T11:00Z,92
134+
CAN,Canada,2024-04-08T10:00Z,1005
135+
MEX,Mexico,2024-04-08T10:00Z,-43
136+
MEX,Mexico,2024-04-08T09:00Z,-27
137+
CAN,Canada,2024-04-08T09:00Z,1226
138+
CAN,Canada,2024-04-08T08:00Z,1610
139+
MEX,Mexico,2024-04-08T08:00Z,-36
140+
MEX,Mexico,2024-04-08T07:00Z,-37
141+
CAN,Canada,2024-04-08T07:00Z,1659
142+
MEX,Mexico,2024-04-08T06:00Z,-37
143+
CAN,Canada,2024-04-08T06:00Z,1364
144+
CAN,Canada,2024-04-08T05:00Z,1228
145+
MEX,Mexico,2024-04-08T05:00Z,67
146+
MEX,Mexico,2024-04-08T04:00Z,112
147+
CAN,Canada,2024-04-08T04:00Z,1710
148+
MEX,Mexico,2024-04-08T03:00Z,7
149+
CAN,Canada,2024-04-08T03:00Z,680
150+
CAN,Canada,2024-04-08T02:00Z,-287
151+
MEX,Mexico,2024-04-08T02:00Z,-198
152+
CAN,Canada,2024-04-08T01:00Z,361
153+
MEX,Mexico,2024-04-08T01:00Z,-179
154+
CAN,Canada,2024-04-08,418
155+
MEX,Mexico,2024-04-08,-112
156+
MEX,Mexico,2024-04-07T23:00Z,-49
157+
CAN,Canada,2024-04-07T23:00Z,1268
158+
MEX,Mexico,2024-04-07T22:00Z,-47
159+
CAN,Canada,2024-04-07T22:00Z,2139
160+
MEX,Mexico,2024-04-07T21:00Z,105
161+
CAN,Canada,2024-04-07T21:00Z,2715
162+
MEX,Mexico,2024-04-07T20:00Z,111
163+
CAN,Canada,2024-04-07T20:00Z,2603
164+
MEX,Mexico,2024-04-07T19:00Z,129
165+
CAN,Canada,2024-04-07T19:00Z,2362
166+
CAN,Canada,2024-04-07T18:00Z,2335
167+
MEX,Mexico,2024-04-07T18:00Z,152
168+
MEX,Mexico,2024-04-07T17:00Z,90
169+
CAN,Canada,2024-04-07T17:00Z,2355
170+
CAN,Canada,2024-04-07T16:00Z,1803
171+
MEX,Mexico,2024-04-07T16:00Z,56
172+
CAN,Canada,2024-04-07T15:00Z,1934
173+
MEX,Mexico,2024-04-07T15:00Z,0
174+
CAN,Canada,2024-04-07T14:00Z,2183
175+
MEX,Mexico,2024-04-07T14:00Z,-22
176+
CAN,Canada,2024-04-07T13:00Z,1903
177+
MEX,Mexico,2024-04-07T13:00Z,28
178+
CAN,Canada,2024-04-07T12:00Z,1617
179+
MEX,Mexico,2024-04-07T12:00Z,28
180+
CAN,Canada,2024-04-07T11:00Z,1754
181+
MEX,Mexico,2024-04-07T11:00Z,131
182+
CAN,Canada,2024-04-07T10:00Z,2165
183+
MEX,Mexico,2024-04-07T10:00Z,151
184+
MEX,Mexico,2024-04-07T09:00Z,153
185+
CAN,Canada,2024-04-07T09:00Z,2856
186+
CAN,Canada,2024-04-07T08:00Z,2668
187+
MEX,Mexico,2024-04-07T08:00Z,152
188+
MEX,Mexico,2024-04-07T07:00Z,135
189+
CAN,Canada,2024-04-07T07:00Z,3119
190+
CAN,Canada,2024-04-07T06:00Z,3237
191+
MEX,Mexico,2024-04-07T06:00Z,68
192+
MEX,Mexico,2024-04-07T05:00Z,146
193+
CAN,Canada,2024-04-07T05:00Z,1882
194+
MEX,Mexico,2024-04-07T04:00Z,180
195+
CAN,Canada,2024-04-07T04:00Z,1846
196+
MEX,Mexico,2024-04-07T03:00Z,189
197+
CAN,Canada,2024-04-07T03:00Z,1298
198+
MEX,Mexico,2024-04-07T02:00Z,173
199+
CAN,Canada,2024-04-07T02:00Z,658
200+
MEX,Mexico,2024-04-07T01:00Z,190
201+
CAN,Canada,2024-04-07T01:00Z,685
202+
CAN,Canada,2024-04-07,912
203+
MEX,Mexico,2024-04-07,116
204+
MEX,Mexico,2024-04-06T23:00Z,132
205+
CAN,Canada,2024-04-06T23:00Z,1643
206+
MEX,Mexico,2024-04-06T22:00Z,180
207+
CAN,Canada,2024-04-06T22:00Z,1659
208+
CAN,Canada,2024-04-06T21:00Z,2845
209+
MEX,Mexico,2024-04-06T21:00Z,197
210+
CAN,Canada,2024-04-06T20:00Z,3037
211+
MEX,Mexico,2024-04-06T20:00Z,165
212+
MEX,Mexico,2024-04-06T19:00Z,164
213+
CAN,Canada,2024-04-06T19:00Z,3083
214+
MEX,Mexico,2024-04-06T18:00Z,179
215+
CAN,Canada,2024-04-06T18:00Z,2943
216+
MEX,Mexico,2024-04-06T17:00Z,174
217+
CAN,Canada,2024-04-06T17:00Z,2690
218+
CAN,Canada,2024-04-06T16:00Z,1987
219+
MEX,Mexico,2024-04-06T16:00Z,136
Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
1+
import "dotenv/config";
12
import * as d3 from "d3";
23

4+
// Access key from .env
5+
const {EIA_KEY} = process.env;
6+
37
const end = d3.timeDay.offset(d3.timeHour(new Date()), 1);
48
const start = d3.timeHour(d3.utcDay.offset(end, -7));
5-
const convertDate = d3.timeFormat("%m%d%Y %H:%M:%S"); // Convert dates into the format the EIA web API expects
9+
const convertDate = d3.timeFormat("%Y-%m-%dT%H");
610

711
// Electricity exported (in GWh) from the lower 48 US states to Canada and Mexico
8-
const countryInterchangeUrl = `https://www.eia.gov/electricity/930-api/interchange/series_data?type[0]=TI&start=${convertDate(start)}&end=${convertDate(end)}&frequency=hourly&from_respondent[0]=US48&timezone=Eastern&limit=10000&offset=0`;
12+
const countryInterchangeUrl = `https://api.eia.gov/v2/electricity/rto/interchange-data/data/?api_key=${EIA_KEY}&frequency=hourly&data[0]=value&facets[fromba][]=US48&start=${convertDate(
13+
start
14+
)}&end=${convertDate(end)}&sort[0][column]=period&sort[0][direction]=desc&offset=0&length=5000`;
15+
16+
const countryInterchange = await d3.json(countryInterchangeUrl);
917

10-
const tidySeries = (response, id, name) => {
11-
let series = response[0].data;
12-
let datetimeFormat = d3.utcParse("%m/%d/%Y %H:%M:%S");
13-
let dateFormat = d3.utcParse("%m/%d/%Y");
14-
return series.flatMap((s) => {
15-
return s.VALUES.DATES.map((d, i) => {
16-
return {
17-
id: s[id],
18-
name: s[name],
19-
date: datetimeFormat(d) ?? dateFormat(d),
20-
value: s.VALUES.DATA[i]
21-
};
22-
});
23-
});
24-
};
18+
const dateParse = d3.utcParse("%Y-%m-%dT%H");
2519

26-
const countryInterchangeSeries = await d3.json(countryInterchangeUrl).then((response) => {
27-
return tidySeries(response, "TO_RESPONDENT_ID", "TO_RESPONDENT_NAME");
28-
});
20+
const countryInterchangeSeries = await countryInterchange.response.data.map((d) => ({
21+
id: d.toba,
22+
name: d["toba-name"],
23+
date: dateParse(d.period),
24+
value: +d.value
25+
}));
2926

3027
process.stdout.write(d3.csvFormat(countryInterchangeSeries));

0 commit comments

Comments
 (0)