chellow 1752836620.0.0__py3-none-any.whl → 1753175604.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")
@@ -5714,20 +5713,34 @@ def supply_post(supply_id):
5714
5713
  if "new_msn" in request.form:
5715
5714
  start_date_str = req_str("start_date")
5716
5715
  start_date = parse_hh_start(start_date_str)
5716
+ if start_date is None:
5717
+ raise BadRequest("The data of the MSN change is blank in ECOES.")
5717
5718
 
5718
5719
  msn = req_str("msn")
5720
+ msg = ""
5719
5721
  era = supply.find_era_at(g.sess, start_date)
5720
5722
  if era is None:
5721
- raise BadRequest(f"There isn't an era at {start_date}")
5722
- if era.msn == msn:
5723
- raise BadRequest(f"The era at {start_date} already has the MSN {msn}")
5723
+ raise BadRequest(f"There are no eras from {start_date|hh_format}")
5724
+ else:
5725
+ if era.start_date != start_date:
5726
+ era = supply.insert_era_at(g.sess, start_date)
5727
+ g.sess.commit()
5728
+ for era in supply.find_eras(g.sess, start_date, None):
5729
+ if era.msn == msn:
5730
+ msg += (
5731
+ f"The era at {hh_format(era.start_date)} already has the "
5732
+ f"MSN {msn}. "
5733
+ )
5734
+ else:
5735
+ era.msn = msn
5724
5736
 
5725
- if era.start_date != start_date:
5726
- era = supply.insert_era_at(g.sess, start_date)
5727
- era.msn = msn
5728
- g.sess.commit()
5729
- flash("MSN updated successfully")
5730
- return render_template("supply_post.html")
5737
+ g.sess.commit()
5738
+ msg += (
5739
+ f"The era at {hh_format(era.start_date)} has been "
5740
+ f"successfully updated with the MSN {msn}. "
5741
+ )
5742
+ flash(msg)
5743
+ return render_template("supply_post.html")
5731
5744
 
5732
5745
  except BadRequest as e:
5733
5746
  flash(e.description)
chellow/models.py CHANGED
@@ -4271,16 +4271,16 @@ class Supply(Base, PersistentClass):
4271
4271
 
4272
4272
  def find_eras(self, sess, start, finish):
4273
4273
  eras = (
4274
- sess.query(Era)
4275
- .filter(
4274
+ select(Era)
4275
+ .where(
4276
4276
  Era.supply == self,
4277
4277
  or_(Era.finish_date == null(), Era.finish_date >= start),
4278
4278
  )
4279
4279
  .order_by(Era.start_date)
4280
4280
  )
4281
4281
  if finish is not None:
4282
- eras = eras.filter(Era.start_date <= finish)
4283
- return eras.all()
4282
+ eras = eras.where(Era.start_date <= finish)
4283
+ return sess.scalars(eras).all()
4284
4284
 
4285
4285
  def update_era(
4286
4286
  self,
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: 1752836620.0.0
3
+ Version: 1753175604.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)
@@ -6,14 +6,14 @@ chellow/dloads.py,sha256=dixp-O0MF2_mlwrnKx3D9DH09Qu05BjTo0rZfigTjR4,5534
6
6
  chellow/edi_lib.py,sha256=alu20x9ZX06iPfnNI9dEJzuP6RIf4We3Y_M_bl7RrcY,51789
7
7
  chellow/fake_batch_updater.py,sha256=khAmvSUn9qN04w8C92kRg1UeyQvfLztE7QXv9tUz6nE,11611
8
8
  chellow/general_import.py,sha256=bm8FoaC9xUajGvJYShuS5GEwPwcL5eCF9D9g6o_AkB0,68089
9
- chellow/models.py,sha256=XD5wl3Pa8vZFGA0aB1Pu-xJs3iBoBoeX44E8Myho_68,244648
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=e5rMZFT2fNO3P14_0nCyOEwNWnMiayx2wqo4PJmBwRM,220111
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
@@ -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-1752836620.0.0.dist-info/METADATA,sha256=r0CxGsqFVviRAdFYIzkcWwlvSYAO6E39BuqT11clQIk,12585
389
- chellow-1752836620.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
390
- chellow-1752836620.0.0.dist-info/RECORD,,
388
+ chellow-1753175604.0.0.dist-info/METADATA,sha256=jyoTCzAK7PWcHx5zECDlMdAjYry29dMAQXmL90z-3aE,12585
389
+ chellow-1753175604.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
390
+ chellow-1753175604.0.0.dist-info/RECORD,,