chellow 1729760318.0.0__py3-none-any.whl → 1729849426.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/gas/engine.py CHANGED
@@ -76,8 +76,14 @@ def get_g_engine_cache(caches, name):
76
76
  try:
77
77
  return caches["g_engine"][name]
78
78
  except KeyError:
79
- caches["g_engine"] = defaultdict(dict)
80
- return caches["g_engine"][name]
79
+ try:
80
+ gcache = caches["g_engine"]
81
+ except KeyError:
82
+ gcache = caches["g_enine"] = {}
83
+
84
+ cache = gcache[name] = {}
85
+
86
+ return cache
81
87
 
82
88
 
83
89
  def g_contract_func(caches, contract, func_name):
@@ -14,7 +14,7 @@ from werkzeug.exceptions import BadRequest
14
14
  import chellow.e.computer
15
15
  from chellow.dloads import open_file
16
16
  from chellow.e.computer import contract_func, forecast_date
17
- from chellow.gas.engine import GDataSource
17
+ from chellow.gas.engine import GDataSource, g_rates
18
18
  from chellow.models import (
19
19
  GBill,
20
20
  GContract,
@@ -28,11 +28,13 @@ from chellow.models import (
28
28
  User,
29
29
  )
30
30
  from chellow.utils import (
31
+ PropDict,
31
32
  c_months_c,
32
33
  c_months_u,
33
34
  hh_format,
34
35
  hh_max,
35
36
  hh_min,
37
+ hh_range,
36
38
  make_val,
37
39
  req_bool,
38
40
  req_int,
@@ -162,6 +164,16 @@ def _process_era(
162
164
 
163
165
  def content(scenario_props, user_id, compression, now, base_name):
164
166
  report_context = {}
167
+ try:
168
+ eng = report_context["g_engine"]
169
+ except KeyError:
170
+ eng = report_context["g_engine"] = {}
171
+
172
+ try:
173
+ rss_cache = eng["rates"]
174
+ except KeyError:
175
+ rss_cache = eng["rates"] = {}
176
+
165
177
  try:
166
178
  with RSession() as sess:
167
179
  start_year = scenario_props["scenario_start_year"]
@@ -197,7 +209,7 @@ def content(scenario_props, user_id, compression, now, base_name):
197
209
  else:
198
210
  forecast_from = to_utc(forecast_from)
199
211
 
200
- sites = sess.query(Site).distinct().order_by(Site.code)
212
+ sites = select(Site).join(SiteGEra).distinct().order_by(Site.code)
201
213
 
202
214
  mprns = scenario_props.get("mprns")
203
215
  g_supply_ids = None
@@ -214,10 +226,7 @@ def content(scenario_props, user_id, compression, now, base_name):
214
226
  base_name.append("mprns")
215
227
 
216
228
  sites = (
217
- sites.join(SiteGEra)
218
- .join(GEra)
219
- .join(GSupply)
220
- .where(GSupply.id.in_(g_supply_ids))
229
+ sites.join(GEra).join(GSupply).where(GSupply.id.in_(g_supply_ids))
221
230
  )
222
231
 
223
232
  site_codes = scenario_props.get("site_codes")
@@ -229,6 +238,53 @@ def content(scenario_props, user_id, compression, now, base_name):
229
238
  base_name.append("sitecodes")
230
239
  sites = sites.where(Site.code.in_(site_codes))
231
240
 
241
+ for is_industry, rates_prop in (
242
+ (True, "industry_rates"),
243
+ (False, "supplier_rates"),
244
+ ):
245
+
246
+ for rate_script in scenario_props.get(rates_prop, []):
247
+ g_contract_id = rate_script["g_contract_id"]
248
+ try:
249
+ i_cache = rss_cache[is_industry]
250
+ except KeyError:
251
+ i_cache = rss_cache[is_industry] = {}
252
+
253
+ try:
254
+ cont_cache = i_cache[g_contract_id]
255
+ except KeyError:
256
+ cont_cache = i_cache[g_contract_id] = {}
257
+
258
+ try:
259
+ rate_script_start = rate_script["start_date"]
260
+ except KeyError:
261
+ raise BadRequest(
262
+ f"Problem in the scenario properties. Can't find the "
263
+ f"'start_date' key of the contract {g_contract_id} in the "
264
+ f"'{rates_prop}' map."
265
+ )
266
+
267
+ try:
268
+ rate_script_finish = rate_script["finish_date"]
269
+ except KeyError:
270
+ raise BadRequest(
271
+ f"Problem in the scenario properties. Can't find the "
272
+ f"'finish_date' key of the contract {g_contract_id} in the "
273
+ f"'{rates_prop}' map."
274
+ )
275
+
276
+ for dt in hh_range(
277
+ report_context, rate_script_start, rate_script_finish
278
+ ):
279
+ g_rates(sess, report_context, g_contract_id, dt, is_industry)
280
+
281
+ for dt in hh_range(
282
+ report_context, rate_script_start, rate_script_finish
283
+ ):
284
+ storage = cont_cache[dt]._storage.copy()
285
+ storage.update(rate_script["script"])
286
+ cont_cache[dt] = PropDict("scenario properties", storage)
287
+
232
288
  user = User.get_by_id(sess, user_id)
233
289
  fname = "_".join(base_name) + ".ods"
234
290
  rf = open_file(fname, user, mode="wb")
@@ -279,7 +335,7 @@ def content(scenario_props, user_id, compression, now, base_name):
279
335
  sess.query(GContract)
280
336
  .join(GEra)
281
337
  .join(GSupply)
282
- .filter(
338
+ .where(
283
339
  GEra.start_date <= finish_date,
284
340
  or_(GEra.finish_date == null(), GEra.finish_date >= start_date),
285
341
  )
@@ -318,9 +374,13 @@ def content(scenario_props, user_id, compression, now, base_name):
318
374
  "billed_vat_gbp": 0,
319
375
  "billed_gross_gbp": 0,
320
376
  }
321
- for site in sites.filter(
322
- GEra.start_date <= month_finish,
323
- or_(GEra.finish_date == null(), GEra.finish_date >= month_start),
377
+ for site in sess.scalars(
378
+ sites.where(
379
+ GEra.start_date <= month_finish,
380
+ or_(
381
+ GEra.finish_date == null(), GEra.finish_date >= month_start
382
+ ),
383
+ )
324
384
  ):
325
385
  linked_sites = {
326
386
  s.code
@@ -15,9 +15,9 @@
15
15
  <legend>Run With Monthly Duration</legend>
16
16
  <fieldset>
17
17
  <input type="hidden" name="scenario_id" value="{{scenario.id}}">
18
- <label>Months</label> {{input_text('months', '1', 2, 2)}}
18
+ <label>Months</label> {{input_text('months', initial=scenario_duration, size=2, maxlength=2)}}
19
19
  <label>Finish Month</label>
20
- {{input_date('finish', month_finish, resolution='month')}}
20
+ {{input_date('finish', scenario_finish_date, resolution='month')}}
21
21
  <input type="submit" value="Run">
22
22
  </fieldset>
23
23
  </form>
@@ -224,11 +224,11 @@
224
224
  "XJJK4",
225
225
  ],
226
226
 
227
- /* Rates */
227
+ /* Supplier Rates */
228
228
 
229
- "rates": [
229
+ "supplier_rates": [
230
230
  {
231
- "contract_id": 46,
231
+ "g_contract_id": 46,
232
232
  "start_date": 2014-10-01T00:00:00Z,
233
233
  "finish_date": 2015-05-01T00:00:00Z,
234
234
  "script": {
@@ -237,7 +237,7 @@
237
237
  },
238
238
 
239
239
  {
240
- "contract_id": 3,
240
+ "g_contract_id": 3,
241
241
  "start_date": 2015-01-01T00:00:00Z,
242
242
  "finish_date": 2015-03-01T00:00:00Z,
243
243
  "script": {
@@ -246,8 +246,29 @@
246
246
  }
247
247
  ],
248
248
 
249
+ /* Industry Rates */
249
250
 
250
- "era_maps": {
251
+ "industry_rates": [
252
+ {
253
+ "g_contract_id": 46,
254
+ "start_date": 2014-10-01T00:00:00Z,
255
+ "finish_date": 2015-05-01T00:00:00Z,
256
+ "script": {
257
+ "gbp_per_msp_kwh": 0.667
258
+ }
259
+ },
260
+
261
+ {
262
+ "g_contract_id": 3,
263
+ "start_date": 2015-01-01T00:00:00Z,
264
+ "finish_date": 2015-03-01T00:00:00Z,
265
+ "script": {
266
+ "gbp_per_gsp_kwh": 5.77
267
+ }
268
+ }
269
+ ],
270
+
271
+ "g_era_maps": {
251
272
  2012-09-01T00:00:00Z: {
252
273
  },
253
274
  },
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: chellow
3
- Version: 1729760318.0.0
3
+ Version: 1729849426.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)
@@ -70,7 +70,7 @@ chellow/gas/bill_parser_total_edi.py,sha256=bMAeIkzHwNhv0qdKYXtRl-tzUUYtjNkbM3PM
70
70
  chellow/gas/ccl.py,sha256=DMlcPUELZi00CaDekVJINYk3GgH5apFrImVdmkbyba0,2913
71
71
  chellow/gas/cv.py,sha256=4cdYYQ8Qak6NeYdBCB4YaQ0jX8-UkaydIIdibCQuXxM,7344
72
72
  chellow/gas/dn_rate_parser.py,sha256=Mq8rAcUEUxIQOks59bsCKl8GrefvoHbrTCHqon9N0z0,11340
73
- chellow/gas/engine.py,sha256=jT7m6vddi5GnWd51wCYEVhBS-LZEn1T9ggZX7Y9HGK0,25263
73
+ chellow/gas/engine.py,sha256=NR96BtZKVYQ8hnZVb5oZelb8IhaxupyovNWoHK5ZhTk,25355
74
74
  chellow/gas/transportation.py,sha256=Bkg8TWOs-v0ES-4qqwbleiOhqbE_t2KauUx9JYMZELM,5300
75
75
  chellow/gas/views.py,sha256=R4Ky8syioWSQJLTuSKVLsc266eDv8a6WEo_e60u_4ug,59021
76
76
  chellow/reports/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -101,7 +101,7 @@ chellow/reports/report_csv_llfcs.py,sha256=OHSbP64lQ6dlAMcQYgvdANlA4lQyF0iBlwk7V
101
101
  chellow/reports/report_csv_site_hh_data.py,sha256=yWhEoGGyg_ctM8T55raksTPRJ5ycVO6lVfUx5tRBzTQ,4372
102
102
  chellow/reports/report_csv_site_snags.py,sha256=gG2sYQrLoIBwCoMUC8rhmAL7Kffh_rvNb9UOX7cYDko,2668
103
103
  chellow/reports/report_ecoes_comparison.py,sha256=CaeMCpLifP-kh2O9MZPs0EYf4UqksL-xFjwki41DTRA,21444
104
- chellow/reports/report_g_monthly_duration.py,sha256=0b2ze1qW0jSVTEGQhJAg0s42AvkeqjMGNge4OQTIm7s,15919
104
+ chellow/reports/report_g_monthly_duration.py,sha256=I1MsLr-VD6VczRB8YrDGuTXVXv_iKpBZiCA7DLqZQQc,18305
105
105
  chellow/reports/report_g_supplies_snapshot.py,sha256=0M0x_0o0985Hu45gUJJJwzfx0DDOAuXBJ1UVUDbQ36g,4718
106
106
  chellow/reports/report_g_supply_virtual_bill.py,sha256=x_KtQ02dwgmXvAEUXJ1poK0BRwqxa-GcbJ5pddEina0,3694
107
107
  chellow/reports/report_g_virtual_bills.py,sha256=t3hmTiURk1E_mPucIboCdPBlSLapDIUdHYRpVTFtJgw,4569
@@ -147,9 +147,9 @@ chellow/templates/report_run_row.html,sha256=bmtcdqJaS1CXpL0i8PuqvmeF98jKNYX5-mn
147
147
  chellow/templates/report_run_row_bill_check.html,sha256=aC2LMu_6NvmTN3ZdxHJPPPczyxPN6hg0F-PPcqIWUws,4683
148
148
  chellow/templates/report_run_supply_contacts.html,sha256=JNzwz9M6qbLRDMkCzFCxxANapUer5klxo7t5a48nAzg,2117
149
149
  chellow/templates/report_runs.html,sha256=ecoIkl2WtfYtifiTxnslmpMGYYGVQW-CVSBpqhXyiE4,1131
150
- chellow/templates/scenario.html,sha256=eHXgCszqyPW7fzBH-nr25XpKbPj4FIobKRFv3G8uJFY,2010
150
+ chellow/templates/scenario.html,sha256=tCoq1wBq4l9PRS-zFtPcCWXlxD_SSFvFFkERf4FWVNU,2055
151
151
  chellow/templates/scenario_add.html,sha256=xFTb9CaA-qV2iwnVqcS44vD8JlYatBQet8Rat4daU7A,512
152
- chellow/templates/scenario_docs.html,sha256=901ug6cOmcErEGOqY1H2wcVxl4KavD7-mZz12h3RRB4,6508
152
+ chellow/templates/scenario_docs.html,sha256=0YP_h8GYkqCFLBoCj2w4PE4Js15DT_WoxYlK9nRSMlA,6949
153
153
  chellow/templates/scenario_edit.html,sha256=x2Eicq_eFs7ax2EtL4GrD73qKF-LhN41OQdPFbDivrc,1060
154
154
  chellow/templates/scenarios.html,sha256=FIDOSWs9VO_3bJkQoNHh-DdRzVfUyJGK9WbdEHRxxdM,841
155
155
  chellow/templates/site.html,sha256=dj0VgcmjaKJHuTOZDESO2E2MOyluYJtx4YaSOaWOkwU,10024
@@ -377,6 +377,6 @@ chellow/templates/g/supply_note_edit.html,sha256=b8mB6_ucBwoljp03iy6AgVaZUhGw3-1
377
377
  chellow/templates/g/supply_notes.html,sha256=6epNmZ3NKdXZz27fvmRUGeffg_oc1kmwuBeyRzQe3Rg,854
378
378
  chellow/templates/g/unit.html,sha256=KouNVU0-i84afANkLQ_heJ0uDfJ9H5A05PuLqb8iCN8,438
379
379
  chellow/templates/g/units.html,sha256=p5Nd-lAIboKPEOO6N451hx1bcKxMg4BDODnZ-43MmJc,441
380
- chellow-1729760318.0.0.dist-info/METADATA,sha256=cFK5LJ_vPjWeg5bxXRe_rjFj0EZVUMaR6PP9UKfrwAs,12204
381
- chellow-1729760318.0.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
382
- chellow-1729760318.0.0.dist-info/RECORD,,
380
+ chellow-1729849426.0.0.dist-info/METADATA,sha256=l0ROSjJXuLVti1C4484g9I-i6_O6pR1RNfgQk2uICCM,12204
381
+ chellow-1729849426.0.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
382
+ chellow-1729849426.0.0.dist-info/RECORD,,