Skip to content

Commit

Permalink
Merge pull request #512 from NREL/develop
Browse files Browse the repository at this point in the history
BREAKING official release of the V3 API as the stable version
  • Loading branch information
Bill-Becker authored Sep 26, 2023
2 parents 0cff4a0 + 2b6e738 commit d1f6dd0
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 56 deletions.
2 changes: 1 addition & 1 deletion reo/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def setup_pv(pv_dict, latitude, longitude, time_steps_per_hour):
ground_k_inputs = {"latitude": ghpghx_post["latitude"],
"longitude": ghpghx_post["longitude"]}
# Call to the django view endpoint /ghp_efficiency_thermal_factors which calls the http.jl endpoint
ground_k_resp = client.get(f'/dev/ghpghx/ground_conductivity', data=ground_k_inputs)
ground_k_resp = client.get(f'/v3/ghpghx/ground_conductivity', data=ground_k_inputs)
ground_k_response = json.loads(ground_k_resp.content)
ghpghx_post["ground_thermal_conductivity_btu_per_hr_ft_f"] = ground_k_response["thermal_conductivity"]

Expand Down
19 changes: 8 additions & 11 deletions reopt_api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,16 @@

v3_api = Api(api_name='v3')
v3_api.register(REoptJLJob())
v3_api.register(GHPGHXJob())
v3_api.register(ERPJob())
v3_api.register(GHPGHXJob())

stable_api = Api(api_name='stable')
stable_api.register(Job2())
stable_api.register(OutageSimJob())
stable_api.register(REoptJLJob())
stable_api.register(ERPJob())
stable_api.register(GHPGHXJob())

dev_api = Api(api_name='dev')
dev_api.register(REoptJLJob())
dev_api.register(FutureCostsAPI())
dev_api.register(GHPGHXJob())
dev_api.register(ERPJob())


def page_not_found(request, url):
Expand Down Expand Up @@ -77,12 +74,12 @@ def page_not_found(request, url):
# (summary is within reoptjl.urls)
re_path(r'', include(v3_api.urls)),

path('stable/', include('reo.urls_v2')),
path('stable/', include('resilience_stats.urls_v1_v2')),
path('stable/', include('proforma.urls')),
path('stable/', include('load_builder.urls')),
path('stable/', include('summary.urls')),
path('stable/', include('reoptjl.urls')),
path('stable/', include('resilience_stats.urls_v3plus')),
path('stable/', include('ghpghx.urls')),
path('stable/', include('load_builder.urls')),
# TODO proforma for v3
# (summary is within reoptjl.urls)
re_path(r'', include(stable_api.urls)),

path('dev/', include('reoptjl.urls')),
Expand Down
36 changes: 18 additions & 18 deletions reoptjl/test/test_http_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_chp_defaults(self):
http_response = response.json()

# Call to the django view endpoint /chp_defaults which calls the http.jl endpoint
resp = self.api_client.get(f'/dev/chp_defaults', data=inputs)
resp = self.api_client.get(f'/v3/chp_defaults', data=inputs)
view_response = json.loads(resp.content)

mismatch = []
Expand Down Expand Up @@ -59,7 +59,7 @@ def test_steamturbine_defaults(self):
http_response = response.json()

# Call to the django view endpoint /chp_defaults which calls the http.jl endpoint
resp = self.api_client.get(f'/dev/chp_defaults', data=inputs)
resp = self.api_client.get(f'/v3/chp_defaults', data=inputs)
view_response = json.loads(resp.content)

mismatch = []
Expand All @@ -86,7 +86,7 @@ def test_absorption_chiller_defaults(self):
http_response = response.json()

# Call to the django view endpoint /absorption_chiller_defaults which calls the http.jl endpoint
resp = self.api_client.get(f'/dev/absorption_chiller_defaults', data=inputs)
resp = self.api_client.get(f'/v3/absorption_chiller_defaults', data=inputs)
view_response = json.loads(resp.content)

mismatch = []
Expand All @@ -112,8 +112,8 @@ def test_simulated_load(self):
"longitude": -122.45
}

# The /dev/simulated_load endpoint calls the http.jl /simulated_load endpoint
response = self.api_client.get(f'/dev/simulated_load', data=inputs)
# The /v3/simulated_load endpoint calls the http.jl /simulated_load endpoint
response = self.api_client.get(f'/v3/simulated_load', data=inputs)
http_response = json.loads(response.content)

# Call to the v2 /simulated_load to check for consistency
Expand All @@ -129,8 +129,8 @@ def test_simulated_load(self):
inputs["percent_share[0]"] = 25.0
inputs["percent_share[1]"] = 100.0 - inputs["percent_share[0]"]

# The /dev/simulated_load endpoint calls the http.jl /simulated_load endpoint
response = self.api_client.get(f'/dev/simulated_load', data=inputs)
# The /v3/simulated_load endpoint calls the http.jl /simulated_load endpoint
response = self.api_client.get(f'/v3/simulated_load', data=inputs)
http_response = json.loads(response.content)

# Call to the v2 /simulated_load to check for consistency
Expand All @@ -150,7 +150,7 @@ def test_emissions_profile_endpoint(self):
"latitude": 47.606211,
"longitude": -122.336052
}
resp = self.api_client.get(f'/dev/emissions_profile', data=inputs)
resp = self.api_client.get(f'/v3/emissions_profile', data=inputs)
self.assertHttpOK(resp)
view_response = json.loads(resp.content)
self.assertEquals(view_response["meters_to_region"], 0.0)
Expand All @@ -160,7 +160,7 @@ def test_emissions_profile_endpoint(self):
"latitude": 47.606211,
"longitude": 122.336052
}
resp = self.api_client.get(f'/dev/emissions_profile', data=inputs)
resp = self.api_client.get(f'/v3/emissions_profile', data=inputs)
self.assertHttpBadRequest(resp)
view_response = json.loads(resp.content)
self.assertTrue("error" in view_response)
Expand All @@ -172,7 +172,7 @@ def test_easiur_endpoint(self):
"longitude": -122.336052,
"inflation": 0.025
}
resp = self.api_client.get(f'/dev/easiur_costs', data=inputs)
resp = self.api_client.get(f'/v3/easiur_costs', data=inputs)
self.assertHttpOK(resp)
view_response = json.loads(resp.content)
for ekey in ["NOx", "SO2", "PM25"]:
Expand All @@ -183,7 +183,7 @@ def test_easiur_endpoint(self):
"longitude": 122.336052,
"inflation": 0.025
}
resp = self.api_client.get(f'/dev/easiur_costs', data=inputs)
resp = self.api_client.get(f'/v3/easiur_costs', data=inputs)
self.assertHttpBadRequest(resp)
view_response = json.loads(resp.content)
self.assertTrue("error" in view_response)
Expand All @@ -195,7 +195,7 @@ def test_ghp_endpoints(self):
"doe_reference_name": "MediumOffice"}

# Call to the django view endpoint /ghp_efficiency_thermal_factors which calls the http.jl endpoint
resp = self.api_client.get(f'/dev/ghp_efficiency_thermal_factors', data=inputs_dict)
resp = self.api_client.get(f'/v3/ghp_efficiency_thermal_factors', data=inputs_dict)
view_response = json.loads(resp.content)

self.assertEqual(view_response["cooling_efficiency_thermal_factor"], 0.43)
Expand All @@ -206,7 +206,7 @@ def test_ghp_endpoints(self):
"longitude": -122.45}

# Call to the django view endpoint /ghpghx/ground_conductivity which calls the http.jl endpoint
resp = self.api_client.get(f'/dev/ghpghx/ground_conductivity', data=inputs_dict)
resp = self.api_client.get(f'/v3/ghpghx/ground_conductivity', data=inputs_dict)
view_response = json.loads(resp.content)

self.assertEqual(view_response["thermal_conductivity"], 1.117)
Expand All @@ -220,7 +220,7 @@ def test_default_existing_chiller_cop(self):
}

# Call to the django view endpoint /get_existing_chiller_default_cop which calls the http.jl endpoint
resp = self.api_client.get(f'/dev/get_existing_chiller_default_cop', data=inputs_dict)
resp = self.api_client.get(f'/v3/get_existing_chiller_default_cop', data=inputs_dict)
view_response = json.loads(resp.content)
print(view_response)

Expand All @@ -230,7 +230,7 @@ def test_default_existing_chiller_cop(self):
inputs_dict = {}

# Call to the django view endpoint /get_existing_chiller_default_cop which calls the http.jl endpoint
resp = self.api_client.get(f'/dev/get_existing_chiller_default_cop', data=inputs_dict)
resp = self.api_client.get(f'/v3/get_existing_chiller_default_cop', data=inputs_dict)
view_response = json.loads(resp.content)
print(view_response)

Expand All @@ -244,7 +244,7 @@ def test_default_existing_chiller_cop(self):
}

# Call to the django view endpoint /get_existing_chiller_default_cop which calls the http.jl endpoint
resp = self.api_client.get(f'/dev/get_existing_chiller_default_cop', data=inputs_dict)
resp = self.api_client.get(f'/v3/get_existing_chiller_default_cop', data=inputs_dict)
view_response = json.loads(resp.content)
print(view_response)

Expand All @@ -257,7 +257,7 @@ def test_default_existing_chiller_cop(self):
}

# Call to the django view endpoint /get_existing_chiller_default_cop which calls the http.jl endpoint
resp = self.api_client.get(f'/dev/get_existing_chiller_default_cop', data=inputs_dict)
resp = self.api_client.get(f'/v3/get_existing_chiller_default_cop', data=inputs_dict)
view_response = json.loads(resp.content)
print(view_response)

Expand All @@ -269,7 +269,7 @@ def test_default_existing_chiller_cop(self):
}

# Call to the django view endpoint /get_existing_chiller_default_cop which calls the http.jl endpoint
resp = self.api_client.get(f'/dev/get_existing_chiller_default_cop', data=inputs_dict)
resp = self.api_client.get(f'/v3/get_existing_chiller_default_cop', data=inputs_dict)
view_response = json.loads(resp.content)
print(view_response)

Expand Down
40 changes: 20 additions & 20 deletions reoptjl/test/test_job_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ def test_multiple_outages(self):

scenario_file = os.path.join('reoptjl', 'test', 'posts', 'outage.json')
scenario = json.load(open(scenario_file, 'r'))
resp = self.api_client.post('/dev/job/', format='json', data=scenario)
resp = self.api_client.post('/v3/job/', format='json', data=scenario)
self.assertHttpCreated(resp)
r = json.loads(resp.content)
run_uuid = r.get('run_uuid')
resp = self.api_client.get(f'/dev/job/{run_uuid}/results')
resp = self.api_client.get(f'/v3/job/{run_uuid}/results')
r = json.loads(resp.content)
results = r["outputs"]
self.assertEqual(np.array(results["Outages"]["unserved_load_series_kw"]).shape, (1,2,5))
Expand All @@ -42,12 +42,12 @@ def test_pv_battery_and_emissions_defaults_from_julia(self):
post_file = os.path.join('reoptjl', 'test', 'posts', 'pv_batt_emissions.json')
post = json.load(open(post_file, 'r'))

resp = self.api_client.post('/dev/job/', format='json', data=post)
resp = self.api_client.post('/v3/job/', format='json', data=post)
self.assertHttpCreated(resp)
r = json.loads(resp.content)
run_uuid = r.get('run_uuid')

resp = self.api_client.get(f'/dev/job/{run_uuid}/results')
resp = self.api_client.get(f'/v3/job/{run_uuid}/results')
r = json.loads(resp.content)
results = r["outputs"]

Expand Down Expand Up @@ -75,12 +75,12 @@ def test_off_grid_defaults(self):
post_file = os.path.join('reoptjl', 'test', 'posts', 'off_grid_defaults.json')
post = json.load(open(post_file, 'r'))

resp = self.api_client.post('/dev/job/', format='json', data=post)
resp = self.api_client.post('/v3/job/', format='json', data=post)
self.assertHttpCreated(resp)
r = json.loads(resp.content)
run_uuid = r.get('run_uuid')

resp = self.api_client.get(f'/dev/job/{run_uuid}/results')
resp = self.api_client.get(f'/v3/job/{run_uuid}/results')
r = json.loads(resp.content)
results = r["outputs"]

Expand All @@ -99,12 +99,12 @@ def test_process_reopt_error(self):
post_file = os.path.join('reoptjl', 'test', 'posts', 'handle_reopt_error.json')
post = json.load(open(post_file, 'r'))

resp = self.api_client.post('/dev/job/', format='json', data=post)
resp = self.api_client.post('/v3/job/', format='json', data=post)
self.assertHttpCreated(resp)
r = json.loads(resp.content)
run_uuid = r.get('run_uuid')

resp = self.api_client.get(f'/dev/job/{run_uuid}/results')
resp = self.api_client.get(f'/v3/job/{run_uuid}/results')
r = json.loads(resp.content)
assert('errors' in r["messages"].keys())
assert('warnings' in r["messages"].keys())
Expand Down Expand Up @@ -185,12 +185,12 @@ def test_thermal_in_results(self):
ghpghx_response = json.load(open(ghpghx_response_file, 'r'))
scenario["GHP"]["ghpghx_responses"] = [ghpghx_response]

resp = self.api_client.post('/dev/job/', format='json', data=scenario)
resp = self.api_client.post('/v3/job/', format='json', data=scenario)
self.assertHttpCreated(resp)
r = json.loads(resp.content)
run_uuid = r.get('run_uuid')

resp = self.api_client.get(f'/dev/job/{run_uuid}/results')
resp = self.api_client.get(f'/v3/job/{run_uuid}/results')
r = json.loads(resp.content)
inputs = r["inputs"]
results = r["outputs"]
Expand All @@ -214,12 +214,12 @@ def test_chp_defaults_from_julia(self):
# Default ExistingBoiler efficiency for production_type = steam is 0.75
post["SpaceHeatingLoad"]["annual_mmbtu"] = 8760 * 8 / 0.75
post["DomesticHotWaterLoad"]["annual_mmbtu"] = 8760 * 8 / 0.75
resp = self.api_client.post('/dev/job/', format='json', data=post)
resp = self.api_client.post('/v3/job/', format='json', data=post)
self.assertHttpCreated(resp)
r = json.loads(resp.content)
run_uuid = r.get('run_uuid')

resp = self.api_client.get(f'/dev/job/{run_uuid}/results')
resp = self.api_client.get(f'/v3/job/{run_uuid}/results')
r = json.loads(resp.content)

inputs_chp = r["inputs"]["CHP"]
Expand All @@ -231,7 +231,7 @@ def test_chp_defaults_from_julia(self):
}

# Call to the django view endpoint /chp_defaults which calls the http.jl endpoint
resp = self.api_client.get(f'/dev/chp_defaults', data=inputs_chp_defaults)
resp = self.api_client.get(f'/v3/chp_defaults', data=inputs_chp_defaults)
view_response = json.loads(resp.content)

for key in view_response["default_inputs"].keys():
Expand Down Expand Up @@ -260,15 +260,15 @@ def test_peak_load_outage_times(self):
"start_not_center_on_peaks": False
}
expected_time_steps = [50*24-1-47+1, 70*24+13-47+1, 170*24-47+1, 243*24-47+1]
resp = self.api_client.post(f'/dev/peak_load_outage_times', data=outage_inputs)
resp = self.api_client.post(f'/v3/peak_load_outage_times', data=outage_inputs)
self.assertHttpOK(resp)
resp = json.loads(resp.content)
self.assertEquals(resp["outage_start_time_steps"], expected_time_steps)

