scenario.ts 6.53 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
    views: View[];
}

interface AdapterScenario {
    materializedView: View;
    noSelectionView: View;
    withSelectionView: View;
    subDimensionView: View;
    join4View: View;
    dateView: View;
44
    aggrView: View;
45 46
}

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

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

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

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({
67
    name: "sub:0",
68 69 70 71 72 73 74 75
    dataType: "integer",
    parent: dims[0],
    relation: RelationType.DAY
});

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

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

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

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

164 165
const subDimView = new View({
    metrics: [mets[0]],
166
    dimensions: [subdims[0], subdims[1], dims[7], dims[8]],
167
    materialized: false,
168
    origin: false,
169 170 171 172
    childViews: [
        {
            view: views[0],
            metrics: [mets[0]],
173
            dimensions: [dims[0], dims[7]]
174 175
        },
        {
176
            view: views[1],
177
            metrics: [],
178 179 180 181 182 183
            dimensions: [dims[1], dims[8]]
        },
        {
            view: views[4],
            metrics: [],
            dimensions: []
184 185 186 187 188
        }
    ]
});

const join4View = new View({
189 190
    metrics: [mets[0], mets[1], mets[2], mets[3], mets[4], mets[5]],
    dimensions: [dims[2], dims[7], dims[8]],
191
    materialized: false,
192
    origin: false,
193 194
    childViews: [
        {
195 196 197
            view: views[0],
            metrics: [mets[0], mets[1], mets[2]],
            dimensions: [dims[7]]
198 199
        },
        {
200 201 202
            view: views[1],
            metrics: [mets[3], mets[4]],
            dimensions: [dims[8]]
203 204
        },
        {
205
            view: views[2],
206
            metrics: [mets[5], mets[6]],
207
            dimensions: [dims[2]]
208 209 210 211
        },
        {
            view: views[4],
            metrics: [],
212
            dimensions: []
213 214 215 216 217 218 219 220
        }
    ]
});

const noSelView = new View({
    metrics: [mets[0], mets[3]],
    dimensions: [],
    materialized: false,
221
    origin: false,
222 223 224 225 226 227 228
    childViews: [
        {
            view: views[0],
            metrics: [mets[0]],
            dimensions: []
        },
        {
229
            view: views[1],
230 231 232 233 234 235 236
            metrics: [mets[3]],
            dimensions: []
        }
    ]
});

const withSelView = new View({
237 238
    metrics: [mets[0], mets[1]],
    dimensions: [dims[7], dims[8]],
239
    materialized: false,
240
    origin: false,
241 242 243 244
    childViews: [
        {
            view: views[0],
            metrics: [mets[0], mets[1]],
245
            dimensions: [dims[7]]
246 247
        },
        {
248 249 250
            view: views[4],
            metrics: [],
            dimensions: [dims[7], dims[8]]
251 252 253 254 255
        }
    ]
});

export const engineScenario: EngineScenario = {
256 257 258 259
    metrics: mets,
    dimensions: dims,
    wrongMet: wrongMet,
    wrongDim: wrongDim,
260
    subDimensions: subdims,
261
    views: views
262 263 264 265 266 267 268 269
};

export const adapterScenario: AdapterScenario = {
    materializedView: views[0],
    noSelectionView: noSelView,
    withSelectionView: withSelView,
    subDimensionView: subDimView,
    join4View: join4View,
270 271
    dateView: dateView,
    aggrView: aggrView
272
};
273 274 275 276 277 278

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