def test_download_weather_1():
    # Setup
    test_folder, _ = helper.setup_test_folders()
    source_folder = os.path.dirname(os.path.realpath(__file__)) + '/test_files'
    delphin_id, weather_ids, material_ids = helper.upload_needed_project(
        'download_project_1')
    weather_interactions.download_weather(str(delphin_id), test_folder)

    def get_weather_files(path):
        files = []
        for file in [
                'diffuse_radiation.ccd', 'direct_radiation.ccd',
                'indoor_relative_humidity.ccd', 'indoor_temperature.ccd',
                'long_wave_radiation.ccd', 'relative_humidity.ccd',
                'temperature.ccd', 'vertical_rain.ccd', 'wind_direction.ccd',
                'wind_speed.ccd'
        ]:
            file_obj = open(path + '/' + file, 'r')
            files.append(file_obj.readlines())
        return files

    # Get files
    test_files = get_weather_files(test_folder)
    source_files = get_weather_files(source_folder)

    # Clean up
    delphin_db.Delphin.objects(id=delphin_id).first().delete()
    for material_id in material_ids:
        material_db.Material.objects(id=material_id).first().delete()
    for weather_id in weather_ids:
        weather_db.Weather.objects(id=weather_id).first().delete()
    helper.clean_up_test_folders()

    # Assert
    assert test_files == source_files
def test_download_materials_1():
    test_folder, _ = helper.setup_test_folders()
    delphin_id, material_ids = helper.upload_needed_project(
        'download_material_project_1')
    material_interactions.download_materials(str(delphin_id), test_folder)
    source_folder = os.path.dirname(
        os.path.realpath(__file__)) + '/test_files/helper_files'

    def get_material_files(path):
        files = []
        for file in [
                'BrickWienerberger_512.m6', 'IQTop_726.m6',
                'RemmersiQFix_437.m6', 'RemmersiQTherm_438.m6',
                'RestorationRender_210.m6',
                'WietersdorfPeggauerMineralischeKalkzementLeichtputz_630.m6'
        ]:
            file_path = path + '/' + file
            files.append(codecs.open(file_path, "r", "utf-8").readlines())
        return files

    # Get files
    test_files = get_material_files(test_folder)
    source_files = get_material_files(source_folder)

    # Clean up
    delphin_db.Delphin.objects(id=delphin_id).first().delete()
    for material_id in material_ids:
        material_db.Material.objects(id=material_id).first().delete()
    helper.clean_up_test_folders()

    # Assert
    assert test_files == source_files
Esempio n. 3
0
def test_change_orientation():
    source_path = os.path.dirname(os.path.realpath(__file__)) + '/test_files'
    test_path, _ = helper.setup_test_folders()
    delphin_dict = delphin_parser.dp6_to_dict(source_path +
                                              '/delphin_project.d6p')
    new_delphin = delphin_permutations.change_orientation(delphin_dict, 300)

    xmltodict.unparse(new_delphin,
                      output=open(test_path + '/modified_delphin_project.d6p',
                                  'w'),
                      pretty=True)
    helper.clean_up_test_folders()
    assert new_delphin['DelphinProject']['Conditions']['Interfaces'][
        'Interface'][0]['IBK:Parameter']['#text'] == str(300)
Esempio n. 4
0
def test_change_coefficient_1():
    source_path = os.path.dirname(os.path.realpath(__file__)) + '/test_files'
    test_path, _ = helper.setup_test_folders()
    delphin_dict = delphin_parser.dp6_to_dict(source_path +
                                              '/delphin_project.d6p')
    new_delphin = delphin_permutations.change_boundary_coefficient(
        delphin_dict, 'Indoor heat conduction', 'ExchangeCoefficient', 12)

    xmltodict.unparse(new_delphin,
                      output=open(test_path + '/modified_delphin_project.d6p',
                                  'w'),
                      pretty=True)
    helper.clean_up_test_folders()
    assert new_delphin['DelphinProject']['Conditions']['BoundaryConditions'][
        'BoundaryCondition'][0]['IBK:Parameter']['#text'] == str(12)
Esempio n. 5
0
def test_change_weather():
    source_path = os.path.dirname(os.path.realpath(__file__)) + '/test_files'
    test_path, _ = helper.setup_test_folders()
    delphin_dict = delphin_parser.dp6_to_dict(source_path +
                                              '/delphin_project.d6p')
    weather_path = os.path.dirname(
        os.path.realpath(__file__)) + '/test_files/temperature.ccd'
    new_delphin = delphin_permutations.change_weather(delphin_dict, 'Temp Out',
                                                      weather_path)
    xmltodict.unparse(new_delphin,
                      output=open(test_path + '/modified_delphin_project.d6p',
                                  'w'),
                      pretty=True)
    helper.clean_up_test_folders()

    assert new_delphin['DelphinProject']['Conditions']['ClimateConditions'][
        'ClimateCondition'][2]['Filename'] == weather_path
