Skip to content
Snippets Groups Projects
Commit 538bfb99 authored by kopareigns's avatar kopareigns
Browse files

NaN debug helper

parent 084f3c47
No related branches found
No related tags found
1 merge request!2722NaN debug helper
......@@ -31480,4 +31480,89 @@ window.progress = function(x,max) {
for (i=0;i<x;i++) out += `█⏐`;
for (i=0;i<z;i++) out += `<span style=\"opacity: 0;\">█</span>⏐`;}
return `${out}`;
};
\ No newline at end of file
};
/*:: DebugJS [script]*/
/*
Given an object, this will return an array where for each property of the original object, we include the object
{variable: property, oldVal: _oldDiff.property, newVal: _newDiff.property}
*/
window.generateDiffArray = function generateDiffArray(obj) {
var diffArray = Object.keys(obj).map(function(key) {
return {variable: key, oldVal: State.temporary.oldDiff[key], newVal: State.temporary.newDiff[key]};
});
return diffArray;
};
/*
Shamelessly copied from https://codereview.stackexchange.com/a/11580
Finds and returns the difference between two objects. Potentially will have arbitrary nestings of objects.
*/
window.difference = function difference(o1, o2) {
var k, kDiff, diff = {};
for (k in o1) {
if (!o1.hasOwnProperty(k)) {
} else if (typeof o1[k] != 'object' || typeof o2[k] != 'object') {
if (!(k in o2) || o1[k] !== o2[k]) {
diff[k] = o2[k];
}
} else if (kDiff = difference(o1[k], o2[k])) {
diff[k] = kDiff;
}
}
for (k in o2) {
if (o2.hasOwnProperty(k) && !(k in o1)) {
diff[k] = o2[k];
}
}
for (k in diff) {
if (diff.hasOwnProperty(k)) {
return diff;
}
}
return false;
};
/*
Shamelessly copied from https://stackoverflow.com/a/19101235
Flattens an object while concatenating property names.
For example {id: {number: 4, name: "A"}} --> {id.number: 4, id.name: "A"}
*/
window.diffFlatten = function diffFlatten(data) {
var result = {};
function recurse (cur, prop) {
if (Object(cur) !== cur) {
result[prop] = cur;
} else if (Array.isArray(cur)) {
for(var i=0, l=cur.length; i<l; i++)
recurse(cur[i], prop + "[" + i + "]");
if (l == 0)
result[prop] = [];
} else {
var isEmpty = true;
for (var p in cur) {
isEmpty = false;
recurse(cur[p], prop ? prop+"."+p : p);
}
if (isEmpty && prop)
result[prop] = {};
}
}
recurse(data, "");
return result;
};
/*
Finds all NaN values anywhere in the State.variables object. Returns an array with the names of the NaNed variables.
*/
window.findNaN = function findNan() {
const flatV = diffFlatten(State.variables);
var result = [];
for (var key in flatV) {
if (Number.isNaN(flatV[key])) {
result.push('$'+key);
}
}
return result;
};
......@@ -68,3 +68,17 @@ window.diffFlatten = function diffFlatten(data) {
recurse(data, "");
return result;
};
/*
Finds all NaN values anywhere in the State.variables object. Returns an array with the names of the NaNed variables.
*/
window.findNaN = function findNan() {
const flatV = diffFlatten(State.variables);
var result = [];
for (var key in flatV) {
if (Number.isNaN(flatV[key])) {
result.push('$'+key);
}
}
return result;
};
......@@ -37,6 +37,13 @@
<<if $slaves.includes(null)>>
<br><br>@@.red;ERROR: Main slaves array contains a null entry! Please report this.@@ <<link "Repair">><<set $slaves.delete(null)>><</link>><<goto "Main">><br><br>
<</if>>
<<set _NaNArray = findNaN()>>
<<if _NaNArray.length > 0>>
<br><br>@@.red;ERROR: The following variables are NaN! Please report this.@@<br>
<<for _main = 0; _main < _NaNArray.length; _main++>>
_NaNArray[_main] <br>
<</for>><br>
<</if>>
/* end extra sanity checks and repair */
<<set _duplicateSlaves = _($slaves).countBy(s => s.ID).pickBy(v => v > 1).keys().map(v => Number(v)).value()>>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment