Created
November 6, 2014 20:15
-
-
Save tristanpendergrass/15913b4813071dbd51fe to your computer and use it in GitHub Desktop.
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
elasticSearchService.post('_all/_search',query).then(function (response){ | |
$scope.graph1Data = []; | |
$scope.graph2Data = []; | |
$scope.graph3Data = []; | |
var locationData = response.data.aggregations.UniqueLocation.buckets; | |
var tempData = []; | |
// for filling in 0 for blank data point | |
var rawArray = []; | |
var longestArray = []; | |
$.each(locationData, function (key, loc){ | |
if(!$scope.graph1Data.length){ | |
$scope.graph1Data[0] = { | |
"values": [] | |
} | |
} | |
if(!$scope.graph2Data.length){ | |
$scope.graph2Data[0] = { | |
"values": [] | |
} | |
} | |
var key = $scope.getLocName(loc.key); | |
$scope.graph1Data[0].values.push({x:key,y:loc.byDevice.buckets.length}); | |
if (loc.time.timespent_stats.count > 0) $scope.graph2Data[0].values.push({x:key,y:loc.time.timespent_stats.avg,stat:loc.time.timespent_stats}); | |
var values = []; | |
$.each(loc.deviceOverTime.buckets, function (key, valueInner){ | |
values.push([valueInner.key,valueInner.doc_count]); | |
}) | |
// For filling in 0 for blank data point | |
rawArray.push(values); | |
if(values.length > longestArray.length) longestArray = values; | |
tempData.push({"key":key,"values":values}) | |
}); | |
// fill in 0 for blank data point | |
$.each(rawArray, function (outterKey, outterArray){ | |
if(outterArray != longestArray && outterArray.length != longestArray.length){ | |
var rawKey = 0; | |
var newArray = []; | |
$.each(longestArray, function (innerKey, innerArray){ | |
if(innerArray[0] != outterArray[rawKey][0]){ | |
newArray.push([innerArray[0],0]) | |
}else{ | |
newArray.push([innerArray[0],outterArray[rawKey][1]]); | |
if(rawKey+1< outterArray.length) rawKey++; | |
} | |
}) | |
tempData[outterKey].values = newArray; | |
} | |
}); | |
$scope.graph3Data = tempData; | |
var processedData = processGraph3Data($scope.graph3Data); | |
$scope.floorPlanData = scaleGraph3Data(processedData.data); | |
$scope.floorPlanDataChunkCount = processedData.data.length; | |
$scope.legendKeys = processedData.keys; | |
$scope.sliderTimes = processedData.times; | |
$scope.instanceData = $scope.floorPlanData[0]; | |
$scope.locationCoords = mapLocationCoords($scope.legendKeys); | |
$scope.$broadcast('set-chunk', 0); | |
setTime(0); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment