Esempio n. 1
0
def test_get_fv_charts():
    """ Pass a URL, a list of moddle ID's and required API header; return a
        list of FirstView chart objects """

    for site in sites:
        bldgIDct = deltamtrsvs.get_property_bldgs(properties_url, site,
                                                  headers)
        bldgIDs = []
        for key in bldgIDct:
            bldgIDs.append(str(key))

        fvCharts = deltamtrsvs.get_fv_charts(pvt.fv_charts_url, bldgIDs,
                                             headers)
        assert type(fvCharts) == tp.DictType
        assert len(fvCharts) <= len(bldgIDs)
        diagnMsgCodes =[]
        for key, value in fvCharts.iteritems():
            assert type(key) == tp.StringType
            assert re.match('\d{3}', key)
            assert type(value) == tp.DictType
            # TODO (eayoungs): Repeat selections & attribute assertions for
            #                  remaining fields
            diagnstcs = value['Diagnostics']
            msgCode = [diagnstc['MessageCode'] for diagnstc in diagnstcs]
            diagnMsgCodes.append(msgCode)
            assert len(msgCode) == 10
            assert [type(diagnstc['MessageCode'])==tp.StringType for diagnstc
                    in diagnstcs]
def test_get_fv_charts():
    """ Pass a URL, a list of moddle ID's and required API header; return a
        list of FirstView chart objects """

    with HTTMock(firstview_charts_response_content):
        bldgIDs = ['1266']
        fvCharts = deltamtrsvs.get_fv_charts(fv_charts_url, bldgIDs,
                                             private.headers)
        assert type(fvCharts) == tp.DictType
        assert len(fvCharts) <= len(bldgIDs)
        diagnMsgCodes =[]
        for key, value in fvCharts.iteritems():
            assert type(key) == tp.StringType
            assert re.match('\d{3}', key)
            assert type(value) == tp.DictType
            # TODO (eayoungs): Repeat selections & attribute assertions for
            #                  remaining fields
            diagnstcs = value['Diagnostics']
            msgCode = [diagnstc['MessageCode'] for diagnstc in diagnstcs]
            diagnMsgCodes.append(msgCode)
            assert len(msgCode) == 10
            assert [type(diagnstc['MessageCode'])==tp.StringType for diagnstc
                    in diagnstcs]
def test_amsaves_flags():
    """ """

    for site in sites:
        bldgIDct = deltamtrsvs.get_property_bldgs(properties_url, site,
                                                  headers)
        bldgIDs = []
        for key in bldgIDct:
            bldgIDs.append(str(key))

        modelsJsonDct = deltamtrsvs.get_bldg_models(model_url, bldgIDs,
                                                            headers)
        valBldgIDs = []
        for key in modelsJsonDct:
            valBldgIDs.append(str(key))

        fvCharts = deltamtrsvs.get_fv_charts(pvt.fv_charts_url, valBldgIDs,
                                         headers)
        diagnMsgCodes = ams.amsaves_flags(fvCharts)
        # TODO (eayoungs): Needs more robust assertions
        assert type(diagnMsgCodes) == tp.DictType
        siteFlags = []
        for key, value in diagnMsgCodes.iteritems():
            bldgvalues = []
            if value['Occupant Load'][0] == 'A' or \
                value['Occupant Load'][0] == 'B' or \
                value['Occupant Load'][0] == 'C':
                intrnElec = value['Occupant Load'][0]
                ultrHighIntExt = ''
            elif value['Occupant Load'][0] == 'O' or \
                value['Occupant Load'] == 'P':
                ultrHighIntExt = value['Occupant Load'][0]
                intrnElec = ''
            # TODO (eayoungs): Add exception handling for final *else*
            #                  statement
            if value['Summer Gas Use'][1] == "High":
                highGasBaseLd = "M"
            else: highGasBaseLd = ""

            bldgFlags = [key, intrnElec, ultrHighIntExt,
                         value['Controls Heating'][0],
                         value['Shell Ventilation'][0],
                         value['Controls Cooling'][0],
                         value['Cooling Efficiency'][0],
                         value['Data Consistency'][0],
                         highGasBaseLd]

            siteFlags.append(bldgFlags)
            assert len(bldgFlags) == 9
            assert [type(bldgFlag) == tp.StringType for bldgFlag in bldgFlags]
            assert [len(bldgFlag) == 1 for bldgFlag in bldgFlags]
    
            colNms = ['Bldg ID','Int. Elec.', 'Ultra-High Elec.',
                      'Excessive Htg.', 'Shell & Vent.', 'Excessive Clg',
                      'Inefficient Clg', 'Erratic Operation', 'High Gas Eqp.']
            df = pd.DataFrame(data=siteFlags, columns=colNms)

            fname = site+'-flags.csv'
            with open(fname, 'wb') as outf:
                outcsv = df.to_csv(fname)

    assert len(siteFlags) == len(diagnMsgCodes)
    assert len(fvCharts) <= len(bldgIDs)