query_def.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. define([
  2. 'lodash'
  3. ],
  4. function (_) {
  5. 'use strict';
  6. return {
  7. metricAggTypes: [
  8. {text: "Count", value: 'count', requiresField: false},
  9. {text: "Average", value: 'avg', requiresField: true},
  10. {text: "Sum", value: 'sum', requiresField: true},
  11. {text: "Max", value: 'max', requiresField: true},
  12. {text: "Min", value: 'min', requiresField: true},
  13. {text: "Extended Stats", value: 'extended_stats', requiresField: true},
  14. {text: "Percentiles", value: 'percentiles', requiresField: true},
  15. {text: "Moving Avg", value: 'moving_avg', requiresField: false },
  16. {text: "Unique Count", value: "cardinality", requiresField: true},
  17. {text: "Raw Document", value: "raw_document", requiresField: false}
  18. ],
  19. bucketAggTypes: [
  20. {text: "Terms", value: 'terms' },
  21. {text: "Filters", value: 'filters' },
  22. {text: "Date Histogram", value: 'date_histogram' },
  23. ],
  24. orderByOptions: [
  25. {text: "Doc Count", value: '_count' },
  26. {text: "Term value", value: '_term' },
  27. ],
  28. orderOptions: [
  29. {text: "Top", value: 'desc' },
  30. {text: "Bottom", value: 'asc' },
  31. ],
  32. sizeOptions: [
  33. {text: "No limit", value: '0' },
  34. {text: "1", value: '1' },
  35. {text: "2", value: '2' },
  36. {text: "3", value: '3' },
  37. {text: "5", value: '5' },
  38. {text: "10", value: '10' },
  39. {text: "15", value: '15' },
  40. {text: "20", value: '20' },
  41. ],
  42. extendedStats: [
  43. {text: 'Avg', value: 'avg'},
  44. {text: 'Min', value: 'min'},
  45. {text: 'Max', value: 'max'},
  46. {text: 'Sum', value: 'sum'},
  47. {text: 'Count', value: 'count'},
  48. {text: 'Std Dev', value: 'std_deviation'},
  49. {text: 'Std Dev Upper', value: 'std_deviation_bounds_upper'},
  50. {text: 'Std Dev Lower', value: 'std_deviation_bounds_lower'},
  51. ],
  52. intervalOptions: [
  53. {text: 'auto', value: 'auto'},
  54. {text: '10s', value: '10s'},
  55. {text: '1m', value: '1m'},
  56. {text: '5m', value: '5m'},
  57. {text: '10m', value: '10m'},
  58. {text: '20m', value: '20m'},
  59. {text: '1h', value: '1h'},
  60. {text: '1d', value: '1d'},
  61. ],
  62. getMovingAverageSourceOptions: function(targets) {
  63. var self = this;
  64. var result = [];
  65. _.each(targets.metrics, function(metric) {
  66. if (metric.type !== 'moving_avg') {
  67. result.push({text: self.describeMetric(metric), value: metric.id });
  68. }
  69. });
  70. return result;
  71. },
  72. getOrderByOptions: function(target) {
  73. var self = this;
  74. var metricRefs = [];
  75. _.each(target.metrics, function(metric) {
  76. if (metric.type !== 'count') {
  77. metricRefs.push({text: self.describeMetric(metric), value: metric.id});
  78. }
  79. });
  80. return this.orderByOptions.concat(metricRefs);
  81. },
  82. describeOrder: function(order) {
  83. var def = _.findWhere(this.orderOptions, {value: order});
  84. return def.text;
  85. },
  86. describeMetric: function(metric) {
  87. var def = _.findWhere(this.metricAggTypes, {value: metric.type});
  88. return def.text + ' ' + metric.field;
  89. },
  90. describeOrderBy: function(orderBy, target) {
  91. var def = _.findWhere(this.orderByOptions, {value: orderBy});
  92. if (def) {
  93. return def.text;
  94. }
  95. var metric = _.findWhere(target.metrics, {id: orderBy});
  96. if (metric) {
  97. return this.describeMetric(metric);
  98. } else {
  99. return "metric not found";
  100. }
  101. },
  102. };
  103. });