Created
March 22, 2012 21:36
-
-
Save knowuh/2164750 to your computer and use it in GitHub Desktop.
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("No transformations"); | |
} | |
/******************** Original rules follow ***********/ | |
//Energy Source (sun->chlo or sun->plant->chlro) | |
if(!(rules.objectAt(0).check(nodes)||(rules.objectAt(7).check(nodes)&& rules.objectAt(8).check(nodes)))){ | |
suggestions.pushObject("Your diagram does not show how the sun helps plants grow. Go back to Step 1.2 to find out and revise your diagram."); | |
} | |
//Energy Transform | |
// No transformation or Incorrect Transformation | |
if(!rules.objectAt(1).check(nodes)){ | |
suggestions.pushObject("Use evidence from Step 1.2 and Step 1.3 and revise your diagram to show what happens to light energy during photosynthesis."); | |
} else if (rules.objectAt(1).check(nodes)&&!rules.objectAt(2).check(nodes)){ | |
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."); | |
} | |
//Energy release I | |
//Glucose->mito | |
if(!rules.objectAt(3).check(nodes)){ | |
suggestions.pushObject("Your diagram does not show what plants do with glucose during cellular respiration. Review the visualizations in Step 3.3 and Step 3.9 to find out and improve your diagram."); | |
} else if (rules.objectAt(3).check(nodes)&&!rules.objectAt(4).check(nodes)){ | |
suggestions.pushObject("We’ve detected a problem with your diagram. What kind of energy is stored in glucose? Go back to Step 3.3 to find out and revise your diagram."); | |
} | |
//Energy release II | |
//Mitochondria->Plant | |
if(!rules.objectAt(5).check(nodes)){ | |
suggestions.pushObject("Your diagram does not show what mitochondria do during cellular respiration. Review the visualizations in Step 3.3 and Step 3.9 to find out and improve your diagram."); | |
} else if (rules.objectAt(5).check(nodes)&&!rules.objectAt(6).check(nodes)){ | |
suggestions.pushObject("Revise your diagram to show how energy is released during cellular respiration. Use the visualization in Step 3.9 to find out."); | |
} | |
//”Storage feedback”: Glucose -> Plant | |
if(!(rules.objectAt(9).check(nodes) )) { | |
suggestions.pushObject("Review the visualization in Step 3.3 to find out what plants do with the extra glucose and revise your diagram."); | |
} | |
//icons | |
if(!(rules.objectAt(12).check(nodes)&&rules.objectAt(13).check(nodes) &&rules.objectAt(14).check(nodes) &&rules.objectAt(15).check(nodes) &&rules.objectAt(16).check(nodes))) { | |
suggestions.pushObject("You can use each icon only ONCE. Use evidence from the project and revise your diagram."); | |
} | |
// Look for links that don't match one of the 'should' link rules | |
var links = MySystem.store.find(MySystem.Link), | |
notAllowedLink; | |
links = links.filter(function (link) {return link.isComplete();}); | |
notAllowedLink = links.find(function (link) { | |
var positiveLinkRules = rules.filterProperty('hasLink').filter(function(rule){return !rule.get('not');}); | |
var matchingRule = positiveLinkRules.find(function (rule) { | |
// need to handle the link check here, in the future this should be moved into the core code | |
var paletteItem = rule.paletteItem(rule.get('type')), | |
otherPaletteItem = rule.paletteItem(rule.get('otherNodeType')); | |
switch(rule.get('linkDirection')) { | |
case '-->': | |
return rule.checkLink(link, paletteItem, otherPaletteItem); | |
case '<--': | |
return rule.checkLink(link, otherPaletteItem, paletteItem); | |
case '---': | |
return rule.checkLink(link, paletteItem, otherPaletteItem) || rule.checkLink(link, otherPaletteItem, paletteItem); | |
default: | |
throw "Invalid linkDirection value for diagram rule."; | |
} | |
}); | |
if(!matchingRule){ return YES; }; | |
}); | |
if(notAllowedLink) { | |
suggestions.pushObject("You have some incorrect links in your diagram. Use evidence from the project and revise your diagram. "); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment