-
Notifications
You must be signed in to change notification settings - Fork 15
/
\
623 lines (565 loc) · 24.2 KB
/
\
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
import Ember from 'ember';
import ENV from 'analytics-dashboard/config/environment';
import stringify from 'npm:json-stable-stringify';
import dateInterval from '../../utils/date-interval';
//import Q from 'npm:q';
const agg_types = [ // agg_types is this array literal, reduced by the following fn
//
// Average Aggregation
// *******************
{
'elastic_name':'avg',
'pretty_name': 'Average',
'description': 'A single-value metrics aggregation that computes the average of numeric values that are extracted from the aggregated documents. These values can be extracted either from specific numeric fields in the documents, or be generated by a provided script. Script support is not enabled at this time.',
'options': [
{
'elastic_name': 'field',
'pretty_name': 'Field',
'description': 'The name of the field to calculate the average over',
'isValid': function() {
return true;
}
}, {
'elastic_name': 'missing',
'pretty_name': 'Missing',
'description': 'A value to use as a default if a given document does not have a given field. Ignored by default. Documents without a value at \'field\' will be placed into this bucket',
'isValid': function() {
return true;
}
}
],
},
//
// Cardinality Aggregation
// ***********************
{
'elastic_name': 'cardinality',
'pretty_name': 'Cardinality',
'description': 'A single-value metrics aggregation that calculates an approximate count of distinct values. Values can be extracted either from specific fields in the document or generated by a script. Script support is not enabled at this time.',
'options': [
{
'elastic_name': 'field',
'pretty_name': 'Field',
'description': 'The name of the field to calculate the cardinality of',
'isValid': function() {
return true;
}
}, {
'elastic_name': 'precision_threshold',
'pretty_name': 'Precision Threshold',
'description': 'The precision_threshold options allows to trade memory for accuracy, and defines a unique count below which counts are expected to be close to accurate. Above this value, counts might become a bit more fuzzy. The maximum supported value is 40000, thresholds above this number will have the same effect as a threshold of 40000. The default values is 3000.',
'isValid': function() {
return true;
}
}, {
'elastic_name': 'missing',
'pretty_name': 'Missing',
'description': 'A value to use as a default if a given document does not have a given field. Ignored by default. Documents without a value at \'field\' will be placed into this bucket',
'isValid': function(value) {
return true;
}
}
]
},
//
// Extended Stats Aggregation
// **************************
{
'elastic_name': 'extended_stats',
'pretty_name': 'Extended Stats',
'description': 'A multi-value metrics aggregation that computes stats over numeric values extracted from the aggregated documents. These values can be extracted from specific numeric fields in the documents. The extended_stats aggregations is an extended version of the stats aggregation, where additional metrics are added such as sum_of_squares, variance, std_deviation and std_deviation_bounds.',
'options': [
{
'elastic_name': 'field',
'pretty_name': 'Field',
'description': 'The field setting defines the numeric field of the documents the stats will be computed on.',
'isValid': function() {
return true;
}
}, {
'elastic_name': 'sigma',
'pretty_name': 'Sigma',
'description': 'By default, the extended_stats metric will return an object called std_deviation_bounds, which provides an interval of plus/minus two standard deviations from the mean. This can be a useful way to visualize variance of your data. If you want a different boundary, for example three standard deviations, you can set sigma in the request. Sigma can be any non-negative double, meaning you can request non-integer values such as 1.5. A value of 0 is valid, but will simply return the average for both upper and lower bounds. The standard deviation and its bounds are displayed by default, but they are not always applicable to all data-sets. Your data must be normally distributed for the metrics to make sense. The statistics behind standard deviations assumes normally distributed data, so if your data is skewed heavily left or right, the value returned will be misleading.',
'isValid': function*() {
return true;
}
}, {
'elastic_name': 'missing',
'pretty_name': 'Missing',
'description': 'A value to use as a default if a given document does not have a given field. Ignored by default.',
'isValid': function(value) {
return true;
}
}
]
},
//
// Maximum Aggregation
// **************************
{
'elastic_name': 'max',
'pretty_name': 'Maximum',
'description': 'A single-value metrics aggregation that keeps track and returns the maximum value among the numeric values extracted from the aggregated documents.',
'options': [
{
'elastic_name': 'field',
'pretty_name': 'Field',
'description': 'The field setting defines the numeric field of the documents the maximum will be computed on.',
'isValid': function() {
return true;
}
}, {
'elastic_name': 'missing',
'pretty_name': 'Missing',
'description': 'A value to use as a default if a given document does not have a given field. Ignored by default.',
'isValid': function(value) {
return true;
}
}
]
},
//
// Minimum Aggregation
// **************************
{
'elastic_name': 'min',
'pretty_name': 'Minimum',
'description': 'A single-value metrics aggregation that keeps track and returns the minimum value among the numeric values extracted from the aggregated documents.',
'options': [
{
'elastic_name': 'field',
'pretty_name': 'Field',
'description': 'The field setting defines the numeric field of the documents the minimum will be computed on.',
'isValid': function() {
return true;
}
}, {
'elastic_name': 'missing',
'pretty_name': 'Missing',
'description': 'A value to use as a default if a given document does not have a given field. Ignored by default.',
'isValid': function(value) {
return true;
}
}
]
},
//
// Percentiles Aggregation
// **************************
{
'elastic_name': 'percentiles',
'pretty_name': 'Percentiles',
'description': 'A multi-value metrics aggregation that calculates one or more percentiles over numeric values extracted from the aggregated documents. Percentiles show the point at which a certain percentage of observed values occur. For example, the 95th percentile is the value which is greater than 95% of the observed values. Percentiles are often used to find outliers. In normal distributions, the 0.13th and 99.87th percentiles represents three standard deviations from the mean. Any data which falls outside three standard deviations is often considered an anomaly. When a range of percentiles are retrieved, they can be used to estimate the data distribution and determine if the data is skewed, bimodal, etc.',
'options': [
{
'elastic_name': 'field',
'pretty_name': 'Field',
'description': 'The field setting defines the numeric field of the documents the percentiles will be computed on.',
'isValid': function() {
return true;
}
}, {
'elastic_name': 'percents',
'pretty_name': 'Percents',
'description': 'Specify just the percents we are interested in (requested percentiles must be a value between 0-100 inclusive)',
'isValid': function() {
return true;
}
}, {
'elastic_name': 'missing',
'pretty_name': 'Missing',
'description': 'A value to use as a default if a given document does not have a given field. Ignored by default.',
'isValid': function(value) {
return true;
}
}
]
},
//
// Percentile Ranks Aggregation
// *****************************
{
'elastic_name': 'percentile_ranks',
'pretty_name': 'Percentile Ranks',
'description': 'A multi-value metrics aggregation that calculates one or more percentiles over numeric values extracted from the aggregated documents. Percentile rank shows the percentage of observed values which are below certain value. For example, if a value is greater than or equal to 95% of the observed values it is said to be at the 95th percentile rank.',
'options': [
{
'elastic_name': 'field',
'pretty_name': 'Field',
'description': 'The field setting defines the numeric field of the documents the minimum will be computed on.',
'isValid': function() {
return true;
}
}, {
'elastic_name': 'values',
'pretty_name': 'Values',
'description': 'Specify just the values we are interested in',
'isValid': function() {
return true;
}
}, {
'elastic_name': 'missing',
'pretty_name': 'Missing',
'description': 'A value to use as a default if a given document does not have a given field. Ignored by default.',
'isValid': function(value) {
return true;
}
}
]
},
//
// Stats Aggregation
// *****************************
{
'elastic_name': 'stats',
'pretty_name': 'Stats',
'description': 'The stats that are returned consist of: min, max, sum, count and avg.',
'options': [
{
'elastic_name': 'field',
'pretty_name': 'Field',
'description': 'The field setting defines the numeric field of the documents the stats will be calculated on.',
'isValid': function() {
return true;
}
}, {
'elastic_name': 'missing',
'pretty_name': 'Missing',
'description': 'A value to use as a default if a given document does not have a given field. Ignored by default.',
'isValid': function(value) {
return true;
}
}
]
},
//
// Sum Aggregation
// *****************************
{
'elastic_name': 'sum',
'pretty_name': 'Sum',
'description': 'A single-value metrics aggregation that sums up numeric values that are extracted from the aggregated documents. These values can be extracted either from specific numeric fields in the documents',
'options': [
{
'elastic_name': 'field',
'pretty_name': 'Field',
'description': 'The field setting defines the numeric field of the documents to be summed.',
'isValid': function() {
return true;
}
}, {
'elastic_name': 'missing',
'pretty_name': 'Missing',
'description': 'A value to use as a default if a given document does not have a given field. Ignored by default.',
'isValid': function(value) {
return true;
}
}
]
},
//
// Value Count Aggregation
// *****************************
{
'elastic_name': 'value_count',
'pretty_name': 'Value Count',
'description': 'A single-value metrics aggregation that counts the number of values that are extracted from the aggregated documents. These values can be extracted either from specific fields in the documents, or be generated by a provided script. Typically, this aggregator will be used in conjunction with other single-value aggregations. For example, when computing the avg one might be interested in the number of values the average is computed over.',
'options': [
{
'elastic_name': 'field',
'pretty_name': 'Field',
'description': 'The field setting defines the numeric field of the documents to be summed.',
'isValid': function() {
return true;
}
}
]
},
//
// Date Histogram Aggregation
// **************************
{
'elastic_name': 'date_histogram',
'pretty_name': 'Date Histogram',
'description': 'A multi-bucket aggregation similar to the histogram except it can only be applied on date values. Scripting is not supported at this time.',
'options': [
{
'elastic_name': 'field',
'pretty_name': 'Field',
'description': 'The name of the field that contains the date to build the histogram from',
'isValid': function() {
return true;
}
}, {
'elastic_name': 'interval',
'pretty_name': 'Interval',
'description': 'The field setting defines the numeric field of the documents the stats will be computed on.',
'isValid': function() {
return true;
}
}, {
'elastic_name': 'offset',
'pretty_name': 'Offset',
'description': 'The offset parameter is used to change the start value of each bucket by the specified positive (+) or negative offset (-) duration, such as 1h for an hour, or 1M for a month.',
'isValid': function() {
return true;
}
}
]
},
].reduce(function(agg_list, agg_meta) {
agg_meta.class = class {
constructor() {
this.meta = agg_meta
}
createAggregations() {
return this.meta.options.reduce(function(aggs, agg_meta) {
let agg_name = agg_meta.elastic_name;
let agg = this[agg_name];
if (!agg_meta.isValid(agg)) {
throw agg;
}
aggs[agg_name] = agg;
return aggs;
}, {});
}
}
return agg_list[agg_meta.elastic_name] = agg_meta;
}, {});
export default Ember.Component.extend({
aggregations: false,
docs: false,
loadingData: Ember.computed('data', function(){
return !this.get('data');
}),
classNameBindings: ['configuring', 'picking', 'width', 'height'],
widgetType: null,
name: 'tobeDetermined',
jsEngine: 'c3',
widthSetting: 2,
heightSetting: 2,
height: Ember.computed(function() {
return this.get('item').height;
}),
width: Ember.computed('widthSetting', function() {
let new_setting = this.get('widthSetting');
let current_setting = this.get('currentWidth');
if (new_setting < 1) {
new_setting = current_setting;
}
if (new_setting > 12) {
new_setting = 12;
}
this.set('currentWidth', new_setting)
return "col-md-" + new_setting;
}),
computedHeight: 200,
computedWidth: 200,
router: Ember.inject.service('router'),
resizedSignal: false,
// Initialize our query parameters
query: 'UC',
gte: "1996-01-01",
lte: (new Date()).toISOString().split('T')[0], // Set the ending date of our query to today's date, by default
tsInterval: Ember.computed('gte','lte', function(){
let d1 = new Date(this.get('gte'));
let d2 = new Date(this.get('lte'));
return dateInterval(d1, d2);
}),
configuring: false,
picking: false,
init() {
this._super(...arguments);
this.set('widthSetting', this.get('item').width);
Promise.resolve(this.fetchWidgetData()).then(() =>{
return this.applyGraphSetting();
});
},
didRender() {
this.set('computedHeight', this.$().height());
this.set('computedWidth', this.$().width());
//
// Use a closure to hide the local variables from the
// global namespace
//
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
},
fetchWidgetData: async function() {
if(this.get('item').post_body === null){
return;
}
let query = this.get('query');
let gte = this.get('gte');
let lte = this.get('lte');
let interval = this.get('tsInterval');
let item = this.get('item');
var endpoint ='/v2/_search?request_cache=true';
if (item.endpoint) {
endpoint = '/search/' + item.endpoint + '/_search?request_cache=true';
}
if (item.indexVersion) {
endpoint += "&v=" + item.indexVersion;
}
let data = await Ember.$.ajax({
url: ENV.apiUrl + endpoint,
crossDomain: true,
type: 'POST',
contentType: 'application/json',
data: stringify(this.get('item').post_body, {
replacer: function(key, value) {
if (Array.isArray(value)) {
return value.filter(Object);
}
return value;
}
})
});
this.set('data', data);
this.set('aggregations', data.aggregations);
this.set('total', data.hits.total);
if(item.chartType === 'relatedResearchers') {
this.set('total', data.aggregations.relatedContributors.value);
}
/*this.set('docs', data.hits.hits.map((hit) => {
let source = Ember.Object.create(hit._source);
let r = source.getProperties('type', 'title', 'description', 'language', 'date', 'date_created', 'date_modified', 'date_updated', 'date_published', 'tags', 'sources');
r.id = hit._id;
r.contributors = source.lists.contributors;
r.funders = source.lists.funders;
r.publishers = source.lists.publishers;
r.institutions = source.lists.institutions;
r.organizations = source.lists.organizations;
return r;
}));
*/
},
applyGraphSetting: function(){
this.set('chartType', this.get('item').chartType);
this.set('widgetType', this.get('item').widgetType);
},
configureQuery: function() {
},
actions: {
addChart: function(option) {
this.sendAction('addChart', option);
},
showConfig: function() {
this.set('configuring', !this.get('configuring'));
this.set('picking', false);
},
showPicker: function() {
this.set('picking', !this.get('picking'));
this.set('configuring', false);
},
changeEngine: function(jsEngine){
console.log(jsEngine);
},
changeChart: function(chart){
this.set('chartType', chart);
},
widgetPicked: function(index){
let selectedWidget = this.get('widgets')[index];
this.set('item', selectedWidget);
console.log(this.get('item').name);
Promise.resolve(this.fetchWidgetData()).then(() => {
return this.applyGraphSetting();
});
},
removeWidget: function() {
this.sendAction('removeChart', this.get('item'))
},
configChanged: function() {
this.set('configuring', !this.get('configuring'));
let name = this.get('name');
if (this.get('resizedSignal') == true) return;
this.set('resizedSignal', true);
this.set('configuring', false);
},
transitionToFacet: function(dashboardName, newQueryParams) {
let self = this;
var queryParams = Object.keys(newQueryParams).reduce((acc, cur, idx, arr) => {
acc[cur] = newQueryParams[cur];
return acc;
}, this.get("parameters"));
this.get('router').transitionTo('dashboards.dashboard', dashboardName, {
queryParams: queryParams
}).then(function(route) {
//Ember.run.schedule('afterRender', self, function() {
// let controller = route.get('controller');
// Object.keys(queryParams).map((key) => {
// controller.set(key, queryParams[key]);
// });
// controller.set('back', 'backroute');
//});
//route.refresh();
});
},
saveWidget: function(){
console.log('saveWidget');
let widgetType = this.get('chartType');
let name = this.get('name');
let jsEngine = this.get('jsEngine');
let chartType = this.get('chartType');
let author = "tobeDetermined";
let width = this.get('widthSetting');
let height = this.get('heightSetting');
let q = this.get('q');
let gte = this.get('gte');
let lte = this.get('lte');
let interval = this.get('tsInterval');
let query = {
query: {bool: {
must: [{
query_string: {query: q}
}, {
range: {date: {
gte: gte,
lte: lte,
format: "yyyy-MM-dd||yyyy"
}}
}]
}},
from: 0,
aggregations: {
sources: {
terms: {
field: 'sources.raw',
size: 200
}
},
contributors : {
terms : {
field: 'contributors.raw',
size: 200
}
},
tags : {
terms : {
field: 'tags.raw',
size: 200
}
},
articles_over_time: {
date_histogram: {
field: 'date',
interval: interval,
format:'yyyy-MM-dd'
},
aggregations: {
arttype: {terms: {field: 'type'}}
}
}
}
};
let settings = {jsEngine: jsEngine, chartType: chartType};
let information = {
name: name,
width: width,
height: height,
query: query,
settings: settings,
};
this.sendAction('dashboardSaveWidget', information);
}
},
});