chellow 1728924490.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()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: chellow
3
- Version: 1728924490.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
@@ -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-1728924490.0.0.dist-info/METADATA,sha256=cTOCYE3No2O3KQyknsfL2U_hBqJ-zdUbXwI8Q9koTas,12204
372
- chellow-1728924490.0.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
373
- chellow-1728924490.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,,