Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Epjson support #4199

Merged
merged 36 commits into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
feb73d1
Initial take at EPJSON output inside of test code
lefticus Dec 6, 2020
1b72fab
Working towards EPJSON prototype
lefticus Dec 7, 2020
8004427
Closer to EPJSON prototype
lefticus Dec 8, 2020
b0d1e24
Chicago mostly working
lefticus Dec 8, 2020
09fa635
Initial tests in place for EPJSON translation
lefticus Jan 8, 2021
88bf5c7
Simplify test framework for EPJSON Translation
lefticus Jan 8, 2021
f5f507c
Merge branch 'develop' of github.com:NREL/OpenStudio into epjson_support
lefticus Jan 9, 2021
cd7c633
Begin using epJSON schema for epJSON translation from IDF
lefticus Jan 9, 2021
63c1a22
5 working EPJSON conversion tests
lefticus Jan 10, 2021
88dd1b3
Merge branch 'develop' of github.com:NREL/OpenStudio into epjson_support
lefticus Jan 26, 2021
0beca85
Add more tests, and get more passing for epJSON support
lefticus Jan 26, 2021
6f96682
Use epJSON schema to drive type of data inserted into JSON file
lefticus Jan 27, 2021
6789a73
Rename EPJSON to epJSON for consistency
lefticus Jan 27, 2021
959d072
Cache JSON lookups during translation for performance
lefticus Jan 27, 2021
979665c
Ruby tests for epJSON added
lefticus Jan 28, 2021
23b801c
Add epJSON ruby test
lefticus Jan 28, 2021
a2b5c8b
Fix windows build for epJSON support
lefticus Jan 28, 2021
c2643c0
Enhance error handling for epJSONTranslator
lefticus Jan 31, 2021
ddca17d
Merge branch 'epjson_support' of github.com:NREL/OpenStudio into epjs…
lefticus Jan 31, 2021
16b9fb9
Merge branch 'develop' of github.com:NREL/OpenStudio into epjson_support
lefticus Jan 31, 2021
0e3f012
Rely more on epJSON schema and remove special cased code
lefticus Feb 2, 2021
bdb64af
Apply clang-format to epJSON
lefticus Feb 3, 2021
ea2d3d0
Remove unused variables found with apple clang
lefticus Feb 5, 2021
3544f69
Merge remote-tracking branch 'origin/develop' into epjson_support
jmarrec Mar 3, 2021
2c5e40f
Redefine toJSON -> return HASH in ruby
jmarrec Mar 3, 2021
71f7455
Delay NumberOrString log message at calling point to be more informative
jmarrec Mar 3, 2021
a1f821d
clang format
jmarrec Mar 3, 2021
a96a83c
Add epjson to python __init__.py / openstudio.py
jmarrec Mar 3, 2021
362813b
Add a toJSON -> dict python convenience function
jmarrec Mar 3, 2021
4063f50
Fix C# improperly swigged Model type: depending on ModelCore is enoug…
jmarrec Mar 3, 2021
f28e51f
Use Workspace instead of model, and currently only allow IddFileType:…
jmarrec Mar 3, 2021
c630048
take schemaPath as a path, defaults to empty. Call `defaultSchemaPath…
jmarrec Mar 3, 2021
dbf9f96
Allow optionally passing schemaPath in ruby toJSON as well
jmarrec Mar 3, 2021
278d776
clang format and cppcheck
jmarrec Mar 3, 2021
03001c1
Fix (real) problems in OpenStudio.idd identified during the export of…
jmarrec Mar 3, 2021
145268e
Fix forward declaration of IddFileType
jmarrec Mar 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,7 @@ set(project_directories
utilities
model
energyplus
epjson
radiance
gbxml
airflow
Expand Down
1 change: 1 addition & 0 deletions ruby/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ else()
openstudio_airflow
openstudio_model
openstudio_energyplus
openstudio_epjson
openstudio_measure
openstudio_osversion
openstudio_sdd
Expand Down
4 changes: 4 additions & 0 deletions ruby/init_openstudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ extern "C" {
void Init_openstudioutilitiescore(void);
void Init_openstudioutilitiesplot(void);
void Init_openstudioenergyplus(void);
void Init_openstudioepjson(void);
void Init_openstudioosversion(void);
void Init_openstudioutilitiesdata(void);
void Init_openstudioutilitiessql(void);
Expand Down Expand Up @@ -159,6 +160,9 @@ void init_openstudio_internal_extended()
Init_openstudioenergyplus();
rb_provide("openstudioenergyplus");
rb_provide("openstudioenergyplus.so");
Init_openstudioepjson();
rb_provide("openstudioepjson");
rb_provide("openstudioepjson.so");
Init_openstudioradiance();
rb_provide("openstudioradiance");
rb_provide("openstudioradiance.so");
Expand Down
62 changes: 62 additions & 0 deletions ruby/test/epJSON_Test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
########################################################################################################################
# OpenStudio(R), Copyright (c) 2008-2020, Alliance for Sustainable Energy, LLC, and other contributors. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
# following conditions are met:
#
# (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following
# disclaimer.
#
# (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided with the distribution.
#
# (3) Neither the name of the copyright holder nor the names of any contributors may be used to endorse or promote products
# derived from this software without specific prior written permission from the respective party.
#
# (4) Other than as required in clauses (1) and (2), distributions in any form of modifications or other derivative works
# may not use the "OpenStudio" trademark, "OS", "os", or any other confusingly similar designation without specific prior
# written permission from Alliance for Sustainable Energy, LLC.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE UNITED STATES GOVERNMENT, OR THE UNITED
# STATES DEPARTMENT OF ENERGY, NOR ANY OF THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
########################################################################################################################

require 'openstudio'
require 'json'
require 'minitest/autorun'

class EpJSON_Test < MiniTest::Unit::TestCase

# def setup
# end

# def teardown
# end

def test_epJSON

# load IdfFile
idfPath = OpenStudio::Path.new(File.join(File.dirname(__FILE__), "../../resources/energyplus/5ZoneAirCooled/in.idf"))
puts idfPath
assert(OpenStudio::exists(idfPath))

oIdfFile = OpenStudio::IdfFile.load(idfPath,"EnergyPlus".to_IddFileType)
assert(oIdfFile.empty? == false)
idfFile = oIdfFile.get
assert(idfFile.objects().size() > 0)

json = OpenStudio::EPJSON::toJSONString(idfFile);
obj = JSON.parse(json)
#puts(json)
assert(obj["Version"]["Version 1"]["version_identifier"] == "9.4")
end

end


1 change: 1 addition & 0 deletions src/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ target_link_libraries(openstudio
openstudio_airflow
openstudio_model
openstudio_energyplus
openstudio_epjson
openstudio_measure
openstudio_osversion
openstudio_sdd
Expand Down
1 change: 1 addition & 0 deletions src/cli/openstudio_cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@

OpenStudio.autoload(:Airflow, ":/openstudio_init_extended.rb")
OpenStudio.autoload(:EnergyPlus, ":/openstudio_init_extended.rb")
OpenStudio.autoload(:EPJSON, ":/openstudio_init_extended.rb")
OpenStudio.autoload(:GbXML, ":/openstudio_init_extended.rb")
OpenStudio.autoload(:ISOModel, ":/openstudio_init_extended.rb")
OpenStudio.autoload(:Measure, ":/openstudio_init_extended.rb")
Expand Down
1 change: 1 addition & 0 deletions src/cli/openstudio_init_extended.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

::OpenStudio.module_eval { remove_const(:Airflow) }
::OpenStudio.module_eval { remove_const(:EnergyPlus) }
::OpenStudio.module_eval { remove_const(:EPJSON) }
::OpenStudio.module_eval { remove_const(:GbXML) }
::OpenStudio.module_eval { remove_const(:ISOModel) }
::OpenStudio.module_eval { remove_const(:Measure) }
Expand Down
77 changes: 77 additions & 0 deletions src/epjson/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
set(target_name openstudio_epjson)

set(${target_name}_src
mainpage.hpp
epJSONAPI.hpp
epJSONTranslator.hpp
epJSONTranslator.cpp
${CMAKE_CURRENT_BINARY_DIR}/../OpenStudio.hxx
)

set(${target_name}_test_src
test/epJSONFixture.hpp
test/epJSONFixture.cpp
test/epJSONTranslator_GTest.cpp
)

set(${target_name}_swig_src
epJSON.i
)

add_library(${target_name}
OBJECT
${${target_name}_src}
)

set(${target_name}_depends
${openstudio_utilities_depends}
)
set(${target_name}_depends ${${target_name}_depends} PARENT_SCOPE)

target_compile_definitions(${target_name} PRIVATE openstudio_epjson_EXPORTS SHARED_OS_LIBS)
target_link_libraries(${target_name} PUBLIC ${${target_name}_depends})

add_dependencies(${target_name} GenerateIddFactoryRun)

set(${target_name}_test_depends
openstudiolib
)

CREATE_SRC_GROUPS("${${target_name}_src}")
CREATE_SRC_GROUPS("${${target_name}_test_src}")
CREATE_SRC_GROUPS("${${target_name}_swig_src}")

if (BUILD_TESTING)

CREATE_TEST_TARGETS(${target_name} "${${target_name}_test_src}" "${${target_name}_test_depends}")
target_link_libraries(${target_name}_tests CONAN_PKG::fmt)

# Glob all OSM files in test/ folder
# file(GLOB_RECURSE epjson_source_models "${CMAKE_CURRENT_SOURCE_DIR}/test/**/*.osm")

# Copy them to <build_dir>resources/epjson/
# foreach (_FILE ${epjson_source_models})
# file(RELATIVE_PATH REL_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/test/" ${_FILE})
# set(TARGET_PATH "${PROJECT_BINARY_DIR}/resources/epjson/${REL_LOCATION}")
# add_custom_command(
# OUTPUT "${TARGET_PATH}"
# COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_FILE}" "${TARGET_PATH}"
# DEPENDS "${_FILE}"
# )
# list(APPEND epjson_test_models ${TARGET_PATH})
# endforeach ()

# add target
# add_custom_target(openstudio_epjson_test_resources
# DEPENDS ${epjson_test_models}
# SOURCES ${epjson_test_models}
# )

# add_dependencies(${target_name}_tests
# openstudio_epjson_test_resources
# # openstudio_epjson_resources
# )

endif ()

MAKE_SWIG_TARGET(OpenStudioEPJSON EPJSON "${CMAKE_CURRENT_SOURCE_DIR}/epJSON.i" "${${target_name}_swig_src}" ${target_name} OpenStudioModel)
37 changes: 37 additions & 0 deletions src/epjson/epJSON.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef EPJSON_I
#define EPJSON_I

#ifdef SWIGPYTHON
%module openstudioepjson
#endif


#define UTILITIES_API
#define EPJSON_API

// Ignore stuff that takes/returns Json::Value
%ignore openstudio::epJSON::toJSON;
%ignore openstudio::epJSON::loadJSON;
jmarrec marked this conversation as resolved.
Show resolved Hide resolved

%include <utilities/core/CommonInclude.i>
%import <utilities/core/CommonImport.i>
%import <utilities/Utilities.i>


%{
#include <utilities/core/Path.hpp>
#include <epjson/epJSONTranslator.hpp>
%}

%include <epjson/epJSONTranslator.hpp>

#if defined SWIGRUBY
// This isn't super clean and there might be a better way with typemaps in SWIG rather than using a String in between,
// but still helpful I think: we redefine toJSON that will return a native ruby hash. 'json' is part of ruby stdlib since at least ruby 2.5.5
%init %{
rb_eval_string("OpenStudio::EPJSON.module_eval { define_method(:toJSON) { |arg| json_str = self.toJSONString(arg); require 'json'; JSON.load(json_str); }; module_function(:toJSON) }");
%}
#endif

#endif // EPJSON_I

43 changes: 43 additions & 0 deletions src/epjson/epJSONAPI.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/***********************************************************************************************************************
* OpenStudio(R, Copyright (c) 2008-2020, Alliance for Sustainable Energy, LLC, and other contributors. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following
* disclaimer.
*
* (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided with the distribution.
*
* (3) Neither the name of the copyright holder nor the names of any contributors may be used to endorse or promote products
* derived from this software without specific prior written permission from the respective party.
*
* (4) Other than as required in clauses (1) and (2), distributions in any form of modifications or other derivative works
* may not use the "OpenStudio" trademark, "OS", "os", or any other confusingly similar designation without specific prior
* written permission from Alliance for Sustainable Energy, LLC.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE UNITED STATES GOVERNMENT, OR THE UNITED
* STATES DEPARTMENT OF ENERGY, NOR ANY OF THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***********************************************************************************************************************/

#ifndef EPJSON_EPJSONAPI_HPP
#define EPJSON_EPJSONAPI_HPP

#if (_WIN32 || _MSC_VER) && SHARED_OS_LIBS
# if defined(openstudio_epjson_EXPORTS) || defined(openstudio_EXPORTS)
# define EPJSON_API __declspec(dllexport)
# else
# define EPJSON_API __declspec(dllimport)
# endif
#else
# define EPJSON_API
#endif

#endif
Loading