def build(
self,
domain: Domain,
statistic_group: StatisticGroup,
statistic_group_spec: StatisticGroupSpec,
*,
check: bool,
summary: BuildSummary,
) -> None:
from django_spire.metric.utils import ( # noqa: PLC0415
_count_sync,
_report_deleted,
_statistic_key,
)
stored_key = _statistic_key(domain.key, statistic_group_spec, self)
path = f'{domain.key}/{statistic_group_spec.key}/{self.key}'
statistic = Statistic.objects.for_key(stored_key).first()
created = False
if statistic is None:
if check:
summary.missing.append(path)
return
values: dict[str, Any] = {'group': statistic_group, 'name': self.name}
if self.interval:
values['interval'] = self.interval
if self.value_type:
values['value_type'] = self.value_type
statistic, created = Statistic.objects.get_or_create(key=stored_key, defaults=values)
if created:
summary.created += 1
return
if statistic.is_deleted:
_report_deleted(summary, path, check)
return
sync_values: dict[str, Any] = {'name': self.name}
if self.interval:
sync_values['interval'] = self.interval
if self.value_type:
sync_values['value_type'] = self.value_type
_count_sync(summary, statistic, sync_values, path, check)