chellow 1705663424.0.0__py3-none-any.whl → 1706020835.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/cfd.py CHANGED
@@ -1,14 +1,17 @@
1
1
  from datetime import datetime as Datetime
2
2
 
3
3
  from dateutil.relativedelta import relativedelta
4
+
4
5
  from sqlalchemy import null, or_, select
5
6
 
7
+ from werkzeug.exceptions import BadRequest
8
+
6
9
  from chellow.e.lcc import api_search, api_sql
7
10
  from chellow.models import Contract, RateScript
8
11
  from chellow.utils import ct_datetime, hh_format, to_ct, to_utc
9
12
 
10
13
 
11
- def hh(data_source):
14
+ def hh(data_source, use_bill_check=False):
12
15
  try:
13
16
  cfd_cache = data_source.caches["cfd"]
14
17
  except KeyError:
@@ -19,47 +22,60 @@ def hh(data_source):
19
22
  h["cfd-rate"] = cfd_cache[h["start-date"]]
20
23
  except KeyError:
21
24
  h_start = h["start-date"]
22
- daily_contract = Contract.get_non_core_by_name(
23
- data_source.sess, "cfd_reconciled_daily_levy_rates"
24
- )
25
- daily_rs = data_source.sess.scalars(
26
- select(RateScript).where(
27
- RateScript.contract == daily_contract,
28
- RateScript.start_date <= h_start,
29
- or_(
30
- RateScript.finish_date == null(),
31
- RateScript.finish_date >= h_start,
32
- ),
25
+ if use_bill_check:
26
+ base_rate = (
27
+ float(
28
+ data_source.non_core_rate("cfd_forecast_ilr_tra", h_start)[
29
+ "record"
30
+ ]["Interim_Levy_Rate_GBP_Per_MWh"]
31
+ )
32
+ / 1000
33
33
  )
34
- ).one_or_none()
35
- if daily_rs.finish_date is None and h_start >= to_utc(
36
- to_ct(daily_rs.start_date) + relativedelta(months=3)
37
- ):
38
- base_rate = data_source.non_core_rate(
39
- "cfd_in_period_tracking", h_start
40
- )["rate_gbp_per_kwh"]
41
34
  else:
42
- base_rate = data_source.non_core_rate(
43
- "cfd_reconciled_daily_levy_rates", h_start
44
- )["rate_gbp_per_kwh"]
35
+ daily_contract = Contract.get_non_core_by_name(
36
+ data_source.sess, "cfd_reconciled_daily_levy_rates"
37
+ )
38
+ daily_rs = data_source.sess.scalars(
39
+ select(RateScript).where(
40
+ RateScript.contract == daily_contract,
41
+ RateScript.start_date <= h_start,
42
+ or_(
43
+ RateScript.finish_date == null(),
44
+ RateScript.finish_date >= h_start,
45
+ ),
46
+ )
47
+ ).one_or_none()
48
+ if daily_rs.finish_date is None and h_start >= to_utc(
49
+ to_ct(daily_rs.start_date) + relativedelta(months=3)
50
+ ):
51
+ base_rate_dec = data_source.non_core_rate(
52
+ "cfd_in_period_tracking", h_start
53
+ )["rate_gbp_per_kwh"]
54
+ else:
55
+ base_rate_dec = data_source.non_core_rate(
56
+ "cfd_reconciled_daily_levy_rates", h_start
57
+ )["rate_gbp_per_kwh"]
58
+ base_rate = float(base_rate_dec)
45
59
 
46
60
  effective_ocl_rate = data_source.non_core_rate(
47
61
  "cfd_operational_costs_levy", h["start-date"]
48
62
  )["record"]["Effective_OCL_Rate_GBP_Per_MWh"]
49
63
  if effective_ocl_rate == "":
50
64
  levy_rate_str = data_source.non_core_rate(
51
- "cfd_operational_costs_levy", h["start-date"]
65
+ "cfd_operational_costs_levy", h_start
52
66
  )["record"]["OCL_Rate_GBP_Per_MWh"]
53
67
  else:
54
68
  levy_rate_str = effective_ocl_rate
55
69
  levy_rate = float(levy_rate_str) / 1000
56
- h["cfd-rate"] = cfd_cache[h["start-date"]] = float(base_rate) + levy_rate
70
+
71
+ h["cfd-rate"] = cfd_cache[h_start] = base_rate + levy_rate
57
72
 
58
73
 
59
74
  def lcc_import(sess, log, set_progress, s):
60
75
  import_in_period_tracking(sess, log, set_progress, s)
61
76
  import_operational_costs_levy(sess, log, set_progress, s)
62
77
  import_reconciled_daily_levy_rates(sess, log, set_progress, s)
78
+ import_forecast_ilr_tra(sess, log, set_progress, s)
63
79
 
64
80
 
65
81
  def _quarters(s):
@@ -93,6 +109,16 @@ def _parse_date(date_str):
93
109
  return to_utc(to_ct(Datetime.strptime(date_str[:10], "%Y-%m-%d")))
94
110
 
95
111
 
112
+ def _parse_varying_date(date_str):
113
+ if "-" in date_str:
114
+ pattern = "%Y-%m-%d"
115
+ elif "/" in date_str:
116
+ pattern = "%d/%m/%Y"
117
+ else:
118
+ raise BadRequest(f"The date {date_str} is not recognized.")
119
+ return Datetime.strptime(date_str, pattern)
120
+
121
+
96
122
  def import_in_period_tracking(sess, log, set_progress, s):
97
123
  log("Starting to check for new LCC CfD In-Period Tracking")
98
124
 
@@ -303,3 +329,34 @@ def import_reconciled_daily_levy_rates(sess, log, set_progress, s):
303
329
 
304
330
  log("Finished LCC CfD Reconciled Daily Levy Rates")
305
331
  sess.commit()
332
+
333
+
334
+ def import_forecast_ilr_tra(sess, log, set_progress, s):
335
+ log("Starting to check for new LCC CfD Forecast ILR TRA")
336
+
337
+ contract_name = "cfd_forecast_ilr_tra"
338
+ contract = Contract.find_non_core_by_name(sess, contract_name)
339
+ if contract is None:
340
+ contract = Contract.insert_non_core(
341
+ sess, contract_name, "", {}, to_utc(ct_datetime(1996, 4, 1)), None, {}
342
+ )
343
+
344
+ res_j = api_search(s, "fbece4ce-7cfc-42b7-8fb2-387cf59a3c32", sort="Period_Start")
345
+ for record in res_j["result"]["records"]:
346
+ period_start_str = record["Period_Start"]
347
+ period_start = to_utc(to_ct(_parse_varying_date(period_start_str)))
348
+
349
+ rs = sess.execute(
350
+ select(RateScript).where(
351
+ RateScript.contract == contract,
352
+ RateScript.start_date == period_start,
353
+ )
354
+ ).scalar_one_or_none()
355
+ if rs is None:
356
+ rs = contract.insert_rate_script(sess, period_start, {})
357
+
358
+ rs_script = rs.make_script()
359
+ rs_script["record"] = record
360
+ rs.update(rs_script)
361
+ sess.commit()
362
+ log("Finished LCC CfD Forecast ILR TRA")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: chellow
3
- Version: 1705663424.0.0
3
+ Version: 1706020835.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)
@@ -18,7 +18,7 @@ chellow/e/bill_importer.py,sha256=y1bpn49xDwltj0PRFowWsjAVamcD8eyxUbCTdGxEZiE,73
18
18
  chellow/e/bmarketidx.py,sha256=0JCBBnP3xfLq2eFjXO_u-gzHyTizab4Pp6PRK6OZLcw,7134
