コード例 #1
0
def load_construction_set_object(cset_dict):
    """Load a construction set object from a dictionary and add it to the lib dict."""
    try:
        if cset_dict['type'] == 'ConstructionSetAbridged':
            cset = ConstructionSet.from_dict_abridged(cset_dict, _all_constructions)
        else:
            cset = ConstructionSet.from_dict(cset_dict)
        cset.lock()
        assert cset_dict['identifier'] not in _default_sets, 'Cannot overwrite ' \
            'default construction set "{}".'.format(cset_dict['identifier'])
        _construction_sets[cset_dict['identifier']] = cset
    except (TypeError, KeyError, ValueError):
        pass  # not a Honeybee ConstructionSet JSON; possibly a comment
コード例 #2
0

# make a dictionary of all constructions loaded from JSON
_all_constructions = _opaque_constructions.copy()  # start with opaque constructions
_all_constructions.update(_window_constructions)  # add window constructions
_all_constructions.update(_shade_constructions)  # add shade constructions

# empty dictionary to hold loaded construction sets
_construction_sets = {}


# first load the honeybee defaults
with open(folders.defaults_file) as json_file:
    default_data = json.load(json_file)['construction_sets']
for cset_dict in default_data:
    constructionset = ConstructionSet.from_dict_abridged(cset_dict, _all_constructions)
    constructionset.lock()
    _construction_sets[cset_dict['identifier']] = constructionset
_default_sets = set(list(_construction_sets.keys()))


# then load construction sets from the user-supplied files
def load_construction_set_object(cset_dict):
    """Load a construction set object from a dictionary and add it to the lib dict."""
    try:
        if cset_dict['type'] == 'ConstructionSetAbridged':
            cset = ConstructionSet.from_dict_abridged(cset_dict, _all_constructions)
        else:
            cset = ConstructionSet.from_dict(cset_dict)
        cset.lock()
        assert cset_dict['identifier'] not in _default_sets, 'Cannot overwrite ' \
コード例 #3
0
from ._loadconstructions import _idf_opaque_constructions, _idf_window_constructions

import os
import json


# empty dictionaries to hold json-loaded construction sets
_idf_constructions = _idf_opaque_constructions.copy()  # start with opaque constructions
_idf_constructions.update(_idf_window_constructions)  # add window constructions

_json_construction_sets = {}


# load construction sets from the default and user-supplied files
cur_dir = os.path.dirname(__file__)
constr_lib = os.path.join(cur_dir, 'library', 'constructionsets')
for f in os.listdir(constr_lib):
    f_path = os.path.join(constr_lib, f)
    if os.path.isfile(f_path) and f_path.endswith('.json'):
        with open(f_path, 'r') as json_file:
            file_contents = json_file.read()
        c_dict = json.loads(file_contents)
        for c_name in c_dict:
            try:
                constructionset = ConstructionSet.from_dict_abridged(
                    c_dict[c_name], _idf_constructions)
                constructionset.lock()
                _json_construction_sets[constructionset.name] = constructionset
            except ValueError:
                pass  # failed to find the construction in the construction library