scenario.ts 5.92 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * Copyright (C) 2017 Centro de Computacao Cientifica e Software Livre
 * Departamento de Informatica - Universidade Federal do Parana
 *
 * This file is part of blendb.
 *
 * blendb is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * blendb is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with blendb.  If not, see <http://www.gnu.org/licenses/>.
 */

21
import { ConfigParser } from "../src/util/configParser";
22 23 24 25
import { Metric } from "../src/core/metric";
import { Dimension } from "../src/core/dimension";
import { View } from "../src/core/view";
import { AggregationType, RelationType } from "../src/common/types";
26
import { Query} from "../src/common/query";
27 28 29 30 31

interface EngineScenario {
    metrics: Metric[];
    dimensions: Dimension[];
    subDimensions: Dimension[];
32 33
    wrongMet: Metric;
    wrongDim: Dimension;
34 35 36 37 38 39 40 41 42 43 44 45
    views: View[];
}

interface AdapterScenario {
    materializedView: View;
    noSelectionView: View;
    withSelectionView: View;
    subDimensionView: View;
    join4View: View;
    dateView: View;
}

46 47 48 49 50
interface DataCtrlScenario {
    wrongMet: Query;
    wrongDim: Query;
    correct: Query;
}
51

52 53 54 55 56
const config = ConfigParser.parse("config/test.yaml");

const mets = config.metrics;
const dims = config.dimensions;
const views = config.views;
57 58 59 60 61 62 63 64 65

const wrongMet = new Metric({
    name: "met:11",
    aggregation: AggregationType.COUNT,
    dataType: "integer"
});
const wrongDim = new Dimension({ name: "dim:11", dataType: "integer" });

const subdimAux = new Dimension({
66
    name: "sub:0",
67 68 69 70 71 72 73 74
    dataType: "integer",
    parent: dims[0],
    relation: RelationType.DAY
});

const subdims = [
    subdimAux,
    new Dimension({
75
        name: "sub:1",
76
        dataType: "integer",
77
        parent: dims[1],
78 79 80
        relation: RelationType.DAY
    }),
    new Dimension({
81
        name: "sub:2",
82 83 84 85 86
        dataType: "integer",
        parent: subdimAux,
        relation: RelationType.DAY
    }),
    new Dimension({
87
        name: "sub:3",
88 89 90 91 92
        dataType: "integer",
        parent: null,
        relation: RelationType.DAY
    }),
    new Dimension({
93
        name: "sub:4",
94 95 96 97 98 99 100 101
        dataType: "integer",
        parent: dims[1],
        relation: RelationType.DAY
    })
];

const dateSubDim = [
    new Dimension ({
102
        name: "dim:0:month",
103
        dataType: "integer",
104
        parent: dims[0],
105 106 107
        relation: RelationType.MONTH
    }),
    new Dimension ({
108
        name: "dim:0:day",
109
        dataType: "integer",
110
        parent: dims[0],
111 112 113
        relation: RelationType.DAY
    }),
    new Dimension ({
114
        name: "dim:0:year",
115
        dataType: "integer",
116
        parent: dims[0],
117 118 119
        relation: RelationType.YEAR
    }),
    new Dimension ({
120
        name: "dim:0:dow",
121
        dataType: "integer",
122
        parent: dims[0],
123 124 125 126 127 128 129 130 131 132 133
        relation: RelationType.DAYOFWEEK
    }),
];

const dateView = new View({
    metrics: [],
    dimensions: dateSubDim,
    materialized: false,
    childViews: [{
        view: views[0],
        metrics: [],
134
        dimensions: [dims[0]]
135 136 137 138 139
    }]
});

const subDimView = new View({
    metrics: [mets[0]],
140
    dimensions: [subdims[0], subdims[1], dims[7], dims[8]],
141 142 143 144 145
    materialized: false,
    childViews: [
        {
            view: views[0],
            metrics: [mets[0]],
146
            dimensions: [dims[0], dims[7]]
147 148
        },
        {
149
            view: views[1],
150
            metrics: [],
151 152 153 154 155 156
            dimensions: [dims[1], dims[8]]
        },
        {
            view: views[4],
            metrics: [],
            dimensions: []
157 158 159 160 161
        }
    ]
});

const join4View = new View({
162 163
    metrics: [mets[0], mets[1], mets[2], mets[3], mets[4], mets[5]],
    dimensions: [dims[2], dims[7], dims[8]],
164 165 166
    materialized: false,
    childViews: [
        {
167 168 169
            view: views[0],
            metrics: [mets[0], mets[1], mets[2]],
            dimensions: [dims[7]]
170 171
        },
        {
172 173 174
            view: views[1],
            metrics: [mets[3], mets[4]],
            dimensions: [dims[8]]
175 176
        },
        {
177
            view: views[2],
178
            metrics: [mets[5], mets[6]],
179
            dimensions: [dims[2]]
180 181 182 183
        },
        {
            view: views[4],
            metrics: [],
184
            dimensions: []
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
        }
    ]
});

const noSelView = new View({
    metrics: [mets[0], mets[3]],
    dimensions: [],
    materialized: false,
    childViews: [
        {
            view: views[0],
            metrics: [mets[0]],
            dimensions: []
        },
        {
200
            view: views[1],
201 202 203 204 205 206 207
            metrics: [mets[3]],
            dimensions: []
        }
    ]
});

const withSelView = new View({
208 209
    metrics: [mets[0], mets[1]],
    dimensions: [dims[7], dims[8]],
210 211 212 213 214
    materialized: false,
    childViews: [
        {
            view: views[0],
            metrics: [mets[0], mets[1]],
215
            dimensions: [dims[7]]
216 217
        },
        {
218 219 220
            view: views[4],
            metrics: [],
            dimensions: [dims[7], dims[8]]
221 222 223 224 225
        }
    ]
});

export const engineScenario: EngineScenario = {
226 227 228 229
    metrics: mets,
    dimensions: dims,
    wrongMet: wrongMet,
    wrongDim: wrongDim,
230
    subDimensions: subdims,
231
    views: views
232 233 234 235 236 237 238 239 240 241
};

export const adapterScenario: AdapterScenario = {
    materializedView: views[0],
    noSelectionView: noSelView,
    withSelectionView: withSelView,
    subDimensionView: subDimView,
    join4View: join4View,
    dateView: dateView
};
242 243 244 245 246 247

export const dataCtrlScenario: DataCtrlScenario = {
    wrongMet: { metrics: [wrongMet], dimensions: [dims[0]] },
    wrongDim: { metrics: [mets[0]], dimensions: [wrongDim] },
    correct: { metrics: [mets[0]], dimensions: [dims[0]] }
};