PostProcessMultiEdgeMeasures.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5. /*
  6. *+------------------------------------------------------------------------+
  7. *| Licensed Materials - Property of IBM
  8. *| IBM Cognos Products: BI Dashboard
  9. *| (C) Copyright IBM Corp. 2019, 2020
  10. *|
  11. *| US Government Users Restricted Rights - Use, duplication or disclosure
  12. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  13. *+------------------------------------------------------------------------+
  14. */
  15. define(['./QueryPostProcessor', './PostProcessMultiEdgeShowNulls', './QueryResultDataPoints.v2'], function (QueryPostprocessor, PostProcessMultiEdgeShowNulls, QueryResultDataPointsV2) {
  16. 'use strict';
  17. /**
  18. * This post processor has two purposes:
  19. * 1) To make multi-edge, multi-measure data more compatible with row-based output
  20. * by collecting measures into a single data point. [ pt: [0, 1, 0, {v:msr1}, {v:msr2}, ... {v:msrN}]]
  21. * 2) To fill gaps in data where different measures have different numbers of missing values
  22. * By default, v2 responses simply skip cells that have no value.
  23. * Imagine Canada 17 and China 18 have no value for Cost, USA has value 22
  24. * Canada has no value of UnitCost for product trees (7) but both US and Canada have a value for Quantity
  25. * V2 RESPONSE: EG:
  26. * [ pt: [ 16, 7, 0, { v:15 }]], Brazil cost = 15
  27. * GAP....no cost for Canada, or China.
  28. * [ pt: [ 19, 7, 0, { v:21 }]], Colombia cost = 21
  29. * : etc.
  30. * [ pt: [ 22, 7, 0, { v:122 } ]], USA cost = 122
  31. * :
  32. * [ pt: [ 17, 7, 1, { v:1000 }]], Canada Quantity = 1000
  33. * :
  34. * [ pt: [ 22, 7, 1, { v:2000 }]] USA Quantity = 2000
  35. *
  36. * AFTER POST-PROCESSING: In the end, these rows appear like this.
  37. * [ pt: [ 16, 7, 0, { v:15}, { v:500 } ]],
  38. * [ pt: [ 17, 7, 0, { v:null }, { v:1000 } ]], //Canada Cost null, Quantity 1000
  39. * [ pt: [ 18, 7, 0, { v:null }, { v:3200 }]], //China Cost null, Quantity 3200
  40. * :
  41. * [ pt: [ 22, 7, 0, { v:122 }, { v:2000 }]] //USA Cost: 122, Quantity 2000
  42. **/
  43. return function (_QueryPostprocessor) {
  44. _inherits(PostProcessMultiEdgeMeasures, _QueryPostprocessor);
  45. /**
  46. * @Constructor
  47. * @param {Object} options
  48. */
  49. function PostProcessMultiEdgeMeasures(_ref) {
  50. var queryResultData = _ref.queryResultData,
  51. queryDefinition = _ref.queryDefinition,
  52. suppressionEnabled = _ref.suppressionEnabled;
  53. _classCallCheck(this, PostProcessMultiEdgeMeasures);
  54. var _this = _possibleConstructorReturn(this, _QueryPostprocessor.call(this, { queryResultData: queryResultData }));
  55. _this.queryDefinition = queryDefinition;
  56. _this.data = _this._queryResultData.data;
  57. _this.dataItems = _this._queryResultData.dataItems;
  58. _this.suppressionEnabled = suppressionEnabled;
  59. return _this;
  60. }
  61. /**
  62. * Apply the users overrides
  63. * @return {QueryResultData}
  64. */
  65. PostProcessMultiEdgeMeasures.prototype._processData = function _processData() {
  66. if (this._queryResultData.edges && this._queryResultData.edges.length > 1 && this._queryResultData.data && this._queryResultData.data.length > 0) {
  67. //This post processor is only for multi-edge.
  68. //in v2, regardless suppression is on or off, we will need to populate the null values;
  69. var dataPoints = this._buildQueryResultDataPoints();
  70. if (dataPoints) {
  71. var showNullsProcessor = new PostProcessMultiEdgeShowNulls({
  72. queryResultDataPoints: dataPoints,
  73. queryResultData: this._queryResultData
  74. });
  75. this._queryResultData = showNullsProcessor._processData();
  76. }
  77. }
  78. //For V1 or single edge V2, this postProcessor is a no-op.
  79. return this._queryResultData;
  80. };
  81. //If there is more than 1 measure, process the measure edge, otherwise postprocessor is no-op.
  82. PostProcessMultiEdgeMeasures.prototype._buildQueryResultDataPoints = function _buildQueryResultDataPoints() {
  83. var measureEdgeIndex = this.queryDefinition && this.queryDefinition.getDataItemSetList().length && this.queryDefinition.getDataItemSetList().findIndex(function (dataItemSet) {
  84. return dataItemSet.isMeasureItemSet();
  85. });
  86. if (measureEdgeIndex !== -1) {
  87. //Both measures and calculations should be included in the measure count.
  88. var measureCount = 0;
  89. this.queryDefinition.getDataItemSetList().forEach(function (dataItemSet) {
  90. if (dataItemSet.isMeasureItemSet()) {
  91. measureCount += dataItemSet.getDataItemList().length + dataItemSet.getCalculationList().length;
  92. }
  93. });
  94. return this._loadQueryResultDataPoints(measureCount, measureEdgeIndex);
  95. }
  96. return null; //No multiEdge data could be built (we had no measures)
  97. };
  98. PostProcessMultiEdgeMeasures.prototype._loadQueryResultDataPoints = function _loadQueryResultDataPoints(measureCount, measureEdgeIndex) {
  99. var edgeCount = this._queryResultData.edges && this._queryResultData.edges.length;
  100. var queryResultDataPoints = new QueryResultDataPointsV2(edgeCount, measureCount, measureEdgeIndex, this.suppressionEnabled);
  101. queryResultDataPoints.loadPoints(this.data);
  102. return queryResultDataPoints;
  103. };
  104. return PostProcessMultiEdgeMeasures;
  105. }(QueryPostprocessor);
  106. });
  107. //# sourceMappingURL=PostProcessMultiEdgeMeasures.js.map