chellow 1723041465.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/e/computer.py +22 -22
- chellow/e/scenario.py +68 -68
- chellow/e/views.py +8 -8
- chellow/models.py +40 -28
- chellow/reports/report_109.py +6 -5
- chellow/reports/report_247.py +146 -151
- chellow/reports/report_59.py +134 -87
- chellow/templates/e/csv_sites_hh_data.html +2 -2
- chellow/templates/e/em_months.html +18 -18
- chellow/templates/e/scenario_docs.html +6 -6
- chellow/templates/site.html +2 -2
- chellow/templates/site_months.html +18 -18
- chellow/views.py +11 -11
- {chellow-1723041465.0.0.dist-info → chellow-1723449410.0.0.dist-info}/METADATA +1 -1
- {chellow-1723041465.0.0.dist-info → chellow-1723449410.0.0.dist-info}/RECORD +16 -16
- {chellow-1723041465.0.0.dist-info → chellow-1723449410.0.0.dist-info}/WHEEL +0 -0
chellow/e/computer.py
CHANGED
|
@@ -63,8 +63,8 @@ cons_types = ["construction", "commissioning", "operation"]
|
|
|
63
63
|
lec_cats = list(
|
|
64
64
|
(f"{v}-kwh", f"hist-{v}-kwh")
|
|
65
65
|
for v in [
|
|
66
|
-
"import-
|
|
67
|
-
"export-
|
|
66
|
+
"import-grid",
|
|
67
|
+
"export-grid",
|
|
68
68
|
"import-gen",
|
|
69
69
|
"export-gen",
|
|
70
70
|
"import-3rd-party",
|
|
@@ -265,9 +265,9 @@ def displaced_era(
|
|
|
265
265
|
era = site_era.era
|
|
266
266
|
source_code = era.supply.source.code
|
|
267
267
|
if site_era.is_physical and (
|
|
268
|
-
source_code in ("gen", "gen-
|
|
268
|
+
source_code in ("gen", "gen-grid")
|
|
269
269
|
or (
|
|
270
|
-
source_code == "
|
|
270
|
+
source_code == "grid"
|
|
271
271
|
and sess.query(Channel)
|
|
272
272
|
.filter(
|
|
273
273
|
Channel.era == era,
|
|
@@ -280,7 +280,7 @@ def displaced_era(
|
|
|
280
280
|
):
|
|
281
281
|
has_displaced = True
|
|
282
282
|
|
|
283
|
-
if source_code in ("
|
|
283
|
+
if source_code in ("grid", "gen-grid") and era.imp_mpan_core is not None:
|
|
284
284
|
eras[
|
|
285
285
|
"_".join(
|
|
286
286
|
(
|
|
@@ -482,8 +482,8 @@ def datum_range(sess, caches, years_back, start_date, finish_date):
|
|
|
482
482
|
"exp-msp-kvar": 0,
|
|
483
483
|
"msp-kw": 0,
|
|
484
484
|
"msp-kwh": 0,
|
|
485
|
-
"hist-import-
|
|
486
|
-
"hist-export-
|
|
485
|
+
"hist-import-grid-kvarh": 0,
|
|
486
|
+
"hist-export-grid-kvarh": 0,
|
|
487
487
|
"anti-msp-kwh": 0,
|
|
488
488
|
"anti-msp-kw": 0,
|
|
489
489
|
"imp-msp-kvarh": 0,
|
|
@@ -740,8 +740,8 @@ class SiteSource(DataSource):
|
|
|
740
740
|
hist_map = {}
|
|
741
741
|
|
|
742
742
|
for hist_date in hh_range(self.caches, self.history_start, self.history_finish):
|
|
743
|
-
|
|
744
|
-
|
|
743
|
+
export_grid_kwh = 0
|
|
744
|
+
import_grid_kwh = 0
|
|
745
745
|
export_gen_kwh = 0
|
|
746
746
|
import_gen_kwh = 0
|
|
747
747
|
import_3rd_party_kwh = 0
|
|
@@ -749,16 +749,16 @@ class SiteSource(DataSource):
|
|
|
749
749
|
export_3rd_party_kwh = 0
|
|
750
750
|
while hh_start_date == hist_date:
|
|
751
751
|
statuses.add(status)
|
|
752
|
-
if not imp_related and source_code in ("
|
|
753
|
-
|
|
754
|
-
if imp_related and source_code in ("
|
|
755
|
-
|
|
752
|
+
if not imp_related and source_code in ("grid", "gen-grid"):
|
|
753
|
+
export_grid_kwh += hh_value
|
|
754
|
+
if imp_related and source_code in ("grid", "gen-grid"):
|
|
755
|
+
import_grid_kwh += hh_value
|
|
756
756
|
if (imp_related and source_code == "gen") or (
|
|
757
|
-
not imp_related and source_code == "gen-
|
|
757
|
+
not imp_related and source_code == "gen-grid"
|
|
758
758
|
):
|
|
759
759
|
import_gen_kwh += hh_value
|
|
760
760
|
if (not imp_related and source_code == "gen") or (
|
|
761
|
-
imp_related and source_code == "gen-
|
|
761
|
+
imp_related and source_code == "gen-grid"
|
|
762
762
|
):
|
|
763
763
|
export_gen_kwh += hh_value
|
|
764
764
|
if (imp_related and source_code == "3rd-party") or (
|
|
@@ -781,8 +781,8 @@ class SiteSource(DataSource):
|
|
|
781
781
|
|
|
782
782
|
hh_values = {
|
|
783
783
|
"status": status,
|
|
784
|
-
"hist-import-
|
|
785
|
-
"hist-export-
|
|
784
|
+
"hist-import-grid-kwh": import_grid_kwh,
|
|
785
|
+
"hist-export-grid-kwh": export_grid_kwh,
|
|
786
786
|
"hist-import-gen-kwh": import_gen_kwh,
|
|
787
787
|
"hist-export-gen-kwh": export_gen_kwh,
|
|
788
788
|
"hist-import-3rd-party-kwh": import_3rd_party_kwh,
|
|
@@ -794,7 +794,7 @@ class SiteSource(DataSource):
|
|
|
794
794
|
hh_values["hist-kwh"] = hh_values["hist-used-gen-msp-kwh"] = (
|
|
795
795
|
hh_values["hist-import-gen-kwh"]
|
|
796
796
|
- hh_values["hist-export-gen-kwh"]
|
|
797
|
-
- hh_values["hist-export-
|
|
797
|
+
- hh_values["hist-export-grid-kwh"]
|
|
798
798
|
)
|
|
799
799
|
|
|
800
800
|
hh_values["msp-kwh"] = hh_values["used-gen-msp-kwh"] = hh_values[
|
|
@@ -805,12 +805,12 @@ class SiteSource(DataSource):
|
|
|
805
805
|
|
|
806
806
|
hh_values["hist-used-kwh"] = (
|
|
807
807
|
hh_values["hist-used-gen-msp-kwh"]
|
|
808
|
-
+ hh_values["hist-import-
|
|
808
|
+
+ hh_values["hist-import-grid-kwh"]
|
|
809
809
|
+ hh_values["hist-used-3rd-party-kwh"]
|
|
810
810
|
)
|
|
811
811
|
|
|
812
812
|
hh_values["used-kwh"] = hh_values["hist-used-kwh"]
|
|
813
|
-
hh_values["import-
|
|
813
|
+
hh_values["import-grid-kwh"] = hh_values["hist-import-grid-kwh"]
|
|
814
814
|
hh_values["msp-kw"] = hh_values["used-gen-msp-kw"] = (
|
|
815
815
|
hh_values["used-gen-msp-kwh"] * 2
|
|
816
816
|
)
|
|
@@ -835,8 +835,8 @@ class SiteSource(DataSource):
|
|
|
835
835
|
for hh in self.hh_data:
|
|
836
836
|
try:
|
|
837
837
|
delt_hh = self.deltas["hhs"][hh["start-date"]]
|
|
838
|
-
hh["import-
|
|
839
|
-
hh["export-
|
|
838
|
+
hh["import-grid-kwh"] = delt_hh["import-grid-kwh"]
|
|
839
|
+
hh["export-grid-kwh"] = delt_hh["export-grid-kwh"]
|
|
840
840
|
hh["import-gen-kwh"] = delt_hh["import-gen-kwh"]
|
|
841
841
|
hh["msp-kwh"] = delt_hh["msp-kwh"]
|
|
842
842
|
hh["used-kwh"] = delt_hh["used-kwh"]
|
chellow/e/scenario.py
CHANGED
|
@@ -89,14 +89,14 @@ def make_site_deltas(
|
|
|
89
89
|
delts = site_deltas["supply_deltas"] = {}
|
|
90
90
|
for is_import in (True, False):
|
|
91
91
|
delts[is_import] = {}
|
|
92
|
-
for src in ("gen", "
|
|
92
|
+
for src in ("gen", "grid", "gen-grid", "3rd-party", "3rd-party-reverse", "sub"):
|
|
93
93
|
delts[is_import][src] = {"site": {}}
|
|
94
94
|
|
|
95
95
|
earliest_delta = to_utc(Datetime.max)
|
|
96
96
|
latest_delta = to_utc(Datetime.min)
|
|
97
97
|
|
|
98
98
|
found_hh = False
|
|
99
|
-
for typ in ("used", "generated", "parasitic", "
|
|
99
|
+
for typ in ("used", "generated", "parasitic", "gen_grid"):
|
|
100
100
|
hh_str = site_scenario_hh.get(typ, "")
|
|
101
101
|
hh_data = site_scenario_hh[typ] = {}
|
|
102
102
|
for row in csv.reader(StringIO(hh_str)):
|
|
@@ -129,7 +129,7 @@ def make_site_deltas(
|
|
|
129
129
|
scenario_used = site_scenario_hh["used"]
|
|
130
130
|
scenario_generated = site_scenario_hh["generated"]
|
|
131
131
|
scenario_parasitic = site_scenario_hh["parasitic"]
|
|
132
|
-
|
|
132
|
+
scenario_gen_grid = site_scenario_hh["gen_grid"]
|
|
133
133
|
|
|
134
134
|
earliest_delta_ct = to_ct(earliest_delta)
|
|
135
135
|
for month_start, month_finish in c_months_u(
|
|
@@ -170,7 +170,7 @@ def make_site_deltas(
|
|
|
170
170
|
|
|
171
171
|
for hh in ss.hh_data:
|
|
172
172
|
sdatum = hh_map[hh["start-date"]]
|
|
173
|
-
sdatum["import-
|
|
173
|
+
sdatum["import-grid-kwh"] += hh["msp-kwh"]
|
|
174
174
|
sdatum["used-kwh"] += hh["msp-kwh"]
|
|
175
175
|
|
|
176
176
|
for era in (
|
|
@@ -185,7 +185,7 @@ def make_site_deltas(
|
|
|
185
185
|
Era.imp_mpan_core != null(),
|
|
186
186
|
Era.start_date <= chunk_finish,
|
|
187
187
|
or_(Era.finish_date == null(), Era.finish_date >= chunk_start),
|
|
188
|
-
Source.code == "gen-
|
|
188
|
+
Source.code == "gen-grid",
|
|
189
189
|
)
|
|
190
190
|
):
|
|
191
191
|
if supply_ids is not None and era.supply_id not in supply_ids:
|
|
@@ -201,65 +201,65 @@ def make_site_deltas(
|
|
|
201
201
|
for hh in ss.hh_data:
|
|
202
202
|
sdatum = hh_map[hh["start-date"]]
|
|
203
203
|
try:
|
|
204
|
-
sdatum["gen-
|
|
204
|
+
sdatum["gen-grid-kwh"] += hh["msp-kwh"]
|
|
205
205
|
except KeyError:
|
|
206
|
-
sdatum["gen-
|
|
206
|
+
sdatum["gen-grid-kwh"] = hh["msp-kwh"]
|
|
207
207
|
|
|
208
208
|
for hh_start, hh in hh_map.items():
|
|
209
209
|
if hh_start in scenario_used:
|
|
210
210
|
used_delt = scenario_used[hh_start] - hh["used-kwh"]
|
|
211
|
-
|
|
212
|
-
|
|
211
|
+
imp_grid_delt = 0
|
|
212
|
+
exp_grid_delt = 0
|
|
213
213
|
|
|
214
214
|
if used_delt < 0:
|
|
215
|
-
diff = hh["import-
|
|
215
|
+
diff = hh["import-grid-kwh"] + used_delt
|
|
216
216
|
if diff < 0:
|
|
217
|
-
|
|
218
|
-
|
|
217
|
+
imp_grid_delt -= hh["import-grid-kwh"]
|
|
218
|
+
exp_grid_delt -= diff
|
|
219
219
|
else:
|
|
220
|
-
|
|
220
|
+
imp_grid_delt += used_delt
|
|
221
221
|
else:
|
|
222
|
-
diff = hh["export-
|
|
222
|
+
diff = hh["export-grid-kwh"] - used_delt
|
|
223
223
|
if diff < 0:
|
|
224
|
-
|
|
225
|
-
|
|
224
|
+
exp_grid_delt -= hh["export-grid-kwh"]
|
|
225
|
+
imp_grid_delt -= diff
|
|
226
226
|
else:
|
|
227
|
-
|
|
227
|
+
exp_grid_delt -= used_delt
|
|
228
228
|
|
|
229
229
|
try:
|
|
230
|
-
delts[False]["
|
|
230
|
+
delts[False]["grid"]["site"][hh_start] += exp_grid_delt
|
|
231
231
|
except KeyError:
|
|
232
|
-
delts[False]["
|
|
232
|
+
delts[False]["grid"]["site"][hh_start] = exp_grid_delt
|
|
233
233
|
|
|
234
234
|
try:
|
|
235
|
-
delts[True]["
|
|
235
|
+
delts[True]["grid"]["site"][hh_start] += imp_grid_delt
|
|
236
236
|
except KeyError:
|
|
237
|
-
delts[True]["
|
|
237
|
+
delts[True]["grid"]["site"][hh_start] = imp_grid_delt
|
|
238
238
|
|
|
239
|
-
hh["import-
|
|
240
|
-
hh["export-
|
|
239
|
+
hh["import-grid-kwh"] += imp_grid_delt
|
|
240
|
+
hh["export-grid-kwh"] += exp_grid_delt
|
|
241
241
|
hh["used-kwh"] += used_delt
|
|
242
|
-
hh["msp-kwh"] -=
|
|
242
|
+
hh["msp-kwh"] -= exp_grid_delt
|
|
243
243
|
|
|
244
244
|
if hh_start in scenario_generated:
|
|
245
245
|
imp_gen_delt = scenario_generated[hh_start] - hh["import-gen-kwh"]
|
|
246
|
-
|
|
247
|
-
|
|
246
|
+
imp_grid_delt = 0
|
|
247
|
+
exp_grid_delt = 0
|
|
248
248
|
|
|
249
249
|
if imp_gen_delt < 0:
|
|
250
|
-
diff = hh["export-
|
|
250
|
+
diff = hh["export-grid-kwh"] + imp_gen_delt
|
|
251
251
|
if diff < 0:
|
|
252
|
-
|
|
253
|
-
|
|
252
|
+
exp_grid_delt -= hh["export-grid-kwh"]
|
|
253
|
+
imp_grid_delt -= diff
|
|
254
254
|
else:
|
|
255
|
-
|
|
255
|
+
exp_grid_delt += imp_gen_delt
|
|
256
256
|
else:
|
|
257
|
-
diff = hh["import-
|
|
257
|
+
diff = hh["import-grid-kwh"] - imp_gen_delt
|
|
258
258
|
if diff < 0:
|
|
259
|
-
|
|
260
|
-
|
|
259
|
+
imp_grid_delt -= hh["import-grid-kwh"]
|
|
260
|
+
exp_grid_delt -= diff
|
|
261
261
|
else:
|
|
262
|
-
|
|
262
|
+
imp_grid_delt -= imp_gen_delt
|
|
263
263
|
|
|
264
264
|
try:
|
|
265
265
|
delts[True]["gen"]["site"][hh_start] += imp_gen_delt
|
|
@@ -267,39 +267,39 @@ def make_site_deltas(
|
|
|
267
267
|
delts[True]["gen"]["site"][hh_start] = imp_gen_delt
|
|
268
268
|
|
|
269
269
|
try:
|
|
270
|
-
delts[False]["
|
|
270
|
+
delts[False]["grid"]["site"][hh_start] += exp_grid_delt
|
|
271
271
|
except KeyError:
|
|
272
|
-
delts[False]["
|
|
272
|
+
delts[False]["grid"]["site"][hh_start] = exp_grid_delt
|
|
273
273
|
|
|
274
274
|
try:
|
|
275
|
-
delts[True]["
|
|
275
|
+
delts[True]["grid"]["site"][hh_start] += imp_grid_delt
|
|
276
276
|
except KeyError:
|
|
277
|
-
delts[True]["
|
|
277
|
+
delts[True]["grid"]["site"][hh_start] = imp_grid_delt
|
|
278
278
|
|
|
279
|
-
hh["import-
|
|
280
|
-
hh["export-
|
|
279
|
+
hh["import-grid-kwh"] += imp_grid_delt
|
|
280
|
+
hh["export-grid-kwh"] += exp_grid_delt
|
|
281
281
|
hh["import-gen-kwh"] += imp_gen_delt
|
|
282
|
-
hh["msp-kwh"] -=
|
|
282
|
+
hh["msp-kwh"] -= imp_grid_delt
|
|
283
283
|
|
|
284
284
|
if hh_start in scenario_parasitic:
|
|
285
285
|
exp_gen_delt = scenario_parasitic[hh_start] - hh["export-gen-kwh"]
|
|
286
|
-
|
|
287
|
-
|
|
286
|
+
imp_grid_delt = 0
|
|
287
|
+
exp_grid_delt = 0
|
|
288
288
|
|
|
289
289
|
if exp_gen_delt < 0:
|
|
290
|
-
diff = hh["import-
|
|
290
|
+
diff = hh["import-grid-kwh"] + exp_gen_delt
|
|
291
291
|
if diff < 0:
|
|
292
|
-
|
|
293
|
-
|
|
292
|
+
imp_grid_delt -= hh["import-grid-kwh"]
|
|
293
|
+
exp_grid_delt -= diff
|
|
294
294
|
else:
|
|
295
|
-
|
|
295
|
+
imp_grid_delt += exp_gen_delt
|
|
296
296
|
else:
|
|
297
|
-
diff = hh["export-
|
|
297
|
+
diff = hh["export-grid-kwh"] - exp_gen_delt
|
|
298
298
|
if diff < 0:
|
|
299
|
-
|
|
300
|
-
|
|
299
|
+
exp_grid_delt -= hh["export-grid-kwh"]
|
|
300
|
+
imp_grid_delt -= diff
|
|
301
301
|
else:
|
|
302
|
-
|
|
302
|
+
exp_grid_delt -= exp_gen_delt
|
|
303
303
|
|
|
304
304
|
try:
|
|
305
305
|
delts[False]["gen"]["site"][hh_start] += imp_gen_delt
|
|
@@ -307,34 +307,34 @@ def make_site_deltas(
|
|
|
307
307
|
delts[False]["gen"]["site"][hh_start] = exp_gen_delt
|
|
308
308
|
|
|
309
309
|
try:
|
|
310
|
-
delts[False]["
|
|
310
|
+
delts[False]["grid"]["site"][hh_start] += exp_grid_delt
|
|
311
311
|
except KeyError:
|
|
312
|
-
delts[False]["
|
|
312
|
+
delts[False]["grid"]["site"][hh_start] = exp_grid_delt
|
|
313
313
|
|
|
314
314
|
try:
|
|
315
|
-
delts[True]["
|
|
315
|
+
delts[True]["grid"]["site"][hh_start] += imp_grid_delt
|
|
316
316
|
except KeyError:
|
|
317
|
-
delts[True]["
|
|
317
|
+
delts[True]["grid"]["site"][hh_start] = imp_grid_delt
|
|
318
318
|
|
|
319
|
-
hh["import-
|
|
320
|
-
hh["export-
|
|
319
|
+
hh["import-grid-kwh"] += imp_grid_delt
|
|
320
|
+
hh["export-grid-kwh"] += exp_grid_delt
|
|
321
321
|
hh["export-gen-kwh"] += exp_gen_delt
|
|
322
|
-
hh["msp-kwh"] -=
|
|
322
|
+
hh["msp-kwh"] -= imp_grid_delt
|
|
323
323
|
|
|
324
|
-
if hh_start in
|
|
325
|
-
|
|
324
|
+
if hh_start in scenario_gen_grid:
|
|
325
|
+
gen_grid_delt = scenario_gen_grid[hh_start] - hh["gen-grid-kwh"]
|
|
326
326
|
|
|
327
327
|
try:
|
|
328
|
-
delts[False]["gen-
|
|
328
|
+
delts[False]["gen-grid"]["site"][hh_start] += gen_grid_delt
|
|
329
329
|
except KeyError:
|
|
330
|
-
delts[False]["gen-
|
|
330
|
+
delts[False]["gen-grid"]["site"][hh_start] = gen_grid_delt
|
|
331
331
|
|
|
332
|
-
hh["import-gen-kwh"] +=
|
|
333
|
-
hh["export-
|
|
332
|
+
hh["import-gen-kwh"] += gen_grid_delt
|
|
333
|
+
hh["export-grid-kwh"] += gen_grid_delt
|
|
334
334
|
|
|
335
335
|
site_deltas["hhs"][hh_start] = hh
|
|
336
336
|
|
|
337
|
-
sup_deltas = site_deltas["supply_deltas"][False]["
|
|
337
|
+
sup_deltas = site_deltas["supply_deltas"][False]["grid"]["site"]
|
|
338
338
|
if all(v == 0 for v in sup_deltas.values()):
|
|
339
339
|
sup_deltas.clear()
|
|
340
340
|
|
|
@@ -569,10 +569,10 @@ def make_calcs(
|
|
|
569
569
|
|
|
570
570
|
calcs.append(("0", imp_ss_name, exp_ss_name, imp_ss, exp_ss))
|
|
571
571
|
|
|
572
|
-
# Check if exp
|
|
573
|
-
sup_deltas = site_deltas["supply_deltas"][False]["
|
|
572
|
+
# Check if exp grid deltas haven't been consumed
|
|
573
|
+
sup_deltas = site_deltas["supply_deltas"][False]["grid"]
|
|
574
574
|
if len(list(t for t in sup_deltas["site"] if ss_start <= t <= ss_finish)) > 0:
|
|
575
|
-
ss_name = site.code + "
|
|
575
|
+
ss_name = site.code + "_extra_grid_export"
|
|
576
576
|
ss = SupplySource(
|
|
577
577
|
sess,
|
|
578
578
|
ss_start,
|
chellow/e/views.py
CHANGED
|
@@ -4168,16 +4168,16 @@ def em_hh_data_get(site_id):
|
|
|
4168
4168
|
sup_hh[prefix + "kwh"] = datum.value
|
|
4169
4169
|
sup_hh[prefix + "status"] = datum.status
|
|
4170
4170
|
|
|
4171
|
-
if not imp_related and source_code in ("
|
|
4171
|
+
if not imp_related and source_code in ("grid", "gen-grid"):
|
|
4172
4172
|
hh_dict["export_kwh"] += hh_float_value
|
|
4173
|
-
if imp_related and source_code in ("
|
|
4173
|
+
if imp_related and source_code in ("grid", "gen-grid"):
|
|
4174
4174
|
hh_dict["import_kwh"] += hh_float_value
|
|
4175
4175
|
if (imp_related and source_code == "gen") or (
|
|
4176
|
-
not imp_related and source_code == "gen-
|
|
4176
|
+
not imp_related and source_code == "gen-grid"
|
|
4177
4177
|
):
|
|
4178
4178
|
hh_dict["generated_kwh"] += hh_float_value
|
|
4179
4179
|
if (not imp_related and source_code == "gen") or (
|
|
4180
|
-
imp_related and source_code == "gen-
|
|
4180
|
+
imp_related and source_code == "gen-grid"
|
|
4181
4181
|
):
|
|
4182
4182
|
hh_dict["parasitic_kwh"] += hh_float_value
|
|
4183
4183
|
if (imp_related and source_code == "3rd-party") or (
|
|
@@ -4213,9 +4213,9 @@ def site_energy_management_months_get(site_id):
|
|
|
4213
4213
|
site = Site.get_by_id(g.sess, site_id)
|
|
4214
4214
|
|
|
4215
4215
|
typs = (
|
|
4216
|
-
"
|
|
4216
|
+
"imp_grid",
|
|
4217
4217
|
"imp_3p",
|
|
4218
|
-
"
|
|
4218
|
+
"exp_grid",
|
|
4219
4219
|
"exp_3p",
|
|
4220
4220
|
"used",
|
|
4221
4221
|
"displaced",
|
|
@@ -4332,7 +4332,7 @@ def site_add_e_supply_form_get(site_id):
|
|
|
4332
4332
|
sources = g.sess.scalars(select(Source).order_by(Source.code))
|
|
4333
4333
|
source_id = req_int_none("source_id")
|
|
4334
4334
|
if source_id is None:
|
|
4335
|
-
source = Source.get_by_code(g.sess, "
|
|
4335
|
+
source = Source.get_by_code(g.sess, "grid")
|
|
4336
4336
|
else:
|
|
4337
4337
|
source = Source.get_by_id(g.sess, source_id)
|
|
4338
4338
|
generator_types = g.sess.query(GeneratorType).order_by(GeneratorType.code)
|
|
@@ -5894,7 +5894,7 @@ def supply_edit_post(supply_id):
|
|
|
5894
5894
|
source_id = req_int("source_id")
|
|
5895
5895
|
gsp_group_id = req_int("gsp_group_id")
|
|
5896
5896
|
source = Source.get_by_id(g.sess, source_id)
|
|
5897
|
-
if source.code in ("gen", "gen-
|
|
5897
|
+
if source.code in ("gen", "gen-grid"):
|
|
5898
5898
|
generator_type_id = req_int("generator_type_id")
|
|
5899
5899
|
generator_type = GeneratorType.get_by_id(g.sess, generator_type_id)
|
|
5900
5900
|
else:
|
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 '
|
|
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
|
-
"
|
|
1784
|
-
"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
|
-
"
|
|
1833
|
-
"
|
|
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["
|
|
1848
|
-
dd["used"] = dd["displaced"] + dd["
|
|
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-
|
|
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-
|
|
4228
|
+
"If the source is 'gen' or 'gen-grid', there must be a generator type."
|
|
4229
4229
|
)
|
|
4230
4230
|
|
|
4231
|
-
if source.code == "
|
|
4232
|
-
raise BadRequest("A
|
|
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-
|
|
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
|
-
|
|
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
|
-
"
|
|
4763
|
-
"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
|
-
"
|
|
4774
|
-
"
|
|
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["
|
|
4831
|
+
dd["displaced"] = dd["imp_gen"] - dd["exp_gen"] - dd["exp_grid"]
|
|
4832
4832
|
dd["used"] = (
|
|
4833
|
-
dd["displaced"] + dd["
|
|
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["
|
|
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.
|
|
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.
|
|
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["
|
|
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["
|
|
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.
|
|
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.
|
|
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
|
-
("
|
|
6559
|
+
("grid", "Public grid."),
|
|
6560
6560
|
("sub", "Sub meter"),
|
|
6561
|
-
("gen-
|
|
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
|
|