Commit f5ba9af8 authored by Simantini Shinde's avatar Simantini Shinde
Browse files

Filename database.py changed to residential.py

parent d3763bf4
Pipeline #44210 passed with stage
in 2 minutes and 19 seconds
......@@ -20,7 +20,7 @@
import logging
import sys
import sqlite3
from database import JapanDatabase # pylint: disable=E0611,E0401
from residential import ResidentialAggregatedExposure
# Add a logger printing error, warning, info and debug messages to the screen
......@@ -34,25 +34,26 @@ def main():
# Example logging output
logger.info("exposurejapan started")
db = JapanDatabase("test.sqlite", "mod_spatialite")
# Run the residential aggregated exposure model
res_db = ResidentialAggregatedExposure("test.sqlite", "mod_spatialite")
try:
db.connect()
res_db.connect()
except sqlite3.OperationalError:
logger.warning("Spatialite extension cannot be loaded. Exiting ...")
exit()
db.create_tables()
db.import_districts_and_boundaries("data/Boundary.gpkg")
db.import_exposure_data(
res_db.create_tables()
res_db.import_districts_and_boundaries("data/Boundary.gpkg")
res_db.import_exposure_data(
"data/population_sub_municipal.csv",
"data/e039_3e.xlsx",
"data/e008_3e.xlsx",
"data/e011_2e.xlsx",
"data/e014e.xlsx",
)
db.import_gem_building_class_mapping("mapping_files/GEM_Tax_Building_class.xlsx")
db.assign_building_assets()
db.export_to_csv("output.csv")
res_db.import_gem_building_class_mapping("mapping_files/GEM_Tax_Building_class.xlsx")
res_db.assign_building_assets()
res_db.export_to_csv("output.csv")
# Leave the program
sys.exit()
......
......@@ -50,10 +50,10 @@ def add_element_and_get_index(element, element_list):
return element_list.index(element)
class JapanDatabase(SpatialiteDatabase):
class ResidentialAggregatedExposure(SpatialiteDatabase):
"""
The JapanDatabase class represents a Spatialite database for the Japan
exposure model. It is derived from the generic Database class.
The ResidentialAggregatedExposure class represents a Spatialite database for the residential
exposure model for Japan. It is derived from the generic Database class.
Args:
database_filepath (str):
......@@ -374,7 +374,7 @@ class JapanDatabase(SpatialiteDatabase):
File path to the boundary file
"""
# Attach Geopackage boundary database to the Japan database
# Attach Geopackage boundary database to the Japan residential database
sql_statement = "SELECT EnableGpkgAmphibiousMode();"
self.connection.execute(sql_statement)
sql_statement = "ATTACH '%s' AS BoundaryDatabase" % district_boundary_filepath
......@@ -382,7 +382,7 @@ class JapanDatabase(SpatialiteDatabase):
self.connection.execute(sql_statement)
# From the boundary database select id, name and geometry
# and insert into Districts table in the Japan database
# and insert into Districts table in the Japan residential database
sql_statement = (
"INSERT INTO District (id, name, geom) "
"SELECT key_code_ward, CITY_NAME, "
......@@ -413,7 +413,7 @@ class JapanDatabase(SpatialiteDatabase):
self.cursor.execute(sql_statement)
self.connection.commit()
# Detach Geopackage boundary database from the Japan database
# Detach Geopackage boundary database from the Japan residential database
sql_statement = "DETACH DATABASE 'BoundaryDatabase'"
logger.debug(sql_statement)
self.connection.execute(sql_statement)
......
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