def create_pdf( self, title, output_directory, impact_layer, count=0, index=None): """Create PDF report from impact layer. Create map & table report PDF based from impact_layer data. :param title: Report title. :type title: str :param output_directory: Output directory. :type output_directory: str :param impact_layer: Impact layer instance. :type impact_layer: QgsMapLayer :param count: The number of scenarios that were run. :type count: int :param index: A sequential number to place at the beginning of the file name. :type index: int, None See also: Dock.printMap() """ inasafe_map = Map(self.iface) # FIXME: check if impact_layer is the real impact layer... inasafe_map.set_impact_layer(impact_layer) LOGGER.debug('Create Report: %s' % title) map_path, table_path = self.report_path( output_directory, title, count, index) # create map pdf inasafe_map.make_pdf(map_path) # create table report pdf html_renderer = HtmlRenderer(inasafe_map.page_dpi) keywords = inasafe_map.keyword_io.read_keywords(impact_layer) html_renderer.print_impact_table(keywords, table_path) LOGGER.debug("Report done %s %s" % (map_path, table_path))
def test_printImpactTable(self): """Test that we can render html from impact table keywords.""" LOGGER.debug('InaSAFE HtmlRenderer testing printImpactTable') myFilename = 'test_floodimpact.tif' myLayer, _ = load_layer(myFilename) myMessage = 'Layer is not valid: %s' % myFilename assert myLayer.isValid(), myMessage myPageDpi = 300 myHtmlRenderer = HtmlRenderer(myPageDpi) myPath = unique_filename(prefix='impactTable', suffix='.pdf', dir=temp_dir('test')) myKeywordIO = KeywordIO() myKeywords = myKeywordIO.read_keywords(myLayer) myPath = myHtmlRenderer.print_impact_table(myKeywords, filename=myPath) myMessage = 'Rendered output does not exist: %s' % myPath assert os.path.exists(myPath), myMessage # pdf rendering is non deterministic so we can't do a hash check # test_renderComposition renders just the image instead of pdf # so we hash check there and here we just do a basic minimum file # size check. mySize = os.stat(myPath).st_size myExpectedSizes = [20936, # as rendered on linux ub 12.04 64 21523, # as rendered on linux ub 12.10 64 20605, # as rendered on linux ub 13.04 64 21527, # as rendered on Jenkins post 22 June 2013 377191, # as rendered on OSX 252699L, # as rendered on Windows 7 64 bit 251782L, # as rendered on Windows 8 64 bit amd 21491, # as rendered on Slackware64 14.0 ] print 'Output pdf to %s' % myPath self.assertIn(mySize, myExpectedSizes)
def create_pdf(self, title, output_directory, impact_layer, count=0, index=None): """Create PDF report from impact layer. Create map & table report PDF based from impact_layer data. :param title: Report title. :type title: str :param output_directory: Output directory. :type output_directory: str :param impact_layer: Impact layer instance. :type impact_layer: QgsMapLayer :param count: The number of scenarios that were run. :type count: int :param index: A sequential number to place at the beginning of the file name. :type index: int, None See also: Dock.printMap() """ inasafe_map = Map(self.iface) # FIXME: check if impact_layer is the real impact layer... inasafe_map.set_impact_layer(impact_layer) LOGGER.debug('Create Report: %s' % title) map_path, table_path = self.report_path(output_directory, title, count, index) # create map pdf inasafe_map.make_pdf(map_path) # create table report pdf html_renderer = HtmlRenderer(inasafe_map.page_dpi) keywords = inasafe_map.keyword_io.read_keywords(impact_layer) html_renderer.print_impact_table(keywords, table_path) LOGGER.debug("Report done %s %s" % (map_path, table_path))
def test_print_impact_table(self): """Test that we can render html from impact table keywords.""" LOGGER.debug('InaSAFE HtmlRenderer testing printImpactTable') file_name = 'test_floodimpact.tif' layer, _ = load_layer(file_name) message = 'Layer is not valid: %s' % file_name self.assertTrue(layer.isValid(), message) page_dpi = 300 html_renderer = HtmlRenderer(page_dpi) path = unique_filename( prefix='impact_table', suffix='.pdf', dir=temp_dir('test')) keyword_io = KeywordIO() keywords = keyword_io.read_keywords(layer) path = html_renderer.print_impact_table(keywords, filename=path) message = 'Rendered output does not exist: %s' % path self.assertTrue(os.path.exists(path), message) # pdf rendering is non deterministic so we can't do a hash check # test_renderComposition renders just the image instead of pdf # so we hash check there and here we just do a basic minimum file # size check. size = os.stat(path).st_size expected_sizes = [ 20936, # as rendered on linux ub 12.04 64 21523, # as rendered on linux ub 12.10 64 20605, # as rendered on linux ub 13.04 64 13965, # as rendered on linux ub 13.10 64 14220, # as rendered on linux ub 13.04 64 MB 11085, # as rendered on linux ub 14.04 64 AG 17306, # as rendered on linux ub 14.04_64 TS 17127, # as rendered on linux ub 14.04_64 MB 17295, # as rendered on linux ub 14.04_64 IS 18665, # as rendered on Jenkins per 19 June 2014 377191, # as rendered on OSX 17556, # as rendered on Windows 7_32 16163L, # as rendered on Windows 7 64 bit Ultimate i3 251782L, # as rendered on Windows 8 64 bit amd 21491, # as rendered on Slackware64 14.0 18667, # as rendered on Linux Mint 14_64 ] print 'Output pdf to %s' % path self.assertIn(size, expected_sizes)
def test_print_impact_table(self): """Test that we can render html from impact table keywords.""" LOGGER.debug('InaSAFE HtmlRenderer testing printImpactTable') file_name = 'test_floodimpact.tif' layer, _ = load_layer(file_name) message = 'Layer is not valid: %s' % file_name self.assertTrue(layer.isValid(), message) page_dpi = 300 html_renderer = HtmlRenderer(page_dpi) path = unique_filename(prefix='impact_table', suffix='.pdf', dir=temp_dir('test')) keyword_io = KeywordIO() keywords = keyword_io.read_keywords(layer) path = html_renderer.print_impact_table(keywords, filename=path) message = 'Rendered output does not exist: %s' % path self.assertTrue(os.path.exists(path), message) # pdf rendering is non deterministic so we can't do a hash check # test_renderComposition renders just the image instead of pdf # so we hash check there and here we just do a basic minimum file # size check. size = os.stat(path).st_size expected_sizes = [ 20936, # as rendered on linux ub 12.04 64 21523, # as rendered on linux ub 12.10 64 20605, # as rendered on linux ub 13.04 64 13965, # as rendered on linux ub 13.10 64 14220, # as rendered on linux ub 13.04 64 MB 11085, # as rendered on linux ub 14.04 64 AG 17306, # as rendered on linux ub 14.04_64 TS 17127, # as rendered on linux ub 14.04_64 MB 17295, # as rendered on linux ub 14.04_64 IS 18665, # as rendered on Jenkins per 19 June 2014 377191, # as rendered on OSX 17556, # as rendered on Windows 7_32 16163L, # as rendered on Windows 7 64 bit Ultimate i3 251782L, # as rendered on Windows 8 64 bit amd 21491, # as rendered on Slackware64 14.0 18667, # as rendered on Linux Mint 14_64 ] print 'Output pdf to %s' % path self.assertIn(size, expected_sizes)