<commit_before>var performance = system.performance,
    dateFormat = '%m-%d-%y-%I%M%p';

function arrayToCSVFile (arr, path) {
    var data = csv().from.array(arr);
    return data.to.stream(fs.createWriteStream(path));
}

exports.exportNumFollowersResults = function(results){
    var csvPath = system.pathTo(performance.RESULTS_DIR, 'performance-followers-' + moment().strftime(dateFormat) + '.csv');

    //Convert to results to CSV table
    var csvResults = [['Number of Followers', 'Completion Time']].concat(_.map(results, function (result) {
        return [result.user.follows.length, result.time];
    }));

    //Ensure results folder exists
    return fs.makeIfExists(performance.RESULTS_DIR).then(function () {
        //Write array to file
        arrayToCSVFile(csvResults, csvPath);
        console.log('results written to ' + csvPath);
    });
}

exports.exportConcurrencyResults = function(results){
    var csvPath = system.pathTo(performance.RESULTS_DIR, 'performance-concurrency-' + moment().strftime(dateFormat) + '.csv');

    //Convert to results to CSV table
    var csvResults = [['# Concurrent Requests', 'Mean Completion Time']].concat(_.map(results, function (resultSet) {
        var meanReply = _.reduce(resultSet, function(mem, obj) {
            return mem + obj.time;
        }, 0) / resultSet.length || 0;

        return [resultSet.length, meanReply];
    }));

    //Ensure results folder exists
    return fs.makeIfExists(performance.RESULTS_DIR).then(function () {
        //Write array to file
        arrayToCSVFile(csvResults, csvPath);
        console.log('results written to ' + csvPath);
    });
}<commit_msg>Return promise resolved after CSV is written<commit_after>var performance = system.performance,
    dateFormat = '%m-%d-%y-%I%M%p';

function arrayToCSVFile (arr, path) {
    var defer = q.defer(),
        data = csv().from.array(arr);
    return data.to.stream(fs.createWriteStream(path))
        .on('close', function () {
            console.log('results written to ' + path);
            defer.resolve();
        });

    return defer.promise;
}

exports.exportNumFollowersResults = function(results){
    var csvPath = system.pathTo(performance.RESULTS_DIR, 'performance-followers-' + moment().strftime(dateFormat) + '.csv');

    //Convert to results to CSV table
    var csvResults = [['Number of Followers', 'Completion Time']].concat(_.map(results, function (result) {
        return [result.user.follows.length, result.time];
    }));

    //Ensure results folder exists
    return fs.makeIfExists(performance.RESULTS_DIR).then(function () {
        //Write array to file
        return arrayToCSVFile(csvResults, csvPath);
    });
}

exports.exportConcurrencyResults = function(results){
    var csvPath = system.pathTo(performance.RESULTS_DIR, 'performance-concurrency-' + moment().strftime(dateFormat) + '.csv');

    //Convert to results to CSV table
    var csvResults = [['# Concurrent Requests', 'Mean Completion Time']].concat(_.map(results, function (resultSet) {
        var meanReply = _.reduce(resultSet, function(mem, obj) {
            return mem + obj.time;
        }, 0) / resultSet.length || 0;

        return [resultSet.length, meanReply];
    }));

    //Ensure results folder exists
    return fs.makeIfExists(performance.RESULTS_DIR).then(function () {
        //Write array to file
        return arrayToCSVFile(csvResults, csvPath);
    });
}
{'fraction_non_alphanumeric': 0.13756922180122413, 'fraction_numerical': 0.0011658408627222385, 'mean_word_length': 3.322418136020151, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2741905', 'n_tokens_mistral': 1044, 'n_tokens_neox': 979, 'n_words': 229}