first commit
This commit is contained in:
27
backend/app/services/catalog.py
Normal file
27
backend/app/services/catalog.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
from app.core_settings import AppSettings, get_settings
|
||||
from app.models.definitions import MetricDefinition
|
||||
|
||||
|
||||
@dataclass
|
||||
class MetricCatalog:
|
||||
settings: AppSettings
|
||||
|
||||
def get(self, metric_id: str) -> MetricDefinition:
|
||||
if metric_id not in self.settings.metrics:
|
||||
raise KeyError(f"Unknown metric: {metric_id}")
|
||||
return self.settings.metrics[metric_id]
|
||||
|
||||
def safe_get(self, metric_id: str) -> MetricDefinition | None:
|
||||
return self.settings.metrics.get(metric_id)
|
||||
|
||||
def visible_entities(self) -> list[MetricDefinition]:
|
||||
return [self.get(metric_id) for metric_id in self.settings.visible_entity_table if metric_id in self.settings.metrics]
|
||||
|
||||
|
||||
|
||||
def get_catalog() -> MetricCatalog:
|
||||
return MetricCatalog(get_settings())
|
||||
Reference in New Issue
Block a user