Result.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. /**
  4. * Licensed Materials - Property of IBM
  5. * IBM Cognos Products: Dashboard
  6. * (C) Copyright IBM Corp. 2019, 2020
  7. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. */
  9. define(['underscore', '../../dataSources/nls/StringResources', '../../lib/@waca/core-client/js/core-client/i18n/Formatter'], function (_, StringResources, Formatter) {
  10. /*
  11. * Resolve data item references in the forecast statistical details
  12. */
  13. var refResolver = function refResolver(reference, options) {
  14. var queryResult = options.queryResult;
  15. if (reference.category) {
  16. return reference.category;
  17. }
  18. var dataItem = queryResult.getDefaultQueryResult().getFacetData().getDataItem(reference.field);
  19. return dataItem.getTupleHeader()[0].d;
  20. };
  21. var bold = { border: 'none', fontWeight: '700', padding: '8px' };
  22. // regex to match numbers in scientific notation. e.g. "1.123e+32"
  23. var exponentialRegex = new RegExp('[-+]?[0-9]*.?[0-9]+([eE][-+]?[0-9]+)', 'g');
  24. /**
  25. * Item:
  26. * {
  27. * path - Array of strings indicating path to the value of a column
  28. * resolver - Function to resolve references in stat details payload
  29. * style - Object describing style to be applied on the column
  30. * header - header style
  31. * members - member style
  32. * value - Value to display display in cell
  33. * format - Format to be applied to value
  34. * }
  35. * */
  36. var HEADER_0 = [{ style: { header: { left: '0px' } }, value: StringResources.get('forecastDetailsForecastLabel') }, {}, { style: { header: { left: '400px', width: '200px' } }, value: StringResources.get('forecastDetailsModelLabel') }, {}, {}, {}, {}, {}, { style: { header: { left: '1250px', width: '220px' } }, value: StringResources.get('forecastDetailsQualityMetricLabel') }, {}, {}, {}, {}, {}, {}, { style: { header: { left: '2365px', width: '200px' } }, value: StringResources.get('forecastDetailsSmoothingCoefLabel') }, {}, {}, {}, {}, {}, {}, { style: { header: { left: '3550px', width: '200px' } }, value: StringResources.get('forecastDetailsDiagnostics') }, {}, {}];
  37. var HEADER_1 = [{ path: ['status'], value: StringResources.get('forecastDetailsStatusLabel') }, {}, { path: ['model', 'trend', 'type'], value: StringResources.get('forecastDetailsTrendLabel') }, { path: ['model', 'season', 'type'], value: StringResources.get('forecastDetailsSeasonLabel') }, {}, { path: ['accuracy', 'accuracy'], value: StringResources.get('forecastDetailsAccuracyPercentLabel'), format: { type: 'percent', minimumFractionDigits: 1 }, style: { members: bold } }, { path: ['accuracy', 'MASE'], value: 'MASE', format: { type: 'number', minimumFractionDigits: 3 }, style: { members: bold } }, { path: ['accuracy', 'MAE'], value: 'MAE', format: { type: 'number', minimumFractionDigits: 3 } }, { path: ['accuracy', 'RMSE'], value: 'RMSE', format: { type: 'number', minimumFractionDigits: 3 } }, { path: ['accuracy', 'MAPE'], value: 'MAPE', format: { type: 'percent', minimumFractionDigits: 1 } }, { path: ['accuracy', 'AIC'], value: 'AIC', format: { type: 'number', minimumFractionDigits: 3 } }, {}, { path: ['model', 'season', 'period'], value: StringResources.get('forecastDetailsSeasonalPeriodLabel') }, { path: ['model', 'parameters', 'alpha'], value: StringResources.get('forecastDetailsAlphaLabel'), format: { type: 'number', minimumFractionDigits: 3 } }, { path: ['model', 'parameters', 'beta'], value: StringResources.get('forecastDetailsBetaLabel'), format: { type: 'number', minimumFractionDigits: 3 } }, { path: ['model', 'parameters', 'gamma'], value: StringResources.get('forecastDetailsGammaLabel'), format: { type: 'number', minimumFractionDigits: 3 } }, { path: ['model', 'parameters', 'phi'], value: StringResources.get('forecastDetailsPhiLabel'), format: { type: 'number', minimumFractionDigits: 3 } }, {}, { path: ['data', 'missingCount'], value: StringResources.get('forecastDetailsMissingCount') }, { path: ['data', 'seriesLength'], value: StringResources.get('forecastDetailsSeriesLengthLabel') }, { path: ['model', 'ignoredPeriods'], value: StringResources.get('forecastDetailsIgnoredPeriods') }, { path: ['model', 'trend', 'strength'], value: StringResources.get('forecastDetailsTrendStrength'), format: { type: 'percent', minimumFractionDigits: 1 } }, { path: ['model', 'season', 'strength'], value: StringResources.get('forecastDetailsSeasonalityStrength'), format: { type: 'percent', minimumFractionDigits: 1 } }, { path: ['data', 'timeDeltaUnit'], value: StringResources.get('forecastDetailsTimeDeltaUnit') }, { path: ['notes'], value: StringResources.get('forecastDetailsNotes') }];
  38. var HEADER = [HEADER_0, HEADER_1];
  39. var FIXED_COLUMN_STYLE = {
  40. members: {
  41. display: 'flex',
  42. alignItems: 'center'
  43. }
  44. };
  45. var FIXED_COLUMN = [{ path: ['reference'], resolver: refResolver, style: FIXED_COLUMN_STYLE }];
  46. var Result = function () {
  47. function Result(queryResult) {
  48. _classCallCheck(this, Result);
  49. this.queryResult = queryResult;
  50. this.statisticalDetails = queryResult.getStatisticalDetails();
  51. this.formatter = Formatter;
  52. }
  53. Result.prototype.getNumFixedColumns = function getNumFixedColumns() {
  54. return FIXED_COLUMN.length;
  55. };
  56. Result.prototype.getNumColumns = function getNumColumns() {
  57. return HEADER_1.length;
  58. };
  59. Result.prototype.getNumRows = function getNumRows() {
  60. return this.statisticalDetails.length;
  61. };
  62. Result.prototype.getHeader = function getHeader(rowIndex, colIndex) {
  63. var headerInfo = HEADER[rowIndex][colIndex];
  64. var header = {
  65. style: {},
  66. value: headerInfo.value
  67. };
  68. if (_.isEmpty(headerInfo)) {
  69. return {
  70. value: '',
  71. style: { gridCell: { display: 'none' }, cellValue: {} }
  72. };
  73. }
  74. header.style.gridCell = headerInfo.style && headerInfo.style.header || {};
  75. _.extend(header.style.gridCell, bold);
  76. header.style.cellValue = { alignment: 'center' };
  77. if (rowIndex === 1) {
  78. delete header.style.gridCell.border;
  79. header.style.gridCell.borderRight = 'none';
  80. }
  81. return header;
  82. };
  83. Result.prototype.getNumHeaderRows = function getNumHeaderRows() {
  84. return HEADER.length;
  85. };
  86. Result.prototype.getFixedColumn = function getFixedColumn(rowIndex, colIndex) {
  87. return this._getCell(rowIndex, colIndex, FIXED_COLUMN[colIndex]);
  88. };
  89. Result.prototype._getCell = function _getCell(rowIndex, colIndex, info) {
  90. var headerInfo = info;
  91. if (_.isUndefined(headerInfo.path)) {
  92. return {
  93. style: { gridCell: { display: 'none' }, cellValue: { alignment: 'center' } }
  94. };
  95. }
  96. var data = this.statisticalDetails[rowIndex];
  97. _.each(headerInfo.path, function (p) {
  98. return data = data[p];
  99. });
  100. if (headerInfo.resolver) {
  101. var option = {
  102. queryResult: this.queryResult,
  103. statisticalDetails: this.statisticalDetails
  104. };
  105. data = headerInfo.resolver(data, option);
  106. }
  107. var shouldFormat = true;
  108. if (_.isNull(data) || _.isEmpty(data) && !_.isNumber(data)) {
  109. data = StringResources.get('nullValueText');
  110. shouldFormat = false;
  111. }
  112. if (data.toString().match(exponentialRegex)) {
  113. shouldFormat = false;
  114. }
  115. var gridStyle = headerInfo.style && headerInfo.style.members || {};
  116. return {
  117. value: shouldFormat ? this.formatter.format(data, headerInfo.format) : data,
  118. style: { gridCell: _.extend({ border: 'none' }, gridStyle), cellValue: { alignment: 'center' } }
  119. };
  120. };
  121. Result.prototype.getCell = function getCell(rowIndex, colIndex) {
  122. return this._getCell(rowIndex, colIndex, HEADER[1][colIndex]);
  123. };
  124. return Result;
  125. }();
  126. return Result;
  127. });
  128. //# sourceMappingURL=Result.js.map