queryDef.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. define([
  2. 'lodash'
  3. ],
  4. function (_) {
  5. 'use strict';
  6. return {
  7. metricAggTypes: [
  8. {text: "Count", value: 'count' },
  9. {text: "Average of", value: 'avg' },
  10. {text: "Sum of", value: 'sum' },
  11. {text: "Max of", value: 'max' },
  12. {text: "Min of", value: 'min' },
  13. {text: "Extended Stats", value: 'extended_stats' },
  14. {text: "Percentiles", value: 'percentiles' },
  15. {text: "Unique Count", value: "cardinality" }
  16. ],
  17. bucketAggTypes: [
  18. {text: "Terms", value: 'terms' },
  19. {text: "Date Histogram", value: 'date_histogram' },
  20. ],
  21. orderByOptions: [
  22. {text: "Doc Count", value: '_count' },
  23. {text: "Term value", value: '_term' },
  24. ],
  25. orderOptions: [
  26. {text: "Top", value: 'desc' },
  27. {text: "Bottom", value: 'asc' },
  28. ],
  29. sizeOptions: [
  30. {text: "No limit", value: '0' },
  31. {text: "1", value: '1' },
  32. {text: "2", value: '2' },
  33. {text: "3", value: '4' },
  34. {text: "5", value: '5' },
  35. {text: "10", value: '10' },
  36. {text: "15", value: '15' },
  37. {text: "20", value: '20' },
  38. ],
  39. extendedStats: [
  40. {text: 'Avg', value: 'avg'},
  41. {text: 'Min', value: 'min'},
  42. {text: 'Max', value: 'max'},
  43. {text: 'Sum', value: 'sum'},
  44. {text: 'Count', value: 'count'},
  45. {text: 'Std Dev', value: 'std_deviation'},
  46. {text: 'Std Dev Upper', value: 'std_deviation_bounds_upper'},
  47. {text: 'Std Dev Lower', value: 'std_deviation_bounds_lower'},
  48. ],
  49. getOrderByOptions: function(target) {
  50. var self = this;
  51. var metricRefs = [];
  52. _.each(target.metrics, function(metric) {
  53. if (metric.type !== 'count') {
  54. metricRefs.push({text: self.describeMetric(metric), value: metric.id});
  55. }
  56. });
  57. return this.orderByOptions.concat(metricRefs);
  58. },
  59. describeOrder: function(order) {
  60. var def = _.findWhere(this.orderOptions, {value: order});
  61. return def.text;
  62. },
  63. describeMetric: function(metric) {
  64. var def = _.findWhere(this.metricAggTypes, {value: metric.type});
  65. return def.text + ' ' + metric.field;
  66. },
  67. describeOrderBy: function(orderBy, target) {
  68. var def = _.findWhere(this.orderByOptions, {value: orderBy});
  69. if (def) {
  70. return def.text;
  71. }
  72. var metric = _.findWhere(target.metrics, {id: orderBy});
  73. if (metric) {
  74. return this.describeMetric(metric);
  75. } else {
  76. return "metric not found";
  77. }
  78. },
  79. };
  80. });