-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5f1bb75
commit 60dacbe
Showing
13 changed files
with
176 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from internal.domain.task.entities import FdTask # noqa: F401 | ||
from internal.domain.task.entities import AfdTask # noqa: F401 | ||
from internal.domain.task.entities import AcTask # noqa: F401 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from internal.domain.task.entities.ac.ac_task import AcTask # noqa: F401 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from desbordante.ac.algorithms import AcAlgorithm | ||
from desbordante.ac.algorithms import Default | ||
|
||
from internal.domain.task.entities.task import Task | ||
from internal.domain.task.value_objects import PrimitiveName, IncorrectAlgorithmName | ||
from internal.domain.task.value_objects.ac import AcTaskConfig, AcTaskResult | ||
from internal.domain.task.value_objects.ac import ( | ||
AcAlgoName, | ||
AcModel, | ||
AcAlgoResult, | ||
AcExceptionModel, | ||
) | ||
|
||
|
||
class AcTask(Task[AcAlgorithm, AcTaskConfig, AcTaskResult]): | ||
""" | ||
Task class for Approximate Consistency (AC) profiling. | ||
This class handles the execution of different AC algorithms and processes | ||
the results into the appropriate format. It implements the abstract methods | ||
defined in the Task base class. | ||
Methods: | ||
- _match_algo_by_name(algo_name: AcAlgoName) -> AcAlgorithm: | ||
Match AC algorithm by its name. | ||
- _collect_result(algo: AcAlgorithm) -> AcTaskResult: | ||
Process the output of the AC algorithm and return the result. | ||
""" | ||
|
||
def _collect_result(self, algo: AcAlgorithm) -> AcTaskResult: | ||
""" | ||
Collect and process the AC result. | ||
Args: | ||
algo (AcAlgorithm): AC algorithm to process. | ||
Returns: | ||
AcTaskResult: The processed result containing AC ranges and exceptions. | ||
""" | ||
ac_ranges = algo.get_ac_ranges() | ||
ac_exceptions = algo.get_ac_exceptions() | ||
algo_result = AcAlgoResult( | ||
ranges=list(map(AcModel.from_ac_range, ac_ranges)), | ||
exceptions=list(map(AcExceptionModel.from_ac_exception, ac_exceptions)), | ||
) | ||
return AcTaskResult(primitive_name=PrimitiveName.ac, result=algo_result) | ||
|
||
def _match_algo_by_name(self, algo_name: str) -> AcAlgorithm: | ||
""" | ||
Match the approximate consistency algorithm by name. | ||
Args: | ||
algo_name (AcAlgoName): The name of the AC algorithm. | ||
Returns: | ||
AcAlgorithm: The corresponding algorithm instance. | ||
""" | ||
match algo_name: | ||
case AcAlgoName.Default: | ||
return Default() | ||
case _: | ||
raise IncorrectAlgorithmName(algo_name, "AC") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from typing import Literal | ||
|
||
from pydantic import BaseModel | ||
|
||
from internal.domain.task.value_objects.primitive_name import PrimitiveName | ||
from internal.domain.task.value_objects.ac.algo_config import OneOfAcAlgoConfig | ||
from internal.domain.task.value_objects.ac.algo_result import ( # noqa: F401 | ||
AcAlgoResult, | ||
AcModel, | ||
AcExceptionModel, | ||
) | ||
from internal.domain.task.value_objects.ac.algo_name import AcAlgoName # noqa: F401 | ||
|
||
|
||
class BaseAcTaskModel(BaseModel): | ||
primitive_name: Literal[PrimitiveName.ac] | ||
|
||
|
||
class AcTaskConfig(BaseAcTaskModel): | ||
config: OneOfAcAlgoConfig | ||
|
||
|
||
class AcTaskResult(BaseAcTaskModel): | ||
result: AcAlgoResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from typing import Literal, Annotated | ||
from pydantic import Field | ||
from internal.domain.common import OptionalModel | ||
from internal.domain.task.value_objects.ac.algo_name import AcAlgoName | ||
from internal.domain.task.value_objects.ac.algo_descriptions import descriptions | ||
|
||
|
||
class BaseAcConfig(OptionalModel): | ||
__non_optional_fields__ = { | ||
"algo_name", | ||
} | ||
|
||
|
||
class DefaultAcConfig(BaseAcConfig): | ||
algo_name: Literal[AcAlgoName.Default] | ||
|
||
bin_operation: Annotated[str, Field(description=descriptions["bin_operation"])] | ||
fuzziness: Annotated[ | ||
float, Field(ge=0.1, le=1.0, description=descriptions["fuzziness"]) | ||
] | ||
p_fuzz: Annotated[float, Field(ge=0.1, le=1.0, description=descriptions["p_fuzz"])] | ||
weight: Annotated[float, Field(ge=0.1, le=1.0, description=descriptions["weight"])] | ||
bumps_limit: Annotated[int, Field(ge=0, description=descriptions["bumps_limit"])] | ||
iterations_limit: Annotated[ | ||
int, Field(ge=1, description=descriptions["iterations_limit"]) | ||
] | ||
ac_seed: Annotated[int, Field(description=descriptions["ac_seed"])] | ||
|
||
|
||
OneOfAcAlgoConfig = Annotated[ | ||
DefaultAcConfig, | ||
Field(discriminator="algo_name"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
descriptions = { | ||
"bin_operation": "Binary operation: one of available operations: /, *, +, -", | ||
"fuzziness": "Fraction of exceptional records, lies in (0, 1]", | ||
"p_fuzz": "Probability, the fraction of exceptional records outside the bump intervals", | ||
"weight": "Value lies in (0, 1]. Closer to 0 - many short intervals, closer to 1 - small number of long intervals", | ||
"bumps_limit": "Maximum number of intervals considered. Pass 0 to remove limit", | ||
"iterations_limit": "Limit for iterations of sampling", | ||
"ac_seed": "Seed for random number generation in data sampling", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from enum import StrEnum, auto | ||
|
||
|
||
class AcAlgoName(StrEnum): | ||
Default = auto() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from pydantic import BaseModel | ||
from desbordante.ac import ACRanges, ACException | ||
|
||
|
||
class AcModel(BaseModel): | ||
@classmethod | ||
def from_ac_range(cls, ac_range: ACRanges): | ||
return cls(column_indices=ac_range.column_indices, ranges=ac_range.ranges) | ||
|
||
column_indices: tuple[int, int] | ||
ranges: list[tuple[float, float]] | ||
|
||
|
||
class AcExceptionModel(BaseModel): | ||
@classmethod | ||
def from_ac_exception(cls, ac_exception: ACException): | ||
return cls( | ||
row_index=ac_exception.row_index, column_pairs=ac_exception.column_pairs | ||
) | ||
|
||
row_index: int | ||
column_pairs: list[tuple[int, int]] | ||
|
||
|
||
class AcAlgoResult(BaseModel): | ||
ranges: list[AcModel] | ||
exceptions: list[AcExceptionModel] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters