Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fc-pregmod
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pregmodfan
fc-pregmod
Commits
538bfb99
Commit
538bfb99
authored
6 years ago
by
kopareigns
Browse files
Options
Downloads
Patches
Plain Diff
NaN debug helper
parent
084f3c47
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!2722
NaN debug helper
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
devNotes/twine JS.txt
+86
-1
86 additions, 1 deletion
devNotes/twine JS.txt
src/debugging/debugJS.tw
+14
-0
14 additions, 0 deletions
src/debugging/debugJS.tw
src/uncategorized/main.tw
+7
-0
7 additions, 0 deletions
src/uncategorized/main.tw
with
107 additions
and
1 deletion
devNotes/twine JS.txt
+
86
−
1
View file @
538bfb99
...
...
@@ -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;
};
This diff is collapsed.
Click to expand it.
src/debugging/debugJS.tw
+
14
−
0
View file @
538bfb99
...
...
@@ -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;
};
This diff is collapsed.
Click to expand it.
src/uncategorized/main.tw
+
7
−
0
View file @
538bfb99
...
...
@@ -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()>>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment