chellow 1753106469.0.0__py3-none-any.whl → 1753180539.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/elexon.py CHANGED
@@ -62,7 +62,12 @@ def run_import(sess, log, set_progress, scripting_key):
62
62
  s = requests.Session()
63
63
  s.verify = False
64
64
 
65
- for mod_name in ("chellow.e.system_price", "chellow.e.tlms", "chellow.e.rcrc"):
65
+ for mod_name in (
66
+ "chellow.e.system_price",
67
+ "chellow.e.tlms",
68
+ "chellow.e.rcrc",
69
+ "chellow.e.lafs",
70
+ ):
66
71
  mod = import_module(mod_name)
67
72
  mod.elexon_import(sess, log, set_progress, s, scripting_key)
68
73
 
@@ -4,10 +4,10 @@ from decimal import Decimal
4
4
  from io import BytesIO, StringIO
5
5
  from zipfile import ZipFile
6
6
 
7
- # from sqlalchemy.dialects.postgresql import insert
8
7
  from sqlalchemy import text
9
8
 
10
9
  from werkzeug.exceptions import BadRequest
10
+ from werkzeug.http import parse_options_header
11
11
 
12
12
  from chellow.models import Contract, Party
13
13
  from chellow.rate_server import download
@@ -30,7 +30,12 @@ DO UPDATE SET (llfc_id, timestamp, value) =
30
30
  )
31
31
  fname = name_list[0]
32
32
  csv_file = StringIO(zip_file.read(fname).decode("utf-8"))
33
- csv_dt = to_utc(to_ct(Datetime.strptime(fname[-12:-4], "%Y%m%d")))
33
+ try:
34
+ csv_dt = to_utc(to_ct(Datetime.strptime(fname[-12:-4], "%Y%m%d")))
35
+ except ValueError as e:
36
+ log(f"Can't parse the date in the file name {fname} {e}")
37
+ return
38
+
34
39
  for llfc_ids, timestamps, values in laf_days(
35
40
  sess, log, set_progress, csv_file, csv_dt
36
41
  ):
@@ -110,6 +115,67 @@ LAF_START = "llf"
110
115
  LAF_END = "ptf.zip"
111
116
 
112
117
 
118
+ def elexon_import(sess, log, set_progress, s, scripting_key):
119
+ log(
120
+ "Starting to check for new LAF files for participant codes in "
121
+ "configuration.properties.laf_importer.participant_codes"
122
+ )
123
+ conf = Contract.get_non_core_by_name(sess, "configuration")
124
+ props = conf.make_properties()
125
+ state = conf.make_state()
126
+
127
+ try:
128
+ laf_state = state["laf_importer"]
129
+ except KeyError:
130
+ laf_state = state["laf_importer"] = {}
131
+
132
+ url = "https://downloads.elexonportal.co.uk/svallf/download"
133
+
134
+ laf_props = props.get("laf_importer", {})
135
+ for participant_code in laf_props.get("participant_codes", []):
136
+ params = {"key": scripting_key, "ldso": participant_code, "format": "PTF"}
137
+
138
+ log(
139
+ f"Downloading from {url}?key={scripting_key}&ldso={participant_code}&"
140
+ f"format=PTF"
141
+ )
142
+ sess.rollback() # Avoid long-running transactions
143
+ res = s.get(url, params=params)
144
+ log(f"Received {res.status_code} {res.reason}")
145
+ res.raise_for_status()
146
+ try:
147
+ cd_header = res.headers["Content-Disposition"]
148
+ except KeyError:
149
+ log("No Content-Disposition header found, so skipping.")
150
+ continue
151
+
152
+ cd = parse_options_header(cd_header)
153
+ file_name = cd[1]["filename"]
154
+
155
+ # File name llfetcl20220401ptf.zip
156
+ if not file_name.startswith(LAF_START):
157
+ raise BadRequest(f"A laf file must begin with '{LAF_START}'")
158
+ if not file_name.endswith(LAF_END):
159
+ raise BadRequest(f"A laf file must end with '{LAF_END}'")
160
+
161
+ participant_code = file_name[3:7]
162
+ timestamp = file_name[7:15]
163
+ log(f"File name {file_name}")
164
+
165
+ if timestamp > laf_state.get(participant_code, ""):
166
+ data = res.content
167
+ _process(sess, log, set_progress, BytesIO(data))
168
+ laf_state[participant_code] = timestamp
169
+ conf.update_state(state)
170
+ sess.commit()
171
+ log(f"Processed file {file_name}.")
172
+ else:
173
+ log(f"Already loaded {file_name}.")
174
+
175
+ log("Finished LAF files")
176
+ sess.commit()
177
+
178
+
113
179
  def find_participant_entries(paths, laf_state):
