Commit 9f54c205 authored by Danijel Schorlemmer's avatar Danijel Schorlemmer
Browse files

Implemented the import of dwelling floorspace and sizes

parent 272c86f9
......@@ -573,7 +573,7 @@ class JapanDatabase(SpatialiteDatabase):
logger.info("Districts and boundaries added")
def import_exposure_data(
self, dwelling_numbers_filepath, building_numbers_filepath, household_numbers_filepath
self, dwelling_numbers_filepath, building_numbers_filepath, household_numbers_filepath, dwelling_sizes_filepath
):
"""
Imports all exposure data from the Excel files provided by E-Stat, Japan. The following
......@@ -587,6 +587,8 @@ class JapanDatabase(SpatialiteDatabase):
File path to the file of number of buildings
household_numbers_filepath (str):
File path to the file of numbers of households
dwelling_sizes_filepath (str):
File path to the file of dwelling sizes
"""
# Tables for building classifications
......@@ -601,6 +603,15 @@ class JapanDatabase(SpatialiteDatabase):
"102_Wooden and fire-proofed",
"2_Non-wooden",
]
dwelling_size_type_list = [
"0_Total",
"1_29m2 and under",
"2_30 to 49m2",
"3_50 to 69m2",
"4_70 to 99m2",
"5_100 to 149m2",
"6_150m2 and over",
]
# Read numbers of dwellings
dwelling_numbers_input = pandas.read_excel(
......@@ -758,6 +769,83 @@ class JapanDatabase(SpatialiteDatabase):
)
logger.info("Number of households added")
# Read numbers of dwellings by size
dwelling_sizes_input = pandas.read_excel(
dwelling_sizes_filepath,
header=10,
usecols=[4, 5, 7, 9, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21]
)
for index, row in dwelling_sizes_input.iterrows():
admin_id = int((row["Area classification"].split("_"))[0])
# Identify district_id based on admin_id from the District table
sql_statement = "SELECT id FROM District "
sql_statement += "WHERE admin_id = %d" % admin_id
self.cursor.execute(sql_statement)
result = self.cursor.fetchone()
if result is None: # Only data for which a district exist matter
continue
district_id = result[0]
# Get ID of building type, dwelling type, and tenure type
building_type_id = add_element_and_get_index(
row["Type of building"], building_type_list
)
dwelling_type_id = add_element_and_get_index(
row["Type of dwelling"], dwelling_type_list
)
tenure_type_id = add_element_and_get_index(
row["Tenure of dwelling"], tenure_type_list
)
construction_material_id = add_element_and_get_index(
row["Construction material"], construction_material_list
)
# Prepare and insert the data to the DwellingFloorspace table
floorspace = float(str(row[13]).replace("-", "0"))
self.insert_dwelling_floorspace(
district_id,
building_type_id,
dwelling_type_id,
tenure_type_id,
construction_material_id,
floorspace,
)
logger.debug(
"Floorspace for district %s, type %s, %s, %s, %s added"
% (
admin_id,
building_type_list[building_type_id],
dwelling_type_list[dwelling_type_id],
tenure_type_list[tenure_type_id],
construction_material_list[construction_material_id],
)
)
# Prepare and insert the data to the DwellingSizeNumber table
for dwelling_size_type_id in range(7):
number_dwelling = float(str(row[6 + dwelling_size_type_id]).replace("-", "0"))
self.insert_dwelling_size_number(
district_id,
building_type_id,
dwelling_type_id,
tenure_type_id,
construction_material_id,
dwelling_size_type_id,
number_dwelling,
)
logger.debug(
"Dwelling numbers for district %s, type %s, %s, %s, %s added"
% (
admin_id,
building_type_list[building_type_id],
dwelling_type_list[dwelling_type_id],
tenure_type_list[tenure_type_id],
construction_material_list[construction_material_id],
)
)
logger.info("Number and sizes of dwellings added")
# Add the building types to the database
for building_type_id, building_type in enumerate(building_type_list):
self.insert_building_type(building_type_id, building_type)
......@@ -783,6 +871,11 @@ class JapanDatabase(SpatialiteDatabase):
construction_material_list
):
self.insert_construction_material(construction_material_id, construction_material)
logger.info("construction-material types added")
logger.info("Construction-material types added")
# Add the types of dwelling sizes to the database
for dwelling_size_type_id, dwelling_size_type in enumerate(dwelling_size_type_list):
self.insert_dwelling_size_type(dwelling_size_type_id, dwelling_size_type)
logger.info("Dwelling-size types added")
self.connection.commit()
......@@ -43,7 +43,7 @@ def main():
exit()
db.create_tables()
db.read_districts_and_boundaries("data/estat_bound_municipal.gpkg")
db.import_exposure_data("data/e008_3e.xlsx", "data/e039_3e.xlsx", "data/e011_2e.xlsx")
db.import_exposure_data("data/e008_3e.xlsx", "data/e039_3e.xlsx", "data/e011_2e.xlsx", "data/e014e.xlsx")
# Leave the program
sys.exit()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment