<commit_before>var fs = require('fs');
var request = require('request');
var async = require('async');
var getOsmSubmissionsDirs = require('../helpers/get-osm-submissions-dirs');
var generateChangeset = require('../osm/generate-changeset');
var osm2osc = require('../osm/osm2osc');

var NUM_PARALLEL_SUBMISSIONS = 3;

module.exports = {
    submitAllChangesetsForForm: submitAllChangesetsForForm,
    createAndSubmitChangesets: createAndSubmitChangesets
};

/**
 * Submits all of the OSM files in a form's submissions directory
 * that have not yet been submitted.
 * 
 * @param formName - the name of the form (form_id)
 * @param osmApi   - OSM API endpoint and credentials
 * @param cb       - callback with error or status
 */
function submitAllChangesetsForForm(formName, osmApi, cb) {
    getOsmSubmissionsDirs(formName, {unsubmittedOnly: true}, function (err, osmDirs) {
        if (err) {
            cb(err);
            return;
        }
        createAndSubmitChangesets(osmDirs, osmApi, cb);
    });
}

function createAndSubmitChangesets(osmDirs, osmApi, cb) {
    // if case no callback is supplied, noop
    if (typeof cb !== 'function') {
        cb = function() {};
    }

    if (Object.keys(osmDirs).length < 1) {
        cb(null, {
            done: true,
            msg: 'There are no OSM files to submit. Skipping creating and submitting changesets.',
            status: 200
        });
        return;
    }

    async.forEachOfLimit(osmDirs, NUM_PARALLEL_SUBMISSIONS, createChangesetAndOsc, function (err) {
        if (err) {<commit_msg>#63 OSM API is having major deadlock problem when submitting automatically when ODK Collect uploads.<commit_after>var fs = require('fs');
var request = require('request');
var async = require('async');
var getOsmSubmissionsDirs = require('../helpers/get-osm-submissions-dirs');
var generateChangeset = require('../osm/generate-changeset');
var osm2osc = require('../osm/osm2osc');

var NUM_PARALLEL_SUBMISSIONS = 3;

module.exports = {
    submitAllChangesetsForForm: submitAllChangesetsForForm,
    createAndSubmitChangesets: createAndSubmitChangesets
};

/**
 * Submits all of the OSM files in a form's submissions directory
 * that have not yet been submitted.
 * 
 * @param formName - the name of the form (form_id)
 * @param osmApi   - OSM API endpoint and credentials
 * @param cb       - callback with error or status
 */
function submitAllChangesetsForForm(formName, osmApi, cb) {
    getOsmSubmissionsDirs(formName, {unsubmittedOnly: true}, function (err, osmDirs) {
        if (err) {
            cb(err);
            return;
        }
        createAndSubmitChangesets(osmDirs, osmApi, cb);
    });
}

function createAndSubmitChangesets(osmDirs, osmApi, cb) {

    if (typeof cb !== 'function') {
        cb = function(err) {
            if (err) {
                console.error('Automatic OMK submission OSM API error. ' + JSON.stringify(err));
            }
        };
    }

    if (Object.keys(osmDirs).length < 1) {
        cb(null, {
            done: true,
            msg: 'There are no OSM files to submit. Skipping creating and submitting changesets.',
            status: 200
        });
        return;
    }

    async.forEachOfLimit(osmDirs, NUM_PARALLEL_SUBMISSIONS, createChangesetAndOsc, function (err) {
        if (err) {
{'fraction_non_alphanumeric': 0.11107757319649864, 'fraction_numerical': 0.004829459704195593, 'mean_word_length': 2.964114832535885, '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': '905351', 'n_tokens_mistral': 1053, 'n_tokens_neox': 1002, 'n_words': 272}