chellow 1714148308.0.0__py3-none-any.whl → 1714396467.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/ccl.py CHANGED
@@ -1,3 +1,13 @@
1
+ import json
2
+ from decimal import Decimal
3
+ from io import BytesIO
4
+ from sqlalchemy import select
5
+
6
+ from chellow.models import Contract, RateScript
7
+ from chellow.rate_server import download
8
+ from chellow.utils import ct_datetime, hh_format, to_utc
9
+
10
+
1
11
  def ccl(data_source):
2
12
  try:
3
13
  ccl_cache = data_source.caches["ccl"]
@@ -15,3 +25,71 @@ def ccl(data_source):
15
25
  hh["ccl-kwh"] = hh["msp-kwh"]
16
26
  hh["ccl-rate"] = rate
17
27
  hh["ccl-gbp"] = hh["msp-kwh"] * rate
28
+
29
+
30
+ def rate_server_import(sess, log, set_progress, s, paths):
31
+ log("Starting to check for new electricity CCL rates")
32
+ contract_name = "ccl"
33
+ contract = Contract.find_non_core_by_name(sess, contract_name)
34
+ if contract is None:
35
+ contract = Contract.insert_non_core(
36
+ sess,
37
+ contract_name,
38
+ "",
39
+ {"enabled": True},
40
+ to_utc(ct_datetime(1996, 4, 1)),
41
+ None,
42
+ {},
43
+ )
44
+ sess.commit()
45
+ contract_props = contract.make_properties()
46
+
47
+ if not contract_props.get("enabled", False):
48
+ log(
49
+ "The automatic importer is disabled. To enable it, edit "
50
+ "the contract properties to set 'enabled' to true."
51
+ )
52
+ return
53
+
54
+ year_entries = {}
55
+ for path, url in paths:
56
+ if len(path) == 4:
57
+ year, utility, rate_type, file_name = path
58
+ if utility == "electricity" and rate_type == "ccl":
59
+ try:
60
+ fl_entries = year_entries[year]
61
+ except KeyError:
62
+ fl_entries = year_entries[year] = {}
63
+
64
+ fl_entries[file_name] = url
65
+
66
+ for year, year_files in sorted(year_entries.items()):
67
+ year_start = to_utc(ct_datetime(year, 4, 1))
68
+ if year_start < contract.start_rate_script.start_date:
69
+ continue
70
+ rs = sess.execute(
71
+ select(RateScript).where(
72
+ RateScript.contract == contract,
73
+ RateScript.start_date == year_start,
74
+ )
75
+ ).scalar_one_or_none()
76
+ if rs is None:
77
+ rs = contract.insert_rate_script(sess, year_start, {})
78
+
79
+ if len(year_files) > 0:
80
+ file_name, url = sorted(year_files.items())[-1]
81
+
82
+ rs_script = rs.make_script()
83
+ if rs_script.get("a_file_name") != file_name:
84
+ log(
85
+ f"Found new file {file_name} for rate script starting "
86
+ f"{hh_format(year_start)}"
87
+ )
88
+ script = {"a_file_name": file_name}
89
+ server_j = json.load(BytesIO(download(s, url)))
90
+ script["ccl_gbp_per_msp_kwh"] = Decimal(server_j["ccl_gbp_per_msp_kwh"])
91
+ rs.update(script)
92
+ log(f"Updated CCL rate script for {hh_format(year_start)}")
93
+
94
+ log("Finished CCL rates")
95
+ sess.commit()
chellow/gas/ccl.py CHANGED
@@ -1,4 +1,13 @@
1
+ import json
2
+ from decimal import Decimal
3
+ from io import BytesIO
4
+
5
+ from sqlalchemy import select
6
+
1
7
  from chellow.gas.engine import g_rates
8
+ from chellow.models import GContract, GRateScript
9
+ from chellow.rate_server import download
10
+ from chellow.utils import ct_datetime, hh_format, to_utc
2
11
 
3
12
 
4
13
  DAILY_THRESHOLD = 145
@@ -13,3 +22,71 @@ def vb(ds):
13
22
  )
14
23
 
15
24
  hh["ccl"] = rate
