Skip to content

Commit 4b08836

Browse files
authored
Merge pull request #615 from NREL/develop
Hot Fix: ASHP defaults updating from REopt.jl
2 parents 96856a7 + aaf7896 commit 4b08836

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

reoptjl/src/process_results.py

+12
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,10 @@ def update_inputs_in_database(inputs_to_update: dict, run_uuid: str) -> None:
141141
else:
142142
ExistingChillerInputs.objects.filter(meta__run_uuid=run_uuid).update(**inputs_to_update["ExistingChiller"])
143143
if inputs_to_update["ASHPSpaceHeater"]:
144+
prune_update_fields(ASHPSpaceHeaterInputs, inputs_to_update["ASHPSpaceHeater"])
144145
ASHPSpaceHeaterInputs.objects.filter(meta__run_uuid=run_uuid).update(**inputs_to_update["ASHPSpaceHeater"])
145146
if inputs_to_update["ASHPWaterHeater"]:
147+
prune_update_fields(ASHPWaterHeaterInputs, inputs_to_update["ASHPWaterHeater"])
146148
ASHPWaterHeaterInputs.objects.filter(meta__run_uuid=run_uuid).update(**inputs_to_update["ASHPWaterHeater"])
147149
except Exception as e:
148150
exc_type, exc_value, exc_traceback = sys.exc_info()
@@ -152,3 +154,13 @@ def update_inputs_in_database(inputs_to_update: dict, run_uuid: str) -> None:
152154
tb.format_tb(exc_traceback)
153155
)
154156
log.debug(debug_msg)
157+
158+
def prune_update_fields(model_obj, dict_to_update):
159+
"""
160+
REopt.jl may return more fields than the API has to update, so prune those extra ones before updating the model/db object
161+
"""
162+
field_names = [field.name for field in model_obj._meta.get_fields()]
163+
dict_to_update_keys = list(dict_to_update.keys())
164+
for key in dict_to_update_keys:
165+
if key not in field_names:
166+
del dict_to_update[key]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"user_uuid": "1d2ef71e-fd93-4c4a-b5c3-1485a87f772e",
3+
"webtool_uuid": "1ab7530f-74b8-4ea8-b8ed-f11bd953f61f",
4+
"Settings": {
5+
"optimality_tolerance": 0.001,
6+
"solver_name": "HiGHS",
7+
"off_grid_flag": false,
8+
"include_climate_in_objective": false,
9+
"include_health_in_objective": false
10+
},
11+
"Meta": {
12+
"address": "San Francisco CA USA"
13+
},
14+
"Site": {
15+
"latitude": 37.7749295,
16+
"longitude": -122.4194155,
17+
"include_exported_renewable_electricity_in_total": true,
18+
"include_exported_elec_emissions_in_total": true,
19+
"land_acres": 1000000.0,
20+
"roof_squarefeet": 0
21+
},
22+
"ElectricLoad": {
23+
"doe_reference_name": "Hospital"
24+
},
25+
"ElectricTariff": {
26+
"blended_annual_energy_rate": 0.15,
27+
"blended_annual_demand_rate": 0.0
28+
},
29+
"ElectricUtility": {
30+
"cambium_location_type": "GEA Regions",
31+
"cambium_metric_col": "lrmer_co2e",
32+
"cambium_scenario": "Mid-case",
33+
"cambium_grid_level": "enduse"
34+
},
35+
"SpaceHeatingLoad": {
36+
"annual_mmbtu": 11570.916,
37+
"doe_reference_name": "Hospital"
38+
},
39+
"DomesticHotWaterLoad": {
40+
"annual_mmbtu": 671.405,
41+
"doe_reference_name": "Hospital"
42+
},
43+
"ExistingBoiler": {
44+
"fuel_type": "natural_gas",
45+
"fuel_cost_per_mmbtu": 25.0
46+
},
47+
"ASHPSpaceHeater": {
48+
"force_into_system": true,
49+
"can_serve_cooling": false
50+
}
51+
}

reoptjl/test/test_job_endpoint.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -311,4 +311,19 @@ def test_centralghp(self):
311311
resp = self.api_client.get(f'/v3/job/{run_uuid}/results')
312312
r = json.loads(resp.content)
313313

314-
self.assertAlmostEqual(r["outputs"]["Financial"]["lifecycle_capital_costs"], 1046066.8, delta=1000)
314+
self.assertAlmostEqual(r["outputs"]["Financial"]["lifecycle_capital_costs"], 1046066.8, delta=1000)
315+
316+
def test_ashp_defaults_update_from_julia(self):
317+
# Test that the inputs_with_defaults_set_in_julia feature worked for ASHPSpaceHeater
318+
post_file = os.path.join('reoptjl', 'test', 'posts', 'ashp_defaults_update.json')
319+
post = json.load(open(post_file, 'r'))
320+
resp = self.api_client.post('/stable/job/', format='json', data=post)
321+
self.assertHttpCreated(resp)
322+
r = json.loads(resp.content)
323+
run_uuid = r.get('run_uuid')
324+
325+
resp = self.api_client.get(f'/stable/job/{run_uuid}/results')
326+
r = json.loads(resp.content)
327+
328+
self.assertEquals(r["inputs"]["ASHPSpaceHeater"]["om_cost_per_ton"], 0.0)
329+
self.assertEquals(r["inputs"]["ASHPSpaceHeater"]["sizing_factor"], 1.1)

0 commit comments

Comments
 (0)