<commit_before>from KBaseReport.KBaseReportClient import KBaseReport
from DataFileUtil.DataFileUtilClient import DataFileUtil
import uuid
import os
import errno


class ExampleReport(object):
    def __init__(self, callback_url, scratch_dir):
        self.scratch_dir = scratch_dir
        self.report_client = KBaseReport(callback_url)
        self.dfu_client = DataFileUtil(callback_url)

    def run(self, params):
        """
        params should have the following:
        * workspace_id = id of the workspace to save the report
        * text_input = some random string for the report
        * checkbox_input = a checkbox so we can add other params
        """
        ws_name = params.get('workspace_name', None)
        if ws_name is None:
            raise ValueError('workspace_name is required!')
        report_dir = self._build_report(params.get('text_input', ''),
                                        params.get('checkbox_input', 0))
        results = self._upload_report(report_dir, ws_name)
        return results

    def _build_report(self, text, checked):
        # make the directory
        report_dir = os.path.join(self.scratch_dir, str(uuid.uuid4()))
        self._mkdir_p(report_dir)
        # make some example content
        report_file_content = """
        <html>
        <body>
        <p>
        I am an HTML report. Here's my contents:
        <br>
        <b>Text input:</b><pre>
        {}
        </pre>
        <br>
        <b>Checkbox checked?</b>
        <br>
        {}
        </body>
        </html>
        """.format(text, "yes" if checked == 1 else "no")

        # write the file to <report_dir>/index.html
        report_filename = os.path.join(report_dir, "index.html")
        with open(report_filename, "w") as report_file:
            report_file.write(report_file_content)
        return report_dir

    def _upload_report(self, report_dir, workspace_name):
        upload_info = self.dfu_client.file_to_shock({
            'file_path': report_dir,
            'pack': 'zip'
        })
        shock_id = upload_info['shock_id']

        report_params = {
            'message': 'This is a report message',
            'direct_html_link_index': 0,
            'html_links': [{
                'shock_id': shock_id,
                'name': 'example_report',<commit_msg>another test<commit_after>from KBaseReport.KBaseReportClient import KBaseReport
from DataFileUtil.DataFileUtilClient import DataFileUtil
import uuid
import os
import errno


class ExampleReport(object):
    def __init__(self, callback_url, scratch_dir):
        self.scratch_dir = scratch_dir
        self.report_client = KBaseReport(callback_url)
        self.dfu_client = DataFileUtil(callback_url)

    def run(self, params):
        """
        params should have the following:
        * workspace_id = id of the workspace to save the report
        * text_input = some random string for the report
        * checkbox_input = a checkbox so we can add other params
        """
        ws_name = params.get('workspace_name', None)
        if ws_name is None:
            raise ValueError('workspace_name is required!')
        report_dir = self._build_report(params.get('text_input', ''),
                                        params.get('checkbox_input', 0))
        results = self._upload_report(report_dir, ws_name)
        return results

    def _build_report(self, text, checked):
        # make the directory
        report_dir = os.path.join(self.scratch_dir, str(uuid.uuid4()))
        self._mkdir_p(report_dir)
        # make some example content
        report_file_content = """
        <html>
        <body>
        <p>
        I am an HTML report. Here's my contents:
        <br>
        <b>Text input:</b><pre>
        {}
        </pre>
        <br>
        <b>Checkbox checked?</b>
        <br>
        {}
        </body>
        </html>
        """.format(text, "yes" if checked == 1 else "no")

        # write the file to <report_dir>/index.html
        report_filename = os.path.join(report_dir, "index.html")
        with open(report_filename, "w") as report_file:
            report_file.write(report_file_content)
        return report_dir

    def _upload_report(self, report_dir, workspace_name):
        upload_info = self.dfu_client.file_to_shock({
            'file_path': report_dir,
            'pack': 'zip'
        })
        shock_id = upload_info['shock_id']

        report_params = {
            'message': 'This is a report message',
            'direct_html_link_index': 0,
            'html_links': [{
                'shock_id': shock_id,
                'name': 'index.html',
{'fraction_non_alphanumeric': 0.10088191008819102, 'fraction_numerical': 0.0017208001720800173, 'mean_word_length': 2.135536075522589, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3205211', 'n_tokens_mistral': 1369, 'n_tokens_neox': 1329, 'n_words': 330}