-
-
Save javisantana/622437e65cae00a7cb20 to your computer and use it in GitHub Desktop.
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
torque.providers.windshaft.prototype.aggregateByKey = function(callback) { | |
var url = this.templateUrl | |
.replace('{x}', 0) | |
.replace('{y}', 0) | |
.replace('{z}', 0) | |
.replace('{s}', 0) | |
var self = this; | |
var extra = this._extraParams(); | |
torque.net.get( url, function (data) { | |
var rows = JSON.parse(data.responseText); | |
callback(self._aggregateByKey(rows)); | |
}) | |
} | |
torque.providers.windshaft.prototype._aggregateByKey = function(rows) { | |
function getKeys(row) { | |
var keys = {}; | |
var dates = row.dates__uint16; | |
var vals = row.vals__uint8; | |
var valuesCount = vals.length; | |
for (var s = 0; s < valuesCount; ++s) { | |
keys[dates[s]] = vals[s]; | |
} | |
return keys; | |
} | |
var keys = {}; | |
for (r = 0; r < rows.length; ++r) { | |
var rowKeys = getKeys(rows[r]); | |
for(var k in rowKeys) { | |
keys[k] = keys[k] || 0; | |
keys[k] += rowKeys[k]; | |
} | |
} | |
return keys; | |
} | |
// usage | |
torqueLayer.provider.aggregateByKey(function(a) { | |
console.log(a); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment