/** * Contains the details of a query for data. * * dimensions - descriptive characteristics of facts * dimension level - a dimension in a hierarchy dimensions * dimension pivot - are dimensions to compare against the above dimensions or the dimension levels * facts - measurements, metrics or facts about a business process. * filters - reduces the results of the data query to those that match the rule specifed by the filter */ export class QueryData { data; /** * Constructor * @param data */ constructor(data: any) { /* Expected format of data parameter: { dim: [], dim_level: [], dim_pivot: [], facts: [] -- facts formatted as ${dimension}+${aggregation}: ["fact_dimension_1+sum", "fact_dimension_1+max", ...] } */ this.data = data; } get factColumns() { let fArray, columns = []; if (this.data.facts) { for (const f of this.data.facts) { fArray = f.split('+'); columns.push(fArray[0]); } } return columns; } get dimensions() { return this.data.dim; } get dimension_levels() { return this.data.dim_level; } get dimension_pivots() { return this.data.dim_pivot; } get hasDimensions() { return this.data.dim && this.data.dim.length > 0; } get hasDimensionLevels() { return this.data.dim_level && this.data.dim_level.length > 0; } get hasDimensionPivots() { return this.data.dim_pivot && this.data.dim_pivot.length > 0; } get hasFacts() { const factColumns = this.factColumns; return factColumns && factColumns.length > 0; } get hasPivot() { return this.hasDimensionPivots; } get isValid() { return (this.hasDimensions || this.hasDimensionLevels) && this.hasFacts; } get columns() { let columns = []; if (this.hasDimensionLevels) { columns.push('levels'); } if (this.hasDimensions) { columns = columns.concat(this.data.dim); } if (this.hasFacts) { columns = columns.concat(this.factColumns); } if (this.hasDimensionPivots) { columns = columns.concat(this.data.dim_pivot); } return columns; } }