<commit_before>##############################################################################
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
##############################################################################
# -*- coding: utf-8 -*-
import logging
import os
import pickle
import csv
import numpy as np

__author__ = "<NAME>"
__copyright__ = "Copyright 2016, PMP SA"
__license__ = "GPL2.0"
__email__ = "<EMAIL>"

logger = logging.getLogger(__name__)


class BenchStore(object):
    @staticmethod
    def report(folder, kind="raw", path=None):
        """ By default, report creates a CSV file with the benchmark results
        for each function and method used
        If kind is ``raw`` no file is generated, a dict is returned with
        Method/Function/values
        If kind is ``csv``, a csv file is generated with the results
        If kind is ``rst``, a rst file is generated with the table in rst
        format.
        """
        files = os.listdir(folder)
        files = [x for x in files if x.endswith('.data')]
        files = sorted(files)
        if kind == 'csv':
            with open(path, 'wb') as csvfile:
                csvwriter = csv.writer(
                        csvfile, delimiter=',',
                        quotechar='|', quoting=csv.QUOTE_MINIMAL
                        )
                csvwriter.writerow([
                    'Function name', 'Algorithm', 'Success Rate', 'Best',
                    'Average', 'Worst', 'Std', 'fvalue (mean)',
                    'Mean time (ms)', 'Median All',
                    ])
                for f in files:
                    with open(os.path.join(folder, f), 'rb') as fh:
                        bu = pickle.load(fh)
                        logger.info('Processing benchunit: {0}'.format(bu))
                        et = bu.time
                        if et < 0:
                            et = np.inf
                        else:
                            et *= 1000
                        success_rate = np.round(np.where(
                            bu.success)[0].size * 100 / bu.success.size, 1)<commit_msg>Fixed writing csv files in ascii mode, binary created issues<commit_after>##############################################################################
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
##############################################################################
# -*- coding: utf-8 -*-
import logging
import os
import pickle
import csv
import numpy as np

__author__ = "<NAME>"
__copyright__ = "Copyright 2016, PMP SA"
__license__ = "GPL2.0"
__email__ = "<EMAIL>"

logger = logging.getLogger(__name__)


class BenchStore(object):
    @staticmethod
    def report(folder, kind="raw", path=None):
        """ By default, report creates a CSV file with the benchmark results
        for each function and method used
        If kind is ``raw`` no file is generated, a dict is returned with
        Method/Function/values
        If kind is ``csv``, a csv file is generated with the results
        If kind is ``rst``, a rst file is generated with the table in rst
        format.
        """
        files = os.listdir(folder)
        files = [x for x in files if x.endswith('.data')]
        files = sorted(files)
        if kind == 'csv':
            with open(path, 'w') as csvfile:
                csvwriter = csv.writer(
                        csvfile, delimiter=',',
                        quotechar='|', quoting=csv.QUOTE_MINIMAL
                        )
                csvwriter.writerow([
                    'Function name', 'Algorithm', 'Success Rate', 'Best',
                    'Average', 'Worst', 'Std', 'fvalue (mean)',
                    'Mean time (ms)', 'Median All',
                    ])
                for f in files:
                    with open(os.path.join(folder, f), 'rb') as fh:
                        bu = pickle.load(fh)
                        logger.info('Processing benchunit: {0}'.format(bu))
                        et = bu.time
                        if et < 0:
                            et = np.inf
                        else:
                            et *= 1000
                        success_rate = np.round(np.where(
                            bu.success)[0].size * 100 / bu.success.size, 1)
{'fraction_non_alphanumeric': 0.15910064239828695, 'fraction_numerical': 0.007708779443254818, 'mean_word_length': 1.7836710369487485, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4589773', 'n_tokens_mistral': 1224, 'n_tokens_neox': 1112, 'n_words': 418}