Switch to using an aggregated logs query and infinite scrolling

This should allow users to work with large logs set.

Fixes #294
This commit is contained in:
Joseph Schorr 2015-07-31 13:38:02 -04:00
parent 572d6ba53c
commit 3d6c92901c
15 changed files with 270 additions and 99 deletions

View file

@ -1616,22 +1616,22 @@ UsageChart.prototype.draw = function(container) {
function LogUsageChart(titleMap) {
this.titleMap_ = titleMap;
this.colorScale_ = d3.scale.category20();
this.entryMap_ = {};
}
/**
* Builds the D3-representation of the data.
*/
LogUsageChart.prototype.buildData_ = function(logs) {
LogUsageChart.prototype.buildData_ = function(aggregatedLogs) {
var parseDate = d3.time.format("%a, %d %b %Y %H:%M:%S %Z").parse
// Build entries for each kind of event that occurred, on each day. We have one
// entry per {kind, day} pair.
var map = {};
var entries = [];
for (var i = 0; i < logs.length; ++i) {
var log = logs[i];
var title = this.titleMap_[log.kind] || log.kind;
var datetime = parseDate(log.datetime);
for (var i = 0; i < aggregatedLogs.length; ++i) {
var aggregated = aggregatedLogs[i];
var title = this.titleMap_[aggregated.kind] || aggregated.kind;
var datetime = parseDate(aggregated.datetime);
var dateDay = datetime.getDate();
if (dateDay < 10) {
dateDay = '0' + dateDay;
@ -1640,24 +1640,18 @@ LogUsageChart.prototype.buildData_ = function(logs) {
var formatted = (datetime.getMonth() + 1) + '/' + dateDay;
var adjusted = new Date(datetime.getFullYear(), datetime.getMonth(), datetime.getDate());
var key = title + '_' + formatted;
var found = map[key];
if (!found) {
found = {
'kind': log.kind,
'title': title,
'adjusted': adjusted,
'formatted': datetime.getDate(),
'count': 0
};
var entry = {
'kind': aggregated.kind,
'title': title,
'adjusted': adjusted,
'formatted': datetime.getDate(),
'count': aggregated.count
};
map[key] = found;
entries.push(found);
}
found['count']++;
entries.push(entry);
this.entryMap_[key] = entry;
}
this.entries_ = map;
// Build the data itself. We create a single entry for each possible kind of data, and then add (x, y) pairs
// for the number of times that kind of event occurred on a particular day.
var dataArray = [];
@ -1727,7 +1721,7 @@ LogUsageChart.prototype.renderTooltip_ = function(d, e) {
}
var key = d + '_' + e;
var entry = this.entries_[key];
var entry = this.entryMap_[key];
if (!entry) {
entry = {'count': 0};
}