Commit 5e7b6adb authored by Simantini Shinde's avatar Simantini Shinde
Browse files

Imported dwelling numbers into the DwellingNumber table

parent fd6b955a
Pipeline #39038 passed with stage
in 1 minute and 28 seconds
......@@ -593,6 +593,92 @@ class JapanDatabase(SpatialiteDatabase):
self.connection.commit()
logger.info("Building numbers added")
def import_dwelling_numbers(
self,
dwelling_numbers_filepath,
building_type_list,
construction_material_list,
story_number_list,
):
"""
Imports all dwelling data from the 2018 building statistics files provided
by E-Stat, Japan. The following file is needed:
List of numbers of dwellings by municipality (dwelling_numbers_filepath)
The dwelling data provide the dwelling numbers for a combination of different
building attributes:
- building types (total, detached house, tenement house,apartments and others),
- construction material type (total, wooden, wooden (excluding wooden and
fire-proofed), wooden and fire-proofed and non-wooden)
- story number type (total, 1 story, 2 stories and over, 2 stories,
3 to 5 stories and 6 stories) except for building type `Other` which is
given for story number `total` only.
These dwelling numbers are not available for all districts in Japan
i.e. the districts with population less than 15000 are ignored in the
building statistics.
Args:
dwelling_numbers_filepath (str):
Filepath of the file containing dwelling numbers
building_type_list (list):
Collection of types of buildings from the dwelling numbers file.
construction_material_list (list):
Collection of types of construction materials from the dwelling numbers file.
story_number_list (list):
Collection of the number of stories from the dwelling numbers file.
"""
# Read columns identification area code, district, building type, construction material
# type, story number type and number of dwellings from input csv file
dwelling_numbers_input = pandas.read_excel(
dwelling_numbers_filepath, header=10, usecols=[4, 5, 7, 9, 10, 11, 12, 13, 14]
)
# Iterate through each district
for index, row in dwelling_numbers_input.iterrows():
admin_id = int((row["Area classification"].split("_"))[0])
# Identify district_id based on admin_id from the District table
district_id_result = self.get_district_id(admin_id)
if district_id_result is None: # Only data for which a district exist matter
continue
district_id = district_id_result[0]
# Get ID of building type and number of stories
building_type_id = add_element_and_get_index(
row["Type of building"], building_type_list
)
story_number_id = add_element_and_get_index(
row["Stories of building"], story_number_list
)
# Insert dwelling numbers for each construction material
for construction_material_id in range(len(construction_material_list)):
dwelling_number = float(
str(row[constants.NUMBER_DWELLING + construction_material_id]).replace(
"-", "0"
)
)
# Insert the data to the DwellingNumber table
sql_statement = (
"INSERT INTO DwellingNumber (district_id, building_type_id, "
"construction_material_id, story_number_id, number_dwelling) "
"VALUES (%d, %d, %d, %d, %f)"
% (
district_id,
building_type_id,
construction_material_id,
story_number_id,
dwelling_number,
)
)
self.cursor.execute(sql_statement)
self.connection.commit()
logger.info("Dwelling numbers added")
def calculate_frequency_distributions(self):
"""
Fixes rounding-up errors observed between the sum of building numbers of the
......@@ -815,18 +901,27 @@ class JapanDatabase(SpatialiteDatabase):
self.cursor.execute(sql_statement)
self.connection.commit()
def import_exposure_data(self, population_distribution_filepath, building_numbers_filepath):
def import_exposure_data(
self,
population_distribution_filepath,
building_numbers_filepath,
dwelling_numbers_filepath,
):
"""
Imports all exposure data from the CSV and Excel files provided by E-Stat, Japan.
The following files are needed:
Number of people distributed by municipality (population_distribution_filepath)
List of numbers of buildings by municipality (building_numbers_filepath)
List of numbers of dwellings by municipality (dwelling_numbers_filepath)
Args:
population_distribution_filepath (str):
Filepath to the path of population distribution
building_numbers_filepath (str):
File path to the file of number of buildings
Filepath to the file of number of buildings
dwelling_numbers_filepath (str):
Filepath to the file of number of dwellings
"""
# Create lists to store building attribute classifications
......@@ -850,6 +945,14 @@ class JapanDatabase(SpatialiteDatabase):
building_numbers_filepath, building_type_list, story_number_list
)
# Import dwelling numbers data into the database
self.import_dwelling_numbers(
dwelling_numbers_filepath,
building_type_list,
construction_material_list,
story_number_list,
)
# Calculate the frequency distributions of building numbers
# and update the BuildingNumber table
self.calculate_frequency_distributions()
......
......@@ -43,7 +43,9 @@ def main():
exit()
db.create_tables()
db.import_districts_and_boundaries("data/Boundary.gpkg")
db.import_exposure_data("data/population_sub_municipal.csv", "data/e039_3e.xlsx")
db.import_exposure_data(
"data/population_sub_municipal.csv", "data/e039_3e.xlsx", "data/e008_3e.xlsx"
)
# Leave the program
sys.exit()
......
Supports Markdown
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