Exemplo n.º 1
0
def test_amsaves_results():
    """ Pass the results of get_model_comparisons to the amsaves_results 
        function, confirm DataFrame returned in requested results format for
        the 'America Saves!' program (write contents to .CSV file for review)
        """

    for site in sites:
        bldgIDct = deltamtrsvs.get_property_bldgs(properties_url, site,
                                                    headers)
        bldgIDs = []
        for key in bldgIDct:
            bldgIDs.append(str(key))
        bldgModelsDct = deltamtrsvs.get_bldg_models(model_url, bldgIDs,
                                                headers)
        modelIDs = []
        for key, value in bldgModelsDct.iteritems():
            jsonModelsDct = value
            for key, value in jsonModelsDct.iteritems():
                modelIDs.append(str(value['SolutionID']))
                
        comparisonsDct = deltamtrsvs.get_model_comparisons(comparison_url,
                                                           bldgModelsDct,
                                                           headers)
        bldgModelsDct = deltamtrsvs.get_bldg_models(model_url, bldgIDs,
                                                    headers)
        usesDf = ams.amsaves_results(comparisonsDct, bldgModelsDct, bldgIDct)

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

    assert isinstance(usesDf, pd.DataFrame)
    assert usesDf.shape[1] == 16
def test_get_model_comparisons():
    """ Pass a list of models' data, confirm the fuction returns the expected
        model IDs """

    with HTTMock(model_response_content):
        bldgModelsDct = {'1266': {'Reference Model': {"SolutionID": 234},
                                  'Proposed Model': {"SolutionID": 235}}}
        comparisonsDct = deltamtrsvs.get_model_comparisons(comparison_url,
                                                           bldgModelsDct,
                                                           private.headers)
        assert type(comparisonsDct) == tp.DictType
        for key, value in comparisonsDct.iteritems():
            assert type(key) == tp.StringType
            assert re.match('\d{4}', key)
            assert type(value) == tp.ListType
            assert [type(val) == tp.DictType for val in value]
Exemplo n.º 3
0
def test_get_meter_records():
    """ Pass a dictionary of *audit* spans from amsaves_usage_range with
        reference model IDs from the amsaves_usage_range function as keys and
        a list of meter IDs from get_bldg_meters function  """

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

    bldgModelsDct = deltamtrsvs.get_bldg_models(model_url, bldgIDs,
                                                headers)
    refModelsDct = {}
    for key, value in bldgModelsDct.iteritems():
        refModelsDct[key] = value['Reference Model']
            
    comparisonsDct = deltamtrsvs.get_model_comparisons(comparison_url,
                                                       bldgModelsDct,
                                                       headers)
    audits = deltamtrsvs.get_model_audits(audit_url, refModelsDct, headers)
    auditSpans = ams.amsaves_usage_range(audits)
    bldgMeterDct = deltamtrsvs.get_bldg_meters(pvt.bldg_meters_url, bldgIDs,
                                               headers)
    bldgMeterRecordsDct = deltamtrsvs.get_meter_records(auditSpans,
                                                        bldgMeterDct,
                                                        pvt.meter_records_url,
                                                        headers)
    assert type(bldgMeterRecordsDct) == tp.DictType
    for key, value in bldgMeterRecordsDct.iteritems():
        assert type(key) == tp.StringType
        assert type(value) == tp.DictType
        assert len(value) <= 2
        elecMtrVals = value['Elec. Meter Records']
        assert type(elecMtrVals) == tp.ListType
        assert [type(elecMtrVal) == tp.DictType for elecMtrVal in elecMtrVals]
        if len(value) == 2:
            gasMtrVals = value['Gas Meter Records']
            assert type(gasMtrVals) == tp.ListType
            assert [type(gasMtrVal) == tp.DictType for gasMtrVal in gasMtrVals]
            assert elecMtrVals != gasMtrVals
Exemplo n.º 4
0
def test_get_model_comparisons():
    """ Pass a list of models' data, confirm the fuction returns the expected
        model IDs """

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

        bldgModelsDct = deltamtrsvs.get_bldg_models(model_url, bldgIDs,
                                                    headers)
        comparisonsDct = deltamtrsvs.get_model_comparisons(comparison_url,
                                                           bldgModelsDct,
                                                           headers)
        assert type(comparisonsDct) == tp.DictType
        for key, value in comparisonsDct.iteritems():
            assert type(key) == tp.StringType
            assert type(value) == tp.DictType