Skip to content

Base KPI Definition

KPIDefinition

Bases: ABC

Abstract base for KPI specifications.

Defines WHAT to compute, not HOW to compute efficiently. Subclasses implement generate_kpis() to create KPI instances.

A KPIDefinition is a lightweight specification that can be created once and used to generate KPIs for multiple datasets.

Source code in submodules/mesqual/mesqual/kpis/definitions/base.py
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
39
40
41
42
43
44
45
46
47
48
49
50
class KPIDefinition(ABC):
    """
    Abstract base for KPI specifications.

    Defines WHAT to compute, not HOW to compute efficiently.
    Subclasses implement generate_kpis() to create KPI instances.

    A KPIDefinition is a lightweight specification that can be created
    once and used to generate KPIs for multiple datasets.
    """

    @abstractmethod
    def generate_kpis(self, dataset: Dataset) -> list[KPI]:
        """
        Generate KPI instances from this definition.

        This method is responsible for:
        1. Fetching required data from dataset
        2. Computing values
        3. Creating KPI instances with proper attributes

        Args:
            dataset: Dataset to compute KPIs for

        Returns:
            List of computed KPI instances
        """
        pass

    @abstractmethod
    def required_flags(self) -> set[FlagTypeProtocol]:
        """
        Return set of flags needed for computation.

        Returns:
            Set of flags required by this definition
        """
        pass

generate_kpis abstractmethod

generate_kpis(dataset: Dataset) -> list[KPI]

Generate KPI instances from this definition.

This method is responsible for: 1. Fetching required data from dataset 2. Computing values 3. Creating KPI instances with proper attributes

Parameters:

Name Type Description Default
dataset Dataset

Dataset to compute KPIs for

required

Returns:

Type Description
list[KPI]

List of computed KPI instances

Source code in submodules/mesqual/mesqual/kpis/definitions/base.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
@abstractmethod
def generate_kpis(self, dataset: Dataset) -> list[KPI]:
    """
    Generate KPI instances from this definition.

    This method is responsible for:
    1. Fetching required data from dataset
    2. Computing values
    3. Creating KPI instances with proper attributes

    Args:
        dataset: Dataset to compute KPIs for

    Returns:
        List of computed KPI instances
    """
    pass

required_flags abstractmethod

required_flags() -> set[FlagTypeProtocol]

Return set of flags needed for computation.

Returns:

Type Description
set[FlagTypeProtocol]

Set of flags required by this definition

Source code in submodules/mesqual/mesqual/kpis/definitions/base.py
42
43
44
45
46
47
48
49
50
@abstractmethod
def required_flags(self) -> set[FlagTypeProtocol]:
    """
    Return set of flags needed for computation.

    Returns:
        Set of flags required by this definition
    """
    pass