chellow 1722367388.0.0__py3-none-any.whl → 1723449410.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/models.py CHANGED
@@ -456,7 +456,7 @@ class Source(Base, PersistentClass):
456
456
  def get_by_code(sess, code):
457
457
  source = sess.query(Source).filter_by(code=code.strip()).first()
458
458
  if source is None:
459
- raise BadRequest("There's no source with the code '" + code + "'")
459
+ raise BadRequest(f"There's no source with the code '{code}'")
460
460
  return source
461
461
 
462
462
  __tablename__ = "source"
@@ -1780,8 +1780,8 @@ class Site(Base, PersistentClass):
1780
1780
  def hh_data(self, sess, start_date, finish_date, exclude_virtual=False):
1781
1781
  cache = {}
1782
1782
  keys = {
1783
- "net": {True: ["imp_net"], False: ["exp_net"]},
1784
- "gen-net": {True: ["imp_net", "exp_gen"], False: ["exp_net", "imp_gen"]},
1783
+ "grid": {True: ["imp_grid"], False: ["exp_grid"]},
1784
+ "gen-grid": {True: ["imp_grid", "exp_gen"], False: ["exp_grid", "imp_gen"]},
1785
1785
  "gen": {True: ["imp_gen"], False: ["exp_gen"]},
1786
1786
  "3rd-party": {True: ["imp_3p"], False: ["exp_3p"]},
1787
1787
  "3rd-party-reverse": {True: ["exp_3p"], False: ["imp_3p"]},
@@ -1829,8 +1829,8 @@ class Site(Base, PersistentClass):
1829
1829
  for hh_start in hh_range(cache, start_date, finish_date):
1830
1830
  dd = {
1831
1831
  "start_date": hh_start,
1832
- "imp_net": 0,
1833
- "exp_net": 0,
1832
+ "imp_grid": 0,
1833
+ "exp_grid": 0,
1834
1834
  "imp_gen": 0,
1835
1835
  "exp_gen": 0,
1836
1836
  "imp_3p": 0,
@@ -1844,8 +1844,8 @@ class Site(Base, PersistentClass):
1844
1844
  db_data, (None, None, None, None)
1845
1845
  )
1846
1846
 
1847
- dd["displaced"] = dd["imp_gen"] - dd["exp_gen"] - dd["exp_net"]
1848
- dd["used"] = dd["displaced"] + dd["imp_net"] + dd["imp_3p"] - dd["exp_3p"]
1847
+ dd["displaced"] = dd["imp_gen"] - dd["exp_gen"] - dd["exp_grid"]
1848
+ dd["used"] = dd["displaced"] + dd["imp_grid"] + dd["imp_3p"] - dd["exp_3p"]
1849
1849
 
1850
1850
  return data
1851
1851
 
@@ -4223,15 +4223,15 @@ class Supply(Base, PersistentClass):
4223
4223
 
4224
4224
  self.name = name
4225
4225
  self.source = source
4226
- if source.code in ("gen", "gen-net") and generator_type is None:
4226
+ if source.code in ("gen", "gen-grid") and generator_type is None:
4227
4227
  raise BadRequest(
4228
- "If the source is 'gen' or 'gen-net', there must be a generator type."
4228
+ "If the source is 'gen' or 'gen-grid', there must be a generator type."
4229
4229
  )
4230
4230
 
4231
- if source.code == "net" and dno.dno_code == "99":
4232
- raise BadRequest("A network supply can't have a DNO code of 99.")
4231
+ if source.code == "grid" and dno.dno_code == "99":
4232
+ raise BadRequest("A grid supply can't have a DNO code of 99.")
4233
4233
 
4234
- if source.code in ("gen", "gen-net"):
4234
+ if source.code in ("gen", "gen-grid"):
4235
4235
  self.generator_type = generator_type
4236
4236
  else:
4237
4237
  self.generator_type = None
@@ -4746,7 +4746,7 @@ class Report(Base, PersistentClass):
4746
4746
 
4747
4747
 
4748
4748
  class SiteGroup:
4749
- EXPORT_NET_GT_IMPORT_GEN = "Export to net > import from generators."
4749
+ EXPORT_GRID_GT_IMPORT_GEN = "Export to grid > import from generators."
4750
4750
  EXPORT_GEN_GT_IMPORT = "Export to generators > import."
4751
4751
  EXPORT_3P_GT_IMPORT = "Export to 3rd party > import."
4752
4752
 
@@ -4759,8 +4759,8 @@ class SiteGroup:
4759
4759
  def hh_data(self, sess):
4760
4760
  caches = {}
4761
4761
  keys = {
4762
- "net": {True: ["imp_net"], False: ["exp_net"]},
4763
- "gen-net": {True: ["imp_net", "exp_gen"], False: ["exp_net", "imp_gen"]},
4762
+ "grid": {True: ["imp_grid"], False: ["exp_grid"]},
4763
+ "gen-grid": {True: ["imp_grid", "exp_gen"], False: ["exp_grid", "imp_gen"]},
4764
4764
  "gen": {True: ["imp_gen"], False: ["exp_gen"]},
4765
4765
  "3rd-party": {True: ["imp_3p"], False: ["exp_3p"]},
4766
4766
  "3rd-party-reverse": {True: ["exp_3p"], False: ["imp_3p"]},
@@ -4770,8 +4770,8 @@ class SiteGroup:
4770
4770
  hh_start: {
4771
4771
  "start_date": hh_start,
4772
4772
  "status": "A",
4773
- "imp_net": 0,
4774
- "exp_net": 0,
4773
+ "imp_grid": 0,
4774
+ "exp_grid": 0,
4775
4775
  "imp_gen": 0,
4776
4776
  "exp_gen": 0,
4777
4777
  "imp_3p": 0,
@@ -4828,9 +4828,9 @@ class SiteGroup:
4828
4828
  if dd["status"] == "A":
4829
4829
  dd["status"] = "E"
4830
4830
 
4831
- dd["displaced"] = dd["imp_gen"] - dd["exp_gen"] - dd["exp_net"]
4831
+ dd["displaced"] = dd["imp_gen"] - dd["exp_gen"] - dd["exp_grid"]
4832
4832
  dd["used"] = (
4833
- dd["displaced"] + dd["imp_net"] + dd["imp_3p"] - dd["exp_3p"]
4833
+ dd["displaced"] + dd["imp_grid"] + dd["imp_3p"] - dd["exp_3p"]
4834
4834
  )
4835
4835
 
4836
4836
  return data.values()
@@ -4856,7 +4856,7 @@ class SiteGroup:
4856
4856
  for hh in self.hh_data(sess):
4857
4857
  hh_start_date = hh["start_date"]
4858
4858
 
4859
- if hh["exp_net"] > hh["imp_gen"] and hh["status"] == "A":
4859
+ if hh["exp_grid"] > hh["imp_gen"] and hh["status"] == "A":
4860
4860
  if snag_1_start is None:
4861
4861
  snag_1_start = hh_start_date
4862
4862
 
@@ -4865,7 +4865,7 @@ class SiteGroup:
4865
4865
  if resolve_1_start is not None:
4866
4866
  self.delete_snag(
4867
4867
  sess,
4868
- SiteGroup.EXPORT_NET_GT_IMPORT_GEN,
4868
+ SiteGroup.EXPORT_GROSS_GT_IMPORT_GEN,
4869
4869
  resolve_1_start,
4870
4870
  resolve_1_finish,
4871
4871
  )
@@ -4879,13 +4879,13 @@ class SiteGroup:
4879
4879
  if snag_1_start is not None:
4880
4880
  self.add_snag(
4881
4881
  sess,
4882
- SiteGroup.EXPORT_NET_GT_IMPORT_GEN,
4882
+ SiteGroup.EXPORT_GRID_GT_IMPORT_GEN,
4883
4883
  snag_1_start,
4884
4884
  snag_1_finish,
4885
4885
  )
4886
4886
  snag_1_start = None
4887
4887
 
4888
- if hh["exp_gen"] > hh["imp_net"] + hh["imp_gen"] and hh["status"] == "A":
4888
+ if hh["exp_gen"] > hh["imp_grid"] + hh["imp_gen"] and hh["status"] == "A":
4889
4889
  if snag_2_start is None:
4890
4890
  snag_2_start = hh_start_date
4891
4891
 
@@ -4915,7 +4915,7 @@ class SiteGroup:
4915
4915
  snag_2_start = None
4916
4916
 
4917
4917
  if (
4918
- hh["exp_3p"] > hh["imp_net"] + hh["imp_gen"] + hh["imp_3p"]
4918
+ hh["exp_3p"] > hh["imp_grid"] + hh["imp_gen"] + hh["imp_3p"]
4919
4919
  and hh["status"] == "A"
4920
4920
  ):
4921
4921
  if snag_3_start is None:
@@ -4948,13 +4948,13 @@ class SiteGroup:
4948
4948
 
4949
4949
  if snag_1_start is not None:
4950
4950
  self.add_snag(
4951
- sess, SiteGroup.EXPORT_NET_GT_IMPORT_GEN, snag_1_start, snag_1_finish
4951
+ sess, SiteGroup.EXPORT_GRID_GT_IMPORT_GEN, snag_1_start, snag_1_finish
4952
4952
  )
4953
4953
 
4954
4954
  if resolve_1_start is not None:
4955
4955
  self.delete_snag(
4956
4956
  sess,
4957
- SiteGroup.EXPORT_NET_GT_IMPORT_GEN,
4957
+ SiteGroup.EXPORT_GRID_GT_IMPORT_GEN,
4958
4958
  resolve_1_start,
4959
4959
  resolve_1_finish,
4960
4960
  )
@@ -6556,9 +6556,9 @@ def insert_comms(sess):
6556
6556
 
6557
6557
  def insert_sources(sess):
6558
6558
  for code, desc in (
6559
- ("net", "Public distribution system."),
6559
+ ("grid", "Public grid."),
6560
6560
  ("sub", "Sub meter"),
6561
- ("gen-net", "Generator connected directly to network."),
6561
+ ("gen-grid", "Generator connected directly to the grid."),
6562
6562
  ("gen", "Generator."),
6563
6563
  ("3rd-party", "Third party supply."),
6564
6564
  ("3rd-party-reverse", "Third party supply with import going out of the site."),
@@ -7502,6 +7502,17 @@ def db_upgrade_48_to_49(sess, root_path):
7502
7502
  sess.flush()
7503
7503
 
7504
7504
 
7505
+ def db_upgrade_49_to_50(sess, root_path):
7506
+ source = Source.get_by_code(sess, "net")
7507
+ source.code = "grid"
7508
+ source.name = "Public grid."
7509
+ sess.flush()
7510
+ source = Source.get_by_code(sess, "gen-net")
7511
+ source.code = "gen-grid"
7512
+ source.name = "Generator connected directly to the grid."
7513
+ sess.flush()
7514
+
7515
+
7505
7516
  upgrade_funcs = [None] * 18
7506
7517
  upgrade_funcs.extend(
7507
7518
  [
@@ -7536,6 +7547,7 @@ upgrade_funcs.extend(
7536
7547
  db_upgrade_46_to_47,
7537
7548
  db_upgrade_47_to_48,
7538
7549
  db_upgrade_48_to_49,
7550
+ db_upgrade_49_to_50,
7539
7551
  ]
7540
7552
  )
7541
7553
 
@@ -66,7 +66,8 @@ def content(contract_id, end_year, end_month, months, user):
66
66
  or_(Era.finish_date == null(), Era.finish_date >= start_date),
67
67
  Era.start_date <= finish_date,
68
68
  or_(
69
- Source.code.in_(("gen", "gen-net")), Era.exp_mpan_core != null()
69
+ Source.code.in_(("gen", "gen-grid")),
70
+ Era.exp_mpan_core != null(),
70
71
  ),
71
72
  )
72
73
  .distinct()
@@ -153,7 +154,7 @@ def content(contract_id, end_year, end_month, months, user):
153
154
  "channel.era_id = era.id and era.supply_id = "
154
155
  "supply.id and supply.source_id = source.id and "
155
156
  "channel.channel_type = 'ACTIVE' and not "
156
- "(source.code = 'net' and channel.imp_related "
157
+ "(source.code = 'grid' and channel.imp_related "
157
158
  "is true) and hh_datum.start_date >= "
158
159
  ":month_start and hh_datum.start_date "
159
160
  "<= :month_finish and "
@@ -181,17 +182,17 @@ def content(contract_id, end_year, end_month, months, user):
181
182
  gen_breakdown = {}
182
183
  exported = 0
183
184
  while hh_start == hh_date:
184
- if not imp_related and source_code in ("net", "gen-net"):
185
+ if not imp_related and source_code in ("grid", "gen-grid"):
185
186
  exported += hh_val
186
187
  if (imp_related and source_code == "gen") or (
187
- not imp_related and source_code == "gen-net"
188
+ not imp_related and source_code == "gen-grid"
188
189
  ):
189
190
  gen_breakdown[gen_type_code] = (
190
191
  gen_breakdown.setdefault(gen_type_code, 0) + hh_val
191
192
  )
192
193
 
193
194
  if (not imp_related and source_code == "gen") or (
194
- imp_related and source_code == "gen-net"
195
+ imp_related and source_code == "gen-grid"
195
196
  ):
196
197
  gen_breakdown[gen_type_code] = (
197
198
  gen_breakdown.setdefault(gen_type_code, 0) - hh_val