19
19
  chellow/e/bsuos.py,sha256=YtEhce5589kJWNp0HlA7N9L1hHl2KjYkUm54cUCOB8w,15080
20
20
  chellow/e/ccl.py,sha256=CYeFrg0TNF7Av49nqxa0guA8CMcJhdMpBRmOq8PH6G0,564
21
- chellow/e/cfd.py,sha256=K0aF-ch20ZlX0XkTxqqjAGDrP-ZzNeWcGssikU7ObLc,10413
21
+ chellow/e/cfd.py,sha256=eWN1U6_q4OqlLuXOo131jC5536Q3KU2S6Bl6uUv379E,12420
22
22
  chellow/e/computer.py,sha256=J8VvYjcSeJNrG2Ak8Zi2t2bb_8tMrkHWny4JQlgIyy8,67032
23
23
  chellow/e/dno_rate_parser.py,sha256=3IqGM2v6Str7S3Rc9FZ7lRWBKthfb3zSjpJLSETPcEE,20631
24
24
  chellow/e/duos.py,sha256=ISTcNqe9KNjVNM2Qs8IBoQxnmSXOt5W_G7tZxp4T78M,28870
@@ -361,6 +361,6 @@ chellow/templates/g/supply_note_edit.html,sha256=6UQf_qbhFDys3cVsTp-c7ABWZpggW9R
361
361
  chellow/templates/g/supply_notes.html,sha256=WR3YwGh_qqTklSJ7JqWX6BKBc9rk_jMff4RiWZiF2CM,936
362
362
  chellow/templates/g/unit.html,sha256=KouNVU0-i84afANkLQ_heJ0uDfJ9H5A05PuLqb8iCN8,438
363
363
  chellow/templates/g/units.html,sha256=p5Nd-lAIboKPEOO6N451hx1bcKxMg4BDODnZ-43MmJc,441
364
- chellow-1705663424.0.0.dist-info/METADATA,sha256=zlKvzcW3MZxwE746KC-47JbIET9Xx1wxna4kD_-ndnI,12160
365
- chellow-1705663424.0.0.dist-info/WHEEL,sha256=mRYSEL3Ih6g5a_CVMIcwiF__0Ae4_gLYh01YFNwiq1k,87
366
- chellow-1705663424.0.0.dist-info/RECORD,,
364
+ chellow-1706020835.0.0.dist-info/METADATA,sha256=ArRKTKkqPCuPDcnv7ta2OVMFShUtAaPkT1XJm_iwFm4,12160
365
+ chellow-1706020835.0.0.dist-info/WHEEL,sha256=mRYSEL3Ih6g5a_CVMIcwiF__0Ae4_gLYh01YFNwiq1k,87
366
+ chellow-1706020835.0.0.dist-info/RECORD,,