コード例 #1
0
ファイル: test_consumption.py プロジェクト: gunduru/eemeter
def test_consumption_history(consumption_list_one_year_electricity,
                             consumption_list_one_year_gas):
    ch_elec = ConsumptionHistory(consumption_list_one_year_electricity)
    ch_gas = ConsumptionHistory(consumption_list_one_year_gas)

    # different ways to get the same data
    assert len(ch_elec.electricity) == 12
    assert len(ch_elec["electricity"]) == 12
    assert len(ch_elec.get("electricity")) == 12

    # other cases
    with pytest.raises(KeyError):
        assert len(ch_elec.natural_gas) == 0
        assert len(ch_gas.electricity) == 0
    assert len(ch_gas.natural_gas) == 12

    for consumption in ch_elec.electricity:
        assert consumption.kWh >= 0
    for consumption in ch_gas.natural_gas:
        assert consumption.therm >= 0

    assert ch_elec
    assert ch_gas

    for fuel_type,consumptions in ch_elec.fuel_types():
        consumptions.sort()

    assert len(ch_gas.before(datetime(2012,7,1)).natural_gas) == 6
    assert len(ch_gas.after(datetime(2012,6,30)).natural_gas) == 6
    assert len(ch_gas.before(datetime(2013,6,30)).natural_gas) == 12
    with pytest.raises(KeyError):
        assert ch_gas.before(datetime(2011,7,1)).natural_gas
        assert ch_gas.after(datetime(2013,6,30)).natural_gas

    assert ch_elec.get("nonexistent") == []
コード例 #2
0
def test_estimated_reading_consolidation_meter_multiple_fuel_type():
    ch1 = ConsumptionHistory([
            Consumption(0,"kWh","electricity",datetime(2012,1,1),datetime(2012,2,1)),
            Consumption(0,"kWh","electricity",datetime(2012,2,1),datetime(2012,3,1),estimated=True),
            Consumption(0,"kWh","electricity",datetime(2012,3,1),datetime(2012,4,1)),
            Consumption(0,"kWh","electricity",datetime(2012,4,1),datetime(2012,5,1)),
            Consumption(0,"therm","natural_gas",datetime(2012,1,1),datetime(2012,2,1)),
            Consumption(0,"therm","natural_gas",datetime(2012,2,1),datetime(2012,3,1),estimated=True),
            Consumption(0,"therm","natural_gas",datetime(2012,3,1),datetime(2012,4,1)),
            Consumption(0,"therm","natural_gas",datetime(2012,4,1),datetime(2012,5,1))
            ])

    ch_no_est = ConsumptionHistory([
            Consumption(0,"therm","natural_gas",datetime(2012,1,1),datetime(2012,2,1)),
            Consumption(0,"therm","natural_gas",datetime(2012,2,1),datetime(2012,4,1)),
            Consumption(0,"kWh","electricity",datetime(2012,1,1),datetime(2012,2,1)),
            Consumption(0,"kWh","electricity",datetime(2012,2,1),datetime(2012,4,1)),
            Consumption(0,"kWh","electricity",datetime(2012,4,1),datetime(2012,5,1)),
            Consumption(0,"therm","natural_gas",datetime(2012,4,1),datetime(2012,5,1))
            ])

    meter = EstimatedReadingConsolidationMeter()
    result1 = meter.evaluate(consumption_history=ch1)

    for result in [result1]:
        for c1,c2 in zip(result["consumption_history_no_estimated"].get("electricity"),
                         ch_no_est.get("electricity")):
            assert c1 == c2
        for c1,c2 in zip(result["consumption_history_no_estimated"].get("natural_gas"),
                         ch_no_est.get("natural_gas")):
            assert c1 == c2
