Created
March 22, 2012 15:53
-
-
Save knowuh/2159155 to your computer and use it in GitHub Desktop.
Transformation rule snippet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*globals MySystem rules nodes suggestions*/ | |
// returns uuids for energytypes or 'unidenitfied_type' | |
var linkTypes = function(node,linkTypes) { | |
var links = node.get(linkTypes); | |
return links.map( function (link) { | |
return link.get('energyType') || 'unidenitfied_type'; | |
}); | |
}; | |
// does <node> have a transform? | |
var hasTransform = function (node) { | |
var inLinks = linkTypes(node,'inLinks').toArray(); | |
var outLinks = linkTypes(node,'outLinks').toArray(); | |
// we must have in and outlinks to transform | |
if (inLinks.length < 1) { return false; } | |
if (outLinks.length < 1) { return false; } | |
// search for an outlink not in inlinks. | |
for (var i = outLinks.length - 1; i >= 0; i--) { | |
if (inLinks.indexOf(outLinks[i]) < 0) { return true; } | |
}; | |
return false; | |
}; | |
// 1) "revise your diagram to show how energy is transformed" | |
// | |
if (nodes.filter(hasTransform).length < 1) { | |
suggestions.pushObject("We’ve detected a problem with your diagram. Use evidence from Step 1.2 and Step 1.3 and revise your diagram to show how energy is transformed."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment