Skip to content

Commit

Permalink
Merge pull request #745 from BIM2SIM/development
Browse files Browse the repository at this point in the history
update main
  • Loading branch information
DaJansenGit authored Nov 7, 2024
2 parents 20ff0eb + 679db76 commit 5a2e25f
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 198 deletions.
10 changes: 8 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -672,8 +672,14 @@ build:main-energyplus:py3.11:
- |
plugin_test_dir=~/bim2sim-coding/bim2sim/plugins/${plugin}/test
if [ -d "${plugin_test_dir}/unit" ] || [ -d "${plugin_test_dir}/integration" ]; then
test_dirs=$(find ${plugin_test_dir} -maxdepth 1 -type d \( -name "unit" -o -name "integration" \) | tr '\n' ' ')
coverage run --source=~/bim2sim-coding/bim2sim/plugins/${plugin} -m unittest discover -v ${test_dirs}
if [ -d "${plugin_test_dir}/unit" ]; then
echo "Running unit tests..."
coverage run --source=~/bim2sim-coding/bim2sim/plugins/${plugin} -m unittest discover -v ${plugin_test_dir}/unit
fi
if [ -d "${plugin_test_dir}/integration" ]; then
echo "Running integration tests..."
coverage run --append --source=~/bim2sim-coding/bim2sim/plugins/${plugin} -m unittest discover -v ${plugin_test_dir}/integration
fi
else
echo "No unit or integration test directories found."
exit 1
Expand Down
3 changes: 2 additions & 1 deletion EnergyPlus.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ USER root
RUN apt-get update && apt-get install -y ca-certificates curl libx11-6 libexpat1 \
&& rm -rf /var/lib/apt/lists/*

RUN curl -SLO $ENERGYPLUS_DOWNLOAD_URL
RUN curl -SLO --retry 5 --retry-delay 15 --retry-max-time 900 --connect-timeout 60 --max-time 3600 $ENERGYPLUS_DOWNLOAD_URL || \
(sleep 30 && curl -SLO --retry 5 --retry-delay 15 --retry-max-time 900 --connect-timeout 60 --max-time 3600 $ENERGYPLUS_DOWNLOAD_URL)

RUN chmod +x $ENERGYPLUS_DOWNLOAD_FILENAME

Expand Down
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@ The focus of the currently released tool is on BPS and HVAC but we already provi

## Installation and Usage
You can find detailed documentation and description how to install and to use in our [documentation](https://bim2sim.github.io/bim2sim//development/docs/overview.html). We recommend reading at least:
* [Big Picture](https://bim2sim.github.io/bim2sim//development/docs/overview.html)
* [Installation](https://bim2sim.github.io/bim2sim//development/docs/installation.html)
* [First Steps](https://bim2sim.github.io/bim2sim//development/docs/first-steps.html)

For questions like why we don't use pip and if we support docker we refer to the linked documentation.

* [Big Picture](https://bim2sim.github.io/bim2sim//development/docs/big-picture.html) to understand the concepts of bim2sim
* [PluginTemplate - How to install?](https://bim2sim.github.io/bim2sim//development/docs/user-guide/PluginTemplate.html#how-to-install) to understand how to install the Base of the framework.

## Related Publications
* [Final Report of BIM2SIM project](https://www.tib.eu/en/search/id/TIBKAT:1819319997)
Expand Down
151 changes: 6 additions & 145 deletions bim2sim/__init__.py
Original file line number Diff line number Diff line change
@@ -1,156 +1,17 @@
"""bim2sim library"""

import os
import re
import sys

import tempfile
from os.path import expanduser
from importlib.metadata import version

from bim2sim.kernel.decision.console import ConsoleDecisionHandler
from bim2sim.kernel.decision.decisionhandler import DecisionHandler
from bim2sim.project import Project

VERSION = '0.1-dev'

try:
__version__ = version("bim2sim")
except Exception:
__version__ = "unknown"


def run_project(project: Project, handler: DecisionHandler):
"""Run project using decision handler."""
return handler.handle(project.run(), project.loaded_decisions)


def _debug_run_hvac():
"""Create example project and copy ifc if necessary"""
path_base = os.path.abspath(os.path.join(os.path.dirname(__file__), "..\\.."))
rel_example = 'ExampleFiles/KM_DPM_Vereinshaus_Gruppe62_Heizung_with_pumps.ifc'
path_ifc = os.path.normpath(os.path.join(path_base, rel_example))
path_example = _get_debug_project_path('hvac')

if Project.is_project_folder(path_example):
project = Project(path_example)
else:
project = Project.create(path_example, path_ifc, 'hkesim', )

# setup_defualt(project.config['Frontend']['use'])
run_project(project, ConsoleDecisionHandler())


def _get_debug_project_path(aux):
path_file = "debug_dir.user"
try:
f = open(path_file)
path_example = f.read()
f.close()
except IOError:
path_example = str(input("Specify debug root path (Leave blank for '" + expanduser('~')
+ "'). This value will be remembered in '" + path_file + "': "))
if len(path_example) == 0:
path_example = expanduser('~')
f = open(path_file, 'a')
f.write(path_example)
f.close()

if not path_example.endswith("/"):
path_example += "/"

max_number = 0
for item in os.listdir(path_example):
m = re.search('testproject_%s([0-9]+)' % aux, item)
if m:
max_number = max(int(m.group(1)), max_number)

return path_example + "testproject_%s" % aux + str(max_number + 1)


def _debug_run_bps():
"""Create example project and copy ifc if necessary"""
path_base = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))

# rel_example = 'ExampleFiles/AC20-FZK-Haus.ifc'
# rel_example = 'ExampleFiles/KM_DPM_Vereinshaus_Gruppe62_Architektur_spaces.ifc'
rel_example = 'ExampleFiles/AC20-Institute-Var-2.ifc'
path_ifc = os.path.normpath(os.path.join(path_base, rel_example))
path_example = _get_debug_project_path('bps')

if Project.is_project_folder(path_example):
project = Project(path_example)
else:
project = Project.create(path_example, path_ifc, 'teaser', )

run_project(project, ConsoleDecisionHandler())


def _debug_run_bps_ep():
"""Create example project and copy ifc if necessary"""
path_base = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))

rel_example = 'ExampleFiles/AC20-FZK-Haus.ifc'
# rel_example = 'ResultFiles/AC20-FZK-Haus_with_SB44.ifc' # aktuell
# rel_example = 'ResultFiles/Proposal_1_Storey_SpaceBoundaries_with_SB.ifc'
# rel_example = 'ResultFiles/2020-10-15-KHH-Test_with_SB.ifc'
# rel_example = 'ExampleFiles/AC20-Institute-Var-2.ifc'
# rel_example = 'ExampleFiles/DigitalHub_Architektur2_2020_Achse_tragend_V2.ifc' # ok
rel_example = 'ResultFiles/FM_ARC_DigitalHub_with_SB89.ifc'
# ok
# rel_example = 'ExampleFiles/AC-20-Smiley-West-10-Bldg.ifc'
path_ifc = os.path.normpath(os.path.join(path_base, rel_example))

path_example = _get_debug_project_path('bps_ep')

if Project.is_project_folder(path_example):
project = Project(path_example)
else:
project = Project.create(path_example, path_ifc, 'energyplus', )

run_project(project, ConsoleDecisionHandler())


def _test_run_bps_ep(rel_path, temp_project=False):
"""Create example project and copy ifc if necessary. Added for EnergyPlus integration tests"""
path_base = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))

path_ifc = os.path.normpath(os.path.join(path_base, rel_path))

if not temp_project:
path_example = _get_debug_project_path('bps_ep')
else:
path_example = tempfile.mkdtemp()

old_stderr = sys.stderr
working_dir = os.getcwd()
success = False
if Project.is_project_folder(path_example):
project = Project(path_example)
else:
project = Project.create(path_example, path_ifc, 'energyplus', )

try:
print("Project directory: " + path_example)
os.chdir(path_example)
if Project.is_project_folder(path_example):
project = Project(path_example)
else:
project = Project.create(path_example, path_ifc, 'energyplus', )

#HACK: We have to remember stderr because eppy resets it currently.
success = run_project(project, ConsoleDecisionHandler())
finally:
os.chdir(working_dir)
sys.stderr = old_stderr
return success


def _debug_run_hvac_aixlib():
"""Create example project and copy ifc if necessary"""
path_base = os.path.abspath(os.path.join(os.path.dirname(__file__), "..\\.."))
rel_example = 'ExampleFiles/KM_DPM_Vereinshaus_Gruppe62_Heizung_with_pumps.ifc'
path_ifc = os.path.normpath(os.path.join(path_base, rel_example))
path_example = _get_debug_project_path('aix')

if Project.is_project_folder(path_example):
project = Project(path_example)
else:
project = Project.create(path_example, path_ifc, 'aixlib', )

project.run()

39 changes: 11 additions & 28 deletions bim2sim/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,27 @@
-i <source> --ifc <source> Path to ifc file
-o --open Open config file
"""

import os
import sys
from importlib.metadata import version

import docopt

from bim2sim import VERSION, run_project
from bim2sim import run_project
from bim2sim.project import Project, FolderStructure
from bim2sim.kernel.decision.console import ConsoleDecisionHandler


def get_version():
"""Get package version"""
try:
return version("bim2sim")
except Exception:
return "unknown"


def commandline_interface():
"""user interface"""

args = docopt.docopt(__doc__, version=VERSION)
args = docopt.docopt(__doc__, version=get_version())

# arguments
project = args.get('project')
Expand All @@ -58,27 +64,4 @@ def commandline_interface():
exit()


def debug_params():
"""Set debug console arguments"""

print("No parameters passed. Using debug parameters.")
path_base = os.path.abspath(os.path.join(os.path.dirname(__file__), "..\\.."))
rel_example = 'ExampleFiles/KM_DPM_Vereinshaus_Gruppe62_Heizung_with_pumps.ifc'
path_ifc = os.path.normcase(os.path.join(path_base, rel_example))

#sys.argv.append('project')
#sys.argv.append('create')
#sys.argv.append(r'C:\temp\bim2sim\testproject')
#sys.argv.extend(['-s', 'hkesim', '-i', path_ifc, '-o'])

sys.argv.append('project')
sys.argv.append('load')
sys.argv.append(r'C:\temp\bim2sim\testproject')

print("Debug parameters:\n%s"%("\n".join(sys.argv[1:])))


if len(sys.argv) <= 1:
debug_params()

commandline_interface()
14 changes: 7 additions & 7 deletions bim2sim/kernel/decision/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- functions save() and load() to save to file system
"""

from importlib.metadata import version
import enum
import hashlib
import json
Expand All @@ -17,8 +18,6 @@
import pint

from bim2sim.elements.mapping.units import ureg
# todo remove version? what is this used for?
__VERSION__ = '0.1'
logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -542,7 +541,7 @@ def save(bunch: DecisionBunch, path):

decisions = bunch.to_serializable()
data = {
'version': __VERSION__,
'version': version("bim2sim"),
'checksum_ifc': None,
'decisions': decisions,
}
Expand All @@ -561,11 +560,12 @@ def load(path) -> Dict[str, Any]:
logger.info(f"Unable to load decisions. "
f"No Existing decisions found at {ex.filename}")
return {}
version = data.get('version', '0')
if version != __VERSION__:
cur_version = data.get('version', '0')
if cur_version != version("bim2sim"):
try:
data = convert(version, __VERSION__, data)
logger.info("Converted stored decisions from version '%s' to '%s'", version, __VERSION__)
data = convert(cur_version, version("bim2sim"), data)
logger.info("Converted stored decisions from version '%s' to '%s'",
cur_version, version("bim2sim"))
except:
logger.error("Decision conversion from %s to %s failed")
return {}
Expand Down
Empty file.
3 changes: 2 additions & 1 deletion bim2sim/plugins/PluginComfort/PluginComfort.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ USER root
RUN apt-get update && apt-get install -y ca-certificates curl libx11-6 libexpat1 \
&& rm -rf /var/lib/apt/lists/*

RUN curl -SLO $ENERGYPLUS_DOWNLOAD_URL
RUN curl -SLO --retry 5 --retry-delay 15 --retry-max-time 900 --connect-timeout 60 --max-time 3600 $ENERGYPLUS_DOWNLOAD_URL || \
(sleep 30 && curl -SLO --retry 5 --retry-delay 15 --retry-max-time 900 --connect-timeout 60 --max-time 3600 $ENERGYPLUS_DOWNLOAD_URL)

RUN chmod +x $ENERGYPLUS_DOWNLOAD_FILENAME

Expand Down
3 changes: 2 additions & 1 deletion bim2sim/plugins/PluginEnergyPlus/PluginEnergyPlus.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ USER root
RUN apt-get update && apt-get install -y ca-certificates curl libx11-6 libexpat1 \
&& rm -rf /var/lib/apt/lists/*

RUN curl -SLO $ENERGYPLUS_DOWNLOAD_URL
RUN curl -SLO --retry 5 --retry-delay 15 --retry-max-time 900 --connect-timeout 60 --max-time 3600 $ENERGYPLUS_DOWNLOAD_URL || \
(sleep 30 && curl -SLO --retry 5 --retry-delay 15 --retry-max-time 900 --connect-timeout 60 --max-time 3600 $ENERGYPLUS_DOWNLOAD_URL)

RUN chmod +x $ENERGYPLUS_DOWNLOAD_FILENAME

Expand Down
2 changes: 1 addition & 1 deletion docs/source/user-guide/PluginTemplate.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ version of [mamba](https://github.com/mamba-org/mamba)) is used.

We will guide you through the process now.
```shell
# create fresh python environment with conda (python 3.9 to 3.11 are supported currently)
# create fresh python environment with conda (python 3.10 to 3.11 are supported currently)
micromamba create -n bim2sim python=3.11 -c conda-forge
# activate your environment
micromamba activate bim2sim
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = 'bim2sim'
version = '0.1'
version = '0.2.1'
authors = [
{name = "David Jansen"},
{name = "Veronika Richter"},
Expand All @@ -25,8 +25,8 @@ description = "bim2sim is a framework to create simulation models for different
readme = "README.md"
requires-python = ">=3.10, <=3.11.10"
classifiers = [
"Development Status :: XXX", # see https://en.wikipedia.org/wiki/Software_release_life_cycle
"License :: XXX",
"Development Status :: 3 - Alpha",
"License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python",
Expand Down
10 changes: 7 additions & 3 deletions test/integration/test_useage.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def test_import_mainlib(self):
except ImportError as err:
self.fail("Unable to import bim2sim\nreason: %s"%(err))
except Exception as err:
self.skipTest("bim2sim available but errors occured on import\ndetails: %s"%(err))
self.skipTest("bim2sim available but errors occured on "
"import\ndetails: %s"%(err))

def test_call_console(self):
"""Test calling bim2sim --version from console"""
Expand All @@ -24,8 +25,11 @@ def test_call_console(self):
self.fail("Unable to localize bim2sim")
path = Path(bim2sim.__file__).parent
cmd = '"%s" %s --version' % (Path(sys.executable), 'bim2sim')
ret = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=path.parent, shell=True)
self.assertIn(bim2sim.VERSION, ret.stdout.decode('utf-8'), 'unexpected output')
ret = subprocess.run(
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
cwd=path.parent, shell=True)
self.assertIn(bim2sim.__version__, ret.stdout.decode('utf-8'),
'unexpected output')

# for some reason the error code is 1 but code runs as expected without errors ...
# if ret.returncode != 0:
Expand Down

0 comments on commit 5a2e25f

Please sign in to comment.