summaryrefslogtreecommitdiffstats
path: root/qtip/loader/qpi.py
blob: ef6e065e65957fdcd7453241bfafeda4138b0fd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
##############################################################################
# Copyright (c) 2016 ZTE Corp and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

from base import BaseLoader
from metric import MetricSpec

from qtip.base.constant import SpecProp
from qtip.util.formula import Formula


class QPISpec(BaseLoader):
    """
    a QPI specification defines how to calculate a performance index from
     collected metrics.
    """
    RELATIVE_PATH = 'QPI'

    def __init__(self, name, paths=None):
        super(QPISpec, self).__init__(name, paths=paths)
        content = self.content
        self.formula = Formula(content[SpecProp.FORMULA])
        self.sections = [Section(record, paths=paths)
                         for record in content[SpecProp.SECTIONS]]


class Section(object):
    def __init__(self, content, paths=None):
        self.name = content[SpecProp.NAME]
        self.weight = content[SpecProp.WEIGHT]
        self.formula = Formula(content[SpecProp.FORMULA])
        self.metrics = [MetricSpec(record, paths=paths)
                        for record in content[SpecProp.METRICS]]