Skip to content

Commit

Permalink
Merge branch 'develop' into year-one-name-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
adfarth committed Jan 10, 2023
2 parents 908fba5 + 666b979 commit ca14a73
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
14 changes: 6 additions & 8 deletions job/test/test_http_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ def test_simulated_load(self):
"longitude": -122.45
}

# Direct call of the http.jl endpoint /chp_defaults
julia_host = os.environ.get('JULIA_HOST', "julia")
response = requests.get("http://" + julia_host + ":8081/simulated_load/", json=inputs)
http_response = response.json()
# The /dev/simulated_load endpoint calls the http.jl /simulated_load endpoint
response = self.api_client.get(f'/dev/simulated_load', data=inputs)
http_response = json.loads(response.content)

# Call to the v2 /simulated_load to check for consistency
resp = self.api_client.get(f'/v2/simulated_load', data=inputs)
Expand All @@ -73,10 +72,9 @@ def test_simulated_load(self):
inputs["percent_share[0]"] = 25.0
inputs["percent_share[1]"] = 100.0 - inputs["percent_share[0]"]

# Direct call of the http.jl endpoint /chp_defaults
julia_host = os.environ.get('JULIA_HOST', "julia")
response = requests.get("http://" + julia_host + ":8081/simulated_load/", json=inputs)
http_response = response.json()
# The /dev/simulated_load endpoint calls the http.jl /simulated_load endpoint
response = self.api_client.get(f'/dev/simulated_load', data=inputs)
http_response = json.loads(response.content)

# Call to the v2 /simulated_load to check for consistency
resp = self.api_client.get(f'/v2/simulated_load', data=inputs)
Expand Down
4 changes: 4 additions & 0 deletions job/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
# OF THE POSSIBILITY OF SUCH DAMAGE.
# *********************************************************************************
from . import views
from reo import views as reoviews
from django.urls import re_path

urlpatterns = [
Expand All @@ -37,4 +38,7 @@
re_path(r'^job/outputs/?$', views.outputs),
re_path(r'^chp_defaults/?$', views.chp_defaults),
re_path(r'^simulated_load/?$', views.simulated_load),

re_path(r'^invalid_urdb/?$', reoviews.invalid_urdb),
re_path(r'^emissions_profile/?$', reoviews.emissions_profile),
]
21 changes: 14 additions & 7 deletions job/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,35 +364,37 @@ def simulated_load(request):
raise ValueError("{} is not a valid input parameter".format(key))
# Build inputs dictionary to send to http.jl /simulated_load endpoint
inputs = {}
# Required - will throw a Missing Error if not included
inputs["latitude"] = float(request.GET['latitude']) # need float to convert unicode
inputs["longitude"] = float(request.GET['longitude'])
# Optional load_type - will default to "electric"
inputs["load_type"] = request.GET.get('load_type')

# This parses the GET request way of sending a list/array for doe_reference_name,
# i.e. doe_reference_name[0], doe_reference_name[1], etc
# i.e. doe_reference_name[0], doe_reference_name[1], etc along with percent_share[0], percent_share[1]
if 'doe_reference_name' in request.GET.keys():
inputs["doe_reference_name"] = request.GET.get('doe_reference_name')
inputs["doe_reference_name"] = str(request.GET.get('doe_reference_name'))
elif 'doe_reference_name[0]' in request.GET.keys():
idx = 0
doe_reference_name = []
percent_share_list = []
while 'doe_reference_name[{}]'.format(idx) in request.GET.keys():
doe_reference_name.append(request.GET['doe_reference_name[{}]'.format(idx)])
doe_reference_name.append(str(request.GET['doe_reference_name[{}]'.format(idx)]))
if 'percent_share[{}]'.format(idx) in request.GET.keys():
percent_share_list.append(float(request.GET['percent_share[{}]'.format(idx)]))
idx += 1
inputs["doe_reference_name"] = doe_reference_name
inputs["percent_share_list"] = percent_share_list
inputs["percent_share"] = percent_share_list

# When wanting cooling profile based on building type(s) for cooling, need separate cooling building(s)
if 'cooling_doe_ref_name' in request.GET.keys():
inputs["cooling_doe_ref_name"] = request.GET.get('cooling_doe_ref_name')
inputs["cooling_doe_ref_name"] = str(request.GET.get('cooling_doe_ref_name'))
elif 'cooling_doe_ref_name[0]' in request.GET.keys():
idx = 0
cooling_doe_ref_name = []
cooling_pct_share_list = []
while 'cooling_doe_ref_name[{}]'.format(idx) in request.GET.keys():
cooling_doe_ref_name.append(request.GET['cooling_doe_ref_name[{}]'.format(idx)])
cooling_doe_ref_name.append(str(request.GET['cooling_doe_ref_name[{}]'.format(idx)]))
if 'cooling_pct_share[{}]'.format(idx) in request.GET.keys():
cooling_pct_share_list.append(float(request.GET['cooling_pct_share[{}]'.format(idx)]))
idx += 1
Expand All @@ -406,7 +408,12 @@ def simulated_load(request):
if key_type in key:
value = request.GET.get(key)
if value is not None:
inputs[key] = value
if type(value) == list:
monthly_list = [request.GET.get(key+'[{}]'.format(i)) for i in range(12)]
k = key.split('[')[0]
inputs[k] = [float(i) for i in monthly_list]
else:
inputs[key] = float(value)

julia_host = os.environ.get('JULIA_HOST', "julia")
http_jl_response = requests.get("http://" + julia_host + ":8081/simulated_load/", json=inputs)
Expand Down
11 changes: 11 additions & 0 deletions julia_src/http.jl
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,17 @@ end
function simulated_load(req::HTTP.Request)
d = JSON.parse(String(req.body))

# Arrays in d are being parsed as type Vector{Any} instead of fixed type Vector{String or <:Real} without conversion
for key in ["doe_reference_name", "cooling_doe_ref_name"]
if key in keys(d) && typeof(d[key]) <: Vector{}
d[key] = convert(Vector{String}, d[key])
end
end

if "percent_share" in keys(d) && typeof(d["percent_share"]) <: Vector{}
d["percent_share"] = convert(Vector{Float64}, d["percent_share"])
end

@info "Getting CRB Loads..."
data = Dict()
error_response = Dict()
Expand Down

0 comments on commit ca14a73

Please sign in to comment.