def createPDFReport(self, theTitle, theOutputDirectory, theImpactLayer, theCount=0, theIndex=''): """Create PDF report from impact layer. Create map & table report PDF based from theImpactLayer data. :param theTitle: the report title. :param theOutputDirectory: output directory :param theImpactLayer: impact layer instance. :param theCount: the number of as scenario has been run :param theIndex: the index for the beginning of the file name See also: Dock.printMap() """ myMap = Map(self.iface) # FIXME: check if theImpactLayer is the real impact layer... myMap.setImpactLayer(theImpactLayer) LOGGER.debug('Create Report: %s' % theTitle) myMapPath, myTablePath = self.reportPath( theOutputDirectory, theTitle, theCount, theIndex) # create map pdf myMap.printToPdf(myMapPath) # create table report pdf myHtmlRenderer = HtmlRenderer(myMap.pageDpi) myKeywords = myMap.keywordIO.read_keywords(theImpactLayer) myHtmlRenderer.printImpactTable(myKeywords, myTablePath) LOGGER.debug("Report done %s %s" % (myMapPath, myTablePath))
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.printImpactTable(myKeywords, theFilename=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 ] self.assertIn(mySize, myExpectedSizes)
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.printImpactTable(myKeywords, theFilename=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 ] self.assertIn(mySize, myExpectedSizes)
def create_pdf(self, title, output_directory, impact_layer, count=0, index=''): """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: The prefix for the beginning of the file name. Note we need a better explanation of this param. :type index: str See also: Dock.printMap() """ myMap = Map(self.iface) # FIXME: check if impact_layer is the real impact layer... myMap.set_impact_layer(impact_layer) LOGGER.debug('Create Report: %s' % title) myMapPath, myTablePath = self.report_path( output_directory, title, count, index) # create map pdf myMap.make_pdf(myMapPath) # create table report pdf myHtmlRenderer = HtmlRenderer(myMap.pageDpi) myKeywords = myMap.keywordIO.read_keywords(impact_layer) myHtmlRenderer.printImpactTable(myKeywords, myTablePath) LOGGER.debug("Report done %s %s" % (myMapPath, myTablePath))
def create_pdf(self, title, output_directory, impact_layer, count=0, index=''): """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: The prefix for the beginning of the file name. Note we need a better explanation of this param. :type index: str See also: Dock.printMap() """ myMap = Map(self.iface) # FIXME: check if impact_layer is the real impact layer... myMap.set_impact_layer(impact_layer) LOGGER.debug('Create Report: %s' % title) myMapPath, myTablePath = self.report_path(output_directory, title, count, index) # create map pdf myMap.make_pdf(myMapPath) # create table report pdf myHtmlRenderer = HtmlRenderer(myMap.pageDpi) myKeywords = myMap.keywordIO.read_keywords(impact_layer) myHtmlRenderer.printImpactTable(myKeywords, myTablePath) LOGGER.debug("Report done %s %s" % (myMapPath, myTablePath))