outage_inputs["seasonal_peaks"] = False
outage_inputs["start_not_center_on_peaks"] = True
expected_time_steps = [243*24+1]
resp = self.api_client.post(f'/dev/peak_load_outage_times', data=outage_inputs)
resp = self.api_client.post(f'/v3/peak_load_outage_times', data=outage_inputs)
self.assertHttpOK(resp)
resp = json.loads(resp.content)
self.assertEquals(resp["outage_start_time_steps"], expected_time_steps)
Expand All @@ -281,12 +281,12 @@ def test_superset_input_fields(self):
post_file = os.path.join('reoptjl', 'test', 'posts', 'all_inputs_test.json')
post = json.load(open(post_file, 'r'))

resp = self.api_client.post('/dev/job/', format='json', data=post)
resp = self.api_client.post('/v3/job/', format='json', data=post)
self.assertHttpCreated(resp)
r = json.loads(resp.content)
run_uuid = r.get('run_uuid')

resp = self.api_client.get(f'/dev/job/{run_uuid}/results')
resp = self.api_client.get(f'/v3/job/{run_uuid}/results')
r = json.loads(resp.content)
results = r["outputs"]

Expand All @@ -299,12 +299,12 @@ def test_steamturbine_defaults_from_julia(self):
post = json.load(open(post_file, 'r'))

# Call http.jl /reopt to run SteamTurbine scenario and get results for defaults from julia checking
resp = self.api_client.post('/dev/job/', format='json', data=post)
resp = self.api_client.post('/v3/job/', format='json', data=post)
self.assertHttpCreated(resp)
r = json.loads(resp.content)
run_uuid = r.get('run_uuid')

resp = self.api_client.get(f'/dev/job/{run_uuid}/results')
resp = self.api_client.get(f'/v3/job/{run_uuid}/results')
r = json.loads(resp.content)

inputs_steamturbine = r["inputs"]["SteamTurbine"]
Expand All @@ -318,7 +318,7 @@ def test_steamturbine_defaults_from_julia(self):
}

# Call to the django view endpoint /chp_defaults which calls the http.jl endpoint
resp = self.api_client.get(f'/dev/chp_defaults', data=inputs_steamturbine_defaults)
resp = self.api_client.get(f'/v3/chp_defaults', data=inputs_steamturbine_defaults)
view_response = json.loads(resp.content)

for key in view_response["default_inputs"].keys():
Expand Down
12 changes: 6 additions & 6 deletions resilience_stats/tests/test_erp.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ def setUp(self):
super(ERPTests, self).setUp()

#for ERP simulation
self.reopt_base_erp = '/dev/erp/'
self.reopt_base_erp_results = '/dev/erp/{}/results/'
self.reopt_base_erp_help = '/dev/erp/help/'
self.reopt_base_erp_chp_defaults = '/dev/erp/chp_defaults/?prime_mover={0}&is_chp={1}&size_kw={2}'
self.reopt_base_erp = '/v3/erp/'
self.reopt_base_erp_results = '/v3/erp/{}/results/'
self.reopt_base_erp_help = '/v3/erp/help/'
self.reopt_base_erp_chp_defaults = '/v3/erp/chp_defaults/?prime_mover={0}&is_chp={1}&size_kw={2}'
self.post_sim_gens_batt_pv_wind = os.path.join('resilience_stats', 'tests', 'ERP_sim_gens_batt_pv_wind_post.json')
self.post_sim_large_stor = os.path.join('resilience_stats', 'tests', 'ERP_sim_large_stor_post.json')
self.post_sim_only = os.path.join('resilience_stats', 'tests', 'ERP_sim_only_post.json')
self.post_sim_long_dur_stor = os.path.join('resilience_stats', 'tests', 'ERP_sim_long_dur_stor_post.json')
#for REopt optimization
self.reopt_base_opt = '/dev/job/'
self.reopt_base_opt_results = '/dev/job/{}/results'
self.reopt_base_opt = '/v3/job/'
self.reopt_base_opt_results = '/v3/job/{}/results'
self.post_opt_gens_batt_pv_wind = os.path.join('resilience_stats', 'tests', 'ERP_opt_gens_batt_pv_wind_post.json')
self.post_opt_long_dur_stor = os.path.join('resilience_stats', 'tests', 'ERP_opt_long_dur_stor_post.json')

Expand Down

0 comments on commit d1f6dd0

Please sign in to comment.