Difference between revisions of "MemEOL"
From Desal Wiki
Line 255: | Line 255: | ||
return result; | return result; | ||
} | } | ||
+ | |||
+ | function initialise(){ | ||
+ | var preferences = getPreferences(); //get preferences | ||
+ | var scores = computePreferenceScores(preferences); //calculate matrix and produce scores for each criterion | ||
+ | console.log(scores); | ||
+ | var scoreObject = scoresArrayToObject(scores); //convert from array to object | ||
+ | //now that we can access the scores by name we can make the additonal calculations for reuse as RO and conversion to UF | ||
+ | for (var property in scoreObject) { | ||
+ | if (scoreObject.hasOwnProperty(property)) { | ||
+ | console.log(scoreObject[property]); | ||
+ | } | ||
+ | } | ||
+ | //adjust UF score | ||
+ | if(scoreObject.hasOwnProperty(CONST_CONV_TO_UF)){ | ||
+ | scoreObject[CONST_CONV_TO_UF] = conversionToUFCalc(scoreObject[CONST_CONV_TO_UF], getPhysicalDamage()); | ||
+ | } | ||
+ | for (var property in scoreObject) { | ||
+ | if (scoreObject.hasOwnProperty(property)) { | ||
+ | console.log(scoreObject[property]); | ||
+ | } | ||
+ | } | ||
+ | //adjust RO score & determine RO reuse quality | ||
+ | var roReuseResult=0; | ||
+ | if(scoreObject.hasOwnProperty(CONST_REUSE_RO)){ | ||
+ | console.log('physical damage: ' + String(getPhysicalDamage())); | ||
+ | console.log('permeability: ' + String(getPermeability())); | ||
+ | console.log('salt rejection: ' + String(getNaClRejection())); | ||
+ | roReuseResult = calculateROReuseQuality(getPhysicalDamage(), getPermeability(), getNaClRejection()); | ||
+ | console.log('roReuseResult: ' + String(roReuseResult)); | ||
+ | if(roReuseResult===-1){ | ||
+ | scoreObject[CONST_REUSE_RO]=0; | ||
+ | } | ||
+ | } | ||
+ | //determine highest score & second highest scores | ||
+ | var max=-1; | ||
+ | var maxName=""; | ||
+ | var second=-1; | ||
+ | var secondName=""; | ||
+ | for (var property in scoreObject) { | ||
+ | if (scoreObject.hasOwnProperty(property)) { | ||
+ | if(scoreObject[property]>max){ | ||
+ | max = scoreObject[property]; | ||
+ | maxName=property; | ||
+ | } else if (scoreObject[property]===max) { | ||
+ | second = scoreObject[property]; | ||
+ | secondName=property; | ||
+ | //ignore case that max===second===third | ||
+ | } else if (scoreObject[property]>=second) { | ||
+ | second = scoreObject[property]; | ||
+ | secondName=property; | ||
+ | } | ||
+ | } | ||
+ | console.log(property + ': ' + String(scoreObject[property])); | ||
+ | console.log(maxName + ': ' + String(max)); | ||
+ | console.log(secondName + ': ' + String(second)); | ||
+ | } | ||
+ | console.log('final ' + maxName + ': ' + String(max)); | ||
+ | console.log('final ' + secondName + ': ' + String(second)); | ||
+ | |||
+ | displayResults(maxName, secondName); | ||
+ | $('.nav-pills > .active').next('li').find('a').trigger('click'); | ||
+ | } | ||
$( document ).ready(function() { | $( document ).ready(function() { | ||
Line 262: | Line 324: | ||
// Prevent form submission | // Prevent form submission | ||
e.preventDefault(); | e.preventDefault(); | ||
+ | initialise(); | ||
//$('.nav-pills > .active').next('li').find('a').trigger('click'); | //$('.nav-pills > .active').next('li').find('a').trigger('click'); | ||
}); | }); | ||
Line 271: | Line 334: | ||
.click(function( event ) { | .click(function( event ) { | ||
event.preventDefault(); //lock the button for now. | event.preventDefault(); //lock the button for now. | ||
− | + | initialise(); | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
}); | }); | ||
Revision as of 08:14, 5 January 2015
Introduction text