<commit_before>const fs = require('fs');
const path = require('path');

class Evaluator {
    constructor ({projectId}) {
        this.problems = this.constructor.ProblemClasses.map(ProblemClass =>
            new ProblemClass({projectId}));

        this.causes = this.constructor.CauseClasses.map(CauseClass =>
            new CauseClass({projectId}));

        this.solvers = this.constructor.SolverClasses.map(SolverClass =>
            new SolverClass({projectId}));
    }

    static get ProblemClasses () {
        return this._requires('problems');
    }

    static get CauseClasses () {
        return this._requires('causes');
    }

    static get SolverClasses () {
        return this._requires('solvers');
    }

    static _requires (dirname) {
        const dirPath = path.join(__dirname, dirname);
        return fs
            .readdirSync(dirPath)
            .filter(file => file.indexOf('.') !== 0)
            .filter(file => !file.endsWith('_abstract.js'))
            .map(file => require(path.join(dirPath, file)));
    }

    serialize () {
        return {
            problems: this.problems.map(problem => ({
                name: problem.constructor.name,
                title: problem.constructor.title,
                goodDescription: problem.constructor.goodDescription,
                badDescription: problem.constructor.badDescription,
                causes: problem.causes.map(cause => cause.constructor.name)
            })),
            causes: this.causes.map(cause => ({
                name: cause.constructor.name,
                title: cause.constructor.title,
                solvers: cause.solvers.map(solver => solver.constructor.name)
            })),
            solvers: this.solvers.map(solver => ({
                name: solver.constructor.name,
                title: solver.constructor.title,
                description: solver.constructor.description
            }))
        };
    }
}

module.exports = Evaluator;<commit_msg>sort evaluations by name<commit_after>const fs = require('fs');
const path = require('path');
const sortBy = require('lodash/sortBy');

class Evaluator {
    constructor ({projectId}) {
        this.problems = this.constructor.ProblemClasses.map(ProblemClass =>
            new ProblemClass({projectId}));

        this.causes = this.constructor.CauseClasses.map(CauseClass =>
            new CauseClass({projectId}));

        this.solvers = this.constructor.SolverClasses.map(SolverClass =>
            new SolverClass({projectId}));
    }

    static get ProblemClasses () {
        return this._requires('problems');
    }

    static get CauseClasses () {
        return this._requires('causes');
    }

    static get SolverClasses () {
        return this._requires('solvers');
    }

    static _requires (dirname) {
        const dirPath = path.join(__dirname, dirname);
        return fs
            .readdirSync(dirPath)
            .filter(file => file.indexOf('.') !== 0)
            .filter(file => !file.endsWith('_abstract.js'))
            .map(file => require(path.join(dirPath, file)));
    }

    serialize () {
        return {
            problems: sortBy(this.problems.map(problem => ({
                name: problem.constructor.name,
                title: problem.constructor.title,
                goodDescription: problem.constructor.goodDescription,
                badDescription: problem.constructor.badDescription,
                causes: problem.causes.map(cause => cause.constructor.name)
            })), 'name'),
            causes: sortBy(this.causes.map(cause => ({
                name: cause.constructor.name,
                title: cause.constructor.title,
                solvers: cause.solvers.map(solver => solver.constructor.name)
            })), 'name'),
            solvers: sortBy(this.solvers.map(solver => ({
                name: solver.constructor.name,
                title: solver.constructor.title,
                description: solver.constructor.description
            })), 'name')
        };
    }
}

module.exports = Evaluator;
{'fraction_non_alphanumeric': 0.1251840942562592, 'fraction_numerical': 0.0004909180166912126, 'mean_word_length': 2.059309309309309, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '2540161', 'n_tokens_mistral': 1123, 'n_tokens_neox': 1046, 'n_words': 186}