Skip to content

Commit d162046

Browse files
authored
fix(parsers): fix return value for some parsers (#8144)
We enforced type checking of the returned value from the parsers. We expects the parsers to return a list. The following were returning a dict and thus were failing. The list of affected parsers is : - production: JP-KN, JP-SK, JP-KY, GB-ORK, CA-AB, AU-WA-RI, AU-TAS-FI, AU-TAS-KI - consumption: KW - price: NZ - exchange: GB->GB-ORK
1 parent fafbc7e commit d162046

File tree

14 files changed

+121
-108
lines changed

14 files changed

+121
-108
lines changed

parsers/CA_AB.py

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -121,40 +121,42 @@ def fetch_production(
121121
}
122122
for row in csv.reader(response.text.split("\r\n\r\n")[3].splitlines())
123123
}
124-
return validation.validate(
125-
{
126-
"capacity": {
127-
"gas": generation["COGENERATION"]["MC"]
128-
+ generation["COMBINED CYCLE"]["MC"]
129-
+ generation["GAS FIRED STEAM"]["MC"]
130-
+ generation["SIMPLE CYCLE"]["MC"],
131-
"wind": generation["WIND"]["MC"],
132-
"solar": generation["SOLAR"]["MC"],
133-
"hydro": generation["HYDRO"]["MC"],
134-
"biomass": generation["OTHER"]["MC"],
135-
"battery storage": generation["ENERGY STORAGE"]["MC"],
124+
return [
125+
validation.validate(
126+
{
127+
"capacity": {
128+
"gas": generation["COGENERATION"]["MC"]
129+
+ generation["COMBINED CYCLE"]["MC"]
130+
+ generation["GAS FIRED STEAM"]["MC"]
131+
+ generation["SIMPLE CYCLE"]["MC"],
132+
"wind": generation["WIND"]["MC"],
133+
"solar": generation["SOLAR"]["MC"],
134+
"hydro": generation["HYDRO"]["MC"],
135+
"biomass": generation["OTHER"]["MC"],
136+
"battery storage": generation["ENERGY STORAGE"]["MC"],
137+
},
138+
"datetime": get_csd_report_timestamp(response.text),
139+
"production": {
140+
"gas": generation["COGENERATION"]["TNG"]
141+
+ generation["COMBINED CYCLE"]["TNG"]
142+
+ generation["GAS FIRED STEAM"]["TNG"]
143+
+ generation["SIMPLE CYCLE"]["TNG"],
144+
"wind": generation["WIND"]["TNG"],
145+
"solar": generation["SOLAR"]["TNG"],
146+
"hydro": generation["HYDRO"]["TNG"],
147+
"biomass": generation["OTHER"]["TNG"],
148+
},
149+
"source": URL.netloc,
150+
"storage": {
151+
"battery": generation["ENERGY STORAGE"]["TNG"],
152+
},
153+
"zoneKey": zone_key,
136154
},
137-
"datetime": get_csd_report_timestamp(response.text),
138-
"production": {
139-
"gas": generation["COGENERATION"]["TNG"]
140-
+ generation["COMBINED CYCLE"]["TNG"]
141-
+ generation["GAS FIRED STEAM"]["TNG"]
142-
+ generation["SIMPLE CYCLE"]["TNG"],
143-
"wind": generation["WIND"]["TNG"],
144-
"solar": generation["SOLAR"]["TNG"],
145-
"hydro": generation["HYDRO"]["TNG"],
146-
"biomass": generation["OTHER"]["TNG"],
147-
},
148-
"source": URL.netloc,
149-
"storage": {
150-
"battery": generation["ENERGY STORAGE"]["TNG"],
151-
},
152-
"zoneKey": zone_key,
153-
},
154-
logger,
155-
floor=MINIMUM_PRODUCTION_THRESHOLD,
156-
remove_negative=True,
157-
)
155+
logger,
156+
floor=MINIMUM_PRODUCTION_THRESHOLD,
157+
remove_negative=True,
158+
)
159+
]
158160

159161

160162
def get_csd_report_timestamp(report):

parsers/GB_ORK.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def fetch_production(
105105
"source": "ssen.co.uk",
106106
}
107107

108-
return data
108+
return [data]
109109

110110

111111
def fetch_exchange(
@@ -132,7 +132,7 @@ def fetch_exchange(
132132
"source": "ssen.co.uk",
133133
}
134134

135-
return data
135+
return [data]
136136

137137

138138
if __name__ == "__main__":

parsers/JP_KN.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def fetch_production(
5151

5252
latest["production"]["nuclear"] = nuclear_mw
5353
latest["production"]["unknown"] = latest["production"]["unknown"] - nuclear_mw
54-
return latest
54+
return [latest]
5555

5656

5757
URL = (

parsers/JP_KY.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def fetch_production(
115115
data["production"]["nuclear"] = nuclear
116116
data["production"]["unknown"] = unknown
117117

118-
return data
118+
return [data]
119119
else:
120120
return []
121121

parsers/JP_SK.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def fetch_production(
5656
latest_data_point_JP_SK["datetime"] - datetime_nuclear
5757
).total_seconds() / 3600 <= 1:
5858
latest_data_point_JP_SK["production"]["nuclear"] = nuclear_power_MW
59-
return latest_data_point_JP_SK
59+
return [latest_data_point_JP_SK]
6060

6161

6262
NUCLEAR_REPORT_URL = "https://www.yonden.co.jp/energy/atom/ikata/ikt722.html"

parsers/KW.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def fetch_consumption(
7474
"source": "mew.gov.kw",
7575
}
7676

77-
return datapoint
77+
return [datapoint]
7878

7979

8080
if __name__ == "__main__":

parsers/NZ.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,15 @@ def fetch_price(
6565
tzinfo=timezone.utc
6666
)
6767

68-
return {
69-
"datetime": date_time,
70-
"price": avg_price,
71-
"currency": "NZD",
72-
"source": "api.em6.co.nz",
73-
"zoneKey": zone_key,
74-
}
68+
return [
69+
{
70+
"datetime": date_time,
71+
"price": avg_price,
72+
"currency": "NZD",
73+
"source": "api.em6.co.nz",
74+
"zoneKey": zone_key,
75+
}
76+
]
7577

7678

7779
def fetch_production(

parsers/ajenti.py

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -161,31 +161,34 @@ def fetch_production(
161161
technologies_parsed = parse_payload(logger, payload)
162162
storage_techs = sum_storage_techs(technologies_parsed)
163163

164-
return {
165-
"zoneKey": zone_key,
166-
"datetime": datetime.now(tz=ZoneInfo(tz)),
167-
"production": {
168-
"biomass": technologies_parsed["biomass"],
169-
"coal": technologies_parsed["coal"],
170-
"gas": technologies_parsed["gas"],
171-
"hydro": technologies_parsed["hydro"],
172-
"nuclear": technologies_parsed["nuclear"],
173-
"oil": technologies_parsed["oil"],
174-
"solar": technologies_parsed["solar"],
175-
"wind": 0
176-
if technologies_parsed["wind"] < 0 and technologies_parsed["wind"] > -0.1
177-
else technologies_parsed[
178-
"wind"
179-
], # If wind between 0 and -0.1 set to 0 to ignore self-consumption
180-
"geothermal": technologies_parsed["geothermal"],
181-
"unknown": technologies_parsed["unknown"],
182-
},
183-
"storage": {
184-
"battery": storage_techs
185-
* -1 # Somewhat counterintuitively,to ElectricityMap positive means charging and negative means discharging
186-
},
187-
"source": source,
188-
}
164+
return [
165+
{
166+
"zoneKey": zone_key,
167+
"datetime": datetime.now(tz=ZoneInfo(tz)),
168+
"production": {
169+
"biomass": technologies_parsed["biomass"],
170+
"coal": technologies_parsed["coal"],
171+
"gas": technologies_parsed["gas"],
172+
"hydro": technologies_parsed["hydro"],
173+
"nuclear": technologies_parsed["nuclear"],
174+
"oil": technologies_parsed["oil"],
175+
"solar": technologies_parsed["solar"],
176+
"wind": 0
177+
if technologies_parsed["wind"] < 0
178+
and technologies_parsed["wind"] > -0.1
179+
else technologies_parsed[
180+
"wind"
181+
], # If wind between 0 and -0.1 set to 0 to ignore self-consumption
182+
"geothermal": technologies_parsed["geothermal"],
183+
"unknown": technologies_parsed["unknown"],
184+
},
185+
"storage": {
186+
"battery": storage_techs
187+
* -1 # Somewhat counterintuitively,to ElectricityMap positive means charging and negative means discharging
188+
},
189+
"source": source,
190+
}
191+
]
189192

190193

191194
if __name__ == "__main__":
Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
# serializer version: 1
22
# name: test_snapshot_fetch_production
3-
dict({
4-
'datetime': datetime.datetime(2025, 4, 25, 16, 40, tzinfo=zoneinfo.ZoneInfo(key='Asia/Tokyo')),
5-
'production': dict({
6-
'biomass': 0,
7-
'coal': 0,
8-
'gas': 0,
9-
'geothermal': None,
10-
'hydro': None,
11-
'nuclear': 3119.0,
12-
'oil': 0,
13-
'solar': 2100.0,
14-
'unknown': 3861.0,
15-
'wind': None,
3+
list([
4+
dict({
5+
'datetime': datetime.datetime(2025, 4, 25, 16, 40, tzinfo=zoneinfo.ZoneInfo(key='Asia/Tokyo')),
6+
'production': dict({
7+
'biomass': 0,
8+
'coal': 0,
9+
'gas': 0,
10+
'geothermal': None,
11+
'hydro': None,
12+
'nuclear': 3119.0,
13+
'oil': 0,
14+
'solar': 2100.0,
15+
'unknown': 3861.0,
16+
'wind': None,
17+
}),
18+
'source': 'www.kyuden.co.jp',
19+
'storage': dict({
20+
}),
21+
'zoneKey': 'JP-KY',
1622
}),
17-
'source': 'www.kyuden.co.jp',
18-
'storage': dict({
19-
}),
20-
'zoneKey': 'JP-KY',
21-
})
23+
])
2224
# ---

parsers/test/__snapshots__/test_NZ.ambr

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
# serializer version: 1
22
# name: test_snapshot_price_data
33
list([
4-
dict({
5-
'currency': 'NZD',
6-
'datetime': datetime.datetime(2024, 4, 24, 18, 30, tzinfo=datetime.timezone.utc),
7-
'price': 79.8623076923077,
8-
'source': 'api.em6.co.nz',
9-
'zoneKey': 'NZ',
10-
}),
11-
dict({
12-
'currency': 'NZD',
13-
'datetime': datetime.datetime(2024, 4, 24, 18, 30, tzinfo=datetime.timezone.utc),
14-
'price': 79.8623076923077,
15-
'source': 'api.em6.co.nz',
16-
'zoneKey': 'NZ',
17-
}),
4+
list([
5+
dict({
6+
'currency': 'NZD',
7+
'datetime': datetime.datetime(2024, 4, 24, 18, 30, tzinfo=datetime.timezone.utc),
8+
'price': 79.8623076923077,
9+
'source': 'api.em6.co.nz',
10+
'zoneKey': 'NZ',
11+
}),
12+
]),
13+
list([
14+
dict({
15+
'currency': 'NZD',
16+
'datetime': datetime.datetime(2024, 4, 24, 18, 30, tzinfo=datetime.timezone.utc),
17+
'price': 79.8623076923077,
18+
'source': 'api.em6.co.nz',
19+
'zoneKey': 'NZ',
20+
}),
21+
]),
1822
])
1923
# ---
2024
# name: test_snapshot_production_data

0 commit comments

Comments
 (0)