Skip to content

Commit

Permalink
Merge pull request #545 from NREL/develop
Browse files Browse the repository at this point in the history
master <- develop for REopt.jl v0.38.0
  • Loading branch information
Bill-Becker committed Nov 18, 2023
2 parents 3ece2a2 + a6d9ae2 commit f1cce91
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ target/
celerybeat-schedule

# dotenv
.env
# .env

# virtualenv
venv/
Expand Down
1 change: 1 addition & 0 deletions julia_src/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NREL_DEVELOPER_API_KEY="gAfosXcQ9Ldfw3qXqvKVb7PxMEkYigozmC9R3mXQ"
11 changes: 8 additions & 3 deletions julia_src/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

julia_version = "1.8.5"
manifest_format = "2.0"
project_hash = "90e66426e70d2bf97b8a3e99508fcb404743b11d"
project_hash = "e6825aaf1b270a6d70a8067b9b1106b9388e5c98"

[[deps.AbstractFFTs]]
deps = ["ChainRulesCore", "LinearAlgebra", "Test"]
Expand Down Expand Up @@ -225,6 +225,11 @@ git-tree-sha1 = "2fb1e02f2b635d0845df5d7c167fec4dd739b00d"
uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
version = "0.9.3"

[[deps.DotEnv]]
git-tree-sha1 = "d48ae0052378d697f8caf0855c4df2c54a97e580"
uuid = "4dc1fcf4-5e3b-5448-94ab-0c38ec0385c1"
version = "0.3.1"

[[deps.Downloads]]
deps = ["ArgTools", "FileWatching", "LibCURL", "NetworkOptions"]
uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
Expand Down Expand Up @@ -729,9 +734,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 = "6f3db36b83c7a3f8aa8d3ab187b91a5a6ac159cb"
git-tree-sha1 = "919f84238b81126f41630ed1bc6daa12342c3f51"
uuid = "d36ad4e8-d74a-4f7a-ace1-eaea049febf6"
version = "0.37.4"
version = "0.38.0"

[[deps.Random]]
deps = ["SHA", "Serialization"]
Expand Down
1 change: 1 addition & 0 deletions julia_src/Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[deps]
AxisArrays = "39de3d68-74b9-583c-8d2d-e117c070f3a9"
DotEnv = "4dc1fcf4-5e3b-5448-94ab-0c38ec0385c1"
GhpGhx = "7ce85f02-24a8-4d69-a3f0-14b5daa7d30c"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
Expand Down
10 changes: 10 additions & 0 deletions julia_src/http.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import Xpress
include("REopt.jl")
import REopt as reoptjl
using GhpGhx
using DotEnv
DotEnv.config()

const test_nrel_developer_api_key = ENV["NREL_DEVELOPER_API_KEY"]

function job(req::HTTP.Request)
d = JSON.parse(String(req.body))
Expand Down Expand Up @@ -35,6 +39,12 @@ end
function reopt(req::HTTP.Request)
d = JSON.parse(String(req.body))
settings = d["Settings"]
if !isempty(get(d, "api_key", ""))
ENV["NREL_DEVELOPER_API_KEY"] = pop!(d, "api_key")
else
ENV["NREL_DEVELOPER_API_KEY"] = test_nrel_developer_api_key
delete!(d, "api_key")
end
timeout_seconds = -pop!(settings, "timeout_seconds")
optimality_tolerance = pop!(settings, "optimality_tolerance")
run_bau = pop!(settings, "run_bau")
Expand Down
5 changes: 4 additions & 1 deletion reoptjl/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def obj_get_list(self, bundle, **kwargs):

def obj_create(self, bundle, **kwargs):
run_uuid = str(uuid.uuid4())

api_key = bundle.request.GET.get("api_key", "")
if 'user_uuid' in bundle.data.keys():

if type(bundle.data['user_uuid']) == str:
Expand Down Expand Up @@ -106,6 +106,9 @@ def obj_create(self, bundle, **kwargs):

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

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

log.addFilter(UUIDFilter(run_uuid))

Expand Down
18 changes: 18 additions & 0 deletions reoptjl/migrations/0050_apimeta_api_key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.0.7 on 2023-11-15 23:56

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('reoptjl', '0049_alter_chpinputs_size_class'),
]

operations = [
migrations.AddField(
model_name='apimeta',
name='api_key',
field=models.TextField(blank=True, default='', help_text='NREL Developer API key of the user'),
),
]
6 changes: 6 additions & 0 deletions reoptjl/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ class APIMeta(BaseModel, models.Model):
default="",
help_text="Version number of the Julia package for REopt that is used to solve the problem."
)
api_key = models.TextField(
blank=True,
default="",
help_text="NREL Developer API key of the user"
)

class UserUnlinkedRuns(models.Model):
run_uuid = models.UUIDField(unique=True)
Expand Down Expand Up @@ -6867,6 +6872,7 @@ def filter_none_and_empty_array(d:dict):

d = dict()
d["user_uuid"] = meta.user_uuid
d["api_key"] = meta.api_key
d["Settings"] = filter_none_and_empty_array(meta.Settings.dict)
d["Financial"] = filter_none_and_empty_array(meta.FinancialInputs.dict)
d["Site"] = filter_none_and_empty_array(meta.SiteInputs.dict)
Expand Down

0 comments on commit f1cce91

Please sign in to comment.