<commit_before>/*
 * This script rely on
    "sgmap-mes-aides-api": "sgmap/mes-aides-api#replicate",
 */
var config = require('../../backend');
var expect = require('expect');
var _ = require('lodash');

var mongoose = require('mongoose');

// Setup mongoose
var AcceptanceTest = mongoose.model('AcceptanceTest');
var LegacySituation = mongoose.model('LegacySituation');
var Situation = mongoose.model('Situation');

var legacyMapping = require('sgmap-mes-aides-api/lib/simulation/openfisca/mapping');

var migration = require('../../backend/lib/migrations/initial');
var mapping = require('../../backend/lib/openfisca/mapping');

function deepDiffRight(left, right) {
  // if they are equals, return undefined
  if (_.isEqual(left, right)) { return; }
  // form now on, we can assure that `left` and `right` are not equals (equivalents)

  // if `left` and `right` are primitives, value changed
  // if `left` is a primitive and `right` an object, value has been replaced with an object
  // if `left` is an object and `right` a primitive, value has been replaced with a primitive
  // use `_.copy` to prevent object referrence issues
  if (! _.isObject(left) || ! _.isObject(right)) { return _.cloneDeep(right); }

  // make `result` the same type as `right`
  var result = _.isArray(right) ? [] : {};

  // since we know that both are objects,
  // iterate on `right` to see what changed or what's new in `right`
  _.forEach(right, function (value, key) {
    // recursion
    var diff = deepDiffRight(left[key], right[key]);
    // since the function returns undefined when `left` and `right` are equals,
    // only assing non-undefined values to result
    if (! _.isUndefined(diff)) {
        result[key] = diff;
    }
  });

  //console.log(result, (! result.length), (! Object.keys(result).length));
  if ((! result.length) && (! Object.keys(result).length)) { return; }

  return result;
}

function processSituations(err, retrievedTests) {
    if (err) {<commit_msg>Improve diff function used in migration validation<commit_after>/*
 * This script rely on
    "sgmap-mes-aides-api": "sgmap/mes-aides-api#replicate",
 */
var config = require('../../backend');
var expect = require('expect');
var _ = require('lodash');

var mongoose = require('mongoose');

// Setup mongoose
var AcceptanceTest = mongoose.model('AcceptanceTest');
var LegacySituation = mongoose.model('LegacySituation');
var Situation = mongoose.model('Situation');

var legacyMapping = require('sgmap-mes-aides-api/lib/simulation/openfisca/mapping');

var migration = require('../../backend/lib/migrations/initial');
var mapping = require('../../backend/lib/openfisca/mapping');

function deepDiffRight(left, right) {
  // if they are equals, return undefined
  if (_.isEqual(left, right)) { return; }
  if (_.isNumber(left) && _.isNumber(right) && Math.abs(right-left)<0.000001) { return; }
  // form now on, we can assure that `left` and `right` are not equals (equivalents)

  // if `left` and `right` are primitives, value changed
  // if `left` is a primitive and `right` an object, value has been replaced with an object
  // if `left` is an object and `right` a primitive, value has been replaced with a primitive
  // use `_.copy` to prevent object referrence issues
  if (! _.isObject(left) || ! _.isObject(right)) { return _.cloneDeep(right); }

  // make `result` the same type as `right`
  var result = _.isArray(right) ? [] : {};

  // since we know that both are objects,
  // iterate on `right` to see what changed or what's new in `right`
  _.forEach(right, function (value, key) {
    // recursion
    var diff = deepDiffRight(left[key], right[key]);
    // since the function returns undefined when `left` and `right` are equals,
    // only assing non-undefined values to result
    if (! _.isUndefined(diff)) {
        result[key] = diff;
    }
  });

  //console.log(result, (! result.length), (! Object.keys(result).length));
  if ((! result.length) && (! Object.keys(result).length)) { return; }

  return result;
}

function processSituations(err, retrievedTests) {
    if (err) {
{'fraction_non_alphanumeric': 0.15314873805439844, 'fraction_numerical': 0.0017152658662092624, 'mean_word_length': 3.7520372526193246, 'pattern_counts': {'":': 2, '<': 4, '<?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': '1749387', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1239, 'n_words': 391}