-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into buildstock
- Loading branch information
Showing
16 changed files
with
18,451 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""This module includes tests for the mechanical aspects of the api, but not necessarily all of the functionality.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import os | ||
from pathlib import Path | ||
|
||
import pytest | ||
from alfalfa_client import AlfalfaClient | ||
from requests import HTTPError | ||
|
||
|
||
@pytest.fixture | ||
def base_url(): | ||
return 'http://localhost/api/v2' | ||
|
||
|
||
@pytest.fixture | ||
def alfalfa_client(): | ||
return AlfalfaClient() | ||
|
||
|
||
@pytest.fixture | ||
def model_path(): | ||
return Path(os.path.dirname(__file__)) / "models" / "small_office" | ||
|
||
|
||
@pytest.fixture | ||
def model_id(alfalfa_client: AlfalfaClient, model_path): | ||
return alfalfa_client.upload_model(model_path) | ||
|
||
|
||
@pytest.fixture | ||
def run_id(alfalfa_client: AlfalfaClient, model_path): | ||
run_id = alfalfa_client.submit(model_path) | ||
yield run_id | ||
try: | ||
if alfalfa_client.status(run_id) not in ["COMPLETE", "ERROR", "STOPPING", "READY"]: | ||
alfalfa_client.stop(run_id) | ||
except HTTPError: | ||
pass |
92 changes: 92 additions & 0 deletions
92
tests/api/models/small_office/measures/alfalfa_vars/measure.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# insert your copyright here | ||
|
||
# see the URL below for information on how to write OpenStudio measures | ||
# http://nrel.github.io/OpenStudio-user-documentation/reference/measure_writing_guide/ | ||
|
||
# start the measure | ||
class AlfalfaVariables < OpenStudio::Measure::ModelMeasure | ||
# human readable name | ||
def name | ||
return 'AlfalfaVariables' | ||
end | ||
|
||
# human readable description | ||
def description | ||
return 'Add custom variables for Alfalfa' | ||
end | ||
|
||
# human readable description of modeling approach | ||
def modeler_description | ||
return 'Add EMS global variables required by Alfalfa' | ||
end | ||
|
||
# define the arguments that the user will input | ||
def arguments(model) | ||
args = OpenStudio::Measure::OSArgumentVector.new | ||
return args | ||
end | ||
|
||
def create_input(model, name, freq) | ||
# The purpose of this function is to create an Alfalfa input that is accessible via python plugins | ||
|
||
global = OpenStudio::Model::EnergyManagementSystemGlobalVariable.new(model, name) | ||
global.setExportToBCVTB(true) | ||
|
||
# The global variable's value must be sent to output an variable so that python programs can read it | ||
# don't be mistaken, An OuputVariable object is created, but this is "input" to the simulation, from Alfalfa clients | ||
global_ems_output = OpenStudio::Model::EnergyManagementSystemOutputVariable.new(model, global) | ||
global_ems_output.setName(name + "_EMS_Value") | ||
global_ems_output.setUpdateFrequency("SystemTimestep") | ||
|
||
# Request the custom ems output var creaed in the previous step | ||
global_output = OpenStudio::Model::OutputVariable.new(global_ems_output.nameString(), model) | ||
global_output.setName(name + "_Value") | ||
global_output.setReportingFrequency(freq) | ||
global_output.setKeyValue("EMS") | ||
# Setting exportToBCVTB to true is optional, and will result in the output variable showing up in the Alfalfa api, | ||
# this might be useful for confirmation of the input | ||
global_output.setExportToBCVTB(true) | ||
|
||
# repeat the previous steps for an "Enable" input | ||
# This value will be 1 (instead of 0) anytime a client writes to the input via the Alfalfa api | ||
global_enable = OpenStudio::Model::EnergyManagementSystemGlobalVariable.new(model, name + "_Enable") | ||
global_enable.setExportToBCVTB(true) | ||
|
||
global_enable_ems_output = OpenStudio::Model::EnergyManagementSystemOutputVariable.new(model, global_enable) | ||
global_enable_ems_output.setName(name + "_Enable_EMS_Value") | ||
global_enable_ems_output.setUpdateFrequency("SystemTimestep") | ||
|
||
global_enable_output = OpenStudio::Model::OutputVariable.new(global_enable_ems_output.nameString(), model) | ||
global_enable_output.setName(name + "_Enable_Value") | ||
global_enable_output.setReportingFrequency(freq) | ||
global_enable_output.setKeyValue("EMS") | ||
global_enable_output.setExportToBCVTB(true) | ||
end | ||
|
||
def create_output(model, var, key, name, freq) | ||
new_var = OpenStudio::Model::OutputVariable.new(var, model) | ||
new_var.setName(name) | ||
new_var.setReportingFrequency(freq) | ||
new_var.setKeyValue(key) | ||
new_var.setExportToBCVTB(true) | ||
end | ||
|
||
# define what happens when the measure is run | ||
def run(model, runner, user_arguments) | ||
super(model, runner, user_arguments) | ||
|
||
# Alfalfa inputs | ||
# These can be set through the Alfalfa API, they will be available as OutputVariables | ||
# in the simulation. Use them as you will | ||
# Also see comments on the create_input method | ||
create_input(model, "Test_Point_1", "Timestep") | ||
|
||
# other OutputVariables might be custom python defined output variables, | ||
# you should still be able to request them here, and as long as exportToBCVTB is true they will be available via Alfalfa | ||
|
||
return true | ||
end | ||
end | ||
|
||
# register the measure to be used by the application | ||
AlfalfaVariables.new.registerWithApplication |
54 changes: 54 additions & 0 deletions
54
tests/api/models/small_office/measures/alfalfa_vars/measure.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?xml version="1.0"?> | ||
<measure> | ||
<schema_version>3.0</schema_version> | ||
<name>alfalfa_variables</name> | ||
<uid>86d51823-68a5-478a-b60b-60891c3c9b5f</uid> | ||
<version_id>5c94ef46-d8e9-4ae9-864e-d884aba51509</version_id> | ||
<version_modified>20201216T214230Z</version_modified> | ||
<xml_checksum>356BE47F</xml_checksum> | ||
<class_name>AlfalfaVariables</class_name> | ||
<display_name>AlfalfaVariables</display_name> | ||
<description>Add custom variables for Alfalfa</description> | ||
<modeler_description>Add EMS global variables required by Alfalfa</modeler_description> | ||
<arguments /> | ||
<outputs /> | ||
<provenances /> | ||
<tags> | ||
<tag>HVAC.HVAC Controls</tag> | ||
</tags> | ||
<attributes> | ||
<attribute> | ||
<name>Measure Type</name> | ||
<value>ModelMeasure</value> | ||
<datatype>string</datatype> | ||
</attribute> | ||
<attribute> | ||
<name>Intended Software Tool</name> | ||
<value>Apply Measure Now</value> | ||
<datatype>string</datatype> | ||
</attribute> | ||
<attribute> | ||
<name>Intended Software Tool</name> | ||
<value>OpenStudio Application</value> | ||
<datatype>string</datatype> | ||
</attribute> | ||
<attribute> | ||
<name>Intended Software Tool</name> | ||
<value>Parametric Analysis Tool</value> | ||
<datatype>string</datatype> | ||
</attribute> | ||
</attributes> | ||
<files> | ||
<file> | ||
<version> | ||
<software_program>OpenStudio</software_program> | ||
<identifier>3.1.0</identifier> | ||
<min_compatible>3.1.0</min_compatible> | ||
</version> | ||
<filename>measure.rb</filename> | ||
<filetype>rb</filetype> | ||
<usage_type>script</usage_type> | ||
<checksum>A9E1EEF2</checksum> | ||
</file> | ||
</files> | ||
</measure> |
Oops, something went wrong.