<commit_before>'use strict'

var times = require('lodash/times')
var shuffle = require('lodash/shuffle')
var { rater, keys } = require('donut-common')
var debug = require('debug')('donut:regression:test')

function generateDonut () {
  const valuesOnlyDonut = []
  const donut = keys.reduce((nut, key) => {
    const value = Math.random()
    // TERRIBLE EVIL SIDE EFFECT WARNING 👹
    valuesOnlyDonut.push(value)
    return Object.assign(nut, { [key]: value })
  }, {})
  const rating = rater.getIndicator(donut)
  donut['DONUT_RATING'] = rating
  return donut
}

function generateDonnies (numDonnies) {
  var donnies = times(numDonnies).map(generateDonut)
  var percentGoodDonnies = 0
  while (percentGoodDonnies < 0.2) {
    donnies.shift()
    var newDonut = generateDonut()
    while (rater.getIndicator(newDonut) < 0.8) {
      newDonut = generateDonut()
    }
    donnies.push(newDonut)
    var numScoring80Plus = donnies.reduce(
      (agg, donut) => {
        var score = rater.getIndicator(donut)
        if (score >= 0.8) ++agg
        return agg
      },
      0
    )
    percentGoodDonnies = numScoring80Plus / donnies.length
    debug(percentGoodDonnies)
  }
  return shuffle(donnies)
}

module.exports = generateDonnies
<commit_msg>docs(regression): document donut generate fixture<commit_after>'use strict'

var times = require('lodash/times')
var shuffle = require('lodash/shuffle')
var { rater, keys } = require('donut-common')
var debug = require('debug')('donut:regression:test')

function generateDonut () {
  const donut = keys.reduce((nut, key) => {
    const value = Math.random()
    return Object.assign(nut, { [key]: value })
  }, {})
  const rating = rater.getIndicator(donut)
  donut['DONUT_RATING'] = rating
  return donut
}

function generateDonnies (numDonnies) {
  var donnies = times(numDonnies).map(generateDonut)
  var percentGoodDonnies = 0
  while (percentGoodDonnies < 0.2) {
    donnies.shift()
    var newDonut = generateDonut()
    while (rater.getIndicator(newDonut) < 0.8) {
      newDonut = generateDonut()
    }
    donnies.push(newDonut)
    var numScoring80Plus = donnies.reduce(
      (agg, donut) => {
        var score = rater.getIndicator(donut)
        if (score >= 0.8) ++agg
        return agg
      },
      0
    )
    percentGoodDonnies = numScoring80Plus / donnies.length
    debug(percentGoodDonnies)
  }
  return shuffle(donnies)
}

module.exports = generateDonnies

/**
 * run node generate.js <num-donuts>
 * to build a json file w/ <num-donuts> random donuts in it.
 * at least 20% of donuts will have a rating of > 0.8.
 */
{'fraction_non_alphanumeric': 0.12630359212050984, 'fraction_numerical': 0.010814986481266898, 'mean_word_length': 3.4122657580919933, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 12, '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': '1074838', 'n_tokens_mistral': 927, 'n_tokens_neox': 902, 'n_words': 199}