Example #1
0
def readdatacommdct1(
        idfname,  # type: str
        iddfile="Energy+.idd",  # type: str
        commdct=None,  # type: Optional[List[List[Dict[str, Any]]]]
        block=None,  # type: Optional[List]
):
    # type: (...) -> Tuple[Optional[List[Any]], Any, List[List[Dict[str, Any]]], Any]
    """Read the idf file.

    This is patched so that the IDD index is not lost when reading a new IDF without reloading the modeleditor module.

    :param idfname: Name of the IDF file to read.
    :param iddfile: Name of the IDD file to use to interpret the IDF.
    :param commdct: Descriptions of IDF fields from the IDD. Defaults to None.
    :param block: EnergyPlus field ID names of the IDF from the IDD. Defaults to None.
    :returns: block EnergyPlus field ID names of the IDF from the IDD.
    :returns data: Eplusdata object containing representions of IDF objects.
    :returns: commdct List of names of IDF objects.
    :returns: idd_index A pair of dicts used for fast lookups of names of groups of objects.

    """
    if not commdct:
        block, commlst, updated_commdct, idd_index = parse_idd.extractidddata(
            iddfile)
        theidd = eplusdata.Idd(block, 2)
    else:
        theidd = eplusdata.Idd(block, 2)
        name2refs = iddindex.makename2refdct(commdct)
        ref2namesdct = iddindex.makeref2namesdct(name2refs)
        idd_index = dict(name2refs=name2refs, ref2names=ref2namesdct)
        updated_commdct = iddindex.ref2names2commdct(ref2namesdct, commdct)
    data = eplusdata.Eplusdata(theidd, idfname)
    return block, data, updated_commdct, idd_index
Example #2
0
def make_idd_index(extract_func, fname, debug):
    """generate the iddindex"""
    astr = _readfname(fname)

    # fname is exhausted by the above read
    # reconstitute fname as a StringIO
    fname = StringIO(astr)

    # glist = iddgroups.iddtxt2grouplist(astr.decode('ISO-8859-2'))

    blocklst, commlst, commdct = extract_func(fname)

    name2refs = iddindex.makename2refdct(commdct)
    ref2namesdct = iddindex.makeref2namesdct(name2refs)
    idd_index = dict(name2refs=name2refs, ref2names=ref2namesdct)
    commdct = iddindex.ref2names2commdct(ref2namesdct, commdct)

    return blocklst, commlst, commdct, idd_index
Example #3
0
def make_idd_index(extract_func, fname, debug):
    """generate the iddindex"""
    astr = _readfname(fname)

    # fname is exhausted by the above read
    # reconstitute fname as a StringIO
    fname = StringIO(astr)

    # glist = iddgroups.iddtxt2grouplist(astr.decode('ISO-8859-2'))
    
    
    blocklst, commlst, commdct = extract_func(fname)
    
    name2refs = iddindex.makename2refdct(commdct)
    ref2namesdct = iddindex.makeref2namesdct(name2refs)
    idd_index = dict(name2refs=name2refs, ref2names=ref2namesdct)
    commdct = iddindex.ref2names2commdct(ref2namesdct, commdct)
    
    return blocklst, commlst, commdct, idd_index
Example #4
0
def test_ref2names2commdct():
    """py.test for ref2names2commdct"""
    thedata = (
        (
            # ------------
            [
                [
                    {
                        "idfobj": "referedto1"
                    },
                    {
                        "field": ["Name"],
                        "reference": ["rname11", "rname12", "rname_both"],
                    },
                ],
                [
                    {
                        "idfobj": "referedto2"
                    },
                    {
                        "field": ["Name"],
                        "reference": ["rname21", "rname22", "rname_both"],
                    },
                ],
                [
                    {
                        "idfobj": "referingobj1"
                    },
                    {
                        "field": ["Name"]
                    },
                    {
                        "field": ["referingfield"],
                        "type": ["object-list"],
                        "object-list": ["rname11"],
                    },
                ],
                [
                    {
                        "idfobj": "referingobj2"
                    },
                    {
                        "field": ["Name"]
                    },
                    {
                        "field": ["referingfield"],
                        "type": ["object-list"],
                        "object-list": ["rname_both"],
                    },
                ],
            ],
            # ------------
            [
                [
                    {
                        "idfobj": "referedto1"
                    },
                    {
                        "field": ["Name"],
                        "reference": ["rname11", "rname12", "rname_both"],
                    },
                ],
                [
                    {
                        "idfobj": "referedto2"
                    },
                    {
                        "field": ["Name"],
                        "reference": ["rname21", "rname22", "rname_both"],
                    },
                ],
                [
                    {
                        "idfobj": "referingobj1"
                    },
                    {
                        "field": ["Name"]
                    },
                    {
                        "field": ["referingfield"],
                        "type": ["object-list"],
                        "object-list": ["rname11"],
                        "validobjects": set(["referedto1".upper()]),
                    },
                ],
                [
                    {
                        "idfobj": "referingobj2"
                    },
                    {
                        "field": ["Name"]
                    },
                    {
                        "field": ["referingfield"],
                        "type": ["object-list"],
                        "object-list": ["rname_both"],
                        "validobjects": set(["REFEREDTO1", "REFEREDTO2"]),
                    },
                ],
            ],
        ),  # commdct, expected
    )
    for commdct, expected in thedata:
        name2refdct = iddindex.makename2refdct(commdct)
        ref2names = iddindex.makeref2namesdct(name2refdct)
        result = iddindex.ref2names2commdct(ref2names, commdct)
        for r_item, e_item in zip(result, expected):
            assert r_item == e_item
            # the test below is ensure that the embedded data is not a copy,
            # but is pointing to the set in ref2names
            for item in r_item:
                try:
                    reference = item["object-list"][0]
                    validobjects = item["validobjects"]
                    assert id(ref2names[reference]) == id(validobjects)
                except KeyError as e:
                    continue