25
+
26
+
27
+ def rate_server_import(sess, log, set_progress, s, paths):
28
+ log("Starting to check for new gas CCL rates")
29
+ g_contract_name = "ccl"
30
+ g_contract = GContract.find_industry_by_name(sess, g_contract_name)
31
+ if g_contract is None:
32
+ g_contract = GContract.insert_industry(
33
+ sess,
34
+ g_contract_name,
35
+ "",
36
+ {"enabled": True},
37
+ to_utc(ct_datetime(1996, 4, 1)),
38
+ None,
39
+ {},
40
+ )
41
+ sess.commit()
42
+ g_contract_props = g_contract.make_properties()
43
+
44
+ if not g_contract_props.get("enabled", False):
45
+ log(
46
+ "The automatic importer is disabled. To enable it, edit "
47
+ "the contract properties to set 'enabled' to true."
48
+ )
49
+ return
50
+
51
+ year_entries = {}
52
+ for path, url in paths:
53
+ if len(path) == 4:
54
+ year, utility, rate_type, file_name = path
55
+ if utility == "gas" and rate_type == "ccl":
56
+ try:
57
+ fl_entries = year_entries[year]
58
+ except KeyError:
59
+ fl_entries = year_entries[year] = {}
60
+
61
+ fl_entries[file_name] = url
62
+
63
+ for year, year_files in sorted(year_entries.items()):
64
+ year_start = to_utc(ct_datetime(year, 4, 1))
65
+ if year_start < g_contract.start_g_rate_script.start_date:
66
+ continue
67
+ rs = sess.execute(
68
+ select(GRateScript).where(
69
+ GRateScript.g_contract == g_contract,
70
+ GRateScript.start_date == year_start,
71
+ )
72
+ ).scalar_one_or_none()
73
+ if rs is None:
74
+ rs = g_contract.insert_g_rate_script(sess, year_start, {})
75
+
76
+ if len(year_files) > 0:
77
+ file_name, url = sorted(year_files.items())[-1]
78
+
79
+ rs_script = rs.make_script()
80
+ if rs_script.get("a_file_name") != file_name:
81
+ log(
82
+ f"Found new file {file_name} for rate script starting "
83
+ f"{hh_format(year_start)}"
84
+ )
85
+ script = {"a_file_name": file_name}
86
+ server_j = json.load(BytesIO(download(s, url)))
87
+ script["ccl_gbp_per_kwh"] = Decimal(server_j["ccl_gbp_per_kwh"])
88
+ rs.update(script)
89
+ log(f"Updated CCL rate script for {hh_format(year_start)}")
90
+
91
+ log("Finished CCL rates")
92
+ sess.commit()
chellow/gas/views.py CHANGED
@@ -1213,7 +1213,7 @@ def industry_contract_edit_patch(g_contract_id):
1213
1213
  g_contract.update(name, charge_script, properties)
1214
1214
 
1215
1215
  g.sess.commit()
1216
- return chellow_redirect(f"/industry_contracts/{g_contract.id}", 204)
1216
+ return hx_redirect(f"/industry_contracts/{g_contract.id}", 303)
1217
1217
  except BadRequest as e:
1218
1218
  flash(e.description)
1219
1219
  g.sess.rollback()
chellow/rate_server.py CHANGED
@@ -85,9 +85,11 @@ def run_import(sess, log, set_progress):
85
85
  for mod_name in (
86
86
  "chellow.e.mdd_importer",
87
87
  "chellow.e.bsuos",
88
+ "chellow.e.ccl",
88
89
  "chellow.e.dno_rate_parser",
89
90
  "chellow.e.laf_import",
90
91
  "chellow.e.triad",
92
+ "chellow.gas.ccl",
91
93
  "chellow.gas.dn_rate_parser",
92
94
  ):
93
95
  mod = import_module(mod_name)
@@ -97,7 +97,7 @@
97
97
  </li>
98
98
  <li><a href="/e/meter_types" title="Meter Types">Meter Types</a></li>
99
99
  <li>
100
- <a href="/dtc_meter_types" title="DTC Meter Types">DTC Meter Types</a>
100
+ <a href="/e/dtc_meter_types" title="DTC Meter Types">DTC Meter Types</a>
101
101
  </li>
102
102
  <li>
103
103
  <a href="/e/meter_payment_types" title="Meter Payments Types"
@@ -143,6 +143,28 @@
143
143
  </table>
144
144
  </td>
145
145
  </tr>
146
+ <tr>
147
+ <th>CCL</th>
148
+ <td>
149
+ <table>
150
+ <thead>
151
+ <tr>
152
+ <th>Start Date</th>
153
+ <th>File Name</th>
154
+ </tr>
155
+ </thead>
156
+ <tbody>
157
+ {% for rs in ccl_rs %}
158
+ {% set script = rs.make_script() %}
159
+ <tr>
160
+ <td>{{rs.start_date|hh_format}}</td>
161
+ <td>{{script.a_file_name}}</td>
162
+ </tr>
163
+ {% endfor %}
164
+ </tbody>
165
+ </table>
166
+ </td>
167
+ </tr>
146
168
  </tbody>
147
169
  </table>
148
170
 
@@ -193,6 +215,28 @@
193
215
  </table>
194
216
  </td>
195
217
  </tr>
218
+ <tr>
219
+ <th>CCL</th>
220
+ <td>
221
+ <table>
222
+ <thead>
223
+ <tr>
224
+ <th>Start Date</th>
225
+ <th>File Name</th>
226
+ </tr>
227
+ </thead>
228
+ <tbody>
229
+ {% for rs in gas_ccl_rs %}
230
+ {% set script = rs.make_script() %}
231
+ <tr>
232
+ <td>{{rs.start_date|hh_format}}</td>
233
+ <td>{{script.a_file_name}}</td>
234
+ </tr>
235
+ {% endfor %}
236
+ </tbody>
237
+ </table>
238
+ </td>
239
+ </tr>
196
240
  </tbody>
197
241
  </table>
198
242
 
chellow/views.py CHANGED
@@ -2056,6 +2056,17 @@ def rate_server_get():
2056
2056
  )
2057
2057
  .order_by(RateScript.start_date.desc())
2058
2058
  ).scalars()
2059
+ ccl_rs = g.sess.execute(
2060
+ select(RateScript)
2061
+ .join(RateScript.contract)
2062
+ .join(MarketRole)
2063
+ .where(
2064
+ MarketRole.code == "Z",
2065
+ RateScript.start_date >= fy_start,
2066
+ Contract.name == "ccl",
2067
+ )
2068
+ .order_by(RateScript.start_date.desc())
2069
+ ).scalars()
2059
2070
  triad_dates_rs = g.sess.execute(
2060
2071
  select(RateScript)
2061
2072
  .join(RateScript.contract)
@@ -2067,6 +2078,16 @@ def rate_server_get():
2067
2078
  )
2068
2079
  .order_by(RateScript.start_date.desc())
2069
2080
  ).scalars()
2081
+ gas_ccl_rs = g.sess.execute(
2082
+ select(GRateScript)
2083
+ .join(GRateScript.g_contract)
2084
+ .where(
2085
+ GContract.is_industry == true(),
2086
+ GRateScript.start_date >= fy_start,
2087
+ GContract.name == "ccl",
2088
+ )
2089
+ .order_by(GRateScript.start_date.desc())
2090
+ ).scalars()
2070
2091
 
2071
2092
  return render_template(
2072
2093
  "rate_server.html",
@@ -2078,6 +2099,8 @@ def rate_server_get():
2078
2099
  dn_rs=dn_rs,
2079
2100
  bsuos_rs=bsuos_rs,
2080
2101
  triad_dates_rs=triad_dates_rs,
2102
+ gas_ccl_rs=gas_ccl_rs,
2103
+ ccl_rs=ccl_rs,
2081
2104
  )
2082
2105
 
2083
2106
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: chellow
3
- Version: 1714148308.0.0
3
+ Version: 1714396467.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)
@@ -8,16 +8,16 @@ chellow/general_import.py,sha256=xx4R0kQ6WKIty1UdXoF0igGJQZGm9lDNGynMi7LP0k8,657
8
8
  chellow/models.py,sha256=POIL0dfwZFuqht7xHZaE6KJ7fk4kxMZC2aXzgg5kEFY,236921
9
9
  chellow/national_grid.py,sha256=uxcv0qisHPyzw9AVIYPzsRqwt2XPAcZL-SBR12qcrS0,4364
10
10
  chellow/proxy.py,sha256=cVXIktPlX3tQ1BYcwxq0nJXKE6r3DtFTtfFHPq55HaM,1351
11
- chellow/rate_server.py,sha256=vNuKzlr0lkAzZ4zG7zboStoo92_6iLKAxbw1yZ-ucII,5626
11
+ chellow/rate_server.py,sha256=fg-Pf_9Hk3bXmC9riPQNGQxBvLvBa_WtNYdwDCjnCSg,5678
12
12
  chellow/testing.py,sha256=Od4HHH6pZrhJ_De118_F55RJEKmAvhUH2S24QE9qFQk,3635
13
13
  chellow/utils.py,sha256=32qPWEGzCPKPhSM7ztpzcR6ZG74sVZanScDIdK50Rq4,19308
