<s> from eemeter . config . yaml_parser import load <EOL> from eemeter . meter import DataCollection <EOL> from eemeter . consumption import ConsumptionData <EOL> from eemeter . evaluation import Period <EOL> from eemeter . location import Location <EOL> from eemeter . project import Project <EOL> from eemeter . meter import TimeSpanMeter <EOL> from eemeter . meter import TotalHDDMeter <EOL> from eemeter . meter import TotalCDDMeter <EOL> from eemeter . meter import NormalAnnualHDD <EOL> from eemeter . meter import NormalAnnualCDD <EOL> from eemeter . meter import NPeriodsMeetingHDDPerDayThreshold <EOL> from eemeter . meter import NPeriodsMeetingCDDPerDayThreshold <EOL> from eemeter . meter import RecentReadingMeter <EOL> from eemeter . meter import GrossSavingsMeter <EOL> from eemeter . meter import AnnualizedGrossSavingsMeter <EOL> from eemeter . meter import AverageDailyUsage <EOL> from eemeter . meter import EstimatedAverageDailyUsage <EOL> from eemeter . meter import ConsumptionDataAttributes <EOL> from eemeter . meter import ProjectAttributes <EOL> from eemeter . meter import ProjectConsumptionDataBaselineReporting <EOL> from eemeter . meter import ProjectFuelTypes <EOL> from eemeter . models import AverageDailyTemperatureSensitivityModel <EOL> from fixtures . weather import gsod_722880_2012_2014_weather_source <EOL> from fixtures . weather import tmy3_722880_weather_source <EOL> from fixtures . consumption import consumption_generator_1 <EOL> from fixtures . consumption import consumption_generator_2 <EOL> from fixtures . consumption import generated_consumption_data_1 <EOL> from fixtures . consumption import generated_consumption_data_2 <EOL> from fixtures . consumption import generated_consumption_data_pre_post_1 <EOL> from fixtures . consumption import generated_consumption_data_with_annualized_usage_1 <EOL> from fixtures . consumption import generated_consumption_data_pre_post_with_gross_savings_1 <EOL> from fixtures . consumption import generated_consumption_data_pre_post_with_annualized_gross_savings_1 <EOL> from fixtures . consumption import consumption_data_1 <EOL> from fixtures . consumption import time_span_1 <EOL> from fixtures . consumption import generated_consumption_data_with_hdd_1 <EOL> from fixtures . consumption import generated_consumption_data_with_cdd_1 <EOL> from fixtures . consumption import generated_consumption_data_with_n_periods_hdd_1 <EOL> from fixtures . consumption import generated_consumption_data_with_n_periods_cdd_1 <EOL> from datetime import datetime <EOL> from datetime import timedelta <EOL> import pytz <EOL> from numpy . testing import assert_allclose <EOL> import numpy as np <EOL> RTOL = <NUM_LIT> <EOL> ATOL = <NUM_LIT> <EOL> import pytest <EOL> @ pytest . mark . slow <EOL> def test_temperature_sensitivity_parameter_optimization ( <EOL> generated_consumption_data_1 , gsod_722880_2012_2014_weather_source ) : <EOL> meter_yaml = """<STR_LIT>""" <EOL> meter = load ( meter_yaml ) <EOL> cd , params = generated_consumption_data_1 <EOL> data_collection = DataCollection ( <EOL> consumption_data = cd , <EOL> weather_source = gsod_722880_2012_2014_weather_source , <EOL> energy_unit_str = "<STR_LIT>" ) <EOL> result = meter . evaluate ( data_collection ) <EOL> assert_allclose ( result . get_data ( '<STR_LIT>' ) . value . to_list ( ) , params . to_list ( ) , <EOL> rtol = RTOL , atol = ATOL ) <EOL> assert result . get_data ( '<STR_LIT>' ) is not None <EOL> assert result . get_data ( '<STR_LIT>' ) is not None <EOL> assert result . get_data ( '<STR_LIT>' ) is not None <EOL> @ pytest . mark . slow <EOL> def test_annualized_usage_meter ( <EOL> generated_consumption_data_with_annualized_usage_1 , <EOL> gsod_722880_2012_2014_weather_source , tmy3_722880_weather_source ) : <EOL> meter_yaml = """<STR_LIT>""" <EOL> meter = load ( meter_yaml ) <EOL> cd , params , annualized_usage = generated_consumption_data_with_annualized_usage_1 <EOL> data_collection = DataCollection ( <EOL> consumption_data = cd , <EOL> weather_source = gsod_722880_2012_2014_weather_source , <EOL> weather_normal_source = tmy3_722880_weather_source , <EOL> energy_unit_str = "<STR_LIT>" ) <EOL> result = meter . evaluate ( data_collection ) <EOL> assert_allclose ( result . get_data ( '<STR_LIT>' ) . value . to_list ( ) , params . to_list ( ) , <EOL> rtol = RTOL , atol = ATOL ) <EOL> assert_allclose ( result . get_data ( '<STR_LIT>' ) . value , <EOL> annualized_usage , rtol = RTOL , atol = ATOL ) <EOL> @ pytest . mark . slow <EOL> def test_gross_savings_metric ( generated_consumption_data_pre_post_with_gross_savings_1 , <EOL> gsod_722880_2012_2014_weather_source ) : <EOL> model = AverageDailyTemperatureSensitivityModel ( heating = True , cooling = True ) <EOL> meter = GrossSavingsMeter ( temperature_unit_str = "<STR_LIT>" , model = model ) <EOL> cd , params_pre , params_post , retrofit_date , savings = generated_consumption_data_pre_post_with_gross_savings_1 <EOL> reporting_period = Period ( retrofit_date , datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> result = meter . evaluate_raw ( <EOL> consumption_data_reporting = cd . filter_by_period ( reporting_period ) , <EOL> model_params_baseline = params_pre , <EOL> weather_source = gsod_722880_2012_2014_weather_source , <EOL> energy_unit_str = "<STR_LIT>" ) <EOL> assert_allclose ( result [ "<STR_LIT>" ] , savings , <EOL> rtol = RTOL , atol = ATOL ) <EOL> @ pytest . mark . slow <EOL> def test_annualized_gross_savings_metric ( <EOL> generated_consumption_data_pre_post_with_annualized_gross_savings_1 , <EOL> gsod_722880_2012_2014_weather_source , tmy3_722880_weather_source ) : <EOL> model = AverageDailyTemperatureSensitivityModel ( heating = True , cooling = True ) <EOL> meter = AnnualizedGrossSavingsMeter ( temperature_unit_str = "<STR_LIT>" , model = model ) <EOL> cd , params_pre , params_post , retrofit_date , savings = generated_consumption_data_pre_post_with_annualized_gross_savings_1 <EOL> reporting_period = Period ( retrofit_date , datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> result = meter . evaluate_raw ( <EOL> model_params_baseline = params_pre , <EOL> model_params_reporting = params_post , <EOL> consumption_data_reporting = cd . filter_by_period ( reporting_period ) , <EOL> weather_normal_source = tmy3_722880_weather_source , <EOL> energy_unit_str = "<STR_LIT>" ) <EOL> assert_allclose ( result [ "<STR_LIT>" ] , savings , <EOL> rtol = RTOL , atol = ATOL ) <EOL> def test_time_span_meter ( time_span_1 ) : <EOL> cd , n_days = time_span_1 <EOL> meter = TimeSpanMeter ( ) <EOL> assert n_days == meter . evaluate_raw ( consumption_data = cd ) [ "<STR_LIT>" ] <EOL> def test_total_hdd_meter ( generated_consumption_data_with_hdd_1 , gsod_722880_2012_2014_weather_source ) : <EOL> cd , hdd , base , temp_unit = generated_consumption_data_with_hdd_1 <EOL> meter = TotalHDDMeter ( base = base , temperature_unit_str = temp_unit ) <EOL> result = meter . evaluate_raw ( consumption_data = cd , <EOL> weather_source = gsod_722880_2012_2014_weather_source ) <EOL> assert_allclose ( hdd , result [ "<STR_LIT>" ] , rtol = RTOL , atol = ATOL ) <EOL> def test_total_cdd_meter ( generated_consumption_data_with_cdd_1 , gsod_722880_2012_2014_weather_source ) : <EOL> cd , cdd , base , temp_unit = generated_consumption_data_with_cdd_1 <EOL> meter = TotalCDDMeter ( base = base , temperature_unit_str = temp_unit ) <EOL> result = meter . evaluate_raw ( consumption_data = cd , <EOL> weather_source = gsod_722880_2012_2014_weather_source ) <EOL> assert_allclose ( cdd , result [ "<STR_LIT>" ] , rtol = RTOL , atol = ATOL ) <EOL> def test_normal_annual_hdd ( tmy3_722880_weather_source ) : <EOL> meter = NormalAnnualHDD ( base = <NUM_LIT> , temperature_unit_str = "<STR_LIT>" ) <EOL> result = meter . evaluate_raw ( weather_normal_source = tmy3_722880_weather_source ) <EOL> assert_allclose ( result [ "<STR_LIT>" ] , <NUM_LIT> , rtol = RTOL , atol = ATOL ) <EOL> def test_normal_annual_cdd ( tmy3_722880_weather_source ) : <EOL> meter = NormalAnnualCDD ( base = <NUM_LIT> , temperature_unit_str = "<STR_LIT>" ) <EOL> result = meter . evaluate_raw ( weather_normal_source = tmy3_722880_weather_source ) <EOL> assert_allclose ( result [ "<STR_LIT>" ] , <NUM_LIT> , rtol = RTOL , atol = ATOL ) <EOL> def test_n_periods_meeting_hdd_per_day_threshold ( generated_consumption_data_with_n_periods_hdd_1 , gsod_722880_2012_2014_weather_source ) : <EOL> cd , n_periods_lt , n_periods_gt , hdd = generated_consumption_data_with_n_periods_hdd_1 <EOL> meter_lt = NPeriodsMeetingHDDPerDayThreshold ( base = <NUM_LIT> , temperature_unit_str = "<STR_LIT>" , operation = "<STR_LIT:<>" ) <EOL> meter_gt = NPeriodsMeetingHDDPerDayThreshold ( base = <NUM_LIT> , temperature_unit_str = "<STR_LIT>" , operation = "<STR_LIT:>>" ) <EOL> result_lt = meter_lt . evaluate_raw ( consumption_data = cd , <EOL> hdd = hdd , <EOL> weather_source = gsod_722880_2012_2014_weather_source ) <EOL> result_gt = meter_gt . evaluate_raw ( consumption_data = cd , <EOL> hdd = hdd , <EOL> weather_source = gsod_722880_2012_2014_weather_source ) <EOL> assert n_periods_lt == result_lt [ "<STR_LIT>" ] <EOL> assert n_periods_gt == result_gt [ "<STR_LIT>" ] <EOL> def test_n_periods_meeting_cdd_per_day_threshold ( generated_consumption_data_with_n_periods_cdd_1 , gsod_722880_2012_2014_weather_source ) : <EOL> cd , n_periods_lt , n_periods_gt , cdd = generated_consumption_data_with_n_periods_cdd_1 <EOL> meter_lt = NPeriodsMeetingCDDPerDayThreshold ( base = <NUM_LIT> , temperature_unit_str = "<STR_LIT>" , operation = "<STR_LIT:<>" ) <EOL> meter_gt = NPeriodsMeetingCDDPerDayThreshold ( base = <NUM_LIT> , temperature_unit_str = "<STR_LIT>" , operation = "<STR_LIT:>>" ) <EOL> result_lt = meter_lt . evaluate_raw ( consumption_data = cd , <EOL> cdd = cdd , <EOL> weather_source = gsod_722880_2012_2014_weather_source ) <EOL> result_gt = meter_gt . evaluate_raw ( consumption_data = cd , <EOL> cdd = cdd , <EOL> weather_source = gsod_722880_2012_2014_weather_source ) <EOL> assert n_periods_lt == result_lt [ "<STR_LIT>" ] <EOL> assert n_periods_gt == result_gt [ "<STR_LIT>" ] <EOL> def test_recent_reading_meter ( ) : <EOL> recent_record = { "<STR_LIT:start>" : datetime . now ( pytz . utc ) - timedelta ( days = <NUM_LIT> ) , <EOL> "<STR_LIT:end>" : datetime . now ( pytz . utc ) - timedelta ( days = <NUM_LIT> ) , "<STR_LIT:value>" : <NUM_LIT:0> } <EOL> old_record = { "<STR_LIT:start>" : datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , tzinfo = pytz . utc ) , <EOL> "<STR_LIT:end>" : datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:1> , tzinfo = pytz . utc ) , "<STR_LIT:value>" : <NUM_LIT:0> } <EOL> no_cd = ConsumptionData ( [ ] , <EOL> "<STR_LIT>" , "<STR_LIT>" , record_type = "<STR_LIT>" ) <EOL> old_cd = ConsumptionData ( [ old_record ] , <EOL> "<STR_LIT>" , "<STR_LIT>" , record_type = "<STR_LIT>" ) <EOL> recent_cd = ConsumptionData ( [ recent_record ] , <EOL> "<STR_LIT>" , "<STR_LIT>" , record_type = "<STR_LIT>" ) <EOL> mixed_cd = ConsumptionData ( [ recent_record , old_record ] , <EOL> "<STR_LIT>" , "<STR_LIT>" , record_type = "<STR_LIT>" ) <EOL> meter = RecentReadingMeter ( ) <EOL> assert meter . evaluate_raw ( consumption_data = no_cd ) [ "<STR_LIT>" ] == np . inf <EOL> assert meter . evaluate_raw ( consumption_data = old_cd ) [ "<STR_LIT>" ] == <NUM_LIT> <EOL> assert meter . evaluate_raw ( consumption_data = recent_cd ) [ "<STR_LIT>" ] == <NUM_LIT:30> <EOL> assert meter . evaluate_raw ( consumption_data = mixed_cd ) [ "<STR_LIT>" ] == <NUM_LIT:30> <EOL> def test_average_daily_usage ( generated_consumption_data_1 ) : <EOL> cd , params = generated_consumption_data_1 <EOL> meter = AverageDailyUsage ( ) <EOL> result = meter . evaluate_raw ( consumption_data = cd , <EOL> energy_unit_str = "<STR_LIT>" ) <EOL> assert result [ "<STR_LIT>" ] is not None <EOL> def test_estimated_average_daily_usage ( generated_consumption_data_1 , gsod_722880_2012_2014_weather_source ) : <EOL> meter_yaml = """<STR_LIT>""" <EOL> meter = load ( meter_yaml ) <EOL> cd , params = generated_consumption_data_1 <EOL> result = meter . evaluate_raw ( <EOL> consumption_data = cd , <EOL> weather_source = gsod_722880_2012_2014_weather_source , <EOL> temp_sensitivity_params = params , <EOL> energy_unit_str = "<STR_LIT>" ) <EOL> assert result [ "<STR_LIT>" ] is not None <EOL> assert result [ "<STR_LIT>" ] is not None <EOL> def test_consumption_data_attributes ( generated_consumption_data_1 ) : <EOL> cd , params = generated_consumption_data_1 <EOL> meter = ConsumptionDataAttributes ( ) <EOL> result = meter . evaluate_raw ( consumption_data = cd ) <EOL> assert result [ "<STR_LIT>" ] == "<STR_LIT>" <EOL> assert result [ "<STR_LIT>" ] == "<STR_LIT>" <EOL> assert result [ "<STR_LIT>" ] == None <EOL> assert result [ "<STR_LIT>" ] == None <EOL> assert result [ "<STR_LIT>" ] == None <EOL> assert result [ "<STR_LIT:name>" ] == None <EOL> def test_project_attributes ( generated_consumption_data_1 ) : <EOL> cd , params = generated_consumption_data_1 <EOL> baseline_period = Period ( datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) , datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> location = Location ( zipcode = "<STR_LIT>" ) <EOL> project = Project ( location , [ cd ] , baseline_period , None ) <EOL> meter = ProjectAttributes ( project ) <EOL> result = meter . evaluate_raw ( project = project ) <EOL> assert result [ "<STR_LIT:location>" ] . zipcode == location . zipcode <EOL> assert result [ "<STR_LIT>" ] [ <NUM_LIT:0> ] is not None <EOL> assert result [ "<STR_LIT>" ] is not None <EOL> assert result [ "<STR_LIT>" ] is None <EOL> assert result [ "<STR_LIT>" ] == [ ] <EOL> assert result [ "<STR_LIT>" ] . station_id == "<STR_LIT>" <EOL> assert result [ "<STR_LIT>" ] . station_id == "<STR_LIT>" <EOL> def test_project_consumption_baseline_reporting ( generated_consumption_data_1 ) : <EOL> cd , _ = generated_consumption_data_1 <EOL> baseline_period = Period ( datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) , datetime ( <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT:1> ) ) <EOL> reporting_period = Period ( datetime ( <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT:1> ) , datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> location = Location ( zipcode = "<STR_LIT>" ) <EOL> project = Project ( location , [ cd ] , baseline_period , reporting_period ) <EOL> meter = ProjectConsumptionDataBaselineReporting ( ) <EOL> result = meter . evaluate_raw ( project = project ) <EOL> assert result [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ "<STR_LIT:value>" ] . data . index [ <NUM_LIT:0> ] == datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> assert result [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ "<STR_LIT:value>" ] . data . index [ <NUM_LIT> ] == datetime ( <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> ) <EOL> assert result [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] == "<STR_LIT>" <EOL> assert result [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ "<STR_LIT>" ] [ <NUM_LIT:1> ] == "<STR_LIT>" <EOL> assert result [ "<STR_LIT>" ] [ <NUM_LIT:1> ] [ "<STR_LIT:value>" ] . data . index [ <NUM_LIT:0> ] == datetime ( <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT> ) <EOL> assert result [ "<STR_LIT>" ] [ <NUM_LIT:1> ] [ "<STR_LIT:value>" ] . data . index [ <NUM_LIT> ] == datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT:16> ) <EOL> assert result [ "<STR_LIT>" ] [ <NUM_LIT:1> ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] == "<STR_LIT>" <EOL> assert result [ "<STR_LIT>" ] [ <NUM_LIT:1> ] [ "<STR_LIT>" ] [ <NUM_LIT:1> ] == "<STR_LIT>" <EOL> def test_project_attributes ( generated_consumption_data_1 ) : <EOL> cd , params = generated_consumption_data_1 <EOL> baseline_period = Period ( datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) , datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> location = Location ( zipcode = "<STR_LIT>" ) <EOL> project = Project ( location , [ cd , cd ] , baseline_period , None ) <EOL> meter = ProjectFuelTypes ( project ) <EOL> result = meter . evaluate_raw ( project = project ) <EOL> assert len ( result [ "<STR_LIT>" ] ) == <NUM_LIT:2> <EOL> assert result [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ "<STR_LIT:value>" ] == "<STR_LIT>" <EOL> assert result [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ "<STR_LIT>" ] == [ "<STR_LIT>" ] <EOL> assert result [ "<STR_LIT>" ] [ <NUM_LIT:1> ] [ "<STR_LIT:value>" ] == "<STR_LIT>" <EOL> assert result [ "<STR_LIT>" ] [ <NUM_LIT:1> ] [ "<STR_LIT>" ] == [ "<STR_LIT>" ] </s>
