chellow 1682689432.0.0__py3-none-any.whl → 1682692302.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/tnuos.py CHANGED
@@ -1,7 +1,10 @@
1
+ from datetime import datetime as Datetime, timedelta as Timedelta
1
2
  from decimal import Decimal, InvalidOperation
3
+ from io import BytesIO
2
4
 
3
5
  from dateutil.relativedelta import relativedelta
4
6
 
7
+ from pypdf import PdfReader
5
8
 
6
9
  from sqlalchemy import null, or_, select
7
10
 
@@ -11,10 +14,12 @@ import chellow.e.computer
11
14
  import chellow.e.duos
12
15
  from chellow.models import Contract, RateScript
13
16
  from chellow.national_grid import api_get
17
+ from chellow.rate_server import download
14
18
  from chellow.utils import (
15
19
  c_months_u,
16
20
  ct_datetime,
17
21
  hh_after,
22
+ hh_format,
18
23
  hh_min,
19
24
  to_ct,
20
25
  to_utc,
@@ -514,3 +519,66 @@ def ng_import_triad(sess, log, set_progress, s):
514
519
 
515
520
  log("Finished TNUoS TRIAD Tariffs")
516
521
  sess.commit()
522
+
523
+
524
+ def _find_triad_dates(file_name, file_like):
525
+ dates = []
526
+ rate_script = {"a_file_name": file_name, "triad_dates": dates}
527
+
528
+ reader = PdfReader(file_like)
529
+ in_table = False
530
+ for page in reader.pages:
531
+ for line in page.extract_text().splitlines():
532
+ if in_table:
533
+ date_str, period_str, _ = line.split()
534
+ date = Datetime.strptime(date_str, "%d/%m/%Y")
535
+ delta = Timedelta(minutes=30) * (int(period_str) - 1)
536
+ dates.append(to_utc(to_ct(date + delta)))
537
+ if len(dates) == 3:
538
+ in_table = False
539
+ else:
540
+ if "Demand (MW)" in line:
541
+ in_table = True
542
+
543
+ return rate_script
544
+
545
+
546
+ def rate_server_import(sess, log, set_progress, s, paths):
547
+ log("Starting to check for new TNUoS triad date PDFs")
548
+
549
+ year_entries = {}
550
+ for path, url in paths:
551
+ if len(path) == 4:
552
+ year, utility, rate_type, file_name = path
553
+ if utility == "electricity" and rate_type == "tnuos":
554
+ try:
555
+ fl_entries = year_entries[year]
556
+ except KeyError:
557
+ fl_entries = year_entries[year] = {}
558
+
559
+ fl_entries[file_name] = url
560
+
561
+ for year, year_pdfs in sorted(year_entries.items()):
562
+ year_start = to_utc(ct_datetime(year, 4, 1))
563
+ contract = Contract.get_non_core_by_name(sess, "triad_dates")
564
+ if year_start < contract.start_rate_script.start_date:
565
+ continue
566
+ rs = sess.execute(
567
+ select(RateScript).where(
568
+ RateScript.contract == contract,
569
+ RateScript.start_date == year_start,
570
+ )
571
+ ).scalar_one_or_none()
572
+ if rs is None:
573
+ rs = contract.insert_rate_script(sess, year_start, {})
574
+
575
+ if len(year_pdfs) > 0:
576
+ file_name, url = sorted(year_pdfs.items())[-1]
577
+
578
+ rs_script = rs.make_script()
579
+ if rs_script.get("a_file_name") != file_name:
580
+ rs.update(_find_triad_dates(file_name, BytesIO(download(s, url))))
581
+ log(f"Updated triad dates rate script for {hh_format(year_start)}")
582
+
583
+ log("Finished TNUoS triad dates PDFs")
584
+ sess.commit()
chellow/rate_server.py CHANGED
@@ -72,8 +72,13 @@ def run_import(sess, log, set_progress):
72
72
  paths_list = []
73
73
  for sub_entry in tree_entry["tree"]:
74
74
  path = sub_entry["path"].split("/")
75
- if path[-1] != "README.md":
76
- paths_list.append((path, sub_entry["url"]))
75
+ if path[-1] == "README.md":
76
+ continue
77
+ if len(path) == 1 and path[0] == "LICENSE":
78
+ continue
79
+
80
+ path[0] = int(path[0])
81
+ paths_list.append((tuple(path), sub_entry["url"]))
77
82
 
78
83
  paths = tuple(paths_list)
79
84
 
@@ -82,6 +87,7 @@ def run_import(sess, log, set_progress):
82
87
  "chellow.e.dno_rate_parser",
83
88
  "chellow.e.laf_import",
84
89
  "chellow.e.mdd_importer",
90
+ "chellow.e.tnuos",
85
91
  "chellow.gas.dn_rate_parser",
86
92
  ):
