Exemple #1
0
 def save_report_to_html(self):
     html = self.page().mainFrame().toHtml()
     if self.report_path is not None:
         html_to_file(html, self.report_path)
     else:
         msg = self.tr('report_path is not set')
         raise InvalidParameterError(msg)
 def save_report_to_html(self):
     html = self.page().mainFrame().toHtml()
     if self.report_path is not None:
         html_to_file(html, self.report_path)
     else:
         msg = self.tr('report_path is not set')
         raise InvalidParameterError(msg)
Exemple #3
0
 def open_current_in_browser(self):
     if self.impact_path is None:
         html = self.page().mainFrame().toHtml()
         html_to_file(html, open_browser=True)
     else:
         if self.action_show_report.isEnabled():
             # if show report is enable, we are looking at a log
             open_in_browser(self.log_path)
         else:
             open_in_browser(self.report_path)
 def open_current_in_browser(self):
     if self.impact_path is None:
         html = self.page().mainFrame().toHtml()
         html_to_file(html, open_browser=True)
     else:
         if self.action_show_report.isEnabled():
             # if show report is enable, we are looking at a log
             open_in_browser(self.log_path)
         else:
             open_in_browser(self.report_path)
 def save_log_to_html(self):
     html = html_header()
     html += ('<img src="qrc:/plugins/inasafe/inasafe-logo.svg" '
              'title="InaSAFE Logo" alt="InaSAFE Logo" />')
     html += ('<h5 class="info"><i class="icon-info-sign icon-white"></i> '
              '%s</h5>' % self.tr('Analysis log'))
     for item in self.dynamic_messages_log:
         html += "%s\n" % item.to_html()
     html += html_footer()
     if self.log_path is not None:
         html_to_file(html, self.log_path)
     else:
         msg = self.tr('log_path is not set')
         raise InvalidParameterError(msg)
 def save_log_to_html(self):
     """Helper to write the log out as an html file."""
     html = html_header()
     html += ('<img src="qrc:/plugins/inasafe/inasafe-logo-url.png" '
              'title="InaSAFE Logo" alt="InaSAFE Logo" />')
     html += ('<h5 class="info"><i class="icon-info-sign icon-white"></i> '
              '%s</h5>' % self.tr('Analysis log'))
     for item in self.dynamic_messages_log:
         html += "%s\n" % item.to_html()
     html += html_footer()
     if self.log_path is not None:
         html_to_file(html, self.log_path)
     else:
         msg = self.tr('log_path is not set')
         raise InvalidParameterError(msg)
    def generate_html_reports(self, first_report_dict, second_report_dict):
        """Generate html file for each aggregation units.

        It also saves the path of the each aggregation unit in
        self.html_reports.
        ::

            Ex. {"jakarta barat": "/home/jakarta barat.html",
                 "jakarta timur": "/home/jakarta timur.html"}

        :param first_report_dict: Dictionary report from first impact.
        :type first_report_dict: dict

        :param second_report_dict: Dictionary report from second impact.
        :type second_report_dict: dict
        """
        for aggregation_area in first_report_dict:
            html = html_header()
            html += ('<table width="100%" style="position:absolute;left:0px;"'
                     'class="table table-condensed table-striped">')
            html += '<caption><h4>%s</h4></caption>' % \
                    aggregation_area.title()

            html += '<tr>'

            # First impact on the left side
            html += '<td width="48%">'
            html += '<table width="100%">'
            html += '<thead><th>%s</th></thead>' % \
                    self.first_impact['exposure_title'].upper()
            first_exposure_report_dict = first_report_dict[aggregation_area]
            for first_exposure in first_exposure_report_dict:
                first_exposure_detail_dict = \
                    first_exposure_report_dict[first_exposure]
                html += '<tr><th><i>%s</i></th><th></th></tr>' % \
                        first_exposure.title()
                for datum in first_exposure_detail_dict:
                    html += ('<tr>'
                             '<td>%s</td>'
                             '<td>%s</td>'
                             '</tr>') % (datum,
                                         first_exposure_detail_dict[datum])
            html += '</table>'
            html += '</td>'

            # Second impact on the right side
            if aggregation_area in second_report_dict:
                # Add spaces between
                html += '<td width="4%">'
                html += '</td>'

                # Second impact report
                html += '<td width="48%">'
                html += '<table width="100%">'
                html += '<thead><th>%s</th></thead>' % \
                        self.second_impact['exposure_title'].upper()
                second_exposure_report_dict = \
                    second_report_dict[aggregation_area]
                for second_exposure in second_exposure_report_dict:
                    second_exposure_detail_dict = \
                        second_exposure_report_dict[second_exposure]
                    html += '<tr><th><i>%s</i></th><th></th></tr>' % \
                            second_exposure.title()
                    for datum in second_exposure_detail_dict:
                        html += ('<tr>'
                                 '<td>%s</td>'
                                 '<td>%s</td>'
                                 '</tr>') % \
                                (datum,
                                 second_exposure_detail_dict[datum])
                html += '</table>'
                html += '</td>'

            html += '</tr>'
            html += '</table>'
            html += html_footer()

            file_path = '%s.html' % aggregation_area
            path = os.path.join(temp_dir(), file_path)
            html_to_file(html, path)
            self.html_reports[aggregation_area.lower()] = path
    def generate_html_reports(self, first_report_dict, second_report_dict):
        """Generate html file for each aggregation units.

        It also saves the path of the each aggregation unit in
        self.html_reports.
        ::

            Ex. {"jakarta barat": "/home/jakarta barat.html",
                 "jakarta timur": "/home/jakarta timur.html"}

        :param first_report_dict: Dictionary report from first impact.
        :type first_report_dict: dict

        :param second_report_dict: Dictionary report from second impact.
        :type second_report_dict: dict
        """
        for aggregation_area in first_report_dict:
            html = html_header()
            html += ('<table width="100%" style="position:absolute;left:0px;"'
                     'class="table table-condensed table-striped">')
            html += '<caption><h4>%s</h4></caption>' % \
                    aggregation_area.title()

            html += '<tr>'

            # First impact on the left side
            html += '<td width="48%">'
            html += '<table width="100%">'
            html += '<thead><th>%s</th></thead>' % \
                    self.first_impact['exposure_title'].upper()
            first_exposure_report_dict = first_report_dict[aggregation_area]
            for first_exposure in first_exposure_report_dict:
                first_exposure_detail_dict = \
                    first_exposure_report_dict[first_exposure]
                html += '<tr><th><i>%s</i></th><th></th></tr>' % \
                        first_exposure.title()
                for datum in first_exposure_detail_dict:
                    html += ('<tr>'
                             '<td>%s</td>'
                             '<td>%s</td>'
                             '</tr>') % (datum,
                                         first_exposure_detail_dict[datum])
            html += '</table>'
            html += '</td>'

            # Second impact on the right side
            if aggregation_area in second_report_dict:
                # Add spaces between
                html += '<td width="4%">'
                html += '</td>'

                # Second impact report
                html += '<td width="48%">'
                html += '<table width="100%">'
                html += '<thead><th>%s</th></thead>' % \
                        self.second_impact['exposure_title'].upper()
                second_exposure_report_dict = \
                    second_report_dict[aggregation_area]
                for second_exposure in second_exposure_report_dict:
                    second_exposure_detail_dict = \
                        second_exposure_report_dict[second_exposure]
                    html += '<tr><th><i>%s</i></th><th></th></tr>' % \
                            second_exposure.title()
                    for datum in second_exposure_detail_dict:
                        html += ('<tr>'
                                 '<td>%s</td>'
                                 '<td>%s</td>'
                                 '</tr>') % \
                                (datum,
                                 second_exposure_detail_dict[datum])
                html += '</table>'
                html += '</td>'

            html += '</tr>'
            html += '</table>'
            html += html_footer()

            file_path = '%s.html' % aggregation_area
            path = os.path.join(temp_dir(), file_path)
            html_to_file(html, path)
            self.html_reports[aggregation_area.lower()] = path