<commit_before>'use strict';

/**
 * Module dependencies.
 */
var mongoose = require('mongoose'),
    ExperimentSchema = mongoose.model('ExperimentSchema');

/**
 * List of Experiment schemas
 */
exports.list = function(req, res) {

    ExperimentSchema.find({}, function(err, schemas) {

        if (err) {
            res.json(500, {error: err.message});
        } else {
            res.json(200, schemas);
        }
    });
};

/**
 * Build a random experiment from a random ExperimentSchema
 */
exports.random = function(req, res) {

    function errorHandler(err) {
        res.json(500, {error: err.message});
    }

    ExperimentSchema.count({}, function(err, count) {

        if (err) {
            return errorHandler(err);
        } else if (count < 1) {
            return errorHandler(new Error('No experiment schemas in' +
                ' database.'));
        } else {

            // Get a random number from [0, number of schema)
            var rand = Math.floor(Math.random() * count);

            // Get a random schema
            ExperimentSchema.find({})
                .skip(rand)
                .limit(1)
                .populate('mediaPool', 'artist title label')
                .exec(function(err, schema) {

                    if (err) {
                        return errorHandler(err);
                    }

                    // Using the controller, build an experiment from this
                    // schema
                    schema[0].buildExperiment(function(err, builtExperiment) {

                        // Send the response
                        res.json(200, builtExperiment);<commit_msg>Change deprecated call to res.json(status, body)<commit_after>'use strict';

/**
 * Module dependencies.
 */
var mongoose = require('mongoose'),
    ExperimentSchema = mongoose.model('ExperimentSchema');

/**
 * List of Experiment schemas
 */
exports.list = function(req, res) {

    ExperimentSchema.find({}, function(err, schemas) {

        if (err) {
            res.json(500, {error: err.message});
        } else {
            res.json(200, schemas);
        }
    });
};

/**
 * Build a random experiment from a random ExperimentSchema
 */
exports.random = function(req, res) {

    function errorHandler(err) {
        res.json(500, {error: err.message});
    }

    ExperimentSchema.count({}, function(err, count) {

        if (err) {
            return errorHandler(err);
        } else if (count < 1) {
            return errorHandler(new Error('No experiment schemas in' +
                ' database.'));
        } else {

            // Get a random number from [0, number of schema)
            var rand = Math.floor(Math.random() * count);

            // Get a random schema
            ExperimentSchema.find({})
                .skip(rand)
                .limit(1)
                .populate('mediaPool', 'artist title label')
                .exec(function(err, schema) {

                    if (err) {
                        return errorHandler(err);
                    }

                    // Using the controller, build an experiment from this
                    // schema
                    schema[0].buildExperiment(function(err, builtExperiment) {

                        // Send the response
                        res.status(200).json(builtExperiment);
{'fraction_non_alphanumeric': 0.1205758848230354, 'fraction_numerical': 0.009598080383923215, 'mean_word_length': 1.611589663273297, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '2763960', 'n_tokens_mistral': 915, 'n_tokens_neox': 850, 'n_words': 219}