Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recalculate bit when a config object changes #3206

Merged
27 changes: 20 additions & 7 deletions octopoes/octopoes/core/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from collections import Counter
from collections.abc import Callable, ValuesView
from datetime import datetime, timezone
from itertools import chain
from logging import getLogger
from typing import overload

Expand All @@ -28,6 +29,7 @@
)
from octopoes.models.exception import ObjectNotFoundException
from octopoes.models.explanation import InheritanceSection
from octopoes.models.ooi.config import Config
from octopoes.models.origin import Origin, OriginParameter, OriginType
from octopoes.models.pagination import Paginated
from octopoes.models.path import (
Expand Down Expand Up @@ -400,14 +402,25 @@ def _on_update_ooi(self, event: OOIDBEvent) -> None:
if event.new_data is None:
raise ValueError("Update event new_data should not be None")

inference_origins = self.origin_repository.list_origins(event.valid_time, source=event.new_data.reference)
inference_params = self.origin_parameter_repository.list_by_reference(
event.new_data.reference, valid_time=event.valid_time
)
for inference_param in inference_params:
inference_origins.append(self.origin_repository.get(inference_param.origin_id, event.valid_time))
if isinstance(event.new_data, Config):
relevant_bits = [bit for bit in get_bit_definitions().values() if bit.config_ooi_relation_path is not None]
inference_origins = list(
{
x.model_dump_json(): x
originalsouth marked this conversation as resolved.
Show resolved Hide resolved
for x in chain.from_iterable(
map(lambda x: self.origin_repository.list_origins(event.valid_time, method=x.id), relevant_bits)
underdarknl marked this conversation as resolved.
Show resolved Hide resolved
)
}.values()
)
else:
inference_origins = self.origin_repository.list_origins(event.valid_time, source=event.new_data.reference)
inference_params = self.origin_parameter_repository.list_by_reference(
event.new_data.reference, valid_time=event.valid_time
)
for inference_param in inference_params:
inference_origins.append(self.origin_repository.get(inference_param.origin_id, event.valid_time))

inference_origins = [o for o in inference_origins if o.origin_type == OriginType.INFERENCE]
inference_origins = [o for o in inference_origins if o.origin_type == OriginType.INFERENCE]
for inference_origin in inference_origins:
self._run_inference(inference_origin, event.valid_time)

Expand Down
5 changes: 5 additions & 0 deletions octopoes/octopoes/repositories/origin_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def list_origins(
task_id: UUID | None = None,
source: Reference | None = None,
result: Reference | None = None,
method: str | None = None,
origin_type: OriginType | None = None,
) -> list[Origin]:
raise NotImplementedError
Expand Down Expand Up @@ -73,6 +74,7 @@ def list_origins(
task_id: UUID | None = None,
source: Reference | None = None,
result: Reference | None = None,
method: str | None = None,
origin_type: OriginType | None = None,
) -> list[Origin]:
where_parameters = {"type": Origin.__name__}
Expand All @@ -86,6 +88,9 @@ def list_origins(
if result:
where_parameters["result"] = str(result)

if method:
where_parameters["method"] = method

if origin_type:
where_parameters["origin_type"] = origin_type.value

Expand Down