123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- 'use strict';
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: Dashboard
- * (C) Copyright IBM Corp. 2019, 2020
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['underscore', '../../dataSources/nls/StringResources', '../../lib/@waca/core-client/js/core-client/i18n/Formatter'], function (_, StringResources, Formatter) {
- /*
- * Resolve data item references in the forecast statistical details
- */
- var refResolver = function refResolver(reference, options) {
- var queryResult = options.queryResult;
- if (reference.category) {
- return reference.category;
- }
- var dataItem = queryResult.getDefaultQueryResult().getFacetData().getDataItem(reference.field);
- return dataItem.getTupleHeader()[0].d;
- };
- var bold = { border: 'none', fontWeight: '700', padding: '8px' };
- // regex to match numbers in scientific notation. e.g. "1.123e+32"
- var exponentialRegex = new RegExp('[-+]?[0-9]*.?[0-9]+([eE][-+]?[0-9]+)', 'g');
- /**
- * Item:
- * {
- * path - Array of strings indicating path to the value of a column
- * resolver - Function to resolve references in stat details payload
- * style - Object describing style to be applied on the column
- * header - header style
- * members - member style
- * value - Value to display display in cell
- * format - Format to be applied to value
- * }
- * */
- 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') }, {}, {}];
- 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') }];
- var HEADER = [HEADER_0, HEADER_1];
- var FIXED_COLUMN_STYLE = {
- members: {
- display: 'flex',
- alignItems: 'center'
- }
- };
- var FIXED_COLUMN = [{ path: ['reference'], resolver: refResolver, style: FIXED_COLUMN_STYLE }];
- var Result = function () {
- function Result(queryResult) {
- _classCallCheck(this, Result);
- this.queryResult = queryResult;
- this.statisticalDetails = queryResult.getStatisticalDetails();
- this.formatter = Formatter;
- }
- Result.prototype.getNumFixedColumns = function getNumFixedColumns() {
- return FIXED_COLUMN.length;
- };
- Result.prototype.getNumColumns = function getNumColumns() {
- return HEADER_1.length;
- };
- Result.prototype.getNumRows = function getNumRows() {
- return this.statisticalDetails.length;
- };
- Result.prototype.getHeader = function getHeader(rowIndex, colIndex) {
- var headerInfo = HEADER[rowIndex][colIndex];
- var header = {
- style: {},
- value: headerInfo.value
- };
- if (_.isEmpty(headerInfo)) {
- return {
- value: '',
- style: { gridCell: { display: 'none' }, cellValue: {} }
- };
- }
- header.style.gridCell = headerInfo.style && headerInfo.style.header || {};
- _.extend(header.style.gridCell, bold);
- header.style.cellValue = { alignment: 'center' };
- if (rowIndex === 1) {
- delete header.style.gridCell.border;
- header.style.gridCell.borderRight = 'none';
- }
- return header;
- };
- Result.prototype.getNumHeaderRows = function getNumHeaderRows() {
- return HEADER.length;
- };
- Result.prototype.getFixedColumn = function getFixedColumn(rowIndex, colIndex) {
- return this._getCell(rowIndex, colIndex, FIXED_COLUMN[colIndex]);
- };
- Result.prototype._getCell = function _getCell(rowIndex, colIndex, info) {
- var headerInfo = info;
- if (_.isUndefined(headerInfo.path)) {
- return {
- style: { gridCell: { display: 'none' }, cellValue: { alignment: 'center' } }
- };
- }
- var data = this.statisticalDetails[rowIndex];
- _.each(headerInfo.path, function (p) {
- return data = data[p];
- });
- if (headerInfo.resolver) {
- var option = {
- queryResult: this.queryResult,
- statisticalDetails: this.statisticalDetails
- };
- data = headerInfo.resolver(data, option);
- }
- var shouldFormat = true;
- if (_.isNull(data) || _.isEmpty(data) && !_.isNumber(data)) {
- data = StringResources.get('nullValueText');
- shouldFormat = false;
- }
- if (data.toString().match(exponentialRegex)) {
- shouldFormat = false;
- }
- var gridStyle = headerInfo.style && headerInfo.style.members || {};
- return {
- value: shouldFormat ? this.formatter.format(data, headerInfo.format) : data,
- style: { gridCell: _.extend({ border: 'none' }, gridStyle), cellValue: { alignment: 'center' } }
- };
- };
- Result.prototype.getCell = function getCell(rowIndex, colIndex) {
- return this._getCell(rowIndex, colIndex, HEADER[1][colIndex]);
- };
- return Result;
- }();
- return Result;
- });
- //# sourceMappingURL=Result.js.map
|