Skip to content

Commit 986b7da

Browse files
committed
Merge branch 'master' of github.com:tmrowco/electricitymap
2 parents 3c5e4b9 + b7bea15 commit 986b7da

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

parsers/CL_SING.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from __future__ import print_function
88
import arrow
99
from bs4 import BeautifulSoup
10-
from collections import defaultdict
10+
from collections import defaultdict, Counter
1111
import datetime
1212
import json
1313
from pytz import timezone
@@ -203,6 +203,16 @@ def fetch_production(zone_key='CL-SING', session=None, target_datetime=None, log
203203
}
204204
production_mix_by_hour.append(production_mix)
205205

206+
# if production is the same for at least 3 in the last 48 hours, it's
207+
# considered constant. Using round because of floating-point precision.
208+
c = Counter([round(sum(v for _, v in e['production'].items()), 3)
209+
for e in production_mix_by_hour])
210+
most_common = c.most_common(1)[0]
211+
if most_common[1] > 3:
212+
raise ValueError(
213+
'Detected constant prod in CL-SING. Value {} occured {} times in '
214+
'the last 48 hours.'.format(most_common[0], most_common[1]))
215+
206216
return production_mix_by_hour
207217

208218

0 commit comments

Comments
 (0)