use splunk's PostProcessManager to request tile data instead of
hardcoded job requests
This commit is contained in:
parent
b69a8e5354
commit
d56b403cfe
@ -58,6 +58,12 @@
|
||||
|
||||
splunk.prototype = {
|
||||
|
||||
setManager: function (PostProcessManager, managerId) {
|
||||
this.searchManagerId = managerId;
|
||||
this.managerClass = PostProcessManager;
|
||||
this.managers = [];
|
||||
},
|
||||
|
||||
/**
|
||||
* return the torque tile encoded in an efficient javascript
|
||||
* structure:
|
||||
@ -198,7 +204,7 @@
|
||||
this.options.cartocss = c;
|
||||
},*/
|
||||
|
||||
setSteps: function(steps, opt) {
|
||||
setSteps: function(steps, opt) {
|
||||
opt = opt || {};
|
||||
if (this.options.steps !== steps) {
|
||||
this.options.steps = steps;
|
||||
@ -266,10 +272,10 @@
|
||||
|
||||
getTileData: function(coord, zoom, callback) {
|
||||
if(!this._ready) {
|
||||
|
||||
|
||||
this._tileQueue.push([coord, zoom, callback]);
|
||||
} else {
|
||||
|
||||
|
||||
this._getTileData(coord, zoom, callback);
|
||||
}
|
||||
},
|
||||
@ -293,7 +299,7 @@
|
||||
*/
|
||||
_getTileData: function(coord, zoom, callback) {
|
||||
console.log("Fetching tile " + coord.zoom + '/' + coord.x + '/' + coord.y);
|
||||
|
||||
|
||||
|
||||
var self = this;
|
||||
|
||||
@ -301,11 +307,11 @@
|
||||
getSplunkData(function(data){
|
||||
//parseData converts splunk results into a valid torque tile
|
||||
var tile = parseData(data);
|
||||
|
||||
|
||||
if (tile) {
|
||||
var rows = tile;
|
||||
|
||||
|
||||
|
||||
|
||||
callback(self.proccessTile(rows, coord, zoom));
|
||||
} else {
|
||||
@ -316,7 +322,7 @@
|
||||
|
||||
|
||||
function getSplunkData(callback) {
|
||||
|
||||
|
||||
|
||||
var tileBounds = boundsFromTile(coord.zoom,coord.x,coord.y);
|
||||
|
||||
@ -330,40 +336,19 @@
|
||||
tileBounds.maxLng <= 180
|
||||
) {
|
||||
|
||||
var options = {
|
||||
host: 'localhost',
|
||||
port: '8000',
|
||||
sid: '1439866488.13',
|
||||
bounds: tileBounds
|
||||
}
|
||||
|
||||
var template = 'http://{{host}}:{{port}}/en-US/splunkd/__raw/services/search/jobs/{{sid}}/results_preview?output_mode=json_rows&count=65536&show_metadata=false&search=geofilter+south={{bounds.minLat}}+west={{bounds.minLng}}+north={{bounds.maxLat}}+east={{bounds.maxLng}}+maxclusters%3D65536';
|
||||
|
||||
var queryString = Mustache.render(template,options);
|
||||
|
||||
console.log(queryString);
|
||||
|
||||
|
||||
$.getJSON(queryString,function(data) {
|
||||
console.log("Got " + (data.rows.length-8) + " bins for this tile");
|
||||
callback(data);
|
||||
if (!self.managers[coord.zoom + "_" + coord.x + "_" + coord.y]) {
|
||||
self.managers[coord.zoom + "_" + coord.x + "_" + coord.y] = new self.managerClass({
|
||||
id: coord.zoom + "_" + coord.x + "_" + coord.y,
|
||||
managerid: self.searchManagerId,
|
||||
search: "geofilter south=" + tileBounds.minLat + " west=" + tileBounds.minLng + " north=" + tileBounds.maxLat + " east=" + tileBounds.maxLng + " maxclusters=65536"
|
||||
});
|
||||
// $.ajax({
|
||||
// type: "POST",
|
||||
// crossDomain: true,
|
||||
// url: "https://localhost:8089/servicesNS/admin/search/search/jobs/export",
|
||||
// username: 'admin',
|
||||
// password: 'cartodb',
|
||||
// dataType: 'text',
|
||||
// data: queryString,
|
||||
// success: callback,
|
||||
// beforeSend: function(xhr) {
|
||||
// xhr.setRequestHeader(
|
||||
// 'Authorization',
|
||||
// 'Basic ' + window.btoa(unescape(encodeURIComponent('admin' + ':' + 'cartodb')))
|
||||
// )
|
||||
// }
|
||||
// });
|
||||
self.managers[coord.zoom + "_" + coord.x + "_" + coord.y].data("results", {count: 0, output_mode: 'json_rows'}).on("data", function (results) {
|
||||
console.log("Got " + (results.data().rows.length - 8) + " bins for this tile");
|
||||
callback(results.data());
|
||||
});
|
||||
}
|
||||
|
||||
self.managers[coord.zoom + "_" + coord.x + "_" + coord.y].startSearch();
|
||||
|
||||
}
|
||||
}
|
||||
@ -373,7 +358,7 @@
|
||||
var bounds = tileBounds(z,x,y);
|
||||
mins = metersToLatLng(bounds[0]);
|
||||
maxs = metersToLatLng(bounds[1]);
|
||||
|
||||
|
||||
bounds={
|
||||
minLat:mins[1],
|
||||
maxLat:maxs[1],
|
||||
@ -386,17 +371,17 @@
|
||||
|
||||
function metersToLatLng(coord) {
|
||||
lng = (coord[0] / (2 * Math.PI * 6378137 / 2.0)) * 180.0
|
||||
|
||||
|
||||
lat = (coord[1] / (2 * Math.PI * 6378137 / 2.0)) * 180.0
|
||||
lat = 180 / Math.PI * (2 * Math.atan( Math.exp( lat * Math.PI / 180.0)) - Math.PI / 2.0)
|
||||
|
||||
|
||||
return [lng,lat]
|
||||
}
|
||||
|
||||
function tileBounds(z,x,y) {
|
||||
var mins = pixelsToMeters( z, x*256, (y+1)*256 )
|
||||
var maxs = pixelsToMeters( z, (x+1)*256, y*256 )
|
||||
|
||||
|
||||
return [mins,maxs];
|
||||
}
|
||||
|
||||
@ -416,7 +401,7 @@
|
||||
// data = '[' + data.split('}}').join('}},').replace(/,\s*$/, "") + ']';
|
||||
|
||||
// data = JSON.parse(data);
|
||||
|
||||
|
||||
|
||||
var torqueTile = [];
|
||||
|
||||
@ -426,10 +411,10 @@
|
||||
//console.log(bin);
|
||||
|
||||
torqueTile.push(torqueTransform(bin));
|
||||
|
||||
|
||||
|
||||
|
||||
function torqueTransform(bin){
|
||||
|
||||
|
||||
//var binSpan = 1010384; //hard coded to figure out step from unixtimestamp, TODO figure out how we will deal with the time range and bin span
|
||||
|
||||
|
||||
@ -451,11 +436,11 @@
|
||||
var point = latLngToTileXY(parseInt(lat),parseInt(lng),zoom)
|
||||
|
||||
//console.log('tileXY', point)
|
||||
|
||||
|
||||
torqueBin.x__uint8 = point.x;
|
||||
torqueBin.y__uint8 = point.y;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//iterate over remaining rows minus the last 6
|
||||
var dates = [],
|
||||
@ -464,7 +449,7 @@
|
||||
if(bin[i] !== null) {
|
||||
dates.push(i);
|
||||
vals.push(bin[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
torqueBin.vals__uint8 = vals;
|
||||
@ -482,7 +467,7 @@
|
||||
MaxLongitude = 180,
|
||||
mapSize = Math.pow(2, zoom) * 256;
|
||||
|
||||
|
||||
|
||||
|
||||
latitude = clip(lat, MinLatitude, MaxLatitude)
|
||||
longitude = clip(lng, MinLongitude, MaxLongitude)
|
||||
@ -491,12 +476,12 @@
|
||||
p.x = (longitude + 180.0) / 360.0 * (1 << zoom)
|
||||
p.y = (1.0 - Math.log(Math.tan(latitude * Math.PI / 180.0) + 1.0 / Math.cos(lat.toRad())) / Math.PI) / 2.0 * (1 << zoom)
|
||||
|
||||
|
||||
|
||||
|
||||
var tilex = parseInt(Math.trunc(p.x));
|
||||
var tiley = parseInt(Math.trunc(p.y));
|
||||
|
||||
|
||||
|
||||
|
||||
var pixelX = clipByRange((tilex * 256) + ((p.x - tilex) * 256), mapSize - 1)/2 //<-- divide by 2 because we only have 128 bins
|
||||
var pixelY = (256 - clipByRange((tiley * 256) + ((p.y - tiley) * 256), mapSize - 1))/2
|
||||
@ -511,7 +496,7 @@
|
||||
}
|
||||
|
||||
function clipByRange(n,range) {
|
||||
|
||||
|
||||
return n % range;
|
||||
}
|
||||
}
|
||||
@ -522,8 +507,8 @@
|
||||
|
||||
return torqueTile;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
},
|
||||
|
||||
|
||||
@ -634,7 +619,7 @@
|
||||
|
||||
|
||||
_fetchMap: function(callback) {
|
||||
|
||||
|
||||
var self = this;
|
||||
var layergroup = {};
|
||||
var host = this.options.dynamic_cdn ? this.url().replace('{s}', '0'): this._tilerHost();
|
||||
@ -662,7 +647,7 @@
|
||||
}]
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
if(this.options.stat_tag){
|
||||
allParams["stat_tag"] = this.options.stat_tag;
|
||||
}
|
||||
@ -680,22 +665,17 @@
|
||||
"&callback=?" + (extra ? "&" + extra: '');
|
||||
|
||||
var map_instance_time = Profiler.metric('torque.provider.windshaft.layergroup.time').start();
|
||||
|
||||
// var opt = {start: 1000, end: 5000, data_steps: 5, column_type: "number"};
|
||||
|
||||
var opt = {start: 1262311701000,
|
||||
end: 1391640787000,
|
||||
data_steps: 8247,
|
||||
// var opt = {start: 1000, end: 5000, data_steps: 5, column_type: "number"};
|
||||
|
||||
var opt = {start: 1262311701000,
|
||||
end: 1391640787000,
|
||||
data_steps: 8247,
|
||||
column_type: "date"};
|
||||
|
||||
|
||||
for(var k in opt) {
|
||||
self.options[k] = opt[k];
|
||||
}
|
||||
|
||||
//in Windshaft, this was happening after an ajax call. Calling self._setReady() too early causes the viz to fail, so it is delayed here. We should fix this
|
||||
setTimeout(function(){
|
||||
self._setReady(true);
|
||||
},500)
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user