14
- chellow/views.py,sha256=8TdoPQAjfPylaiElL5xBZe2H1l92Xd9N81gnC-C24FE,78842
14
+ chellow/views.py,sha256=KiT4yXI5utC4woQY_-Lh15Tu9HbqnspNKZ1HD9kxLVA,79542
15
15
  chellow/e/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
16
  chellow/e/aahedc.py,sha256=d2usudp7KYWpU6Pk3fal5EQ47EbvkvKeaFGylnb3NWw,606
17
17
  chellow/e/bill_importer.py,sha256=y1bpn49xDwltj0PRFowWsjAVamcD8eyxUbCTdGxEZiE,7389
18
18
  chellow/e/bmarketidx.py,sha256=0JCBBnP3xfLq2eFjXO_u-gzHyTizab4Pp6PRK6OZLcw,7134
19
19
  chellow/e/bsuos.py,sha256=hdP9vnOJSuZl46OAkJeUg1XJYvYIBj4J6Sqce1Hy9Vs,15542
20
- chellow/e/ccl.py,sha256=CYeFrg0TNF7Av49nqxa0guA8CMcJhdMpBRmOq8PH6G0,564
20
+ chellow/e/ccl.py,sha256=30dh_SvlgzsTQPPAJNZWILaMvbeDsv9-P-S1JxS5_SQ,3184
21
21
  chellow/e/cfd.py,sha256=V1DTT5XBQbt8hO1gae1u3315fZ4iuYk3XC7J2sUbhKQ,14352
22
22
  chellow/e/computer.py,sha256=YL1JFUYfFW-i9DODfvSnp6gTL_MwIfwoWj1TWtOsxPg,67105
23
23
  chellow/e/dno_rate_parser.py,sha256=thNjT7HeAcvwV5vACvyGZ-yYzCs4keiIJEoCL8FjJ3E,21488
@@ -59,12 +59,12 @@ chellow/e/bill_parsers/sww_xls.py,sha256=QEjiuvwvr5FuWCfqqVw8LaA_vZyAKsvRAS5fw3x
59
59
  chellow/gas/bill_import.py,sha256=w0lPgK_Drzh8rtnEBQe3qFuxrgzZ6qQSgpaGrrGznMU,6549
60
60
  chellow/gas/bill_parser_csv.py,sha256=Ecdy-apFT-mWAxddAsM4k1s-9-FpIaOfjP0oFc0rdQg,5557
61
61
  chellow/gas/bill_parser_engie_edi.py,sha256=2nlroUfNS4DV7fMLiTS_0MZanyFdmRn-4guR3dSK-Vg,8813
62
- chellow/gas/ccl.py,sha256=f4__2kBd6b8n1-7JKKjsJQ2Y0ZxqrIZJ12Y9BQDBxKc,281
62
+ chellow/gas/ccl.py,sha256=DMlcPUELZi00CaDekVJINYk3GgH5apFrImVdmkbyba0,2913
63
63
  chellow/gas/cv.py,sha256=4cdYYQ8Qak6NeYdBCB4YaQ0jX8-UkaydIIdibCQuXxM,7344
64
64
  chellow/gas/dn_rate_parser.py,sha256=Mq8rAcUEUxIQOks59bsCKl8GrefvoHbrTCHqon9N0z0,11340
65
65
  chellow/gas/engine.py,sha256=PhaCWDslhEzDmuCu5PMt3IpFANm27OO1bupq3yQCmc0,25518
66
66
  chellow/gas/transportation.py,sha256=Bkg8TWOs-v0ES-4qqwbleiOhqbE_t2KauUx9JYMZELM,5300
67
- chellow/gas/views.py,sha256=btud2kHMvT_wRWCdRi2JdjUaeGkESaYnY2GwLsMMjl4,56394
67
+ chellow/gas/views.py,sha256=YFP8w0Y1PeH6tb2pPm4JTkUTmQw1AuYeO4pFXcf-1bY,56389
68
68
  chellow/reports/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
69
69
  chellow/reports/report_109.py,sha256=S8fsOwh-jVWGL0RsgyYLdqn00BAvlkBbi4VfTSGI-Mc,11181
70
70
  chellow/reports/report_111.py,sha256=qU5MYPQzZ_cEvuERE8bxq93D-dN1yd4oML6FIqd0Jdk,28278
@@ -106,7 +106,7 @@ chellow/static/images/favicon_test.svg,sha256=HnLS_BjNt8M0Ikko5Z-f_E2aed7y6RRU6j
106
106
  chellow/static/images/logo.png,sha256=XMW2XwukTicKVJ46E2SnbHJYh77uFLVYlwR4xN43YKg,1569
