KPI Builder Base Class¶
KPIBuilder
¶
Bases: ABC, Generic[KPIDefinitionType]
Base class of the KPI builders: methods that configure the builder and return it, then build().
All builders take a name prefix, a name suffix and extra attributes for
the KPIs. A subclass implements build(), which returns the KPI
definitions.
Examples:
>>> from mesqual.kpis import Aggregations, FlagAggKPIBuilder
>>> definitions = (
... FlagAggKPIBuilder()
... .for_flag('Country.Results.price')
... .with_aggregation(Aggregations.Mean)
... .with_name_prefix('Study: ')
... .with_extra_attributes(category='prices')
... .build()
... )
Source code in src/mesqual/kpis/builders/base.py
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
__init__
¶
__init__()
Initialize builder with common attributes.
Source code in src/mesqual/kpis/builders/base.py
29 30 31 32 33 34 | |
with_name_prefix
¶
with_name_prefix(prefix: str) -> KPIBuilder
Set name prefix for generated KPIs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix
|
str
|
Prefix string to prepend to KPI names |
required |
Returns:
| Type | Description |
|---|---|
KPIBuilder
|
Self for method chaining |
Source code in src/mesqual/kpis/builders/base.py
36 37 38 39 40 41 42 43 44 45 46 47 | |
with_name_suffix
¶
with_name_suffix(suffix: str) -> KPIBuilder
Set name suffix for generated KPIs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
suffix
|
str
|
Suffix string to append to KPI names |
required |
Returns:
| Type | Description |
|---|---|
KPIBuilder
|
Self for method chaining |
Source code in src/mesqual/kpis/builders/base.py
49 50 51 52 53 54 55 56 57 58 59 60 | |
with_custom_name
¶
with_custom_name(name: str) -> KPIBuilder
Set custom name that completely overrides automatic name generation.
When set, the KPI will use this exact name instead of generating one from flag, aggregation, object, etc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Custom name for the KPI |
required |
Returns:
| Type | Description |
|---|---|
KPIBuilder
|
Self for method chaining |
Source code in src/mesqual/kpis/builders/base.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
with_extra_attributes
¶
with_extra_attributes(**kwargs) -> KPIBuilder
Set additional extra (custom) attributes.
When set, the KPI will contain these attributes under "kpi.attributes.extra_attributes".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Custom key-value attributes. |
{}
|
Returns:
| Type | Description |
|---|---|
KPIBuilder
|
Self for method chaining |
Source code in src/mesqual/kpis/builders/base.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
build
abstractmethod
¶
build() -> list[KPIDefinitionType]
Generate all KPI definitions from builder configuration.
Returns:
| Type | Description |
|---|---|
list[KPIDefinitionType]
|
List of KPI definition instances |
Source code in src/mesqual/kpis/builders/base.py
93 94 95 96 97 98 99 100 101 | |