chellow 1728660080.0.0__py3-none-any.whl → 1728986476.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of chellow might be problematic. Click here for more details.

chellow/e/hh_importer.py CHANGED
@@ -40,7 +40,7 @@ from chellow.utils import (
40
40
  processes = defaultdict(list)
41
41
  tasks = {}
42
42
 
43
- extensions = [".df2", ".simple.csv", ".bg.csv", ".vital.xlsx"]
43
+ extensions = [".df2", ".simple.csv", ".bg.csv", ".vital.xlsx", ".edf.csv"]
44
44
 
45
45
 
46
46
  class HhDataImportProcess(threading.Thread):
@@ -0,0 +1,102 @@
1
+ import csv
2
+ from codecs import iterdecode
3
+ from datetime import datetime as Datetime
4
+ from decimal import Decimal
5
+
6
+ from werkzeug.exceptions import BadRequest
7
+
8
+ from chellow.utils import (
9
+ HH,
10
+ parse_mpan_core,
11
+ to_ct,
12
+ to_utc,
13
+ )
14
+
15
+ # From the EDF Portal select:
16
+ # - Electricity
17
+ # - Half-hourly
18
+ # - Reactive Power and kWh combined
19
+ # export data as CSV
20
+ #
21
+ #
22
+ # "Month","MPAN","Measurement Type","Settlement Date","00:00",..,"00:00_Act_Est",
23
+ # "Apr-24", "2200000000000", "AI", "01-04-2024", "0.0000", ..., "Actual", "Actual",
24
+
25
+
26
+ def create_parser(reader, mpan_map, messages):
27
+ return HhParserEdfCsv(reader, mpan_map, messages)
28
+
29
+
30
+ CHANNEL_LOOKUP = {
31
+ "AI": "ACTIVE",
32
+ "RI": "REACTIVE_IMP",
33
+ "RE": "REACTIVE_EXP",
34
+ }
35
+
36
+ STATUS_LOOKUP = {
37
+ "Actual": "A",
38
+ "Estimated": "E",
39
+ "-": "E",
40
+ }
41
+
42
+
43
+ def _get_field(values, index, name):
44
+ if len(values) > index:
45
+ return values[index].strip()
46
+ else:
47
+ raise BadRequest(f"Can't find field {index}, {name}.")
48
+
49
+
50
+ def _find_data(shredder):
51
+ try:
52
+ for line_number, values in enumerate(shredder, start=2):
53
+ mpan_core_str = _get_field(values, 1, "MPAN Core")
54
+ mpan_core = parse_mpan_core(mpan_core_str)
55
+ channel_type_str = _get_field(values, 2, "Channel Type")
56
+ channel_type = CHANNEL_LOOKUP[channel_type_str]
57
+ start_day_ct_str = _get_field(values, 3, "Day")
58
+ start_day_ct = to_ct(Datetime.strptime(start_day_ct_str, "%d-%m-%Y"))
59
+
60
+ for i in range(50):
61
+ val_idx = i + 4
62
+ value_str = values[val_idx]
63
+ if value_str == "-":
64
+ break
65
+
66
+ status_idx = val_idx + 50
67
+ status_str = values[status_idx]
68
+ try:
69
+ status = STATUS_LOOKUP[status_str]
70
+ except KeyError:
71
+ raise BadRequest(
72
+ f"Unrecognized status {status_str} at index {status_idx}."
73
+ )
74
+ yield {
75
+ "mpan_core": mpan_core,
76
+ "channel_type": channel_type,
77
+ "start_date": to_utc(start_day_ct + HH * i),
78
+ "value": Decimal(value_str),
79
+ "status": status,
80
+ }
81
+ except BadRequest as e:
82
+ e.description = (
83
+ f"Problem at line number: {line_number} : {values} : {e.description}"
84
+ )
85
+ raise e
86
+
87
+
88
+ class HhParserEdfCsv:
89
+ def __init__(self, reader, mpan_map, messages):
90
+ s = iterdecode(reader, "utf-8")
91
+ self.reader = csv.reader(s)
92
+ next(self.reader) # skip the title line
93
+ self.data = iter(_find_data(self.reader))
94
+
95
+ def __iter__(self):
96
+ return self
97
+
98
+ def __next__(self):
99
+ return next(self.data)
100
+
101
+ def close(self):
102
+ self.shredder.close()
chellow/e/scenario.py CHANGED
@@ -83,7 +83,8 @@ def make_create_future_func_monthly(contract_name, fnames):
83
83
  def make_site_deltas(
84
84
  sess, report_context, site, scenario_hh, forecast_from, supply_ids
85
85
  ):
86
- site_scenario_hh = scenario_hh.get(site.code, {})
86
+ site_scenario_hh_str = scenario_hh.get(site.code, {})
87
+ site_scenario_hh = {}
87
88
 
88
89
  site_deltas = {"hhs": {}}
89
90
  delts = site_deltas["supply_deltas"] = {}
@@ -97,7 +98,7 @@ def make_site_deltas(
97
98
 
98
99
  found_hh = False
99
100
  for typ in ("used", "generated", "parasitic", "gen_grid"):
100
- hh_str = site_scenario_hh.get(typ, "")
101
+ hh_str = site_scenario_hh_str.get(typ, "")
101
102
  hh_data = site_scenario_hh[typ] = {}
102
103
  for row in csv.reader(StringIO(hh_str)):
103
104
  cells = [cell.strip() for cell in row]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: chellow
3
- Version: 1728660080.0.0
3
+ Version: 1728986476.0.0
4
4
  Summary: Web Application for checking UK energy bills.
5
5
  Project-URL: Homepage, https://github.com/WessexWater/chellow
6
6
  Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
@@ -25,9 +25,10 @@ chellow/e/dno_rate_parser.py,sha256=A5TP6KjyfT5lVWh7dX4SiXRi6wnf2lGv-H_T4Sod8CI,
25
25
  chellow/e/duos.py,sha256=nwviRjz-qIt3GxIMHk0hItIT4dtKsxOWq9TUC1z-hO8,30864
26
26
  chellow/e/elexon.py,sha256=ALhXS9Es7PV0z9ukPbIramn3cf3iLyFi-PMWPSm5iOs,5487
27
27
  chellow/e/energy_management.py,sha256=aXC2qlGt3FAODlNl_frWzVYAQrJLP8FFOiNX3m-QE_Y,12388
28
- chellow/e/hh_importer.py,sha256=vD2PRMSBhxmsyJ4xEq2N7Ib5Ohmf1FmQk8-APw8vBEs,21430
28
+ chellow/e/hh_importer.py,sha256=Bo1kWV2po3VY5DJPlNqgWtz4xaU3h1-R2JtFmCEX37g,21442
29
29
  chellow/e/hh_parser_bg_csv.py,sha256=W5SU2MSpa8BGA0VJw1JXF-IwbCNLFy8fe35yxLZ7gEw,2453
30
30
  chellow/e/hh_parser_df2.py,sha256=tRAoVUUoJDlfPopm6usEBnhJz7dXMc2_KEWbkW9Gyq4,4330
31
+ chellow/e/hh_parser_edf_csv.py,sha256=CLkkL1Z6BPgVV_3uwS6McmtMzgXkoEIoJnH8FsQk1C8,2839
31
32
  chellow/e/hh_parser_simple_csv.py,sha256=lJx9tw9BWFSoBmns1Cws_vY-OIn90LPt2yvIN_CFcTE,2177
32
33
  chellow/e/hh_parser_vital_xlsx.py,sha256=g9-CElfH1PPfwpuUcVvD6WQpBlNxCo8j9pq_0Yza0ZM,4125
33
34
  chellow/e/laf_import.py,sha256=aqkcbjnvfBPszBLSNg6getP7iW1uWiTVHy6N5Z5x39U,5514
@@ -35,7 +36,7 @@ chellow/e/lcc.py,sha256=OkpynN8_iAdHRlu-yyU6BhRUqYYOZsUnl0HbHULYo_4,4670
35
36
  chellow/e/mdd_importer.py,sha256=NugJr2JhuzkPTsEMl_5UdQuw5K2p8lVJ-hyz4MK6Hfg,35762
36
37
  chellow/e/rcrc.py,sha256=92CA1uIotIHd1epQ_jEPdJKzXqDFV-AoJOJeRO6MEyA,4274
37
38
  chellow/e/ro.py,sha256=dZKZv_9wXSWuwcb3jiKavoD_9ot-PZseNVeEEe0siLo,596
38
- chellow/e/scenario.py,sha256=fBDZVOdrI1I3XQG-RdpB0-lDF9VYENBu_9bBXJxmvWk,23362
39
+ chellow/e/scenario.py,sha256=86DQIJ6ZK2XYIisHw6DafGcfwo1iPWF1t9rByy2yxbg,23396
39
40
  chellow/e/system_price.py,sha256=6w5J7bzwFAZubE2zdOFRiS8IIrVP8hkoIOaG2yCt-Ic,6232
40
41
  chellow/e/tlms.py,sha256=M33D6YpMixu2KkwSCzDRM3kThLgShg8exp63Obo75l8,8905
41
42
  chellow/e/tnuos.py,sha256=XseYztPUsQXNKuBmystO2kzzwAG9ehCZgpGBTdgSk-A,4313
@@ -368,6 +369,6 @@ chellow/templates/g/supply_note_edit.html,sha256=b8mB6_ucBwoljp03iy6AgVaZUhGw3-1
368
369
  chellow/templates/g/supply_notes.html,sha256=6epNmZ3NKdXZz27fvmRUGeffg_oc1kmwuBeyRzQe3Rg,854
369
370
  chellow/templates/g/unit.html,sha256=KouNVU0-i84afANkLQ_heJ0uDfJ9H5A05PuLqb8iCN8,438
370
371
  chellow/templates/g/units.html,sha256=p5Nd-lAIboKPEOO6N451hx1bcKxMg4BDODnZ-43MmJc,441
371
- chellow-1728660080.0.0.dist-info/METADATA,sha256=35H6CrEAzoMZ04CzYNyl07FqTrIMfAWt7FBsKZKqzss,12204
372
- chellow-1728660080.0.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
373
- chellow-1728660080.0.0.dist-info/RECORD,,
372
+ chellow-1728986476.0.0.dist-info/METADATA,sha256=Ok78n_Nora0YJLcFiP8BesoLcDRKSM8OKZWHFjMZ-Tk,12204
373
+ chellow-1728986476.0.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
374
+ chellow-1728986476.0.0.dist-info/RECORD,,