Skip to content

Commit

Permalink
Merge branch 'ibpsa:master' into issue406_largeoffice_spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
terrancelu92 authored Aug 29, 2023
2 parents 756895c + c3e0192 commit 550e56e
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ jobs:
- python: 3.9
install: pip install --upgrade pip && pip install pandas==1.2.5 numpy==1.20.2 matplotlib==3.3.4 requests==2.25.1
script: cd testing && make build_jm_image && make test_kpis
- python: 3.9
install: pip install --upgrade pip && pip install pandas==1.2.5 numpy==1.20.2 matplotlib==3.3.4 requests==2.25.1
script: cd testing && make build_jm_image && make test_testcase
- python: 3.9
install: pip install --upgrade pip && pip install pandas==1.2.5 numpy==1.20.2 matplotlib==3.3.4 requests==2.25.1
script: cd testing && make build_jm_image && make test_readme_commands
Expand Down
5 changes: 5 additions & 0 deletions releasenotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ Released on xx/xx/xxxx.
- In unit test checking fetching of single forecast variable, specify specific forecast point to check for each test case. This is for [#529](https://github.com/ibpsa/project1-boptest/issues/529).
- Update ``KPI_Calculator.get_computational_time_ratio`` to return ``None`` if no simulation steps have been processed. This is for [#540](https://github.com/ibpsa/project1-boptest/issues/540).
- Add ``forecastParameters`` to dashboard submission with empty dictionary and update url for submitting dashboard results. This is for [#548](https://github.com/ibpsa/project1-boptest/issues/548).
- Fix so that results can be submitted to dashboard if sitting at end of scenario time period instead of needing to try to advance one step past. This is for [#546](https://github.com/ibpsa/project1-boptest/issues/546).

**The following changes are backwards-compatible, but might change benchmark results:**

- Fix check on control input overwrite in ``testcase.TestCase.advance`` when overwriting a value of 0. This will change results if using BOPTEST-Service and delivering control input overwrites, with value of 0, in an /advance request using the ``json`` attribute with the python requests library. This is for [#533](https://github.com/ibpsa/project1-boptest/issues/533).


## BOPTEST v0.4.0
Expand Down
8 changes: 5 additions & 3 deletions testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def advance(self, u):
u : dict
Defines the control input data to be used for the step.
{<input_name>_activate : bool, int, float, or str convertable to 1 or 0
<input_name>_u : int or float}
<input_name>_u : int or float, or str convertable to float}
Returns
-------
Expand Down Expand Up @@ -276,7 +276,7 @@ def advance(self, u):
message = "Unexpected input variable: {}.".format(key)
logging.error(message)
return status, message, payload
if key != 'time' and u[key]:
if (key != 'time' and (u[key] != None)):
if '_activate' in key:
try:
if float(u[key]) == 1:
Expand Down Expand Up @@ -344,6 +344,9 @@ def advance(self, u):
message = alert_message
# Advance start time
self.start_time = self.final_time
# Check if scenario is over
if self.start_time >= self.end_time:
self.scenario_end = True
# Log and return
logging.info(message)
return status, message, payload
Expand All @@ -357,7 +360,6 @@ def advance(self, u):
return status, message, payload
else:
# Simulation at end time
self.scenario_end = True
payload = dict()
message = "End of test case scenario time period reached."
logging.info(message)
Expand Down
24 changes: 24 additions & 0 deletions testing/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ copy_testcase_to_jm:
docker cp ../version.txt ${IMG_NAME}:/usr/local/testing/${TESTCASE}
make exec_jm ARGS="touch ${TESTCASE}/__init__.py"

copy_framework_with_testcase_to_jm:
make copy_to_jm ARGS=data
make copy_to_jm ARGS=kpis
make copy_to_jm ARGS=forecast
docker cp ../testcase.py ${IMG_NAME}:/usr/local/testing
docker cp ../version.txt ${IMG_NAME}:/usr/local/testing
docker exec -it ${IMG_NAME} /bin/bash -c "mkdir /usr/local/testing/testcases && exit"
docker cp ../testcases/${TESTCASE} ${IMG_NAME}:/usr/local/testing/testcases/${TESTCASE}

copy_from_jm:
docker cp ${IMG_NAME}:/usr/local/testing/${ARGS} ../${ARGS}

Expand Down Expand Up @@ -221,6 +230,20 @@ test_kpis:
# Report test results
python report.py

test_testcase:
# Run jm docker container
make run_jm
# Copy the required files and folders for the test
make copy_framework_with_testcase_to_jm TESTCASE=bestest_air
# Run test_kpis.py
make exec_jm ARGS="python test_testcase.py"
docker cp ${IMG_NAME}:/usr/local/testing/references/testcase ./references
docker cp ${IMG_NAME}:/usr/local/testing/test_testcase.log ./test_testcase.log
# Stop jm docker container
make stop_jm
# Report test results
python report.py

test_readme_commands:
# Test readme commands work right after instantiation of test case container
cd .. && TESTCASE=testcase2 docker-compose up -d
Expand Down Expand Up @@ -263,6 +286,7 @@ test_all:
make test_data
make test_forecast
make test_kpis
make test_testcase
make test_readme_commands
make test_testcase1
make test_testcase2
Expand Down
6 changes: 6 additions & 0 deletions testing/references/testcase/check_input_for_zero.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
time,fcu_oveFan_u,fcu_reaPFan_y
0.0,0.0,0.0
30.0,0.5,21.3939783147
60.0,0.5,21.6302109413
90.0,0.0,6.50343645203e-05
120.0,0.0,4.24847777137e-11
31 changes: 31 additions & 0 deletions testing/test_bestest_air.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import unittest
import os
import utilities
import requests

class Run(unittest.TestCase, utilities.partialTestTimePeriod):
'''Tests the example test case.
Expand Down Expand Up @@ -43,6 +44,36 @@ def test_typical_cool_day(self):
def test_mix_day(self):
self.run_time_period('mix_day')

def test_scenario_flag(self):
'''Ensures the scenario flag is set properly.
Parameters
----------
None
Returns
-------
None
'''

length = 86400*14
# Get current step
step_current = requests.get('{0}/step'.format(self.url)).json()['payload']
# Initialize test case scenario
requests.put('{0}/scenario'.format(self.url), json={'time_period':'peak_heat_day'})
# Set simulation step
requests.put('{0}/step'.format(self.url), json={'step':length})
# Simulation Loop
requests.post('{0}/advance'.format(self.url))
# Try submit results to dashboard
status = requests.post("{0}/submit".format(self.url), json={"api_key": 'valid_key',
"unit_test":"True"}).json()['status']
# Check result
self.assertEqual(status,200)
# Return scenario and step to original
requests.put('{0}/step'.format(self.url), json={'step':step_current})

class API(unittest.TestCase, utilities.partialTestAPI):
'''Tests the api for testcase.
Expand Down
50 changes: 50 additions & 0 deletions testing/test_testcase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
"""
This module implements unit tests testcase.py.
"""

import os
import unittest
import pandas as pd
import testcase
import utilities

reference_result_directory = 'testcase'

class Advance(unittest.TestCase, utilities.partialChecks):
'''Unit tests for the testcase.TestCase.advance API.
'''

def test_check_input_for_zero(self):
'''Test that an overwrite value of 0 given in float is used.
'''

self.testcase.set_step(60)
# Advance first wih fan speed of 0.5, then with fan speed of 0.0.
u = {'fcu_oveFan_u': 0.5,
'fcu_oveFan_activate':1}
status, message, payload = self.testcase.advance(u)
u = {'fcu_oveFan_u': 0.0,
'fcu_oveFan_activate':1}
status, message, payload = self.testcase.advance(u)
# Get results
status, message, payload = self.testcase.get_results(['fcu_reaPFan_y', 'fcu_oveFan_u'],
0,
payload['time'])
# Test results
df = pd.DataFrame(payload).set_index('time')
ref_filepath = os.path.join(utilities.get_root_path(), 'testing', 'references', reference_result_directory, 'check_input_for_zero.csv')
self.compare_ref_timeseries_df(df, ref_filepath)

def setUp(self):
'''Set up for unit tests. Uses bestest_air.
'''

self.testcase = testcase.TestCase(fmupath='testcases/bestest_air/models/wrapped.fmu')

if __name__ == '__main__':
utilities.run_tests(os.path.basename(__file__))
2 changes: 1 addition & 1 deletion testing/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def compare_ref_timeseries_df(self, df, ref_filepath):
df : pandas DataFrame
Test dataframe with "time" as index.
ref_filepath : str
Reference file path relative to testing directory.
Reference file path.
Returns
-------
Expand Down

0 comments on commit 550e56e

Please sign in to comment.