From d1cc6858a579f6fad7562ce30d7fe7d338a12950 Mon Sep 17 00:00:00 2001 From: shinde Date: Mon, 28 Feb 2022 10:10:00 +0100 Subject: [PATCH] Added HouseholdData for construction material --- exposurejapan/database.py | 66 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/exposurejapan/database.py b/exposurejapan/database.py index 5568f47..64bf22f 100644 --- a/exposurejapan/database.py +++ b/exposurejapan/database.py @@ -1320,6 +1320,68 @@ class JapanDatabase(SpatialiteDatabase): self.connection.commit() logger.info("Household data added") + def calculate_household_data_for_construction_material(self): + """ + Calculates and inserts the household numbers and household members in the HouseholdData + for construction materials (wooden, wooden (excluding wooden and fire-proofed), wooden + and fire-proofed and non-wooden). + + The household numbers and household members for each construction material is calculated + in the query `MappedHouseholdDataToDwellingNumber` by multiplying their `total` values + to the proportion of dwelling numbers for the respective construction material and + `total` dwelling numbers. + """ + + sql_statement = """ + INSERT INTO HouseholdData + ( + district_id, + building_type_id, + construction_material_id, + tenure_type_id, + dwelling_type_id, + number_household, + number_household_member + ) + SELECT H.district_id AS H_district_id, + H.building_type_id AS H_building_type_id, + DN.construction_material_id AS DN_construction_material_id, + H.tenure_type_id, + H.dwelling_type_id, + DN.number_dwelling / H.number_dwelling * H.number_household + AS target_hh_number, + DN.number_dwelling / H.number_dwelling * H.number_household_member + AS target_hh_member + FROM + ( + ( + SELECT district_id, + building_type_id, + construction_material_id, + tenure_type_id, + dwelling_type_id, + number_household, + number_household_member, + number_dwelling + FROM HouseholdData + WHERE tenure_type_id = 0 AND dwelling_type_id = 0 + ) AS H + INNER JOIN + ( + SELECT * + FROM DwellingNumber + WHERE story_number_id = 0 + ) AS DN + ON H.district_id = DN.district_id + AND H.building_type_id = DN.building_type_id + ) AS MappedHouseholdDataToDwellingNumber + WHERE DN_construction_material_id != 0 + """ + logger.debug(sql_statement) + self.cursor.execute(sql_statement) + self.connection.commit() + logger.info("Added HouseholdData for construction-material types") + def import_floorspace_and_dwelling_sizes( self, dwelling_sizes_filepath, @@ -1572,6 +1634,10 @@ class JapanDatabase(SpatialiteDatabase): household_data_filepath, building_type_list, dwelling_type_list, tenure_type_list ) + # Calculate number_household and number_household_member for construction- + # material types + self.calculate_household_data_for_construction_material() + # Import dwelling floorspace and number of dwellings for # dwelling sizes types into the database self.import_floorspace_and_dwelling_sizes( -- GitLab