in lib/metric-config-parser/metric_config_parser/metric.py [0:0]
def merge(self, other: "MetricsSpec"):
"""
Merges another metrics spec into the current one.
The `other` MetricsSpec overwrites existing metrics.
"""
self.daily = other.daily + self.daily
self.weekly = other.weekly + self.weekly
self.days28 = other.days28 + self.days28
self.overall = other.overall + self.overall
self.preenrollment_weekly = other.preenrollment_weekly + self.preenrollment_weekly
self.preenrollment_days28 = other.preenrollment_days28 + self.preenrollment_days28
seen = set()
for key, _ in self.definitions.items():
for other_key in other.definitions:
# support wildcard characters in `other`
other_key_regex = re.compile(fnmatch.translate(other_key))
if other_key_regex.fullmatch(key):
self.definitions[key].merge(other.definitions[other_key])
seen.add(other_key)
seen.add(key)
for key, definition in other.definitions.items():
if key not in seen and is_valid_slug(key):
self.definitions[key] = definition