<commit_before>var fs = require('fs');
var writeFile = require('fs-writefile-promise');
var path = require('path');
var config = require('../config/config');
var coverageConfig = require('../config/coverage-config');
var util = require('../util');
var RSVP = require('rsvp');

/**
 * Determines whether a certain item of the ArcGIS REST API is covered or not
 * @param {object} coverage Coverage object that contains number of completed items, total count, description all items
 * @param {object} coverageItem Item who coverage will be checked
 * @returns {string} Text representation of whether an item is covered or not
 */
function getCoverage(coverage, coverageItem) {
  if (coverageItem.hasOwnProperty("children") && coverageItem.children.length != 0) {
    coverage.description += "**" + coverageItem.title + "**  \n";
    return coverageItem.children.reduce(getCoverage, coverage);
  }
  else if (!coverageItem.hasOwnProperty("children") && coverageItem.title != "") {
    if (util.checkIfFileExists(config.outputFolder, coverageItem.schema + ".json")) {
      coverage.description += "✔ ";
      coverage.completed += 1;
    }
    else {
      coverage.description += "✖ ";
    }
    coverage.itemsCount += 1;
    coverage.description += "[" + coverageItem.title + "](" + coverageItem.url + ")" + "  \n";
    return coverage;
  }
  else {
    return coverage;
  }
}

/**
 * Collects coverage for all ArcGIS REST API items. Writes results to file specified in config.coverageFile
 * @returns {object} Promise. The resolve function has no parameters.
 */
function collectCoverage() {
  return new RSVP.Promise(function (resolve, reject) {
    var coverage = {
      completed: 0,
      itemsCount: 0,
      description: ""
    };
    coverage = coverageConfig.reduce(getCoverage, coverage);<commit_msg>Fixed having to build twice to get correct coverage<commit_after>var fs = require('fs');
var writeFile = require('fs-writefile-promise');
var path = require('path');
var config = require('../config/config');
var coverageConfig = require('../config/coverage-config');
var util = require('../util');
var RSVP = require('rsvp');

/**
 * Determines whether a certain item of the ArcGIS REST API is covered or not
 * @param {object} coverage Coverage object that contains number of completed items, total count, description all items
 * @param {object} coverageItem Item who coverage will be checked
 * @returns {string} Text representation of whether an item is covered or not
 */
function getCoverage(coverage, coverageItem) {
  if (coverageItem.hasOwnProperty("children") && coverageItem.children.length != 0) {
    coverage.description += "**" + coverageItem.title + "**  \n";
    return coverageItem.children.reduce(getCoverage, coverage);
  }
  else if (!coverageItem.hasOwnProperty("children") && coverageItem.title != "") {
    if (util.checkIfFileExists(config.schemasFolder, coverageItem.schema + ".json")) {
      coverage.description += "✔ ";
      coverage.completed += 1;
    }
    else {
      coverage.description += "✖ ";
    }
    coverage.itemsCount += 1;
    coverage.description += "[" + coverageItem.title + "](" + coverageItem.url + ")" + "  \n";
    return coverage;
  }
  else {
    return coverage;
  }
}

/**
 * Collects coverage for all ArcGIS REST API items. Writes results to file specified in config.coverageFile
 * @returns {object} Promise. The resolve function has no parameters.
 */
function collectCoverage() {
  return new RSVP.Promise(function (resolve, reject) {
    var coverage = {
      completed: 0,
      itemsCount: 0,
      description: ""
    };
    coverage = coverageConfig.reduce(getCoverage, coverage);
{'fraction_non_alphanumeric': 0.13344271260596116, 'fraction_numerical': 0.0027344818156959257, 'mean_word_length': 3.83223249669749, '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': '4517391', 'n_tokens_mistral': 1034, 'n_tokens_neox': 1024, 'n_words': 311}