107
107
  chellow/static/js/htmx.min.js,sha256=_TRunIY51GJIk_xFXyQHoJtBgwFzbdGOu7B3ZGN_tHg,42819
108
108
  chellow/templates/403.html,sha256=49f75OKp0eS8wi2D1YBhdv7bKTNtfs6BTXZPXlxCbDs,344
109
- chellow/templates/base.html,sha256=tilhJHj1oTB7H802TSobnuIDip9o2Ws4zJSleM3bgUM,6581
109
+ chellow/templates/base.html,sha256=dcFxtqmZlJXBsmkkFJHFr7TVLwTBQs4_K1VcpjG395o,6583
110
110
  chellow/templates/bill_type.html,sha256=dNNEaQ9ZVghLCAvxQ6IDalw0K0-BIjEQap6u1zu6TW8,402
111
111
  chellow/templates/bill_types.html,sha256=YKy6cnzzch756dlTnl01ZU0K5NVuTZtBJQV32ZphHvc,471
112
112
  chellow/templates/chain.html,sha256=iOnSoDQOO_-1tfcxUHQKDAUnV4QbCYu5PPNmS4RkOg4,775
@@ -129,7 +129,7 @@ chellow/templates/non_core_rate_script.html,sha256=CqGnuWdzhk_o_2xNFcF8rgk0p7SNh
129
129
  chellow/templates/non_core_rate_script_add.html,sha256=Qx8_cYFRQZrXSyR3uf_8OxUAUz3PqyYc4V11lTU18sE,690
130
130
  chellow/templates/non_core_rate_script_edit.html,sha256=14jFqalqmFg9_2LUlEy7Q4yUx4pVGTHc9fbYnpm-3Y8,1868
131
131
  chellow/templates/object_summary.html,sha256=VGCAAYcWTzgNfL0mxEef2Fa8dP3FcBhzj0fmF82_S4I,244
132
- chellow/templates/rate_server.html,sha256=4f6V8PRW-bn2BQxX-BZqNQZf1w6GJPD-L4AxpSGQWZE,4460
132
+ chellow/templates/rate_server.html,sha256=SezuwdKhHRZ00-R_S6ttKiZ-nvRpwozV9QcIMf9StG8,5360
133
133
  chellow/templates/report_run.html,sha256=O_wjIu43S-mKVyZyku3dJJdvyck3rAgEdhw59TsCcK0,4040
134
134
  chellow/templates/report_run_asset_comparison.html,sha256=VYCCUmIC7Mfe7uuaAHb6ihiK6zsqeTlQbzgtzLqR3zg,2305
135
135
  chellow/templates/report_run_bill_check.html,sha256=yAVFBi0zdamnlRpO2VqKY3UAmAJchSjwSmrmaITLmEA,5055
@@ -363,6 +363,6 @@ chellow/templates/g/supply_note_edit.html,sha256=6UQf_qbhFDys3cVsTp-c7ABWZpggW9R
363
363
  chellow/templates/g/supply_notes.html,sha256=WR3YwGh_qqTklSJ7JqWX6BKBc9rk_jMff4RiWZiF2CM,936
364
364
  chellow/templates/g/unit.html,sha256=KouNVU0-i84afANkLQ_heJ0uDfJ9H5A05PuLqb8iCN8,438
365
365
  chellow/templates/g/units.html,sha256=p5Nd-lAIboKPEOO6N451hx1bcKxMg4BDODnZ-43MmJc,441
366
- chellow-1714148308.0.0.dist-info/METADATA,sha256=rzB_YqVqUTlWTKYMQ9KGagipFv6Dj6Q1IAvPcbse33M,12205
367
- chellow-1714148308.0.0.dist-info/WHEEL,sha256=zEMcRr9Kr03x1ozGwg5v9NQBKn3kndp6LSoSlVg-jhU,87
368
- chellow-1714148308.0.0.dist-info/RECORD,,
366
+ chellow-1714396467.0.0.dist-info/METADATA,sha256=XqwlSvE3Utq6wDib3BS7MXDzgbiVIf8ZIZkNzTdbTCM,12205
367
+ chellow-1714396467.0.0.dist-info/WHEEL,sha256=zEMcRr9Kr03x1ozGwg5v9NQBKn3kndp6LSoSlVg-jhU,87
368
+ chellow-1714396467.0.0.dist-info/RECORD,,