Skip to content

Commit 923f601

Browse files
authored
fix(parsers): NZ production parser slipped through the net (#8145)
- return a list instead of a dict after type checking was enforced
1 parent 9db3ca7 commit 923f601

File tree

2 files changed

+109
-95
lines changed

2 files changed

+109
-95
lines changed

parsers/NZ.py

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -95,41 +95,51 @@ def fetch_production(
9595
region_key = "New Zealand"
9696
productions = obj["soPgenGraph"]["data"][region_key]
9797

98-
data = {
99-
"zoneKey": zone_key,
100-
"datetime": date_time,
101-
"production": {
102-
"coal": productions.get("Coal", {"generation": None})["generation"],
103-
"oil": productions.get("Diesel/Oil", {"generation": None})["generation"],
104-
"gas": productions.get("Gas", {"generation": None})["generation"],
105-
"geothermal": productions.get("Geothermal", {"generation": None})[
106-
"generation"
107-
],
108-
"wind": productions.get("Wind", {"generation": None})["generation"],
109-
"hydro": productions.get("Hydro", {"generation": None})["generation"],
110-
"solar": productions.get("Solar", {"generation": None})["generation"],
111-
"unknown": productions.get("Co-Gen", {"generation": None})["generation"],
112-
"nuclear": 0, # famous issue in NZ politics
113-
},
114-
"capacity": {
115-
"coal": productions.get("Coal", {"capacity": None})["capacity"],
116-
"oil": productions.get("Diesel/Oil", {"capacity": None})["capacity"],
117-
"gas": productions.get("Gas", {"capacity": None})["capacity"],
118-
"geothermal": productions.get("Geothermal", {"capacity": None})["capacity"],
119-
"wind": productions.get("Wind", {"capacity": None})["capacity"],
120-
"hydro": productions.get("Hydro", {"capacity": None})["capacity"],
121-
"solar": productions.get("Solar", {"capacity": None})["capacity"],
122-
"battery storage": productions.get("Battery", {"capacity": None})[
123-
"capacity"
124-
],
125-
"unknown": productions.get("Co-Gen", {"capacity": None})["capacity"],
126-
"nuclear": 0, # famous issue in NZ politics
127-
},
128-
"storage": {
129-
"battery": productions.get("Battery", {"generation": None})["generation"],
130-
},
131-
"source": "transpower.co.nz",
132-
}
98+
data = [
99+
{
100+
"zoneKey": zone_key,
101+
"datetime": date_time,
102+
"production": {
103+
"coal": productions.get("Coal", {"generation": None})["generation"],
104+
"oil": productions.get("Diesel/Oil", {"generation": None})[
105+
"generation"
106+
],
107+
"gas": productions.get("Gas", {"generation": None})["generation"],
108+
"geothermal": productions.get("Geothermal", {"generation": None})[
109+
"generation"
110+
],
111+
"wind": productions.get("Wind", {"generation": None})["generation"],
112+
"hydro": productions.get("Hydro", {"generation": None})["generation"],
113+
"solar": productions.get("Solar", {"generation": None})["generation"],
114+
"unknown": productions.get("Co-Gen", {"generation": None})[
115+
"generation"
116+
],
117+
"nuclear": 0, # famous issue in NZ politics
118+
},
119+
"capacity": {
120+
"coal": productions.get("Coal", {"capacity": None})["capacity"],
121+
"oil": productions.get("Diesel/Oil", {"capacity": None})["capacity"],
122+
"gas": productions.get("Gas", {"capacity": None})["capacity"],
123+
"geothermal": productions.get("Geothermal", {"capacity": None})[
124+
"capacity"
125+
],
126+
"wind": productions.get("Wind", {"capacity": None})["capacity"],
127+
"hydro": productions.get("Hydro", {"capacity": None})["capacity"],
128+
"solar": productions.get("Solar", {"capacity": None})["capacity"],
129+
"battery storage": productions.get("Battery", {"capacity": None})[
130+
"capacity"
131+
],
132+
"unknown": productions.get("Co-Gen", {"capacity": None})["capacity"],
133+
"nuclear": 0, # famous issue in NZ politics
134+
},
135+
"storage": {
136+
"battery": productions.get("Battery", {"generation": None})[
137+
"generation"
138+
],
139+
},
140+
"source": "transpower.co.nz",
141+
}
142+
]
133143

134144
return data
135145

parsers/test/__snapshots__/test_NZ.ambr

Lines changed: 64 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -23,67 +23,71 @@
2323
# ---
2424
# name: test_snapshot_production_data
2525
list([
26-
dict({
27-
'capacity': dict({
28-
'battery storage': 35,
29-
'coal': 750,
30-
'gas': 1280,
31-
'geothermal': 1062,
32-
'hydro': 5415,
33-
'nuclear': 0,
34-
'oil': 156,
35-
'solar': 47,
36-
'unknown': 168,
37-
'wind': 1259,
38-
}),
39-
'datetime': datetime.datetime(2024, 4, 24, 18, 0, tzinfo=datetime.timezone.utc),
40-
'production': dict({
41-
'coal': 156,
42-
'gas': 252,
43-
'geothermal': 964,
44-
'hydro': 1644,
45-
'nuclear': 0,
46-
'oil': 0,
47-
'solar': 0,
48-
'unknown': 117,
49-
'wind': 814,
50-
}),
51-
'source': 'transpower.co.nz',
52-
'storage': dict({
53-
'battery': 0,
54-
}),
55-
'zoneKey': 'NZ',
56-
}),
57-
dict({
58-
'capacity': dict({
59-
'battery storage': 35,
60-
'coal': 750,
61-
'gas': 1280,
62-
'geothermal': 1062,
63-
'hydro': 5415,
64-
'nuclear': 0,
65-
'oil': 156,
66-
'solar': 47,
67-
'unknown': 168,
68-
'wind': 1259,
69-
}),
70-
'datetime': datetime.datetime(2024, 4, 24, 18, 0, tzinfo=datetime.timezone.utc),
71-
'production': dict({
72-
'coal': 156,
73-
'gas': 252,
74-
'geothermal': 964,
75-
'hydro': 1644,
76-
'nuclear': 0,
77-
'oil': 0,
78-
'solar': 0,
79-
'unknown': 117,
80-
'wind': 814,
26+
list([
27+
dict({
28+
'capacity': dict({
29+
'battery storage': 35,
30+
'coal': 750,
31+
'gas': 1280,
32+
'geothermal': 1062,
33+
'hydro': 5415,
34+
'nuclear': 0,
35+
'oil': 156,
36+
'solar': 47,
37+
'unknown': 168,
38+
'wind': 1259,
39+
}),
40+
'datetime': datetime.datetime(2024, 4, 24, 18, 0, tzinfo=datetime.timezone.utc),
41+
'production': dict({
42+
'coal': 156,
43+
'gas': 252,
44+
'geothermal': 964,
45+
'hydro': 1644,
46+
'nuclear': 0,
47+
'oil': 0,
48+
'solar': 0,
49+
'unknown': 117,
50+
'wind': 814,
51+
}),
52+
'source': 'transpower.co.nz',
53+
'storage': dict({
54+
'battery': 0,
55+
}),
56+
'zoneKey': 'NZ',
8157
}),
82-
'source': 'transpower.co.nz',
83-
'storage': dict({
84-
'battery': 0,
58+
]),
59+
list([
60+
dict({
61+
'capacity': dict({
62+
'battery storage': 35,
63+
'coal': 750,
64+
'gas': 1280,
65+
'geothermal': 1062,
66+
'hydro': 5415,
67+
'nuclear': 0,
68+
'oil': 156,
69+
'solar': 47,
70+
'unknown': 168,
71+
'wind': 1259,
72+
}),
73+
'datetime': datetime.datetime(2024, 4, 24, 18, 0, tzinfo=datetime.timezone.utc),
74+
'production': dict({
75+
'coal': 156,
76+
'gas': 252,
77+
'geothermal': 964,
78+
'hydro': 1644,
79+
'nuclear': 0,
80+
'oil': 0,
81+
'solar': 0,
82+
'unknown': 117,
83+
'wind': 814,
84+
}),
85+
'source': 'transpower.co.nz',
86+
'storage': dict({
87+
'battery': 0,
88+
}),
89+
'zoneKey': 'NZ',
8590
}),
86-
'zoneKey': 'NZ',
87-
}),
91+
]),
8892
])
8993
# ---

0 commit comments

Comments
 (0)