Esempio n. 6
0
def test_change_layer_width():
    source_path = os.path.dirname(os.path.realpath(__file__)) + '/test_files'
    test_path, _ = helper.setup_test_folders()
    delphin_dict = delphin_parser.dp6_to_dict(source_path +
                                              '/delphin_project.d6p')
    old_width = sum(
        delphin_permutations.convert_discretization_to_list(delphin_dict))

    new_delphin = delphin_permutations.change_layer_width(
        delphin_dict, 'Normal Brick [512]', 1.0)
    xmltodict.unparse(new_delphin,
                      output=open(test_path + '/modified_delphin_project.d6p',
                                  'w'),
                      pretty=True)
    helper.clean_up_test_folders()

    assert sum(delphin_permutations.convert_discretization_to_list(
        new_delphin)) - old_width - 0.65 <= 0.002
Esempio n. 7
0
def test_upload_results_1():
    # Create test folders
    result_folder, source_path = helper.setup_test_folders()

    # Upload Delphin Project, so it can be linked to
    material_ids = helper.upload_needed_materials('upload_project_1')
    folder = os.path.dirname(os.path.realpath(__file__)) + '/test_files'
    delphin_file = folder + '/delphin_project.d6p'
    delphin_id = delphin_interact.upload_delphin_to_database(delphin_file, 10)

    # Upload results
    result_zip = folder + '/delphin_results.zip'
    shutil.unpack_archive(result_zip, result_folder)
    os.rename(result_folder + '/delphin_results',
              result_folder + '/' + str(delphin_id))
    result_id = delphin_interact.upload_results_to_database(result_folder +
                                                            '/' +
                                                            str(delphin_id))

    # Prepare test
    test_doc = result_db.Result.objects(id=result_id).first()
    test_dict = test_doc.to_mongo()
    test_dict.pop('_id')
    test_dict.pop('added_date')
    test_dict.pop('delphin')
    test_dict.pop('simulation_started')

    with open(folder + '/delphin_result_entry.txt') as outfile:
        source_entry = bson.json_util.loads(json.load(outfile))

    source_entry.pop('_id')
    source_entry.pop('added_date')
    source_entry.pop('delphin')
    source_entry.pop('simulation_started')

    # Clean up
    test_doc.delete()
    delphin_db.Delphin.objects(id=delphin_id).first().delete()
    for material_id in material_ids:
        material_db.Material.objects(id=material_id).first().delete()
    helper.clean_up_test_folders()

    # Assert
    assert test_dict == source_entry
Esempio n. 8
0
def test_change_material_1():
    source_path = os.path.dirname(os.path.realpath(__file__)) + '/test_files'
    test_path, _ = helper.setup_test_folders()
    delphin_dict = delphin_parser.dp6_to_dict(source_path +
                                              '/delphin_project.d6p')
    new_material = OrderedDict(
        (('@name', 'Aerated Concrete [6]'), ('@color', '#ff404060'),
         ('@hatchCode', '13'), ('#text',
                                '${Material Database}/AeratedConcrete_6.m6')))
    new_delphin = delphin_permutations.change_layer_material(
        delphin_dict, 'Normal Brick [512]', new_material)
    xmltodict.unparse(new_delphin,
                      output=open(test_path + '/modified_delphin_project.d6p',
                                  'w'),
                      pretty=True)
    helper.clean_up_test_folders()

    assert new_delphin['DelphinProject']['Materials']['MaterialReference'][
        1] == new_material
def test_download_project_1():

    test_folder, _ = helper.setup_test_folders()
    source_folder = os.path.dirname(os.path.realpath(__file__)) + '/test_files'
    delphin_id, weather_ids, material_ids = helper.upload_needed_project(
        'download_project_1')
    delphin_interactions.download_delphin_entry(str(delphin_id), test_folder)

    test_lines = open(test_folder + '/' + str(delphin_id) + '.d6p',
                      'r').readlines()
    source_lines = open(source_folder + '/delphin_project.d6p',
                        'r').readlines()

    # Clean up
    delphin_db.Delphin.objects(id=delphin_id).first().delete()
    for material_id in material_ids:
        material_db.Material.objects(id=material_id).first().delete()
    for weather_id in weather_ids:
        weather_db.Weather.objects(id=weather_id).first().delete()
    helper.clean_up_test_folders()

    assert test_lines == source_lines