text: import time
  import json
  import os
  import uuid
  import errno
  import subprocess
  import zipfile
  import shutil
  import csv
  import numpy
  
  from DataFileUtil.DataFileUtilClient import DataFileUtil
  from biokbase.workspace.client import Workspace as Workspace
  from KBaseReport.KBaseReportClient import KBaseReport
  
  import matplotlib
  matplotlib.use('Agg')
  import matplotlib.pyplot as plt
  
  
  
  def log(message, prefix_newline=False):
      """Logging function, provides a hook to suppress or redirect log messages."""
      print(('\n' if prefix_newline else '') + '{0:.2f}'.format(time.time()) + ': ' + str(message))
  
  class ReportUtil:
  
  
  
  
      def _mkdir_p(self, path):
          """
          _mkdir_p: make directory for given path
          """
          if not path:
              return
          try:
              os.makedirs(path)
          except OSError as exc:
              if exc.errno == errno.EEXIST and os.path.isdir(path):
                  pass
              else:
                  raise
  
      def _generate_html_report(self, result_directory, 
                                params):
          """
          _generate_html_report: generate html summary report
          """
  
          log('start generating html report')
          html_report = list()
  
          output_directory = os.path.join(self.scratch, str(uuid.uuid4()))
          self._mkdir_p(output_directory)
          result_file_path = os.path.join(output_directory, 'report.html')
  
          shutil.copy2(os.path.join(result_directory, 'plot1.png'),
                       os.path.join(output_directory, 'plot1.png'))
          shutil.copy2(os.path.join(result_directory, 'plot2.png'),
                       os.path.join(output_directory, 'plot2.png'))
  
          overview_content = 'This is overview'
  
          with open(result_file_path, 'w') as result_file:
              with open(os.path.join(os.path.dirname(__file__), 'report_template.html'),
                        'r') as report_template_file:
                  report_template = report_template_file.read()
                  report_template = report_template.replace('<p>Overview_Content</p>',
                                                            overview_content)
                  result_file.write(report_template)
  
          report_shock_id = self.dfu.file_to_shock({'file_path': output_directory,
                                                    'pack': 'zip'})['shock_id']
  
          html_report.append({'shock_id': report_shock_id,
                              'name': os.path.basename(result_file_path),
                              'label': os.path.basename(result_file_path),
                              'description': 'HTML summary report for  App'})
          return html_report
  
  
      def _generate_output_file_list(self, result_directory):
          """
          _generate_output_file_list: zip result files and generate file_links for report
          """
          log('Start packing result files')
          output_files = list()
  
          output_directory = os.path.join(self.scratch, str(uuid.uuid4()))
          self._mkdir_p(output_directory)
          result_file = os.path.join(output_directory, 'result.zip')
          with zipfile.ZipFile(result_file, 'w',
                               zipfile.ZIP_DEFLATED,
                               allowZip64=True) as zip_file:
              for root, dirs, files in os.walk(result_directory):
                  for file in files:
                      if not (file.endswith('.zip') or
                              file.endswith('.png') or
                              file.endswith('.DS_Store')):
                          zip_file.write(os.path.join(root, file), file)
  
          output_files.append({'path': result_file,
                               'name': os.path.basename(result_file),
                               'label': os.path.basename(result_file),
                               'description': 'File(s) generated by App'})
  
          return output_files
  
  
      def _generate_report(self, 
                           params, result_directory):
          """
          _generate_report: generate summary report
          """
          log('creating report')
  
          output_files = self._generate_output_file_list(result_directory)
  
          output_html_files = self._generate_html_report(result_directory,
                                                         params)
  
          report_params = {
                'message': '',
                'workspace_name': params.get('workspace_name'),
                'file_links': output_files,
                'html_links': output_html_files,
                'direct_html_link_index': 0,
                'html_window_height': 333,
                'report_object_name': 'htmlreport_test_' + str(uuid.uuid4())}
  
          kbase_report_client = KBaseReport(self.callback_url)
          output = kbase_report_client.create_extended_report(report_params)
  
          report_output = {'report_name': output['name'], 'report_ref': output['ref']}
  
          return report_output
  
      def __init__(self, config):
          self.ws_url = config["workspace-url"]
          self.callback_url = config['SDK_CALLBACK_URL']
          self.token = config['KB_AUTH_TOKEN']
          self.shock_url = config['shock-url']
          self.dfu = DataFileUtil(self.callback_url)
          self.ws = Workspace(self.ws_url, token=self.token)
          self.scratch = config['scratch']
  
  
  
  