コード例 #3
0
def test_estimated_reading_consolidation_meter_single_fuel_type():
    ch1 = ConsumptionHistory([
            Consumption(0,"kWh","electricity",datetime(2012,1,1),datetime(2012,2,1)),
            Consumption(0,"kWh","electricity",datetime(2012,2,1),datetime(2012,3,1),estimated=True),
            Consumption(0,"kWh","electricity",datetime(2012,3,1),datetime(2012,4,1)),
            Consumption(0,"kWh","electricity",datetime(2012,4,1),datetime(2012,5,1))
            ])

    ch2 = ConsumptionHistory([
            Consumption(0,"kWh","electricity",datetime(2012,1,1),datetime(2012,2,1)),
            Consumption(0,"kWh","electricity",datetime(2012,2,1),datetime(2012,4,1)),
            Consumption(0,"kWh","electricity",datetime(2012,4,1),datetime(2012,5,1))
            ])


    ch3 = ConsumptionHistory([
            Consumption(0,"kWh","electricity",datetime(2012,1,1),datetime(2012,2,1)),
            Consumption(0,"kWh","electricity",datetime(2012,2,1),datetime(2012,4,1)),
            Consumption(0,"kWh","electricity",datetime(2012,4,1),datetime(2012,5,1)),
            Consumption(0,"kWh","electricity",datetime(2012,5,1),datetime(2012,6,1),estimated=True)
            ])

    ch4 = ConsumptionHistory([
            Consumption(0,"kWh","electricity",datetime(2012,1,1),datetime(2012,2,1)),
            Consumption(0,"kWh","electricity",datetime(2012,2,1),datetime(2012,4,1)),
            Consumption(0,"kWh","electricity",datetime(2012,4,1),datetime(2012,5,1)),
            Consumption(0,"kWh","electricity",datetime(2012,5,1),datetime(2012,6,1),estimated=True),
            Consumption(0,"kWh","electricity",datetime(2012,6,1),datetime(2012,7,1),estimated=True)
            ])

    ch5 = ConsumptionHistory([
            Consumption(0,"kWh","electricity",datetime(2012,1,1),datetime(2012,2,1)),
            Consumption(0,"kWh","electricity",datetime(2012,2,1),datetime(2012,2,10),estimated=True),
            Consumption(0,"kWh","electricity",datetime(2012,2,10),datetime(2012,3,1),estimated=True),
            Consumption(0,"kWh","electricity",datetime(2012,3,1),datetime(2012,4,1)),
            Consumption(0,"kWh","electricity",datetime(2012,4,1),datetime(2012,5,1))
            ])

    ch6 = ConsumptionHistory([
            Consumption(0,"kWh","electricity",datetime(2012,1,1),datetime(2012,1,10),estimated=True),
            Consumption(0,"kWh","electricity",datetime(2012,1,10),datetime(2012,2,1)),
            Consumption(0,"kWh","electricity",datetime(2012,2,1),datetime(2012,4,1)),
            Consumption(0,"kWh","electricity",datetime(2012,4,1),datetime(2012,5,1))
            ])

    ch7 = ConsumptionHistory([
            Consumption(0,"kWh","electricity",datetime(2012,4,1),datetime(2012,5,1)),
            Consumption(0,"kWh","electricity",datetime(2012,2,1),datetime(2012,4,1)),
            Consumption(0,"kWh","electricity",datetime(2012,1,1),datetime(2012,1,10),estimated=True),
            Consumption(0,"kWh","electricity",datetime(2012,1,10),datetime(2012,2,1))
            ])

    ch_no_est = ConsumptionHistory([
            Consumption(0,"kWh","electricity",datetime(2012,1,1),datetime(2012,2,1)),
            Consumption(0,"kWh","electricity",datetime(2012,2,1),datetime(2012,4,1)),
            Consumption(0,"kWh","electricity",datetime(2012,4,1),datetime(2012,5,1))
            ])

    meter = EstimatedReadingConsolidationMeter()
    result1 = meter.evaluate(consumption_history=ch1)
    result2 = meter.evaluate(consumption_history=ch2)
    result3 = meter.evaluate(consumption_history=ch3)
    result4 = meter.evaluate(consumption_history=ch4)
    result5 = meter.evaluate(consumption_history=ch5)
    result6 = meter.evaluate(consumption_history=ch6)
    result7 = meter.evaluate(consumption_history=ch7)

    for result in [result1,result2,result3,result4,result5,result6,result7]:
        for c1,c2 in zip(result["consumption_history_no_estimated"].iteritems(),
                         ch_no_est.iteritems()):
            assert c1 == c2