import { ExecuteAFM as AFM, Execution } from "@gooddata/typings"; import { IMockProject } from "../../../model/MockProject"; import { IErrorResponse } from "../executeAfm"; import { IDataResultRandomGeneratorParams } from "./headerItems"; import IMeasureHeaderItem = Execution.IMeasureHeaderItem; import IResultDimension = Execution.IResultDimension; import IResultHeaderItem = Execution.IResultHeaderItem; export declare type RandomMetricValueGenerator = (params: IDataResultRandomGeneratorParams) => string; export declare type RandomData = any[][] | any[]; /** * Result headers for all dimensions */ export declare type Headers = DimensionHeaders[]; /** * Result headers for particular dimension. */ export declare type DimensionHeaders = IResultHeaderItem[][]; export interface IRandomDataResult { /** * Result dimensions - as returned by executeAfm */ dims: IResultDimension[]; /** * Headers - as needed by execution result */ headerItems: Headers; /** * Expanded measure header items matching expanded result header measure items in respective dimension. */ measureHeaderItems: IMeasureHeaderItem[][]; /** * El data */ data: RandomData; /** * Empty data indicator */ isEmpty: boolean; } /** * Data result builder is capable of taking any AFM & result spec and generate the headers and data sheet * accordingly. This builder can be used for all purposes (simple tabular, stacking, pivot table etc) */ export declare class DataResultBuilder { static forProject(project: IMockProject): DataResultBuilder; private readonly project; private execution; private afm?; private resultSpec?; private generator?; private date; private constructor(); forAfmAndResultSpec(execution: AFM.IExecution): DataResultBuilder; withGenerator(generator: RandomMetricValueGenerator): DataResultBuilder; atDate(date: Date): DataResultBuilder; build(): IRandomDataResult | IErrorResponse; private checkInputs; /** * Generates result headers for each dimension (total of 2). * * 1. Each dimension contains a list of header items; * 2. For each header item in the list: * - if attribute expand to attribute elements * - if measure group expand to all measures in the group * 3. This produces a array X = [Y1, Y2, ... Yn] where each Yn is array and N = number of headers in the dim * 4. Do a cartesian between elementf of X * 5. This produces an array A = [B1, B2, ... Bm] where each Bm is a resulting combination produced by cartesian. * Here M = * (Yn.len) and cardinality of each Bm is N * 6. Finally do rotation on A, leading to R = [H1, H2, ... Hn] where N is number of headers in the dim and * cardinality of each Hn is M * * The resulting list R is the format ready to be returned as a result. * * @param dims result dimensions */ private generateHeaders; /** * Generates an expanded array of measure header items for particular dimension. The cardinality of the * resulting array is same as cardinality of header items in the dimension that contains measureGroup. * * The algorithm here is similar to generateHeaders, the only difference in the return value: * * - Measure group is NOT expanded into IResultMeasureHeaderItem but into IMeasureHeaderItem - this structure * contains all necessary detail to generate values for the measure (as opposed to result item which contains * name and order) * * - The result is just the array of IMeasureHeaderItem = one particular subarray * * @param dim result dimensions */ private getExpandedMeasureItems; private getExpandedMeasuresFromRows; private getExpandedMeasuresFromCols; private generateRowData; private generateColumnData; private generateData; private sort; }