Example #5
0
def test_ref2names2commdct():
    """py.test for ref2names2commdct"""
    thedata = (
        (
            # ------------
            [
                [
                    {
                        'idfobj': 'referedto1'
                    },
                    {
                        'field': ['Name'],
                        'reference': ['rname11', 'rname12', 'rname_both'],
                    },
                ],
                [
                    {
                        'idfobj': 'referedto2'
                    },
                    {
                        'field': ['Name'],
                        'reference': ['rname21', 'rname22', 'rname_both'],
                    },
                ],
                [{
                    'idfobj': 'referingobj1'
                }, {
                    'field': ['Name']
                }, {
                    'field': ['referingfield'],
                    'type': ['object-list'],
                    'object-list': ['rname11'],
                }],
                [{
                    'idfobj': 'referingobj2'
                }, {
                    'field': ['Name']
                }, {
                    'field': ['referingfield'],
                    'type': ['object-list'],
                    'object-list': ['rname_both'],
                }],
            ],
            # ------------
            [
                [
                    {
                        'idfobj': 'referedto1'
                    },
                    {
                        'field': ['Name'],
                        'reference': ['rname11', 'rname12', 'rname_both'],
                    },
                ],
                [
                    {
                        'idfobj': 'referedto2'
                    },
                    {
                        'field': ['Name'],
                        'reference': ['rname21', 'rname22', 'rname_both'],
                    },
                ],
                [{
                    'idfobj': 'referingobj1'
                }, {
                    'field': ['Name']
                }, {
                    'field': ['referingfield'],
                    'type': ['object-list'],
                    'object-list': ['rname11'],
                    'validobjects': set(['referedto1'.upper()]),
                }],
                [{
                    'idfobj': 'referingobj2'
                }, {
                    'field': ['Name']
                }, {
                    'field': ['referingfield'],
                    'type': ['object-list'],
                    'object-list': ['rname_both'],
                    'validobjects': set(['REFEREDTO1', 'REFEREDTO2'])
                }],
            ],
        ),  # commdct, expected
    )
    for commdct, expected in thedata:
        name2refdct = iddindex.makename2refdct(commdct)
        ref2names = iddindex.makeref2namesdct(name2refdct)
        result = iddindex.ref2names2commdct(ref2names, commdct)
        for r_item, e_item in zip(result, expected):
            assert r_item == e_item
            # the test below is ensure that the embedded data is not a copy,
            # but is pointing to the set in ref2names
            for item in r_item:
                try:
                    reference = item['object-list'][0]
                    validobjects = item['validobjects']
                    assert id(ref2names[reference]) == id(validobjects)
                except KeyError as e:
                    continue
Example #6
0
def test_ref2names2commdct():
    """py.test for ref2names2commdct"""
    thedata = (
    (
# ------------
[
[
    {'idfobj':'referedto1'},
    {
        'field':['Name'],
        'reference':['rname11', 'rname12', 'rname_both'],
    },
    
],

[
    {'idfobj':'referedto2'},
    {
        'field':['Name'],
        'reference':['rname21', 'rname22', 'rname_both'],
    },
    
],  

[
    {'idfobj':'referingobj1'},
    {'field':['Name']},
    {
        'field':['referingfield'],
        'type':['object-list'],
        'object-list':['rname11'],
    }
    
],  

[
    {'idfobj':'referingobj2'},
    {'field':['Name']},
    {
        'field':['referingfield'],
        'type':['object-list'],
        'object-list':['rname_both'],
    }
    
],  

],
# ------------
[
[
    {'idfobj':'referedto1'},
    {
        'field':['Name'],
        'reference':['rname11', 'rname12', 'rname_both'],
    },
    
],

[
    {'idfobj':'referedto2'},
    {
        'field':['Name'],
        'reference':['rname21', 'rname22', 'rname_both'],
    },
    
],  

[
    {'idfobj':'referingobj1'},
    {'field':['Name']},
    {
        'field':['referingfield'],
        'type':['object-list'],
        'object-list':['rname11'],
        'validobjects':set(['referedto1'.upper()]),
    }
    
],  

[
    {'idfobj':'referingobj2'},
    {'field':['Name']},
    {
        'field':['referingfield'],
        'type':['object-list'],
        'object-list':['rname_both'],
        'validobjects':set(['REFEREDTO1', 'REFEREDTO2'])
    }
    
],  
],
    ), # commdct, expected
    )
    for commdct, expected in thedata:
        name2refdct = iddindex.makename2refdct(commdct)
        ref2names = iddindex.makeref2namesdct(name2refdct)
        result = iddindex.ref2names2commdct(ref2names, commdct)
        for r_item, e_item in zip(result, expected):
            assert r_item == e_item
            # the test below is ensure that the embedded data is not a copy,
            # but is pointing to the set in ref2names
            for item in r_item:
                try:
                    reference = item['object-list'][0]
                    validobjects = item['validobjects']
                    assert id(ref2names[reference]) == id(validobjects)
                except KeyError as e:
                    continue