def load_program_object(pro_dict):
    """Load a program object from a dictionary and add it to the _program_types dict."""
    try:
        if pro_dict['type'] == 'ProgramTypeAbridged':
            program = ProgramType.from_dict_abridged(pro_dict, _schedules)
        else:
            program = ProgramType.from_dict(pro_dict)
        program.lock()
        assert pro_dict['identifier'] not in _default_programs, 'Cannot overwrite ' \
            'default program type "{}".'.format(pro_dict['identifier'])
        _program_types[pro_dict['identifier']] = program
    except (TypeError, KeyError, ValueError):
        pass  # not a Honeybee ProgramType JSON; possibly a comment
示例#2
0
def program_type_by_identifier(program_type_identifier):
    """Get a program_type from the library given its identifier.

    Args:
        program_type_identifier: A text string for the identifier of the ProgramType.
    """
    try:
        return _program_types[program_type_identifier]
    except KeyError:
        try:  # search the extension data
            p_type_dict = _program_types_standards_dict[
                program_type_identifier]
            scheds = _scheds_from_ptype_dict(p_type_dict)
            return ProgramType.from_dict_abridged(p_type_dict, scheds)
        except KeyError:  # construction is nowhere to be found; raise an error
            raise ValueError(
                '"{}" was not found in the program type library.'.format(
                    program_type_identifier))
from honeybee_energy.config import folders
from honeybee_energy.programtype import ProgramType

from ._loadschedules import _schedules

import os
import json

# empty dictionary to hold loaded program types
_program_types = {}

# first load the honeybee defaults
with open(folders.defaults_file) as json_file:
    default_data = json.load(json_file)['program_types']
for pro_dict in default_data:
    program = ProgramType.from_dict_abridged(pro_dict, _schedules)
    program.lock()
    _program_types[pro_dict['identifier']] = program
_default_programs = set(list(_program_types.keys()))


# then load program types from the user-supplied files
def load_program_object(pro_dict):
    """Load a program object from a dictionary and add it to the _program_types dict."""
    try:
        if pro_dict['type'] == 'ProgramTypeAbridged':
            program = ProgramType.from_dict_abridged(pro_dict, _schedules)
        else:
            program = ProgramType.from_dict(pro_dict)
        program.lock()
        assert pro_dict['identifier'] not in _default_programs, 'Cannot overwrite ' \
示例#4
0
"""Load all program types from the JSON libraries."""
from honeybee_energy.programtype import ProgramType

from ._loadschedules import _idf_schedules

import os
import json


# empty dictionaries to hold json-loaded program types
_json_program_types = {}


# load program types from the default and user-supplied files
cur_dir = os.path.dirname(__file__)
program_lib = os.path.join(cur_dir, 'library', 'programtypes')
for f in os.listdir(program_lib):
    f_path = os.path.join(program_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()
        p_dict = json.loads(file_contents)
        for p_name in p_dict:
            try:
                program = ProgramType.from_dict_abridged(p_dict[p_name], _idf_schedules)
                program.lock()
                _json_program_types[program.name] = program
            except ValueError:
                pass  # failed to find the schedule in the schedule library