123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- 'use strict';
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: BI Dashboard
- *| (C) Copyright IBM Corp. 2018, 2020
- *|
- *| US Government Users Restricted Rights - Use, duplication or disclosure
- *| restricted by GSA ADP Schedule Contract with IBM Corp.
- *+------------------------------------------------------------------------+
- */
- /**
- * This Class offers functions to access query result data by keys.
- * @example query result from DSS: dashboard-analytics/widgets/livewidget/features/summary/mocks/SummaryQueryResult.json
- **/
- define(['../../../lib/@waca/core-client/js/core-client/ui/core/Class', 'underscore'], function (BaseClass, _) {
- 'use strict';
- var SummaryQueryResult = BaseClass.extend({
- init: function init(queryResult, logger) {
- this._aDataItems = null; // Array of result data items. Each element is an instance of ResultItem
- this._oDataItemsIndexMap = {}; // Data items map of a summary result for easy access to data items index
- this._oDataPointsMap = {}; // Data points map for easy access to data point by data items index
- this._queryResult = queryResult; // QueryResultData object
- if (this._queryResult.getRowCount() > 0) {
- this._buildDataItemsMap();
- this._buildDataPointsMap();
- }
- this.logger = logger;
- },
- /**
- * @override
- * @public
- * @function getValue
- * @param {string[]} categoryUIds - array of unique category data item ids to identify a summary query result
- * @param {string} measureUId - the unique id of the measure to get the summary
- * @param {string[]} tupleIds - array of unique tuple id to get a summary tuple cell
- * @returns the summary value by category keys (member unique names)
- */
- getValue: function getValue(categoryUIds, measureUId, tupleIds) {
- var _this = this;
- if (!categoryUIds || !tupleIds || this._queryResult.getRowCount() === 0) {
- return null;
- }
- var aCellIdx = []; // Indexes of category member unique ids
- var u;
- var validIdx = true;
- categoryUIds.forEach(function (categoryItemUid, idx) {
- u = tupleIds[idx]; // A category member unique id of the tuple
- var dataIdx = _this._oDataItemsIndexMap[categoryItemUid][u];
- if (dataIdx === undefined) {
- validIdx = false;
- _this.logger.error('Could not find index for: ' + u);
- return;
- }
- aCellIdx.push(dataIdx);
- });
- if (!validIdx) {
- return null;
- }
- var rowIdx = aCellIdx.length ? this._oDataPointsMap[aCellIdx.join()] : 0;
- var measureIdx = this._oDataItemsIndexMap[measureUId]; // Column index in the result
- return this._queryResult.getValue(rowIdx, measureIdx).value;
- },
- /**
- * Build data items map based on item unique IDs and member unique IDs, and store the index of each member of the data item.
- * The indexes will be used to get data point value of the summary query result.
- * @example this._oDataItemsIndexMap:
- * {
- 'model0000016393c2398a_00000001': {
- 'sales_and_marketing_csv.Year_->[2005]': 0,
- 'sales_and_marketing_csv.Year_->[2006]': 1
- },
- 'model00000163b272e450_00000000': 1,
- 'model0000016393c25183_00000000': {
- 'sales_and_marketing_csv.Product_line->[Personal Accessories]': 0,
- 'sales_and_marketing_csv.Product_line->[Camping Equipment]': 1
- },
- 'model0000016393cba0a9_00000003': {
- 'sales_and_marketing_csv.Product_type->[Eyewear]': 0,
- 'sales_and_marketing_csv.Product_type->[Cooking Gear]': 1
- },
- 'model0000016393cc8a97_00000000': {
- 'sales_and_marketing_csv.Order_method_type->[Web]': 0
- },
- 'model0000016393c2744a_00000000': 5
- }
- */
- _buildDataItemsMap: function _buildDataItemsMap() {
- var _this2 = this;
- this._aDataItems = this._aDataItems || this._queryResult.getResultItemList();
- this._aDataItems.forEach(function (resultDataItem, itemIdx) {
- var itemUID = resultDataItem.getId();
- var rowCount = resultDataItem.getRowCount();
- if (rowCount !== 0) {
- _this2._oDataItemsIndexMap[itemUID] = {};
- for (var rowIdx = 0; rowIdx < rowCount; rowIdx++) {
- _this2._oDataItemsIndexMap[itemUID][resultDataItem.getValue(rowIdx)[0].value] = rowIdx;
- }
- } else if (resultDataItem.getDataItemList()[0].getAggregation()) {
- // When there is no tuple and has aggregate, it's a measure. Store the index
- // to be used later to get data point value of the measure.
- _this2._oDataItemsIndexMap[itemUID] = itemIdx;
- }
- });
- },
- /**
- * Build data points map based on item indexes to provide quick access to data point rows
- * @example this._oDataPointsMap
- * {
- '0,0,0,0': 0,
- '1,1,1,0': 1,
- '1,0,0,0': 2
- }
- */
- _buildDataPointsMap: function _buildDataPointsMap() {
- var _this3 = this;
- var dataPoints = this._queryResult.getDataPointValueList();
- dataPoints.forEach(function (dataPoint, idx) {
- /**
- * @example dataPoint: the integers corresponding to category member indexes,
- * and the value object corresponding to measure values, such as avg of Quantity and avg of Revenue.
- * {
- 'pt': [
- 1,
- {
- 'v': 16393.466666666667
- },
- 1,
- 1,
- 0,
- {
- 'v': 338947.1332380951
- }
- ]
- }
- */
- var categoryMemberIndexes = _.filter(dataPoint.pt, function (entry) {
- return typeof entry === 'number';
- });
- _this3._oDataPointsMap[categoryMemberIndexes.join()] = idx;
- });
- }
- });
- return SummaryQueryResult;
- });
- //# sourceMappingURL=SummaryQueryResult.js.map
|