Last active
December 17, 2015 00:29
-
-
Save holyjak/5521694 to your computer and use it in GitHub Desktop.
Intention Hidden In Implementation And Misty Edge of Validity - why does this function do what it does and under what assumptions does it operate? See http://wondersofcode.wordpress.com/2013/05/05/intention-hidden-in-implementation-and-misty-edge-of-validity/
This file contains 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
// compare two series and add the delta to the data for the current period | |
augmentSeriesWithPreviousValues:function (seriesData, previousSeriesData) { | |
var series = seriesData.series; | |
seriesData.previous = []; | |
var previousSeries = previousSeriesData.series; | |
... // checks, computing maxRows, maxColumns, previousCategories | |
// that maps category name to series index (id) | |
for (var seriesId = 0; seriesId < series.length; seriesId++) { | |
var category = seriesData.category[seriesId + 1]; | |
var previousSeriesId = previousCategories[category]; | |
for (var rowId = 0; rowId < maxRows; rowId++) { | |
for (var columnId = 1; columnId < maxColumns; columnId++) { | |
var value = 0; | |
var previousValue = 0; | |
if (previousSeries[previousSeriesId] && previousSeries[previousSeriesId][rowId]) { | |
previousValue = previousSeries[previousSeriesId][rowId][columnId]; | |
if (isNaN(previousValue)) { | |
previousValue = 0; | |
} | |
} | |
if (!series[seriesId]) { | |
series[seriesId] = []; | |
} | |
if (!series[seriesId][rowId]) { | |
series[seriesId][rowId] = []; | |
} | |
value = series[seriesId][rowId][columnId]; | |
if (isNaN(value)) { | |
value = 0; // <- bug: this value is never used! | |
} | |
if (!seriesData.previous[seriesId]) { | |
seriesData.previous[seriesId] = []; | |
} | |
if (!seriesData.previous[seriesId][rowId]) { | |
seriesData.previous[seriesId][rowId] = []; | |
} | |
seriesData.previous[seriesId][rowId][columnId] = previousValue; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment