Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

erp outputs endpoint #589

Merged
merged 10 commits into from
Jul 22, 2024
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Classify the change according to the following categories:

## Develop
### Minor Updates
#### Added
- `/erp/inputs` endpoint (calls `erp_help()`, same as `/erp/help`)
adfarth marked this conversation as resolved.
Show resolved Hide resolved
- `/erp/outputs` endpoint that GETs the ERP output field info (calls `erp_outputs()`)
#### Changed
- Set **reopt_version** in **APIMeta** and **ERPMeta** programatically based on actual REopt.jl package version in Julia environment instead of hardcoded so doesn't need to be updated by hand

Expand Down
18 changes: 17 additions & 1 deletion resilience_stats/tests/test_erp.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def setUp(self):
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_inputs = '/v3/erp/inputs/'
self.reopt_base_erp_outputs = '/v3/erp/outputs/'
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')
Expand All @@ -42,6 +44,12 @@ def get_results_sim(self, run_uuid):
def get_help(self):
return self.api_client.get(self.reopt_base_erp_help)

def get_inputs(self):
return self.api_client.get(self.reopt_base_erp_inputs)

def get_outputs(self):
return self.api_client.get(self.reopt_base_erp_outputs)

def get_chp_defaults(self, prime_mover, is_chp, size_kw):
return self.api_client.get(
self.reopt_base_erp_chp_defaults.format(prime_mover, is_chp, size_kw),
Expand Down Expand Up @@ -184,14 +192,22 @@ def test_erp_with_no_opt(self):
resp = self.get_results_sim(erp_run_uuid)
self.assertHttpOK(resp)

def test_erp_help_view(self):
def test_erp_help_views(self):
"""
Tests hiting the erp/help url to get defaults and other info about inputs
"""

resp = self.get_help()
self.assertHttpOK(resp)
resp = json.loads(resp.content)

resp = self.get_inputs()
self.assertHttpOK(resp)
resp = json.loads(resp.content)

resp = self.get_outputs()
self.assertHttpOK(resp)
resp = json.loads(resp.content)

resp = self.get_chp_defaults("recip_engine", True, 10000)
self.assertHttpOK(resp)
Expand Down
2 changes: 2 additions & 0 deletions resilience_stats/urls_v3plus.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
urlpatterns = [
re_path(r'^erp/(?P<run_uuid>[0-9a-f-]+)/results/?$', views.erp_results),
re_path(r'^erp/help/?$', views.erp_help),
re_path(r'^erp/inputs/?$', views.erp_inputs),
re_path(r'^erp/outputs/?$', views.erp_outputs),
re_path(r'^erp/chp_defaults/?$', views.erp_chp_prime_gen_defaults),
]
57 changes: 46 additions & 11 deletions resilience_stats/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,58 @@ def erp_results(request, run_uuid):
resp['status'] = 'Error'
return JsonResponse(resp, status=500)

def get_erp_inputs_info():
d = dict()
d["reopt_run_uuid"] = ERPMeta.info_dict(ERPMeta)["reopt_run_uuid"]
# do models need to be passed in as arg?
d[ERPOutageInputs.key] = ERPOutageInputs.info_dict(ERPOutageInputs)
d[ERPPVInputs.key] = ERPPVInputs.info_dict(ERPPVInputs)
d[ERPWindInputs.key] = ERPWindInputs.info_dict(ERPWindInputs)
d[ERPElectricStorageInputs.key] = ERPElectricStorageInputs.info_dict(ERPElectricStorageInputs)
d[ERPGeneratorInputs.key] = ERPGeneratorInputs.info_dict(ERPGeneratorInputs)
d[ERPPrimeGeneratorInputs.key] = ERPPrimeGeneratorInputs.info_dict(ERPPrimeGeneratorInputs)
#TODO: add wind once implemented
return JsonResponse(d)

def erp_help(request):
"""
Served at host/erp/help
adfarth marked this conversation as resolved.
Show resolved Hide resolved
:param request:
:return: JSON response with all erp inputs
"""
try:
d = dict()
d["reopt_run_uuid"] = ERPMeta.info_dict(ERPMeta)["reopt_run_uuid"]
# do models need to be passed in as arg?
d[ERPOutageInputs.key] = ERPOutageInputs.info_dict(ERPOutageInputs)
d[ERPPVInputs.key] = ERPPVInputs.info_dict(ERPPVInputs)
d[ERPWindInputs.key] = ERPWindInputs.info_dict(ERPWindInputs)
d[ERPElectricStorageInputs.key] = ERPElectricStorageInputs.info_dict(ERPElectricStorageInputs)
d[ERPGeneratorInputs.key] = ERPGeneratorInputs.info_dict(ERPGeneratorInputs)
d[ERPPrimeGeneratorInputs.key] = ERPPrimeGeneratorInputs.info_dict(ERPPrimeGeneratorInputs)
#TODO: add wind once implemented
return JsonResponse(d)
resp = get_erp_inputs_info()
return resp

except Exception as e:
return JsonResponse({"Error": "Unexpected error in ERP help endpoint: {}".format(e.args[0])}, status=500)

def erp_inputs(request):
"""
Served at host/erp/inputs
:param request:
:return: JSON response with all erp inputs
"""
try:
resp = get_erp_inputs_info()
return resp

except Exception as e:
return JsonResponse({"Error": "Unexpected error in ERP inputs endpoint: {}".format(e.args[0])}, status=500)

def erp_outputs(request):
"""
Served at host/erp/outputs
:return: JSON response with all erp outputs
"""

try:
d = ERPOutputs.info_dict(ERPOutputs)
return JsonResponse(d)

except Exception as e:
return JsonResponse({"Error": "Unexpected error in ERP outputs endpoint: {}".format(e.args[0])}, status=500)

def erp_chp_prime_gen_defaults(request):
prime_mover = str(request.GET.get('prime_mover'))
is_chp = bool(request.GET.get('is_chp'))
Expand Down
Loading