Skip to content

Commit

Permalink
Incremental Results (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
akshaisarma authored Jun 18, 2018
1 parent 43db652 commit 1d6a208
Show file tree
Hide file tree
Showing 99 changed files with 2,060 additions and 779 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ module.exports = {
'no-unneeded-ternary': 2,
'no-whitespace-before-property': 2,
'object-curly-spacing': [2, 'always'],
'semi': 2,
'semi-spacing': 2,
'space-before-blocks': 2,
'space-before-function-paren': [2, 'never'],
Expand Down
16 changes: 15 additions & 1 deletion app/components/pivot-table.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
/*
* Copyright 2018, Yahoo Inc.
* Licensed under the terms of the Apache License, Version 2.0.
* See the LICENSE file associated with the project for terms.
*/
import { computed } from '@ember/object';
import $ from 'jquery';
import Component from '@ember/component';
import { debounce } from '@ember/runloop';

export default Component.extend({
rows: null,
columns: null,
initialOptions: null,

init() {
Expand All @@ -29,6 +34,15 @@ export default Component.extend({

didInsertElement() {
this._super(...arguments);
this.insertPivotTable();
},

didUpdateAttrs() {
this._super(...arguments);
debounce(this, this.insertPivotTable, 500, true);
},

insertPivotTable() {
let { rows, options } = this.getProperties('rows', 'options');
this.$('.pivot-table-container').pivotUI(rows, options);
},
Expand Down
8 changes: 6 additions & 2 deletions app/components/pretty-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ export default Component.extend({
data: null,
defaultLevels: 2,

didInsertElement() {
didRender() {
this._super(...arguments);
this.$().empty().append(this.getRenderData());
},

getRenderData() {
let formatter = new JSONFormatter(this.get('data'), this.get('defaultLevels'), { hoverPreviewEnabled: true });
this.$().append(formatter.render());
return formatter.render();
}
});
1 change: 0 additions & 1 deletion app/components/queries-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export default Component.extend(PaginatedTable, {
classNames: ['queries-table'],
queries: null,
pageSize: 10,
isFixed: true,
extractors: EmberObject.create({
name(row) {
let name = row.get('name');
Expand Down
30 changes: 30 additions & 0 deletions app/components/query-information.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2018, Yahoo Inc.
* Licensed under the terms of the Apache License, Version 2.0.
* See the LICENSE file associated with the project for terms.
*/
import Component from '@ember/component';
import { inject as service } from '@ember/service';
import { alias } from '@ember/object/computed';

export default Component.extend({
querier: service(),
query: null,
querySnapshot: null,

isRunningQuery: alias('querier.isRunningQuery').readOnly(),

actions: {
cancelClick() {
this.sendAction('cancelClick');
},

reRunClick(query) {
this.sendAction('reRunClick', query);
},

queryClick(query) {
this.sendAction('queryClick', query);
}
}
});
11 changes: 3 additions & 8 deletions app/components/query-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Component from '@ember/component';
import { isEqual } from '@ember/utils';
import { SUBFIELD_SEPARATOR } from 'bullet-ui/models/column';
import { AGGREGATIONS } from 'bullet-ui/models/aggregation';
import { EMIT_TYPES } from 'bullet-ui/models/window';
import BuilderAdapter from 'bullet-ui/mixins/builder-adapter';

export default Component.extend(BuilderAdapter, {
Expand All @@ -30,7 +29,6 @@ export default Component.extend(BuilderAdapter, {
scroller: service(),
schema: null,
isListening: false,
listenDuration: 0,
hasError: false,
hasSaved: false,

Expand All @@ -39,9 +37,8 @@ export default Component.extend(BuilderAdapter, {
return this.builderFilters(schema);
}).readOnly(),

showAggregationSize: computed('query.{aggregation.type,window.emit.type,isWindowless}', function() {
return isEqual(this.get('query.aggregation.type'), AGGREGATIONS.get('RAW')) &&
(this.get('query.isWindowless') || isEqual(this.get('query.window.emit.type'), EMIT_TYPES.get('TIME')));
showAggregationSize: computed('query.{aggregation.type,isWindowless}', function() {
return isEqual(this.get('query.aggregation.type'), AGGREGATIONS.get('RAW')) && this.get('query.isWindowless');
}),

didInsertElement() {
Expand Down Expand Up @@ -79,7 +76,6 @@ export default Component.extend(BuilderAdapter, {
reset() {
this.setProperties({
isListening: false,
listenDuration: 0,
hasError: false,
hasSaved: false
});
Expand Down Expand Up @@ -119,8 +115,7 @@ export default Component.extend(BuilderAdapter, {
this.save().then(() => {
this.setProperties({
isListening: true,
hasSaved: true,
listenDuration: this.get('query.duration') * 1000
hasSaved: true
});
this.$(this.get('queryBuilderInputs')).attr('disabled', true);
this.sendAction('fireQuery');
Expand Down
16 changes: 9 additions & 7 deletions app/components/records-charter.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ export default Component.extend({
columns: null,
rows: null,
chartType: 'bar',
config: null,

simpleMode: true,
notSimpleMode: not('simpleMode').readOnly(),
cannotModeSwitch: alias('model.isRaw').readOnly(),
cannotModeSwitch: alias('config.isRaw').readOnly(),
canModeSwitch: not('cannotModeSwitch').readOnly(),
pivotMode: or('notSimpleMode', 'cannotModeSwitch').readOnly(),
pivotOptions: computed('model.pivotOptions', function() {
return JSON.parse(this.get('model.pivotOptions'));
pivotOptions: computed('config.pivotOptions', function() {
let options = this.get('config.pivotOptions') || '{}';
return JSON.parse(options);
}).readOnly(),

sampleRow: computed('rows', 'columns', function() {
Expand All @@ -41,19 +43,19 @@ export default Component.extend({
return typicalRow;
}),

independentColumns: computed('model', 'sampleRow', 'columns', function() {
independentColumns: computed('config', 'sampleRow', 'columns', function() {
let { columns, sampleRow } = this.getProperties('columns', 'sampleRow');
let isDistribution = this.get('model.isDistribution');
let isDistribution = this.get('config.isDistribution');
if (isDistribution) {
return A(columns.filter(c => this.isAny(c, 'Quantile', 'Range')));
}
// Pick all string columns
return A(columns.filter(c => this.isType(sampleRow, c, 'string')));
}),

dependentColumns: computed('model', 'sampleRow', 'columns', function() {
dependentColumns: computed('config', 'sampleRow', 'columns', function() {
let { columns, sampleRow } = this.getProperties('columns', 'sampleRow');
let isDistribution = this.get('model.isDistribution');
let isDistribution = this.get('config.isDistribution');
if (isDistribution) {
return A(columns.filter(c => this.isAny(c, 'Count', 'Value', 'Probability')));
}
Expand Down
20 changes: 17 additions & 3 deletions app/components/records-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@ import EmberObject, { computed } from '@ember/object';
import Component from '@ember/component';
import Table from 'ember-light-table';
import PaginatedTable from 'bullet-ui/mixins/paginated-table';
import { isNone } from '@ember/utils';

export default Component.extend(PaginatedTable, {
classNames: ['records-table'],
columnNames: null,
cellComponent: 'cells/record-entry',
pageSize: 10,
isFixed: true,
appendMode: false,

sortedByColumn: null,

// Use natural types in the results
useDefaultStringExtractor: false,

rawRows: null,
table: null,

columns: computed('columnNames', function() {
let names = this.get('columnNames');
Expand All @@ -33,8 +37,18 @@ export default Component.extend(PaginatedTable, {
init() {
this._super(...arguments);
this.set('table', new Table(this.get('columns')));
this.set('sortColumn', null);
},

didReceiveAttrs() {
this._super(...arguments);
this.set('rows', this.get('rawRows').map(row => EmberObject.create(row)));
this.addPages(1);
let sortColumn = this.get('sortColumn');
let hasSortedColumn = !isNone(sortColumn);
this.reset(hasSortedColumn);
if (hasSortedColumn) {
this.sortBy(sortColumn.valuePath, sortColumn.ascending ? 'ascending' : 'descending');
}
this.addPages();
}
});
16 changes: 13 additions & 3 deletions app/components/records-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ import Component from '@ember/component';
export default Component.extend({
fileSaver: service(),
classNames: ['records-viewer'],
aggregateMode: false,
showRawData: false,
showTable: false,
showChart: false,
// Copy of the model
model: null,
config: null,
metadata: null,
records: null,
fileName: 'results',
model: null,

enableCharting: not('model.isSingleRow').readOnly(),
enableCharting: not('config.isSingleRow').readOnly(),

columns: computed('records', function() {
return A(this.extractUniqueColumns(this.get('records')));
Expand All @@ -50,6 +51,15 @@ export default Component.extend({
return this.makeCSVString(columns, rows);
}).readOnly(),

init() {
this._super(...arguments);
if (this.get('config.isReallyRaw')) {
this.set('showRawData', true);
} else {
this.set('showTable', true);
}
},

extractUniqueColumns(records) {
let columns = new Set();
records.forEach(record => {
Expand Down
99 changes: 99 additions & 0 deletions app/components/result-viewer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright 2018, Yahoo Inc.
* Licensed under the terms of the Apache License, Version 2.0.
* See the LICENSE file associated with the project for terms.
*/
import Component from '@ember/component';
import { computed } from '@ember/object';
import { alias, and, not } from '@ember/object/computed';
import { inject as service } from '@ember/service';
import { isNone } from '@ember/utils';

export default Component.extend({
classNames: ['result-viewer'],
querier: service(),

query: null,
result: null,
selectedWindow: null,
autoUpdate: true,
// Tweaks the time for the window duration by this to adjust for Ember scheduling delays
jitter: -300,

isRunningQuery: alias('querier.isRunningQuery').readOnly(),
isRaw: alias('result.isRaw').readOnly(),
errorWindow: alias('result.errorWindow').readOnly(),
hasData: alias('result.hasData').readOnly(),
numberOfWindows: alias('result.windows.length').readOnly(),
windowEmitEvery: alias('query.window.emit.every').readOnly(),
isTimeWindow: alias('query.window.isTimeBased').readOnly(),
isRecordWindow: not('isTimeWindow').readOnly(),
isRawRecordWindow: and('isRecordWindow', 'isRaw').readOnly(),
aggregateMode: alias('isRawRecordWindow').readOnly(),

showAutoUpdate: computed('hasError', 'aggregateMode', 'hasData', function() {
return this.get('hasData') && !this.get('hasError') && !this.get('aggregateMode');
}),

hasError: computed('errorWindow', function() {
return !isNone(this.get('errorWindow'));
}).readOnly(),

metadata: computed('hasError', 'autoUpdate', 'selectedWindow', 'result.windows.[]', function() {
return this.get('hasError') ? this.get('errorWindow.metadata') : this.getSelectedWindow('metadata');
}).readOnly(),

records: computed('autoUpdate', 'aggregateMode', 'selectedWindow', 'result.windows.[]', function() {
return this.get('aggregateMode') ? this.getAllWindowRecords() : this.getSelectedWindow('records');
}).readOnly(),

queryDuration: computed('query.duration', function() {
return this.get('query.duration') * 1000;
}).readOnly(),

windowDuration: computed('windowEmitEvery', function() {
return this.get('jitter') + (this.get('windowEmitEvery') * 1000);
}).readOnly(),

config: computed('result.{isRaw,isReallyRaw,isDistribution,isSingleRow}', function() {
return {
isRaw: this.get('result.isRaw'),
isReallyRaw: this.get('result.isReallyRaw'),
isDistribution: this.get('result.isDistribution'),
isSingleRow: this.get('result.isSingleRow'),
pivotOptions: this.get('result.pivotOptions')
};
}).readOnly(),

didReceiveAttrs() {
this._super(...arguments);
this.set('selectedWindow', null);
this.set('autoUpdate', true);
},

getSelectedWindow(property) {
let windowProperty = this.get(`result.windows.lastObject.${property}`);
if (!this.get('autoUpdate')) {
let selectedWindow = this.get('selectedWindow');
windowProperty = isNone(selectedWindow) ? windowProperty : selectedWindow[property];
}
return windowProperty;
},

getAllWindowRecords() {
return this.get('result.windows').getEach('records').reduce((p, c) => p.concat(c), []);
},

actions: {
changeWindow(selectedWindow) {
this.set('selectedWindow', selectedWindow);
this.set('autoUpdate', false);
},

changeAutoUpdate(autoUpdate) {
// Turn On => reset selectedWindow. Turn Off => Last window
this.set('selectedWindow', autoUpdate ? null : this.get('result.windows.lastObject'));
this.set('autoUpdate', autoUpdate);
}
}
});
12 changes: 12 additions & 0 deletions app/components/result-window-placeholder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright 2018, Yahoo Inc.
* Licensed under the terms of the Apache License, Version 2.0.
* See the LICENSE file associated with the project for terms.
*/
import Component from '@ember/component';

export default Component.extend({
classNames: ['result-window-placeholder'],
tagName: 'span',
windowCount: 0
});
Loading

0 comments on commit 1d6a208

Please sign in to comment.