This is the repository for the BuildingSync Validator web application.
pyenv install 3.6.5
pyenv virtualenv 3.6.5 bsync-validator-3.6.5
pyenv local bsync-validator-3.6.5
psql -c 'DROP DATABASE bsync_validator;'
psql -c 'CREATE DATABASE bsync_validator;'
psql -c "CREATE USER bsync_validator WITH ENCRYPTED PASSWORD 'bsync_validator';"
psql -c 'GRANT ALL PRIVILEGES ON DATABASE bsync_validator TO bsync_validator;'
psql -c 'ALTER USER bsync_validator CREATEDB;'
pip install -r requirements-test.txt
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver
When making changes to models, run the following command to make migrations:
python manage.py makemigrations
python manage.py migrate
To test schema import, you can run this command:
python manage.py reset_schema --schema_version=1.0.0
NOTE: You will need to be off the NREL VPN to import a schema, otherwise you'll get an error related to http://www.gbxml.org/schema}Area' as the gbXML schema cannot be imported when on the NREL VPN.
This project used pre-commit <https://pre-commit.com/>
_ to ensure code consistency. To enable pre-commit, run the following from the command line.
pip install pre-commit
pre-commit install
To run pre-commit against the files without calling git commit, then run the following. This is useful when cleaning up the repo before committing.
pre-commit run --all-files
To run test:
./manage.py test
To calculate coverage:
coverage run --source='.' manage.py test
coverage report
pre-commit run --all-files
The BuildingSync Schema Viewer can support multiple versions of the BuildingSync schema. Admin users can manage schemas from the Django Administration console. Click on the 'Admin' link in the top navigation bar to access the Django Administration pages.
To add a schema, specify the name, version, and schema file (XSD) to parse and save the record. The schema file will be parsed automatically. NOTE: You will need to be off the NREL VPN to import a schema, otherwise you'll get an error related to http://www.gbxml.org/schema}Area' as the gbXML schema cannot be imported when on the NREL VPN.
To modify an existing schema, click on the edit link. If changes are made to the uploaded XSD schema file and re-uploaded, ensure that the 'schema parsed' checkbox is unchecked before saving the record. This will trigger the automatic schema parsing.
Authenticated users can add private use cases to the BuildingSync Schema Viewer. Use cases are represented by a schematron file that defines a set of rules and patterns.
To add a use case, click on the 'Use Case' link in the top navigation bar, then click on the '+ New Use Case' button. Select a name and a BuildingSync schema version. Select your use case definitions schematron file and upload, then click 'Submit'.
Once ready, contact a BuildingSync admin to make the use case public. Public use cases will be available on the 'Validator' page to validate XML files submitted by users.
Admin users: Find the use case in the Django Administration console and click the edit button. Check the 'Make public' checkbox and save.
The validator page allows users to validate XMLs against the BuildingSync schema and its public use cases. It can be tried with selected example files, or custom XML files can be uploaded for validation.
There is also a validator endpoint to validate XML files against the BuildingSync schema and its public use cases.
Request: POST to https://buildingsync.net/api/validate
Use form-data to specify the following parameters for schema version and XML file: schema_version
and file
.
Example Response:
{
"schema_version": "1.0.0",
"validation_results": {
"schema": {
"valid": true,
"schema_version": "1.0.0"
},
"use_cases": {
"EXAMPLE USE CASE 1": {
"valid": false,
"errors": [
{
"path": "Audits.Audit.Sites.Site.Facilities.Facility.ConditionedFloorsAboveGrade",
"message": "Required element not found"
},
{
"path": "Audits.Audit.Sites.Site.Facilities.Facility.ConditionedFloorsBelowGrade",
"message": "Required element not found"
},
{
"path": "Audits.Audit.Sites.Site.Facilities.Facility.UnconditionedFloorsAboveGrade",
"message": "Required element not found"
}
]
},
"EXAMPLE USE CASE 2": {
"valid": true
}
}
},
"success": true
}
Request: POST to https://buildingsync.net/api/validate
Use form-data to specify the following parameters for schema version and XML file: schema_version
and file
.
Example Response:
{
"schema_version": "2.0.0",
"all_files_valid": true,
"validation_results": [
{
"file": "Example – A Valid Schema.xml",
"results": {
"schema": {
"valid": true,
"schema_version": "2.0.0"
},
"use_cases": {
"LL87": {
"valid": false,
"errors": [
"Usage: stron [schematron] [instance doc]",
"undefined local variable or method `type' for main:Object"
],
"infos": [],
"warnings": []
},
"L000 OpenStudio Simulation": {
"valid": false,
"errors": [
"Usage: stron [schematron] [instance doc]",
"undefined local variable or method `type' for main:Object"
],
"infos": [],
"warnings": []
}
}
}
},
{
"file": "Example – Valid Schema Invalid UseCase.xml",
"results": {
"schema": {
"valid": true,
"schema_version": "2.0.0"
},
"use_cases": {
"LL87": {
"valid": false,
"errors": [
"Usage: stron [schematron] [instance doc]",
"undefined local variable or method `type' for main:Object"
],
"infos": [],
"warnings": []
},
"L000 OpenStudio Simulation": {
"valid": false,
"errors": [
"Usage: stron [schematron] [instance doc]",
"undefined local variable or method `type' for main:Object"
],
"infos": [],
"warnings": []
}
}
}
}
],
"success": true
}
BEDES parsing and mapping to the BuildingSync schema is not an automated process, due to the manual inspections/corrections required.
To parse and map a new BEDES version:
Download the bedes_online_dictionary_uuid-lo.xml
and the bedes_online_dictionary_uuid-terms.xml
files from the BEDES website.
Place these new BEDES XMLs in the lib/bedes/vX.X directory. vX.X refers to the BEDES version here.
Parse the BEDES XMLs into a JSON file and map the BEDES terms to the BuildingSync attributes:
docker exec -it buildingsync-website-web-1 bash
python manage.py bedes --schema_version=X.X.X --bedes_version=X.X
Note that the bedes_version contains a v, ex: v2.2.
This will create a bedes_vX.X.jsonfile in the lib/bedes/vX.X directory. It will also create 2 CSV files:
bedes-mappings-enumerations.csvand
bedes-mappings-terms.csv` in the lib/bedes/vX.X/schemaX.X directory.
Note — The BEDES terms must be mapped for each version of the BuildingSync schema by calling the python manage.py bedes` command above.
Copy the generated bedes files to the git repo on the production server. The command will be something like:
docker cp buildingsync-website-web-1:/srv/buildingsync-website/bsyncviewer/lib/bedes/v2.5/schema2.5.0 .
Review these mapping files and make changes as needed. Commit and push the files to the BuildingSync-website repository (ideally a branch).
Once satisfied with the mappings, run the same command with the --save_to_db flag:
python manage.py bedes --schema_version=X.X.X --bedes_version=X.X --save_to_db
Note that you must run this command without the --save_to_db flag first, in order to create the CSV files.
Login to the admin interface at /user/login
Admin interface is available at /admin
Follow these steps to add a new schema version to the selection tool:
bsyncviewer/lib/validator/examples/schema<VERSION>
directory. Make sure that the example_files.zip file is updated if any of the example files have changed (This is likely since the new example files will be pointing to the new schema).Follow these steps to add new example tables from the TestSuite repo
pandoc README.md -s -o README.html
bsyncviewer/templates/examples.html
.develop
branch of the TestSuite repo. Clone the repo locally.bsyncviewer/testsuitelib
. <include href="https://github.com/BuildingSync/BuildingSync-website/blob/develop/./../testsuitelib/rootElements.sch#root.oneOfEachUntilBuilding"/>
<include href="https://github.com/BuildingSync/BuildingSync-website/blob/develop/./../testsuitelib/rootElements.sch#root.oneOfEachFacilityUntilScenario"/>
<include href="https://github.com/BuildingSync/BuildingSync-website/blob/develop/./../testsuitelib/siteBuildingElements.sch#sbe.cityStateOrClimateZone"/>
<include href="https://github.com/BuildingSync/BuildingSync-website/blob/develop/./../testsuitelib/scenarioElements.sch#sc.baseline.ID"/>
<include href="https://github.com/BuildingSync/BuildingSync-website/blob/develop/./../testsuitelib/scenarioElements.sch#sc.baseline.asPackageOfMeasures"/>
<include href="https://github.com/BuildingSync/BuildingSync-website/blob/develop/./../testsuitelib/buildingElements.sch#be.L000BuildingInfo"/>
<include href="https://github.com/BuildingSync/BuildingSync-website/blob/develop/./../testsuitelib/floorElements.sch#fa.oneOfType"/>
<include href="https://github.com/BuildingSync/BuildingSync-website/blob/develop/./../testsuitelib/floorElements.sch#fa.haveTypeAndValue"/>
/use_cases
URL and clicking the New Use Case button.
bsyncviewer/lib/validator/examples
. Regenerate the example_files.zip
archive. This will make the files available as examples at the /validator
URL.