Created
March 27, 2015 21:04
-
-
Save radio412/6f0f1d0087c956742f49 to your computer and use it in GitHub Desktop.
Applying a non-linear data pattern to a measure
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
| establishCurve = function(curveArray,sumTotal,inverse){ | |
| if(inverse){ | |
| var maxVal = Math.max.apply(Math, curveArray); | |
| var minVal = Math.min.apply(Math, curveArray); | |
| curveArray = curveArray.map(function (x) { | |
| return (maxVal-x)+minVal; | |
| }); | |
| } | |
| var curveTotal = curveArray.reduce(function(a, b) { | |
| return a + b; | |
| }); | |
| var data = []; | |
| var sum = 0; | |
| for(var i = 0; i< curveArray.length; i++){ | |
| var perc = curveArray[i]/curveTotal; | |
| data.push(sumTotal*perc); | |
| sum += sumTotal*perc; | |
| } | |
| return data; | |
| } | |
| //example curve | |
| //monthly sample data applied to actual total population: | |
| console.log(establishCurve([9,9,12,17,22,27,29,29,25,20,15,10], 50000000, false)); | |
| //The curve can be inverted with the last parameter: | |
| console.log(establishCurve([9,9,12,17,22,27,29,29,25,20,15,10], 50000000, true)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment