Skip to content

Commit

Permalink
Update get_html_IO file for test case documentation to work with new …
Browse files Browse the repository at this point in the history
…APIs
  • Loading branch information
EttoreZ committed Nov 1, 2024
1 parent b648373 commit ef54ed0
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions data/get_html_IO.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
This script can be used to generate the html documentation code for I/O.
To run:
1. Build BOPTEST test case
2. Run BOPTEST test case on localhost:5000
3. Run this script
1. Build BOPTEST worker provision
2. Run BOPTEST worker provision
3. Run this script with test case as string input argument (i.e. "bestest_air")
Output:
"inputs_measurements_forecasts.html" html code documenting inputs, outputs and
Expand All @@ -15,10 +15,11 @@
# GENERAL PACKAGE IMPORT
# ----------------------
import requests
import sys
# ----------------------


def run():
def run(test_case_name):
'''Run the script.
Parameters
Expand All @@ -33,47 +34,64 @@ def run():

# SETUP TEST CASE
# ---------------
# Set URL for testcase
url = 'http://127.0.0.1:5000'
# Set URL for test case
url = 'http://127.0.0.1:80'
# Deploy worker container and obtain test case ID
testid = requests.post("{0}/testcases/{1}/select".format(url, test_case_name)).json()["testid"]
# ---------------

# GET TEST INFORMATION
# --------------------
# Create single I/O file
# Inputs available
inputs = requests.get('{0}/inputs'.format(url)).json()['payload']
print('\nGetting available inputs...')
inputs = requests.get('{0}/inputs/{1}'.format(url,testid)).json()['payload']
with open('inputs_measurements_forecasts.html', 'w') as f:
f.write('<h3>Model IO\'s</h3>\n')
f.write('<h4>Inputs</h4>\n')
f.write('The model inputs are:\n')
f.write('<ul>\n')
print('\nWriting inputs to inputs_measurements_forecasts.html...')
for i in sorted(inputs.keys()):
if 'activate' not in i:
f.write('<li>\n<code>{0}</code> [{1}] [min={2}, max={3}]: {4}\n</li>\n'.format(i,inputs[i]['Unit'],inputs[i]['Minimum'], inputs[i]['Maximum'], inputs[i]['Description']))
else:
f.write('<li>\n<code>{0}</code> [1] [min=0, max=1]: Activation signal to overwrite input {1} where 1 activates, 0 deactivates (default value)\n</li>\n'.format(i,i.replace('activate','')+'u'))
f.write('</ul>\n')
# Measurements available
measurements = requests.get('{0}/measurements'.format(url)).json()['payload']
print('\nGetting available measurements...')
measurements = requests.get('{0}/measurements/{1}'.format(url,testid)).json()['payload']
with open('inputs_measurements_forecasts.html', 'a') as f:
f.write('<h4>Outputs</h4>\n')
f.write('The model outputs are:\n')
f.write('<ul>\n')
print('\nWriting measurements to inputs_measurements_forecasts.html...')
for i in sorted(measurements.keys()):
if 'activate' not in i:
f.write('<li>\n<code>{0}</code> [{1}] [min={2}, max={3}]: {4}\n</li>\n'.format(i,measurements[i]['Unit'],measurements[i]['Minimum'], measurements[i]['Maximum'], measurements[i]['Description']))
f.write('</ul>\n')
# Forecasts available
forecast_points = requests.get('{0}/forecast_points'.format(url)).json()['payload']
print('\nGetting available forecasts...')
forecast_points = requests.get('{0}/forecast_points/{1}'.format(url,testid)).json()['payload']
with open('inputs_measurements_forecasts.html', 'a') as f:
f.write('<h4>Forecasts</h4>\n')
f.write('The model forecasts are:\n')
f.write('<ul>\n')
print('\nWriting forecasts to inputs_measurements_forecasts.html...')
for i in sorted(forecast_points.keys()):
if 'activate' not in i:
f.write('<li>\n<code>{0}</code> [{1}]: {2}\n</li>\n'.format(i,forecast_points[i]['Unit'],forecast_points[i]['Description']))
f.write('</ul>\n')
# --------------------

# SHUT DOWN TEST CASE
# -------------------------------------------------------------------------
print('\nShutting down test case...')
res = requests.put("{0}/stop/{1}".format(url,testid))
if res.status_code == 200:
print('Done shutting down test case.')
else:
print('Error shutting down test case.')

if __name__ == "__main__":
run()
test_case_name = sys.argv[1]
run(test_case_name)

0 comments on commit ef54ed0

Please sign in to comment.