Skip to content

Commit

Permalink
Merge branch 'develop' into proforma
Browse files Browse the repository at this point in the history
  • Loading branch information
rathod-b committed Oct 2, 2024
2 parents 9260b43 + 75eca34 commit 6c771e4
Show file tree
Hide file tree
Showing 32 changed files with 3,758 additions and 215 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,29 @@ Classify the change according to the following categories:
##### Removed
### Patches

## v3.10.0
### Minor Updates
#### Added
- Added new model **ElectricHeaterInputs**
- Added new model **ElectricHeaterOutputs**
- Added new model **ASHPWaterHeaterInputs**
- Added new model **ASHPWaterHeaterOutputs**
- Added new model **ASHPSpaceHeaterInputs**
- Added new model **ASHPSpaceHeaterOutputs**
- Added /job/generate_results_table endpoint which takes a list of run_uuid's and creates a results table spreadsheet to download in response

## v3.9.4
### Minor Updates
#### Added
- **portfolio_uuid** is now a field that can be added to API objects
- **PortfolioUnlinkedRuns** tracks which run_uuids were separated from their portfolios
- `/user/<user_uuid>/unlink_from_portfolio/` endpoint (calls `views.unlink_from_portfolio`)
- `/summary_by_runuuids/` endpoint (calls `views.summary_by_runuuids`)
- `/link_run_to_portfolios/` endpoint (calls `views.link_run_to_portfolios`)

#### Changed
- `UnexpectedError`, added portfolio_uuid as a field that can be returned in case of errors

## v3.9.3
### Minor Updates
#### Added
Expand Down
4 changes: 4 additions & 0 deletions julia_src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ ARG NREL_ROOT_CERT_URL_ROOT=""
RUN set -x && if [ -n "$NREL_ROOT_CERT_URL_ROOT" ]; then curl -fsSLk -o /usr/local/share/ca-certificates/nrel_root.crt "${NREL_ROOT_CERT_URL_ROOT}/nrel_root.pem" && curl -fsSLk -o /usr/local/share/ca-certificates/nrel_xca1.crt "${NREL_ROOT_CERT_URL_ROOT}/nrel_xca1.pem" && update-ca-certificates; fi
ENV REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt

# Use git cli instead of Julia's libgit2, since we're facing SSL issues with it.
RUN apt-get update && apt-get -y install git && rm -rf /var/lib/apt/lists/* /var/lib/dpkg/*-old /var/cache/* /var/log/*
ENV JULIA_PKG_USE_CLI_GIT=true

# Install Julia packages
ENV JULIA_NUM_THREADS=2
ENV XPRESS_JL_SKIP_LIB_CHECK=True
Expand Down
4 changes: 2 additions & 2 deletions julia_src/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -917,9 +917,9 @@ uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"

[[deps.REopt]]
deps = ["ArchGDAL", "CSV", "CoolProp", "DataFrames", "Dates", "DelimitedFiles", "HTTP", "JLD", "JSON", "JuMP", "LinDistFlow", "LinearAlgebra", "Logging", "MathOptInterface", "Requires", "Roots", "Statistics", "TestEnv"]
git-tree-sha1 = "c02ff7c0b60352164b89f39789424422083ae4eb"
git-tree-sha1 = "32499f329265d270e9f77c8831892772b5fbf28f"
uuid = "d36ad4e8-d74a-4f7a-ace1-eaea049febf6"
version = "0.47.2"
version = "0.48.0"

[[deps.Random]]
deps = ["SHA"]
Expand Down
75 changes: 72 additions & 3 deletions julia_src/http.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,55 @@ function reopt(req::HTTP.Request)
else
ghp_dict = Dict()
end
if haskey(d, "ASHPSpaceHeater")
inputs_with_defaults_from_ashp = [
:max_ton, :installed_cost_per_ton, :om_cost_per_ton,
:macrs_option_years, :macrs_bonus_fraction, :can_supply_steam_turbine,
:can_serve_process_heat, :can_serve_dhw, :can_serve_space_heating, :can_serve_cooling,
:back_up_temp_threshold_degF, :sizing_factor, :heating_cop_reference, :heating_cf_reference,
:heating_reference_temps_degF, :cooling_cop_reference, :cooling_cf_reference,
:cooling_reference_temps_degF
]
ashp_dict = Dict(key=>getfield(model_inputs.s.ashp, key) for key in inputs_with_defaults_from_ashp)
else
ashp_dict = Dict()
end
if haskey(d, "ASHPWaterHeater")
inputs_with_defaults_from_ashp_wh = [
:max_ton, :installed_cost_per_ton, :om_cost_per_ton,
:macrs_option_years, :macrs_bonus_fraction, :can_supply_steam_turbine,
:can_serve_process_heat, :can_serve_dhw, :can_serve_space_heating, :can_serve_cooling,
:back_up_temp_threshold_degF, :sizing_factor, :heating_cop_reference, :heating_cf_reference,
:heating_reference_temps_degF
]
ashp_wh_dict = Dict(key=>getfield(model_inputs.s.ashp_wh, key) for key in inputs_with_defaults_from_ashp_wh)
else
ashp_wh_dict = Dict()
end
if haskey(d, "CoolingLoad")
inputs_with_defaults_from_chiller = [
:cop
]
chiller_dict = Dict(key=>getfield(model_inputs.s.existing_chiller, key) for key in inputs_with_defaults_from_chiller)
else
chiller_dict = Dict()
end
end
if !isnothing(model_inputs.s.site.outdoor_air_temperature_degF)
site_dict = Dict(:outdoor_air_temperature_degF => model_inputs.s.site.outdoor_air_temperature_degF)
else
site_dict = Dict()
end
inputs_with_defaults_set_in_julia = Dict(
"Financial" => Dict(key=>getfield(model_inputs.s.financial, key) for key in inputs_with_defaults_from_easiur),
"ElectricUtility" => Dict(key=>getfield(model_inputs.s.electric_utility, key) for key in inputs_with_defaults_from_avert_or_cambium),
"Site" => site_dict,
"CHP" => chp_dict,
"SteamTurbine" => steamturbine_dict,
"GHP" => ghp_dict,
"ExistingChiller" => chiller_dict
)
"ExistingChiller" => chiller_dict,
"ASHPSpaceHeater" => ashp_dict,
"ASHPWaterHeater" => ashp_wh_dict
)
catch e
@error "Something went wrong in REopt optimization!" exception=(e, catch_backtrace())
error_response["error"] = sprint(showerror, e) # append instead of rewrite?
Expand Down Expand Up @@ -511,6 +544,41 @@ function get_existing_chiller_default_cop(req::HTTP.Request)
end
end

function get_ashp_defaults(req::HTTP.Request)
d = JSON.parse(String(req.body))
defaults = nothing

if !("load_served" in keys(d))
@info("ASHP load served not provided. Using default of SpaceHeating.")
d["load_served"] = "SpaceHeating"
end
if !("force_into_system" in keys(d))
@info("ASHP force_into_system not provided. Using default of false.")
d["force_into_system"] = false
elseif typeof(d["force_into_system"]) == String
d["force_into_system"] = parse(Bool, d["force_into_system"])
end

@info "Getting default ASHP attributes..."
error_response = Dict()
try
# Have to specify "REopt.get_existing..." because http function has the same name
defaults = reoptjl.get_ashp_defaults(d["load_served"],d["force_into_system"])
catch e
@error "Something went wrong in the get_ashp_defaults endpoint" exception=(e, catch_backtrace())
error_response["error"] = sprint(showerror, e)
end
if isempty(error_response)
@info("ASHP defaults obtained.")
response = defaults
return HTTP.Response(200, JSON.json(response))
else
@info "An error occured in the get_ashp_defaults endpoint"
return HTTP.Response(500, JSON.json(error_response))
end
end


function job_no_xpress(req::HTTP.Request)
error_response = Dict("error" => "V1 and V2 not available without Xpress installation.")
return HTTP.Response(500, JSON.json(error_response))
Expand All @@ -537,4 +605,5 @@ HTTP.register!(ROUTER, "GET", "/ghp_efficiency_thermal_factors", ghp_efficiency_
HTTP.register!(ROUTER, "GET", "/ground_conductivity", ground_conductivity)
HTTP.register!(ROUTER, "GET", "/health", health)
HTTP.register!(ROUTER, "GET", "/get_existing_chiller_default_cop", get_existing_chiller_default_cop)
HTTP.register!(ROUTER, "GET", "/get_ashp_defaults", get_ashp_defaults)
HTTP.serve(ROUTER, "0.0.0.0", 8081, reuseaddr=true)
4 changes: 2 additions & 2 deletions reo/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ class UnexpectedError(REoptError):

__name__ = 'UnexpectedError'

def __init__(self, exc_type, exc_value, exc_traceback, task='', run_uuid='', user_uuid='', message=None):
def __init__(self, exc_type, exc_value, exc_traceback, task='', run_uuid='', user_uuid='', portfolio_uuid='', message=None):
debug_msg = "exc_type: {}; exc_value: {}; exc_traceback: {}".format(exc_type, exc_value, exc_traceback)
if message is None:
message = "Unexpected Error."
super(UnexpectedError, self).__init__(task=task, name=self.__name__, run_uuid=run_uuid, user_uuid=user_uuid,
super(UnexpectedError, self).__init__(task=task, name=self.__name__, run_uuid=run_uuid, user_uuid=user_uuid, portfolio_uuid=portfolio_uuid,
message=message, traceback=debug_msg)


Expand Down
13 changes: 13 additions & 0 deletions reoptjl/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ def obj_create(self, bundle, **kwargs):
else:
webtool_uuid = None

if 'portfolio_uuid' in bundle.data.keys():

if type(bundle.data['portfolio_uuid']) == str:
if len(bundle.data['portfolio_uuid']) == len(run_uuid):
portfolio_uuid = bundle.data['portfolio_uuid']
else:
portfolio_uuid = ''
else:
portfolio_uuid = None

meta = {
"run_uuid": run_uuid,
"api_version": 3,
Expand All @@ -110,6 +120,9 @@ def obj_create(self, bundle, **kwargs):

if api_key != "":
bundle.data['APIMeta']['api_key'] = api_key

if portfolio_uuid is not None:
bundle.data['APIMeta']['portfolio_uuid'] = portfolio_uuid

log.addFilter(UUIDFilter(run_uuid))

Expand Down
Loading

0 comments on commit 6c771e4

Please sign in to comment.