Source code for hazpy.legacy.exporting.classes

from .Setup_Connection import setup
from importlib import import_module
import os
from ...common import Logger


[docs]class Exporting(): """ Export class for Hazus legacy. Can export CSVs, Shapefiles, PDF Reports, and Jsondatetime A combination of a date and a time. \n Use hazus.legacy.createExportObj() to create a base object for keyword arguments \n Exporting method logic follows: setup, getData, toCSV, toShapefile, toReport Keyword arguments: exportObj: dictionary -- { study_region: str -- name of the Hazus study region (HPR name) \n output_directory: str -- directory location for the outputs \n ?title: str -- title on the report \n ?meta: str -- sub-title on the report (ex: Shakemap v5) \n } """ def __init__(self, exportObj): self.exportObj = exportObj try: exportObj['title'] except: self.exportObj['title'] = self.exportObj['study_region'] try: exportObj['meta'] except: self.exportObj['meta'] = '' self.logger = Logger()
[docs] def setup(self): """Establishes the connection to SQL Server """ self.comp_name, self.cnxn, self.date, self.modules = setup( self.exportObj) self.exportObj.update({'created': self.date}) self.result_module = import_module( '.'+self.modules['result_module'], package='hazus.legacy.exporting.results')
[docs] def getData(self): """Queries and parses the data from SQL Server, preparing it for exporting """ self.hazus_results_dict, self.subcounty_results, self.county_results, self.damaged_essential_facilities = self.result_module.read_sql( self.comp_name, self.cnxn, self.exportObj)
[docs] def toCSV(self): """Exports the study region data to CSVs """ self.result_module.to_csv(self.hazus_results_dict, self.subcounty_results, self.county_results, self.damaged_essential_facilities, self.exportObj)
[docs] def toShapefile(self): """Exports the study region data to Shapefile(s) """ self.gdf = self.result_module.to_shp( self.exportObj, self.hazus_results_dict, self.subcounty_results)
[docs] def toReport(self): """Exports the study region data to a one-page PDF report """ try: len(self.gdf) except: self.toShapefile() self.report_module = import_module( '.'+self.modules['report_module'], package='hazus.legacy.exporting.reports') self.report_module.generate_report( self.gdf, self.hazus_results_dict, self.subcounty_results, self.county_results, self.exportObj)