diff --git a/.gitmodules b/.gitmodules index e69de29bb..9f44da9cc 100644 --- a/.gitmodules +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "EVI-EnSitePy"] + path = EVI-EnSitePy + url = https://github.nrel.gov/AVCI/EVI-EnSitePy.git + branch = dev_enlitepy_api_barebone \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index f013a9acd..332d20bd0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,5 +16,9 @@ COPY . /opt/reopt WORKDIR /opt/reopt RUN ["pip", "install", "-r", "requirements.txt"] +RUN if [ -d "EVI-EnSitePy" ] && [ "$(ls -A EVI-EnSitePy)" ]; then \ + cd EVI-EnSitePy && pip install -e .; \ +fi + EXPOSE 8000 ENTRYPOINT ["/bin/bash", "-c"] diff --git a/EVI-EnSitePy b/EVI-EnSitePy new file mode 160000 index 000000000..5a582d20c --- /dev/null +++ b/EVI-EnSitePy @@ -0,0 +1 @@ +Subproject commit 5a582d20c20e6cf0de99ec2c4240efa6c01909d0 diff --git a/load_builder/urls.py b/load_builder/urls.py index f31cfc794..5e707b5e5 100644 --- a/load_builder/urls.py +++ b/load_builder/urls.py @@ -5,4 +5,5 @@ urlpatterns = [ re_path(r'^load_builder/?$', views.load_builder), + re_path(r'^ensite/?$', views.ensite_view), ] \ No newline at end of file diff --git a/load_builder/views.py b/load_builder/views.py index 58614936e..4c0694f70 100644 --- a/load_builder/views.py +++ b/load_builder/views.py @@ -7,6 +7,33 @@ from django.http import JsonResponse from reo.exceptions import UnexpectedError +def get_ensitepy_simulator(): + """ + Attempts to import ensitepy and return the SystemSimulator class. + If the package is not available, returns None. + """ + try: + import ensitepy + from ensitepy import SystemSimulator + return SystemSimulator + except ImportError: + print("Cannot import ensitepy or failure to call ensitepy function") + return None + + +def ensite_view(request): + """ + View to use the ensitepy SystemSimulator if available. + """ + SystemSimulator = get_ensitepy_simulator() + if SystemSimulator is None: + return JsonResponse({"Error": "ensitepy package is not available."}, status=500) + + # Use the private package functionality + sim = SystemSimulator(t_start=0 * 3600, dt=30, t_end=2 * 24 * 3600) + # ...existing code... + + return JsonResponse({"message": "Ensite view and SystemSimulator function called successfully."}) def check_load_builder_inputs(loads_table): required_inputs = ["Power (W)", "Quantity", "% Run Time", "Start Mo.", "Stop Mo.", "Start Hr.", "Stop Hr."]