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/e/bill_parsers/edf_export_xlsx.py +217 -0
- 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-1722367388.0.0.dist-info → chellow-1723449410.0.0.dist-info}/METADATA +1 -1
- {chellow-1722367388.0.0.dist-info → chellow-1723449410.0.0.dist-info}/RECORD +17 -16
- {chellow-1722367388.0.0.dist-info → chellow-1723449410.0.0.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
from datetime import datetime as Datetime
|
|
2
|
+
from decimal import Decimal, InvalidOperation
|
|
3
|
+
|
|
4
|
+
from dateutil.relativedelta import relativedelta
|
|
5
|
+
|
|
6
|
+
from openpyxl import load_workbook
|
|
7
|
+
|
|
8
|
+
from werkzeug.exceptions import BadRequest
|
|
9
|
+
|
|
10
|
+
from chellow.utils import HH, ct_datetime, parse_mpan_core, to_ct, to_utc
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def get_cell(sheet, col, row):
|
|
14
|
+
try:
|
|
15
|
+
coordinates = f"{col}{row}"
|
|
16
|
+
return sheet[coordinates]
|
|
17
|
+
except IndexError:
|
|
18
|
+
raise BadRequest(f"Can't find the cell {coordinates} on sheet {sheet}.")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def get_date(sheet, col, row):
|
|
22
|
+
cell = get_cell(sheet, col, row)
|
|
23
|
+
val = cell.value
|
|
24
|
+
if not isinstance(val, Datetime):
|
|
25
|
+
raise BadRequest(
|
|
26
|
+
f"Problem reading {val} (of type {type(val)}) as a timestamp at "
|
|
27
|
+
f"{cell.coordinate}."
|
|
28
|
+
)
|
|
29
|
+
return val
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def get_str(sheet, col, row):
|
|
33
|
+
return get_cell(sheet, col, row).value.strip()
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def get_dec(sheet, col, row):
|
|
37
|
+
cell = get_cell(sheet, col, row)
|
|
38
|
+
try:
|
|
39
|
+
return Decimal(str(cell.value))
|
|
40
|
+
except InvalidOperation as e:
|
|
41
|
+
raise BadRequest(f"Problem parsing the number at {cell.coordinate}. {e}")
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def get_int(sheet, col, row):
|
|
45
|
+
return int(get_cell(sheet, col, row).value)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
ELEM_LOOKUP = {
|
|
49
|
+
"Capacity": {
|
|
50
|
+
"name": "duos-availability",
|
|
51
|
+
"gbp": "duos-availability-gbp",
|
|
52
|
+
"units": "duos-availability-kva",
|
|
53
|
+
"rate": "duos-availability-rate",
|
|
54
|
+
},
|
|
55
|
+
"Fixed Charge": {
|
|
56
|
+
"name": "duos-fixed",
|
|
57
|
+
"gbp": "duos-fixed-gbp",
|
|
58
|
+
"units": "duos-fixed-days",
|
|
59
|
+
"rate": "duos-fixed-rate",
|
|
60
|
+
},
|
|
61
|
+
"Unit Rate Zero": None,
|
|
62
|
+
"Excess Reactive Power": {
|
|
63
|
+
"name": "duos-reactive",
|
|
64
|
+
"gbp": "duos-reactive-gbp",
|
|
65
|
+
"units": "duos-reactive-kvarh",
|
|
66
|
+
"rate": "duos-reactive-gbp-per-kvarh",
|
|
67
|
+
},
|
|
68
|
+
"Unit Rate Amber": {
|
|
69
|
+
"name": "duos-amber",
|
|
70
|
+
"gbp": "duos-amber-gbp",
|
|
71
|
+
"units": "duos-amber-kwh",
|
|
72
|
+
"rate": "duos-amber-gbp-per-kwh",
|
|
73
|
+
},
|
|
74
|
+
"Unit Rate Green": {
|
|
75
|
+
"name": "duos-green",
|
|
76
|
+
"gbp": "duos-green-gbp",
|
|
77
|
+
"units": "duos-green-kwh",
|
|
78
|
+
"rate": "duos-green-gbp-per-kwh",
|
|
79
|
+
},
|
|
80
|
+
"Unit Rate Red": {
|
|
81
|
+
"name": "duos-red",
|
|
82
|
+
"gbp": "duos-red-gbp",
|
|
83
|
+
"units": "duos-red-kwh",
|
|
84
|
+
"rate": "duos-red-gbp-per-kwh",
|
|
85
|
+
},
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _make_raw_bills(book):
|
|
90
|
+
bills = []
|
|
91
|
+
sheet = book.worksheets[0]
|
|
92
|
+
issue_date_raw = get_date(sheet, "H", 24)
|
|
93
|
+
issue_date = to_utc(
|
|
94
|
+
ct_datetime(issue_date_raw.year, issue_date_raw.month, issue_date_raw.day)
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
mpan_core = parse_mpan_core(str(get_int(sheet, "D", 25)))
|
|
98
|
+
start_date_str = get_str(sheet, "D", 22)
|
|
99
|
+
start_date_ct = to_ct(Datetime.strptime(start_date_str, "%d-%b-%Y"))
|
|
100
|
+
start_date = to_utc(start_date_ct)
|
|
101
|
+
finish_date_str = get_str(sheet, "F", 22)
|
|
102
|
+
finish_date_ct = to_ct(Datetime.strptime(finish_date_str, "%d-%b-%Y"))
|
|
103
|
+
finish_date = to_utc(finish_date_ct + relativedelta(hours=23, minutes=30))
|
|
104
|
+
net = round(get_dec(sheet, "H", 33), 2)
|
|
105
|
+
kwh = get_dec(sheet, "D", 33)
|
|
106
|
+
|
|
107
|
+
breakdown = {
|
|
108
|
+
"ssp-kwh": kwh,
|
|
109
|
+
"ssp-gbp": net,
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
bills.append(
|
|
113
|
+
{
|
|
114
|
+
"bill_type_code": "N",
|
|
115
|
+
"kwh": kwh,
|
|
116
|
+
"vat": Decimal("0.00"),
|
|
117
|
+
"net": net,
|
|
118
|
+
"gross": net,
|
|
119
|
+
"reads": [],
|
|
120
|
+
"breakdown": breakdown,
|
|
121
|
+
"account": mpan_core,
|
|
122
|
+
"issue_date": issue_date,
|
|
123
|
+
"start_date": start_date,
|
|
124
|
+
"finish_date": finish_date,
|
|
125
|
+
"mpan_core": mpan_core,
|
|
126
|
+
"reference": "_".join(
|
|
127
|
+
(
|
|
128
|
+
to_ct(start_date).strftime("%Y%m%d"),
|
|
129
|
+
to_ct(finish_date).strftime("%Y%m%d"),
|
|
130
|
+
to_ct(issue_date).strftime("%Y%m%d"),
|
|
131
|
+
mpan_core,
|
|
132
|
+
"ssp",
|
|
133
|
+
)
|
|
134
|
+
),
|
|
135
|
+
}
|
|
136
|
+
)
|
|
137
|
+
sheet = book.worksheets[3]
|
|
138
|
+
for row in range(2, len(sheet["A"]) + 1):
|
|
139
|
+
val = get_cell(sheet, "A", row).value
|
|
140
|
+
if val is None or val == "":
|
|
141
|
+
break
|
|
142
|
+
|
|
143
|
+
start_date_str = get_str(sheet, "B", row)
|
|
144
|
+
start_date_ct = to_ct(Datetime.strptime(start_date_str, "%Y-%m"))
|
|
145
|
+
start_date = to_utc(start_date_ct)
|
|
146
|
+
finish_date = to_utc(start_date_ct + relativedelta(months=1) - HH)
|
|
147
|
+
|
|
148
|
+
element_desc = get_str(sheet, "D", row).strip()
|
|
149
|
+
units = get_dec(sheet, "E", row)
|
|
150
|
+
rate = get_dec(sheet, "F", row)
|
|
151
|
+
net = round(get_dec(sheet, "G", row), 2)
|
|
152
|
+
|
|
153
|
+
titles = ELEM_LOOKUP[element_desc]
|
|
154
|
+
if titles is None:
|
|
155
|
+
continue
|
|
156
|
+
|
|
157
|
+
breakdown = {
|
|
158
|
+
titles["gbp"]: net,
|
|
159
|
+
titles["units"]: units,
|
|
160
|
+
titles["rate"]: [rate],
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
bills.append(
|
|
164
|
+
{
|
|
165
|
+
"bill_type_code": "N",
|
|
166
|
+
"kwh": Decimal(0),
|
|
167
|
+
"vat": Decimal("0.00"),
|
|
168
|
+
"net": net,
|
|
169
|
+
"gross": net,
|
|
170
|
+
"reads": [],
|
|
171
|
+
"breakdown": breakdown,
|
|
172
|
+
"account": mpan_core,
|
|
173
|
+
"issue_date": issue_date,
|
|
174
|
+
"start_date": start_date,
|
|
175
|
+
"finish_date": finish_date,
|
|
176
|
+
"mpan_core": mpan_core,
|
|
177
|
+
"reference": "_".join(
|
|
178
|
+
(
|
|
179
|
+
to_ct(start_date).strftime("%Y%m%d"),
|
|
180
|
+
to_ct(finish_date).strftime("%Y%m%d"),
|
|
181
|
+
to_ct(issue_date).strftime("%Y%m%d"),
|
|
182
|
+
mpan_core,
|
|
183
|
+
titles["name"],
|
|
184
|
+
)
|
|
185
|
+
),
|
|
186
|
+
}
|
|
187
|
+
)
|
|
188
|
+
return bills
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
class Parser:
|
|
192
|
+
def __init__(self, f):
|
|
193
|
+
self.book = load_workbook(f, data_only=True)
|
|
194
|
+
|
|
195
|
+
self.last_line = None
|
|
196
|
+
self._line_number = None
|
|
197
|
+
self._title_line = None
|
|
198
|
+
|
|
199
|
+
@property
|
|
200
|
+
def line_number(self):
|
|
201
|
+
return None if self._line_number is None else self._line_number + 1
|
|
202
|
+
|
|
203
|
+
def _set_last_line(self, i, line):
|
|
204
|
+
self._line_number = i
|
|
205
|
+
self.last_line = line
|
|
206
|
+
if i == 0:
|
|
207
|
+
self._title_line = line
|
|
208
|
+
return line
|
|
209
|
+
|
|
210
|
+
def make_raw_bills(self):
|
|
211
|
+
row = bills = None
|
|
212
|
+
try:
|
|
213
|
+
bills = _make_raw_bills(self.book)
|
|
214
|
+
except BadRequest as e:
|
|
215
|
+
raise BadRequest(f"Row number: {row} {e.description}")
|
|
216
|
+
|
|
217
|
+
return bills
|
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:
|