114
180
  participant_entries = {}
115
181
  for path, url in paths:
chellow/e/views.py CHANGED
@@ -2344,30 +2344,29 @@ def hh_datum_edit_post(datum_id):
2344
2344
  @e.route("/lafs")
2345
2345
  def lafs_get():
2346
2346
  llfc_id = req_int("llfc_id")
2347
- year = req_int("year")
2348
- month = req_int("month")
2349
-
2347
+ month_start = req_date("timestamp", resolution="month")
2348
+ month_start_ct = to_ct(month_start)
2350
2349
  llfc = Llfc.get_by_id(g.sess, llfc_id)
2351
2350
  dno = llfc.dno
2352
2351
 
2353
- start_date, finish_date = next(
2354
- c_months_u(start_year=year, start_month=month, months=1)
2355
- )
2356
- lafs = (
2357
- g.sess.execute(
2358
- select(Laf)
2359
- .where(
2360
- Laf.llfc == llfc,
2361
- Laf.timestamp >= start_date,
2362
- Laf.timestamp <= finish_date,
2363
- )
2364
- .order_by(Laf.timestamp)
2352
+ month_start, month_finish = next(
2353
+ c_months_u(
2354
+ start_year=month_start_ct.year, start_month=month_start_ct.month, months=1
2365
2355
  )
2366
- .scalars()
2367
- .all()
2368
2356
  )
2357
+ lafs = g.sess.execute(
2358
+ select(Laf)
2359
+ .where(
2360
+ Laf.llfc == llfc,
2361
+ Laf.timestamp >= month_start,
2362
+ Laf.timestamp <= month_finish,
2363
+ )
2364
+ .order_by(Laf.timestamp)
2365
+ ).scalars()
2369
2366
 
2370
- return render_template("lafs.html", dno=dno, llfc=llfc, lafs=lafs)
2367
+ return render_template(
2368
+ "lafs.html", dno=dno, llfc=llfc, lafs=lafs, month_start=month_start
2369
+ )
2371
2370
 
2372
2371
 
2373
2372
  @e.route("/lcc")
@@ -5,12 +5,13 @@ from decimal import Decimal, InvalidOperation
5
5
  from enum import Enum, auto
6
6
  from io import BytesIO
7
7
 
8
+ from dateutil.relativedelta import relativedelta
8
9
 
9
10
  from openpyxl import load_workbook
10
11
 
11
12
  from werkzeug.exceptions import BadRequest
12
13
 
13
- from chellow.utils import c_months_u, to_ct, to_utc
14
+ from chellow.utils import to_ct, to_utc
14
15
 
15
16
 
16
17
  class Title(Enum):
@@ -151,13 +152,13 @@ def _parse_row(bills, sheet, row, title_row):
151
152
  column_map = make_column_map(title_row)
152
153
  mprn_raw = get_value(sheet, row, column_map[Title.MPRN])
153
154
  mprn = str(mprn_raw)
154
- reference = get_value(sheet, row, column_map[Title.BILL])
155
+ reference = str(get_value(sheet, row, column_map[Title.BILL]))
155
156
  account = get_value(sheet, row, column_map[Title.ACCOUNT])
156
157
  issue_date = get_date(sheet, row, column_map[Title.BILL_DATE])
157
- period_naive = get_date_naive(sheet, row, column_map[Title.BILLING_PERIOD])
158
- start_date, finish_date = list(
159
- c_months_u(start_year=period_naive.year, start_month=period_naive.month)
160
- )[0]
158
+ charge_period_from = get_date(sheet, row, column_map[Title.CHARGE_PERIOD_FROM])
159
+ charge_period_end_naive = get_date_naive(
160
+ sheet, row, column_map[Title.CHARGE_PERIOD_END]
161
+ )
161
162
 
162
163
  try:
163
164
  mprn_values = bills[mprn]
@@ -165,16 +166,18 @@ def _parse_row(bills, sheet, row, title_row):
165
166
  mprn_values = bills[mprn] = {}
166
167
 
167
168
  try:
168
- bill = mprn_values[period_naive]
169
+ bill = mprn_values[reference]
169
170
  except KeyError:
170
- bill = mprn_values[period_naive] = {
171
- "bill_type_code": "N",
171
+ bill = mprn_values[reference] = {
172
+ "bill_type_code": "W" if reference.startswith("CR") else "N",
172
173
  "mprn": mprn,
173
174
  "reference": reference,
174
175
  "account": account,
175
176
  "issue_date": issue_date,
176
- "start_date": start_date,
177
- "finish_date": finish_date,
177
+ "start_date": charge_period_from,
178
+ "finish_date": to_utc(
179
+ to_ct(charge_period_end_naive) + relativedelta(hours=23, minutes=30)
180
+ ),
178
181
  "kwh": Decimal("0"),
179
182
  "breakdown": defaultdict(int, {}),
180
183
  "net_gbp": Decimal("0.00"),
@@ -190,6 +193,8 @@ def _parse_row(bills, sheet, row, title_row):
190
193
  qunit = get_value(sheet, row, column_map[Title.QUNIT])
191
194
  charge = get_dec(sheet, row, column_map[Title.CHARGE]) / Decimal("100")
192
195
  total = get_dec(sheet, row, column_map[Title.TOTAL])
196
+ if bill["bill_type_code"] == "W":
197
+ quantity = quantity * -1
193
198
  if element_desc == "VAT":
194
199
  bill["net_gbp"] += quantity
195
200
  bill["vat_gbp"] += total
chellow/rate_server.py CHANGED
@@ -87,8 +87,8 @@ def run_import(sess, log, set_progress):
87
87
  "chellow.e.bsuos",
88
88
  "chellow.e.ccl",
89
89
  "chellow.e.dno_rate_parser",
90
- "chellow.e.laf_import",
91
90
  "chellow.e.triad",
91
+ "chellow.e.lafs",
92
92
  "chellow.gas.ccl",
93
93
  "chellow.gas.dn_rate_parser",
94
94
  ):
@@ -17,7 +17,7 @@
17
17
  <fieldset>
18
18
  <legend>Show data</legend>
19
19
  <input type="hidden" name="llfc_id" value="{{llfc.id}}">
20
- <label>Month</label> {{input_date(None, None, 'month')}}
20
+ <label>Month</label> {{input_date(resolution='month')}}
21
21
  <input type="submit" value="Show">
22
22
  </fieldset>
23
23
  </form>
@@ -45,7 +45,7 @@
45
45
  <tr>
46
46
  <th>Loss Adjustment Factors</th>
47
47
  <td>
48
- <a href="/e/lafs?llfc_id={{llfc.id}}&amp;year={{now.year}}&amp;month={{now.month}}">LAFs</a>
48
+ <a href="/e/lafs?llfc_id={{llfc.id}}&amp;timestamp_year={{now.year}}&amp;timestamp_month={{now.month}}">LAFs</a>
49
49
  </td>
50
50
  </tr>
51
51
  </table>
chellow/views.py CHANGED
@@ -61,7 +61,6 @@ import chellow.e.bill_importer
61
61
  import chellow.e.bsuos
62
62
  import chellow.e.computer
63
63
  import chellow.e.hh_importer
64
- import chellow.e.laf_import
65
64
  import chellow.e.lcc
66
65
  import chellow.e.mdd_importer
67
66
  import chellow.e.rcrc
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: chellow
3
- Version: 1753106469.0.0
3
+ Version: 1753180539.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)
@@ -9,11 +9,11 @@ chellow/general_import.py,sha256=bm8FoaC9xUajGvJYShuS5GEwPwcL5eCF9D9g6o_AkB0,680
9
9
  chellow/models.py,sha256=n6vjsY6jgY98gOY5MGzKuHEEhOs73Pr3XO-auLeQ3es,244656
10
10
  chellow/national_grid.py,sha256=-c_vqNRtpNIQOcm0F1NDhS3_QUiOaLgEJYWzysSNc5Y,4369
11
11
  chellow/proxy.py,sha256=cVXIktPlX3tQ1BYcwxq0nJXKE6r3DtFTtfFHPq55HaM,1351
12
- chellow/rate_server.py,sha256=fg-Pf_9Hk3bXmC9riPQNGQxBvLvBa_WtNYdwDCjnCSg,5678
12
+ chellow/rate_server.py,sha256=RwJo-AzBIdzxx7PAtboZEUH1nUjAeJckw0bk06-9oyM,5672
13
13
  chellow/rrun.py,sha256=1Kt2q_K9UoDG_nsZz-Q6XJiMNKroWqlqFdxn2M6Q8CA,2088
14
14
  chellow/testing.py,sha256=Dj2c1NX8lVlygueOrh2eyYawLW6qKEHxNhXVVUaNRO0,3637
15
15
  chellow/utils.py,sha256=i3GQK9MIcweosZk2gi-nX_IFq2DxURAJDyNoLBg6YwM,19421
16
- chellow/views.py,sha256=fPCuYTWXAAWnu1Cwt4Dk3k7PHNj9gw9HeQRiXgRIn60,85459
16
+ chellow/views.py,sha256=oVZTSQ7k-VCwxzeDpj9sAfERtFw0rEHc58IxtvrhBi0,85431
17
17
  chellow/e/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
18
  chellow/e/aahedc.py,sha256=d2usudp7KYWpU6Pk3fal5EQ47EbvkvKeaFGylnb3NWw,606
19
19
  chellow/e/bill_importer.py,sha256=7UcnqNlKbJc2GhW9gy8sDp9GuqambJVpZLvbafOZztA,7411
@@ -24,7 +24,7 @@ chellow/e/cfd.py,sha256=CWLdYeNjgqT6Ro8YRf4vhwXIAJ2aV4Wi6HLNClVSeaQ,14260
24
24
  chellow/e/computer.py,sha256=lt4Zlr8EOClL1acuuvKA-tNPCI5RRHnAZbsaGQnB9j4,68835
25
25
  chellow/e/dno_rate_parser.py,sha256=NOVfS9HRDsc0rO282hU-IdrcuvMlC7VE8RySqd_5eT0,21762
26
26
  chellow/e/duos.py,sha256=RHrn93I1ASO2uYkuF18qlhG4p-jpuJhd_g3o69wtP4U,31004
27
- chellow/e/elexon.py,sha256=ALhXS9Es7PV0z9ukPbIramn3cf3iLyFi-PMWPSm5iOs,5487
27
+ chellow/e/elexon.py,sha256=eOmX_wpxj6Ty6eaEgGAgXX-MgyJkYQSAT6DtJeP1rUE,5544
28
28
  chellow/e/energy_management.py,sha256=aXC2qlGt3FAODlNl_frWzVYAQrJLP8FFOiNX3m-QE_Y,12388
29
29
  chellow/e/hh_importer.py,sha256=adfogJgPWsJurPOVSBLLQ7m68s1LhfQmDYpAFnGm0eM,21510
30
30
  chellow/e/hh_parser_bg_csv.py,sha256=W5SU2MSpa8BGA0VJw1JXF-IwbCNLFy8fe35yxLZ7gEw,2453
@@ -34,7 +34,7 @@ chellow/e/hh_parser_schneider_csv.py,sha256=m8FHwXp1Tbas91RPS7TriCskSNRuSaFf1SD9
34
34
  chellow/e/hh_parser_schneider_xlsx.py,sha256=Vtq0TNz-oojoKJm4PeH4ZwBp2I-mjArB9-FL71ctCHs,3590
35
35
  chellow/e/hh_parser_simple_csv.py,sha256=lJx9tw9BWFSoBmns1Cws_vY-OIn90LPt2yvIN_CFcTE,2177
36
36
  chellow/e/hh_parser_vital_xlsx.py,sha256=g9-CElfH1PPfwpuUcVvD6WQpBlNxCo8j9pq_0Yza0ZM,4125
37
- chellow/e/laf_import.py,sha256=aqkcbjnvfBPszBLSNg6getP7iW1uWiTVHy6N5Z5x39U,5514
37
+ chellow/e/lafs.py,sha256=SUUFtvn_IQQTrZue1zefCYgzuscA0FVX2ySZ9u8BDPw,7776
38
38
  chellow/e/lcc.py,sha256=OkpynN8_iAdHRlu-yyU6BhRUqYYOZsUnl0HbHULYo_4,4670
39
39
  chellow/e/mdd_importer.py,sha256=NugJr2JhuzkPTsEMl_5UdQuw5K2p8lVJ-hyz4MK6Hfg,35762
40
40
  chellow/e/rcrc.py,sha256=92CA1uIotIHd1epQ_jEPdJKzXqDFV-AoJOJeRO6MEyA,4274
@@ -44,7 +44,7 @@ chellow/e/system_price.py,sha256=6w5J7bzwFAZubE2zdOFRiS8IIrVP8hkoIOaG2yCt-Ic,623
44
44
  chellow/e/tlms.py,sha256=K2n-dF6qNW7VQp4m_sVK1HWnXarmAIzpotWXYqWQacY,9363
45
45
  chellow/e/tnuos.py,sha256=NBmc-f3oezrl4gviAKobljHfICTpBKxxxEGBGJi_lRk,4927
46
46
  chellow/e/triad.py,sha256=uQIngSrz8irBXQ0Rp_s8nAUzu-y2Ms7aj4B38_Ff8y8,13720
47
- chellow/e/views.py,sha256=tCzoVreBLEcNmBDbWWqhQ3qIp-0v93dBhF8yoDeT9mI,220738
47
+ chellow/e/views.py,sha256=pWLbcG04t8mZB6y9Dp8bkcJpnWrfF1x10eCGagMbDl8,220804
48
48
  chellow/e/bill_parsers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
49
49
  chellow/e/bill_parsers/activity_mop_stark_xlsx.py,sha256=opjXRrqrgBTbSKzL0JfTLP0fnz3DL3oRZZ4P0DifQ3I,4119
50
50
  chellow/e/bill_parsers/annual_mop_stark_xlsx.py,sha256=-HMoIfa_utXYKA44RuC0Xqv3vd2HLeQU_4P0iBUd3WA,4219
@@ -67,7 +67,7 @@ chellow/e/bill_parsers/settlement_dc_stark_xlsx.py,sha256=osCpUYUdLcPtlo7ngXWGw0
67
67
  chellow/e/bill_parsers/sse_edi.py,sha256=L85DOfNkqexeEIEr8pCBn_2sHJI-zEaw6cogpE3YyYM,15204
68
68
  chellow/e/bill_parsers/sww_xls.py,sha256=QEjiuvwvr5FuWCfqqVw8LaA_vZyAKsvRAS5fw3xtFhM,7533
69
69
  chellow/gas/bill_import.py,sha256=w0lPgK_Drzh8rtnEBQe3qFuxrgzZ6qQSgpaGrrGznMU,6549
70
- chellow/gas/bill_parser_bgs_xlsx.py,sha256=ySYAa6fq990DW01bQMk8Ix_sziWfm_5d2Il7IrYz9Ys,7522
70
+ chellow/gas/bill_parser_bgs_xlsx.py,sha256=ZuLts8Y31gxtCQoXJq2CQRRMMpYbAWqsbfMB1S6fPqU,7757
71
71
  chellow/gas/bill_parser_csv.py,sha256=Ecdy-apFT-mWAxddAsM4k1s-9-FpIaOfjP0oFc0rdQg,5557
72
72
  chellow/gas/bill_parser_engie_edi.py,sha256=Ko0vZP-QdVQ1uuhS_5cdrii60_cM4b_LFJMoY0pZqnk,8950
73
73
  chellow/gas/bill_parser_total_edi.py,sha256=8HZH5Le24bVNFDc7vaKbauMaYR-n9P6u0ZG7gDdqbIA,11325
@@ -239,9 +239,9 @@ chellow/templates/e/generator_types.html,sha256=672cXDYewLAk32pzp6c8fi2P48FikxRr
239
239
  chellow/templates/e/gsp_group.html,sha256=yzLHZHQPHZAQtjLBszWEc-htw8-MEhSu3kLo-KmW5n8,405
240
240
  chellow/templates/e/gsp_groups.html,sha256=HagDJBJ7YzZDNhDq9ThI2uMrsW_viSuBapB2X4yC3Bk,453
241
241
  chellow/templates/e/hh_datum_edit.html,sha256=TJPvQ7FHw1yjkBwpXul0ZBs8UQtZR98wJ3fLjuQc2XA,1824
242
- chellow/templates/e/lafs.html,sha256=7MQvmoGCY-JCSDDos7vJVRKWAvqqM0eqhA0-hvaO1_o,996
242
+ chellow/templates/e/lafs.html,sha256=QcQnkK_Nk-6cCLOApWQSP4dN0mfuFxIB_K4lBtr0Yv4,995
243
243
  chellow/templates/e/lcc.html,sha256=LLWgB9iNG2jee3p1DrbeDtUR3CPQIXlyDvGQDUsWKEs,1021
244
- chellow/templates/e/llfc.html,sha256=B0tw7PHvEEvxJWhAGe9dZji_J9apAz-TpNlkqvYFKfE,1168
244
+ chellow/templates/e/llfc.html,sha256=vrGoR_7yWli34Ul6xJO1z8FvQU2rjOrOaWlyx-2irus,1188
245
245
  chellow/templates/e/llfc_edit.html,sha256=YwtEf8DwoX_t3RHNxPbZYFzikBL-Ly7UyjHs-YuJ3bk,1038
246
246
  chellow/templates/e/llfcs.html,sha256=OlY9x3XKs0OAoa4ZOZoRokYEjIZ_isfoBtn3DGL-u6o,1228
247
247
  chellow/templates/e/market_role.html,sha256=hQ62PwzByIKDfYRWMLsg8uuA2Yh6u_X9iaee5u31p80,1025
@@ -385,6 +385,6 @@ chellow/templates/g/supply_note_edit.html,sha256=b8mB6_ucBwoljp03iy6AgVaZUhGw3-1
385
385
  chellow/templates/g/supply_notes.html,sha256=6epNmZ3NKdXZz27fvmRUGeffg_oc1kmwuBeyRzQe3Rg,854
386
386
  chellow/templates/g/unit.html,sha256=KouNVU0-i84afANkLQ_heJ0uDfJ9H5A05PuLqb8iCN8,438
387
387
  chellow/templates/g/units.html,sha256=p5Nd-lAIboKPEOO6N451hx1bcKxMg4BDODnZ-43MmJc,441
388
- chellow-1753106469.0.0.dist-info/METADATA,sha256=YMm8-MduiWKqPWeENv_u33zI391ioRp-tDbKrowYsVo,12585
389
- chellow-1753106469.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
390
- chellow-1753106469.0.0.dist-info/RECORD,,
388
+ chellow-1753180539.0.0.dist-info/METADATA,sha256=R7snYgxFJSS1VK-dHXFKW_4rRtTgBe4v6gzOXFUMX6A,12585
389
+ chellow-1753180539.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
390
+ chellow-1753180539.0.0.dist-info/RECORD,,