<commit_before>
// A dataset for a BarChart
export default class BarDataSet {
    constructor(options) {
        this.metricKey = options.metricKey;
        this.scoreUnit = options.scoreUnit;
        this.barGroups = options.barGroups;
        this.data = options.data;
        this.dataMax = options.dataMax;
        this.roundScores = options.roundScores;
        this.paramNames = options.paramNames;
    }
}

import { groupBy, shouldRound, round, formatNumber } from 'functions/util.js'
import { getMetricType } from 'models/MetricType.js'

// The datasets will differ in case the benchmark-class uses params or not:
// 0 - no param => standard
// 1 - one param, single method => convert to (0)
// 2 - one param, multi methods => Bar per param Value
// 3 - 2 params, single methods => convert to (2)
// 4 - 2+ params, multi methods => combine params & convert to (2)
// 5 - 3+ params, single methods => combine params & convert to (0)
export function createDataSetFromBenchmarks(benchmarkBundle, metricExtractor, sort) {
    const benchmarkMethods = benchmarkBundle.benchmarkMethods;
    const methodCount = benchmarkBundle.methodNames.length;
    const metricType = metricExtractor.extractType(benchmarkMethods[0].benchmarks[0]);
    const params = benchmarkMethods[0].params; //TODO get from collection as well ?
    const scoreUnit = metricExtractor.hasMetric(benchmarkMethods[0].benchmarks[0]) ? metricExtractor.extractScoreUnit(benchmarkMethods[0].benchmarks[0]) : '';

    if (!params) {
        //case 0
        return createBarDataSet(benchmarkMethods, metricExtractor, sort, (method) => method.name, () => `${metricType} ${scoreUnit}`, []);
    } else { // all other cases
        const paramNames = params.map(param => param[0]);
        if (paramNames.length == 1) {
            if (methodCount == 1) {
                // case 1
                return createBarDataSet(benchmarkMethods, metricExtractor, sort, (method) => `${method.params[0][0]} =  ${method.params[0][1]}`, () => `${metricType} ${scoreUnit}`, []);
            } else {
                // case 2
                return createBarDataSet(benchmarkMethods, metricExtractor, sort, (method) => method.name, (method) => method.params[0][1], paramNames);
            }
        } else if (paramNames.length == 2 && methodCount == 1) {
            // case 3
            return createBarDataSet(benchmarkMethods, metricExtractor, sort, (method) => `${method.params[0][0]} = ${method.params[0][1]}`, (method) => method.params[1][1], [paramNames[1]]);
        } else {
            if (methodCount > 1) {
                // case 4
                return createBarDataSet(benchmarkMethods, metricExtractor, sort, (method) => method.name, (method) => method.params.map(param => param[1]).join(':'), paramNames);
            } else {<commit_msg>Quick hack for heterogenous test setups of a class<commit_after>
// A dataset for a BarChart
export default class BarDataSet {
    constructor(options) {
        this.metricKey = options.metricKey;
        this.scoreUnit = options.scoreUnit;
        this.barGroups = options.barGroups;
        this.data = options.data;
        this.dataMax = options.dataMax;
        this.roundScores = options.roundScores;
        this.paramNames = options.paramNames;
    }
}

import { groupBy, shouldRound, round, formatNumber } from 'functions/util.js'
import { getMetricType } from 'models/MetricType.js'

// The datasets will differ in case the benchmark-class uses params or not:
// 0 - no param => standard
// 1 - one param, single method => convert to (0)
// 2 - one param, multi methods => Bar per param Value
// 3 - 2 params, single methods => convert to (2)
// 4 - 2+ params, multi methods => combine params & convert to (2)
// 5 - 3+ params, single methods => combine params & convert to (0)
export function createDataSetFromBenchmarks(benchmarkBundle, metricExtractor, sort) {
    const benchmarkMethods = benchmarkBundle.benchmarkMethods;
    const methodCount = benchmarkBundle.methodNames.length;
    const metricType = metricExtractor.extractType(benchmarkMethods[0].benchmarks[0]);
    const params = benchmarkMethods[0].params; //TODO get from collection as well ?
    const scoreUnit = metricExtractor.hasMetric(benchmarkMethods[0].benchmarks[0]) ? metricExtractor.extractScoreUnit(benchmarkMethods[0].benchmarks[0]) : '';

    if (!params) {
        //case 0
        return createBarDataSet(benchmarkMethods, metricExtractor, sort, (method) => method.name, () => `${metricType} ${scoreUnit}`, []);
    } else { // all other cases
        const paramNames = params.map(param => param[0]);
        if (paramNames.length == 1) {
            if (methodCount == 1) {
                // case 1
                return createBarDataSet(benchmarkMethods, metricExtractor, sort, (method) => `${method.params[0][0]} =  ${method.params[0][1]}`, () => `${metricType} ${scoreUnit}`, []);
            } else {
                // case 2
                return createBarDataSet(benchmarkMethods, metricExtractor, sort, (method) => method.name, (method) => {
                  // Kind of a hack.
                  // The tests of a class aren't homogenous but the code is build on that assumption.
                  // While this prevents an inital error, it might lead to a break down later down the road.
                  // The sane option would probably be to distribute the benchmark methods to in different bundles (and have different charts)
                  if (!method.params) {
                    return "";
                  }
                  return method.params[0][1];
                }, paramNames);
            }
        } else if (paramNames.length == 2 && methodCount == 1) {
            // case 3
            return createBarDataSet(benchmarkMethods, metricExtractor, sort, (method) => `${method.params[0][0]} = ${method.params[0][1]}`, (method) => method.params[1][1], [paramNames[1]]);
        } else {
            if (methodCount > 1) {
                // case 4
                return createBarDataSet(benchmarkMethods, metricExtractor, sort, (method) => method.name, (method) => method.params.map(param => param[1]).join(':'), paramNames);
            } else {
{'fraction_non_alphanumeric': 0.12914174882818813, 'fraction_numerical': 0.014546630030709553, 'mean_word_length': 2.7344598672299334, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 41, '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': '2550752', 'n_tokens_mistral': 1735, 'n_tokens_neox': 1675, 'n_words': 483}