def printImpactTable(self, theKeywords, theFilename=None): """High level table generator to print layer keywords. It gets the summary and impact table from a QgsMapLayer's keywords and renders to pdf, returning the resulting PDF file path. Args: theKeywords: dic containing impact layer keywords (required) Returns: str: Path to generated pdf file. Raises: None """ myFilePath = theFilename if theFilename is None: myFilePath = unique_filename(suffix='.pdf', dir=temp_dir()) try: mySummaryTable = theKeywords['impact_summary'] except KeyError: mySummaryTable = None myAttributionTable = impact_attribution(theKeywords) try: myFullTable = theKeywords['impact_table'] except KeyError: myFullTable = None try: myAggregationTable = theKeywords['postprocessing_report'] except KeyError: myAggregationTable = None myHtml = '' if mySummaryTable != myFullTable and mySummaryTable is not None: myHtml = '<h2>%s</h2>' % self.tr('Summary Table') myHtml += mySummaryTable if myAggregationTable is not None: myHtml += myAggregationTable if myAttributionTable is not None: myHtml += myAttributionTable.to_html() myHtml += '<h2>%s</h2>' % self.tr('Detailed Table') myHtml += myFullTable else: if myAggregationTable is not None: myHtml = myAggregationTable if myFullTable is not None: myHtml += myFullTable if myAttributionTable is not None: myHtml += myAttributionTable.to_html() # myNewFilePath should be the same as myFilePath myNewFilePath = self.printToPdf(myHtml, myFilePath) return myNewFilePath
def test_impact_layer_attribution(self): """Test we get an attribution html snippet nicely for impact layers.""" keywords = {'hazard_title': 'Sample Hazard Title', 'hazard_source': 'Sample Hazard Source', 'exposure_title': 'Sample Exposure Title', 'exposure_source': 'Sample Exposure Source'} myAttribution = impact_attribution(keywords) print myAttribution self.assertEqual(len(myAttribution.to_text()), 170)
def test_impactLayerAttribution(self): """Test we get an attribution html snippet nicely for impact layers.""" myKeywords = {'hazard_title': 'Sample Hazard Title', 'hazard_source': 'Sample Hazard Source', 'exposure_title': 'Sample Exposure Title', 'exposure_source': 'Sample Exposure Source'} myAttribution = impact_attribution(myKeywords) print myAttribution self.assertEqual(len(myAttribution.to_text()), 170)
def test_localisedAttribution(self): """Test we can localise attribution.""" os.environ['LANG'] = 'id' myKeywords = {'hazard_title': 'Jakarta 2007 flood', 'hazard_source': 'Sample Hazard Source', 'exposure_title': 'People in Jakarta', 'exposure_source': 'Sample Exposure Source'} myHtml = impact_attribution(myKeywords, True) print myHtml assert myHtml == '11'
def test_localised_attribution(self): """Test we can localise attribution.""" os.environ['LANG'] = 'id' keywords = {'hazard_title': 'Jakarta 2007 flood', 'hazard_source': 'Sample Hazard Source', 'exposure_title': 'People in Jakarta', 'exposure_source': 'Sample Exposure Source'} myHtml = impact_attribution(keywords, True) print myHtml assert myHtml == '11'
def test_impact_layer_attribution(self): """Test we get an attribution html snippet nicely for impact layers.""" keywords = { 'hazard_title': 'Sample Hazard Title', 'hazard_source': 'Sample Hazard Source', 'exposure_title': 'Sample Exposure Title', 'exposure_source': 'Sample Exposure Source'} attribution = impact_attribution(keywords) print attribution # noinspection PyArgumentList self.assertEqual(len(attribution.to_text()), 170)
def print_impact_table(self, keywords, filename=None): """High level table generator to print layer keywords. It gets the summary and impact table from a QgsMapLayer's keywords and renders to pdf, returning the resulting PDF file path. :param keywords: Impact layer keywords (required). :type keywords: dict :param filename: Name of the pdf file to create. :type filename: str :return: Path to generated pdf file. :rtype: str :raises: None """ file_path = filename if filename is None: file_path = unique_filename(suffix='.pdf', dir=temp_dir()) try: summary_table = keywords['impact_summary'] except KeyError: summary_table = None attribution_table = impact_attribution(keywords) try: full_table = keywords['impact_table'] except KeyError: full_table = None try: aggregation_table = keywords['postprocessing_report'] except KeyError: aggregation_table = None # The order of the report: # 1. Summary table # 2. Aggregation table # 3. Attribution table # (AG) We will not use impact_table as most of the IF use that as: # impact_table = impact_summary + some information intended to be # shown on screen (see FloodOsmBuilding) # Unless the impact_summary is None, we will use impact_table as the # alternative html = '' if summary_table is None: html += '<h2>%s</h2>' % self.tr('Detailed Table') html += full_table else: html = '<h2>%s</h2>' % self.tr('Summary Table') html += summary_table if aggregation_table is not None: html += aggregation_table if attribution_table is not None: html += attribution_table.to_html() # new_file_path should be the same as file_path new_file_path = self.to_pdf(html, file_path) return new_file_path
def print_impact_table(self, keywords, filename=None): """High level table generator to print layer keywords. It gets the summary and impact table from a QgsMapLayer's keywords and renders to pdf, returning the resulting PDF file path. :param keywords: Impact layer keywords (required). :type keywords: dict :param filename: Name of the pdf file to create. :type filename: str Returns: str: Path to generated pdf file. Raises: None """ file_path = filename if filename is None: file_path = unique_filename(suffix='.pdf', dir=temp_dir()) try: summary_table = keywords['impact_summary'] except KeyError: summary_table = None attribution_table = impact_attribution(keywords) try: full_table = keywords['impact_table'] except KeyError: full_table = None try: aggregation_table = keywords['postprocessing_report'] except KeyError: aggregation_table = None html = '' if summary_table != full_table and summary_table is not None: html = '<h2>%s</h2>' % self.tr('Summary Table') html += summary_table if aggregation_table is not None: html += aggregation_table if attribution_table is not None: html += attribution_table.to_html() html += '<h2>%s</h2>' % self.tr('Detailed Table') html += full_table else: if aggregation_table is not None: html = aggregation_table if full_table is not None: html += full_table if attribution_table is not None: html += attribution_table.to_html() # new_file_path should be the same as file_path new_file_path = self.to_pdf(html, file_path) return new_file_path
def print_impact_table(self, keywords, filename=None): """High level table generator to print layer keywords. It gets the summary and impact table from a QgsMapLayer's keywords and renders to pdf, returning the resulting PDF file path. :param keywords: Impact layer keywords (required). :type keywords: dict :param filename: Name of the pdf file to create. :type filename: str Returns: str: Path to generated pdf file. Raises: None """ file_path = filename if filename is None: file_path = unique_filename(suffix='.pdf', dir=temp_dir()) try: summary_table = keywords['impact_summary'] except KeyError: summary_table = None attribution_table = impact_attribution(keywords) try: full_table = keywords['impact_table'] except KeyError: full_table = None try: aggregation_table = keywords['postprocessing_report'] except KeyError: aggregation_table = None html = '' if summary_table != full_table and summary_table is not None: html = '<h2>%s</h2>' % self.tr('Summary Table') html += summary_table if aggregation_table is not None: html += aggregation_table if attribution_table is not None: html += attribution_table.to_html() if full_table is not None: html += '<h2>%s</h2>' % self.tr('Detailed Table') html += full_table else: if aggregation_table is not None: html = aggregation_table if full_table is not None: html += full_table if attribution_table is not None: html += attribution_table.to_html() # new_file_path should be the same as file_path new_file_path = self.to_pdf(html, file_path) return new_file_path