Exemple #1
0
def create_data():
    """Create test data to compare against - run this the first time you make changes that affect the results. Note,
    this will overwrite the previous test data."""
    test_config = ConfigParser.SafeConfigParser()
    test_config.read(get_test_config_path())
    if not test_config.has_section('test_mixed_use_archetype_values'):
        test_config.add_section('test_mixed_use_archetype_values')
    locator = ReferenceCaseOpenLocator()
    expected_results = calculate_mixed_use_archetype_values_results(locator)
    test_config.set('test_mixed_use_archetype_values', 'expected_results', expected_results.to_json())

    config = cea.config.Configuration(cea.config.DEFAULT_CONFIG)
    locator = ReferenceCaseOpenLocator()

    # calculate schedules
    building_properties = BuildingProperties(locator, False)
    bpr = building_properties['B1011']
    list_uses = ['OFFICE', 'LAB', 'INDUSTRIAL', 'SERVERRROOM']
    bpr.occupancy = {'OFFICE': 0.5, 'SERVERROOM': 0.5}
    # get year from weather file
    weather_path = locator.get_weather_file()
    weather_data = epwreader.epw_reader(weather_path)[['year']]
    year = weather_data['year'][0]
    date = pd.date_range(str(year) + '/01/01', periods=HOURS_IN_YEAR, freq='H')

    calculated_schedules = schedule_maker_main(locator, config)
    if not test_config.has_section('test_mixed_use_schedules'):
        test_config.add_section('test_mixed_use_schedules')
    test_config.set('test_mixed_use_schedules', 'reference_results', json.dumps(
        {schedule: calculated_schedules[schedule][REFERENCE_TIME] for schedule in calculated_schedules.keys()}))

    with open(get_test_config_path(), 'w') as f:
        test_config.write(f)
Exemple #2
0
    def test_mixed_use_schedules(self):
        locator = ReferenceCaseOpenLocator()
        config = cea.config.Configuration(cea.config.DEFAULT_CONFIG)
        config.scenario = locator.scenario
        config.multiprocessing = False

        building_properties = BuildingProperties(
            locator, epwreader.epw_reader(locator.get_weather_file()))
        bpr = building_properties['B1011']
        bpr.occupancy = {'OFFICE': 0.5, 'SERVERROOM': 0.5}
        bpr.comfort['mainuse'] = 'OFFICE'

        # calculate schedules
        schedule_maker_main(locator, config)
        calculated_schedules = pd.read_csv(
            locator.get_schedule_model_file('B1011')).set_index('DATE')

        test_config = configparser.ConfigParser()
        test_config.read(get_test_config_path())
        reference_results = json.loads(
            test_config.get('test_mixed_use_schedules', 'reference_results'))

        for schedule in reference_results:
            if (isinstance(calculated_schedules[schedule][REFERENCE_TIME],
                           str)) and (isinstance(reference_results[schedule],
                                                 str)):
                self.assertEqual(
                    calculated_schedules[schedule][REFERENCE_TIME],
                    reference_results[schedule],
                    msg="Schedule '{}' at time {}, {} != {}".format(
                        schedule, str(REFERENCE_TIME),
                        calculated_schedules[schedule][REFERENCE_TIME],
                        reference_results[schedule]))
            else:
                self.assertAlmostEqual(
                    calculated_schedules[schedule][REFERENCE_TIME],
                    reference_results[schedule],
                    places=4,
                    msg="Schedule '{}' at time {}, {} != {}".format(
                        schedule, str(REFERENCE_TIME),
                        calculated_schedules[schedule][REFERENCE_TIME],
                        reference_results[schedule]))
    def test_mixed_use_schedules(self):
        locator = ReferenceCaseOpenLocator()
        config = cea.config.Configuration(cea.config.DEFAULT_CONFIG)
        config.scenario = locator.scenario
        stochastic_occupancy = config.demand.use_stochastic_occupancy

        # get year from weather file
        weather_path = locator.get_weather_file()
        weather_data = epwreader.epw_reader(weather_path)[['year']]
        year = weather_data['year'][0]
        date = pd.date_range(str(year) + '/01/01',
                             periods=HOURS_IN_YEAR,
                             freq='H')

        building_properties = BuildingProperties(locator, False)
        bpr = building_properties['B01']
        list_uses = ['OFFICE', 'INDUSTRIAL']
        bpr.occupancy = {'OFFICE': 0.5, 'INDUSTRIAL': 0.5}

        # calculate schedules
        archetype_schedules, archetype_values = schedule_maker(
            date, locator, list_uses)
        calculated_schedules = calc_schedules(list_uses, archetype_schedules,
                                              bpr, archetype_values,
                                              stochastic_occupancy)

        config = ConfigParser.SafeConfigParser()
        config.read(get_test_config_path())
        reference_results = json.loads(
            config.get('test_mixed_use_schedules', 'reference_results'))

        for schedule in reference_results:
            self.assertAlmostEqual(
                calculated_schedules[schedule][REFERENCE_TIME],
                reference_results[schedule],
                places=4,
                msg="Schedule '%s' at time %s, %f != %f" %
                (schedule, str(REFERENCE_TIME),
                 calculated_schedules[schedule][REFERENCE_TIME],
                 reference_results[schedule]))