Skip to content

Instantly share code, notes, and snippets.

@javisantana
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save javisantana/622437e65cae00a7cb20 to your computer and use it in GitHub Desktop.
Save javisantana/622437e65cae00a7cb20 to your computer and use it in GitHub Desktop.
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