87
93
  mod = import_module(mod_name)
@@ -19,6 +19,10 @@
19
19
  <p>
20
20
  <a href="/national_grid">Automatic Importer</a>
21
21
  </p>
22
+ {% elif contract.name == 'triad_dates' %}
23
+ <p>
24
+ <a href="/rate_server">Automatic Importer</a>
25
+ </p>
22
26
  {% endif %}
23
27
 
24
28
 
@@ -100,7 +100,7 @@
100
100
  </td>
101
101
  </tr>
102
102
  <tr>
103
- <th>TNUoS Spreadsheet</th>
103
+ <th>TRIAD Dates PDFs</th>
104
104
  <td>
105
105
  <table>
106
106
  <thead>
@@ -110,7 +110,7 @@
110
110
  </tr>
111
111
  </thead>
112
112
  <tbody>
113
- {% for rs in tnuos_rs %}
113
+ {% for rs in triad_dates_rs %}
114
114
  {% set script = rs.make_script() %}
115
115
  <tr>
116
116
  <td>{{rs.start_date|hh_format}}</td>
chellow/views.py CHANGED
@@ -2176,17 +2176,6 @@ def rate_server_get():
2176
2176
  .where(MarketRole.code == "R", RateScript.start_date >= fy_start)
2177
2177
  .order_by(Contract.name, RateScript.start_date.desc())
2178
2178
  ).scalars()
2179
- tnuos_rs = g.sess.execute(
2180
- select(RateScript)
2181
- .join(RateScript.contract)
2182
- .join(MarketRole)
2183
- .where(
2184
- MarketRole.code == "Z",
2185
- RateScript.start_date >= fy_start,
2186
- Contract.name == "tnuos",
2187
- )
2188
- .order_by(RateScript.start_date.desc())
2189
- ).scalars()
2190
2179
  nts_rs = g.sess.execute(
2191
2180
  select(GRateScript)
2192
2181
  .join(GRateScript.g_contract)
@@ -2218,6 +2207,17 @@ def rate_server_get():
2218
2207
  )
2219
2208
  .order_by(RateScript.start_date.desc())
2220
2209
  ).scalars()
2210
+ triad_dates_rs = g.sess.execute(
2211
+ select(RateScript)
2212
+ .join(RateScript.contract)
2213
+ .join(MarketRole)
2214
+ .where(
2215
+ MarketRole.code == "Z",
2216
+ RateScript.start_date >= fy_start,
2217
+ Contract.name == "triad_dates",
2218
+ )
2219
+ .order_by(RateScript.start_date.desc())
2220
+ ).scalars()
2221
2221
 
2222
2222
  return render_template(
2223
2223
  "rate_server.html",
@@ -2225,10 +2225,10 @@ def rate_server_get():
2225
2225
  config_state=config.make_state(),
2226
2226
  config_properties=props.get("rate_server", {}),
2227
2227
  dno_rs=dno_rs,
2228
- tnuos_rs=tnuos_rs,
2229
2228
  nts_rs=nts_rs,
2230
2229
  dn_rs=dn_rs,
2231
2230
  bsuos_rs=bsuos_rs,
2231
+ triad_dates_rs=triad_dates_rs,
2232
2232
  )
2233
2233
 
2234
2234
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: chellow
3
- Version: 1682689432.0.0
3
+ Version: 1682692302.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,10 +8,10 @@ chellow/general_import.py,sha256=Xuiwl-yeM0MCmPstzQR2E6ASs8sYE8b1GNeDLStnizY,584
8
8
  chellow/models.py,sha256=UhVekL4GM_4zs6ZGu83QFssyEMbwLHWerT1dWcby-ps,233497
9
9
  chellow/national_grid.py,sha256=0lckRMF-udVa0VWzCOlcHx36Su0628fI4Fkvk2ttUWo,4409
10
10
  chellow/proxy.py,sha256=Mzssi9nTf6s_G4RSn8k5oAHqzVYIxMsfbudj1amYucI,1387
11
- chellow/rate_server.py,sha256=iW8cIDSr_fHvxJz5506ua6UxWnJ92zb2vRBmeoP36qk,5540
11
+ chellow/rate_server.py,sha256=xVk15pdSovcD8K8BWcOmjwo_L3a8LYry7L2Gvw56OEQ,5696
12
12
  chellow/testing.py,sha256=1TvNEPjX_VRPDifJWRFJw_8gg0RCsEpYVHkspQ1diJw,3913
13
13
  chellow/utils.py,sha256=IHC4Pcd_9CRbmJXAOlDvTyAcUoaWeLSH37zgjqVYYl4,18981
14
- chellow/views.py,sha256=EB4Af5F3alq-98iPdlTUh09bJWP9a1SMNX-vhmJr2AQ,83449
14
+ chellow/views.py,sha256=27TKAL-nYQg26I4bMaTW3r4U8x2eDwhzBlVJR9_y2VY,83473
15
15
  chellow/e/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
16
  chellow/e/aahedc.py,sha256=DUrYAlrn4jzf6y6C2wivxlFosdVIibG69BWy_KMekGM,706
17
17
  chellow/e/bill_importer.py,sha256=BHrQkcvlOh27k0KexHA8nWJGcHGGpewbkkpncmxbAc4,7183
@@ -33,7 +33,7 @@ chellow/e/ro.py,sha256=A74nFxitFCZ-oLmYzPza54e328VKcqv8L2wVGilaUjA,696
33
33
  chellow/e/scenario.py,sha256=IuyE494XaBLq3FW7NdJePD6J4cTzPogfACO6dThiY00,23239
34
34
  chellow/e/system_price.py,sha256=IPBLSRPzGA3yca4tpR8PJemwPbgqVjn1WnljOMUyWnA,8145
35
35
  chellow/e/tlms.py,sha256=gXBZTHXqGVcaTGHaYGVA5Ir5pzoBDqFC1Kl1mQ0IDqU,9549
36
- chellow/e/tnuos.py,sha256=6T44N6Qg-w3lKnfl8R1vA1cwDZxnbVpce7L1G9u9FDU,16527
36
+ chellow/e/tnuos.py,sha256=gFvNgibycspsyD3I8xxBWPjvyWJfkAiDRMbLenCpEgQ,18947
37
37
  chellow/e/views.py,sha256=5pp-sbUHaiQ1N0RgY73XQbHlqrZP3y64HrZgPTmFxE4,180225
38
38
  chellow/e/bill_parsers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
39
39
  chellow/e/bill_parsers/activity_mop_stark_xlsx.py,sha256=v1s4O8phVJVn9sOs9HKrKYcECAP0ApnUgqCaa2ARYiQ,4234
@@ -117,14 +117,14 @@ chellow/templates/local_report.html,sha256=pV7_0QwyQ-D3OS9LXrly5pq3qprZnwTCoq6vC
117
117
  chellow/templates/local_reports.html,sha256=4wbfVkY4wUfSSfWjxqIsvCpIsa9k7H_dGAjznrG5jNM,701
118
118
  chellow/templates/national_grid.html,sha256=8W92tsjlqPSB0J--nyFIi-wzFae9CyDr6fODXLZp8ic,991
119
119
  chellow/templates/non_core_auto_importer.html,sha256=s9SluRN1bHTHjd8GP6uFhk6LrZYG8dqBG3y94zUKe5Q,944
120
- chellow/templates/non_core_contract.html,sha256=KXvAeOAmdHQ2bmtxX6UKEZ6yZEj29HmrvzCzBBQk2d8,1275
120
+ chellow/templates/non_core_contract.html,sha256=BDld-pGs7OnBqc99i9H7WsPc5iBuyXY2AbIM3oUwxRE,1380
121
121
  chellow/templates/non_core_contract_edit.html,sha256=_EWwJdrez2uI2mA58Jf5WIYs7UfBw1xWV-Bpgliyurw,3005
122
122
  chellow/templates/non_core_contracts.html,sha256=vIrVdn4NUj58Uy17REs_fy2JBQzPkjcg63bg7q6kELg,661
123
123
  chellow/templates/non_core_rate_script.html,sha256=CqGnuWdzhk_o_2xNFcF8rgk0p7SNh0B0c3k1JzOtn98,1283
124
124
  chellow/templates/non_core_rate_script_add.html,sha256=Qx8_cYFRQZrXSyR3uf_8OxUAUz3PqyYc4V11lTU18sE,690
125
125
  chellow/templates/non_core_rate_script_edit.html,sha256=14jFqalqmFg9_2LUlEy7Q4yUx4pVGTHc9fbYnpm-3Y8,1868
126
126
  chellow/templates/object_summary.html,sha256=VGCAAYcWTzgNfL0mxEef2Fa8dP3FcBhzj0fmF82_S4I,244
127
- chellow/templates/rate_server.html,sha256=ISul3S3C5_TYtMXJeHMqpcsPEa5Ky7uoRw0DPcR65Wc,4455
127
+ chellow/templates/rate_server.html,sha256=4f6V8PRW-bn2BQxX-BZqNQZf1w6GJPD-L4AxpSGQWZE,4460
128
128
  chellow/templates/report_run.html,sha256=O_wjIu43S-mKVyZyku3dJJdvyck3rAgEdhw59TsCcK0,4040
129
129
  chellow/templates/report_run_asset_comparison.html,sha256=VYCCUmIC7Mfe7uuaAHb6ihiK6zsqeTlQbzgtzLqR3zg,2305
130
130
  chellow/templates/report_run_bill_check.html,sha256=yAVFBi0zdamnlRpO2VqKY3UAmAJchSjwSmrmaITLmEA,5055
@@ -350,6 +350,6 @@ chellow/templates/g/supply_note_edit.html,sha256=6UQf_qbhFDys3cVsTp-c7ABWZpggW9R
350
350
  chellow/templates/g/supply_notes.html,sha256=WR3YwGh_qqTklSJ7JqWX6BKBc9rk_jMff4RiWZiF2CM,936
351
351
  chellow/templates/g/unit.html,sha256=KouNVU0-i84afANkLQ_heJ0uDfJ9H5A05PuLqb8iCN8,438
352
352
  chellow/templates/g/units.html,sha256=p5Nd-lAIboKPEOO6N451hx1bcKxMg4BDODnZ-43MmJc,441
353
- chellow-1682689432.0.0.dist-info/METADATA,sha256=0geMd95rEXV3TRUMqtqJKO7sbtaeaOvE8JmQK90raKg,12160
354
- chellow-1682689432.0.0.dist-info/WHEEL,sha256=9MIigYJ7D5sOqAPqr0-o6tSMY_nQ7c6kvtvyeUB99YQ,87
355
- chellow-1682689432.0.0.dist-info/RECORD,,
353
+ chellow-1682692302.0.0.dist-info/METADATA,sha256=26vUz8SeW-KBWcrEPeavVVdz4UXj1bBrTswrLk4Dytw,12160
354
+ chellow-1682692302.0.0.dist-info/WHEEL,sha256=9MIigYJ7D5sOqAPqr0-o6tSMY_nQ7c6kvtvyeUB99YQ,87
355
+ chellow-1682692302.0.0.dist-info/RECORD,,