Skip to content

Commit

Permalink
chore: reorganize files
Browse files Browse the repository at this point in the history
  • Loading branch information
toadharvard committed Feb 17, 2024
1 parent 3c38662 commit b3e5e72
Show file tree
Hide file tree
Showing 30 changed files with 257 additions and 10 deletions.
20 changes: 10 additions & 10 deletions app/db/migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
from alembic import context
from app.settings import get_settings
from app.db import Base
from app.db.models.user.code import Code
from app.db.models.user.device import Device
from app.db.models.user.feedback import Feedback
from app.db.models.user.permission import Permission
from app.db.models.user.role import Role
from app.db.models.user.session import Session
from app.db.models.user.user import User
from app.db.models.file.file_info import FileInfo
from app.db.models.file.file_format import FileFormat
from app.tasks.models.task import Task
from app.domain.user.model.code import Code
from app.domain.user.model.device import Device
from app.domain.user.model.feedback import Feedback
from app.domain.user.model.permission import Permission
from app.domain.user.model.role import Role
from app.domain.user.model.session import Session
from app.domain.user.model.user import User
from app.domain.file.model.file_info import FileInfo
from app.domain.file.model.file_format import FileFormat
from app.domain.task.model.task import Task

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
Expand Down
File renamed without changes.
File renamed without changes.
45 changes: 45 additions & 0 deletions app/domain/task/model/task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from datetime import datetime
from enum import StrEnum, auto
from uuid import UUID, uuid4
from sqlalchemy import ForeignKey
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.db import Base


class TaskStatus(StrEnum):
IN_PROCESS = auto()
COMPLETED = auto()
INTERNAL_SERVER_ERROR = auto()
RESOURCE_LIMIT_IS_REACHED = auto()
ADDED_TO_THE_TASK_QUEUE = auto()
ADDING_TO_DB = auto()


class Task(Base):
__tablename__ = "Task"

id: Mapped[UUID] = mapped_column(primary_key=True, default=uuid4)
user_id: Mapped[UUID | None] = mapped_column(
ForeignKey("User.id", ondelete="SET NULL", onupdate="CASCADE")
)
file_id: Mapped[UUID | None] = mapped_column(
ForeignKey("FileInfo.id", ondelete="SET NULL", onupdate="CASCADE")
)
is_private: Mapped[bool] = mapped_column(default=False)
attempt_number: Mapped[int] = mapped_column(default=0)
status: Mapped[TaskStatus]
phase_name: Mapped[str | None] = mapped_column(default=None)
current_phase: Mapped[int | None] = mapped_column(default=None)
progres: Mapped[float] = mapped_column(default=0)
max_phase: Mapped[int | None] = mapped_column(default=None)
error_msg: Mapped[int | None] = mapped_column(default=None)
id_executed: Mapped[bool] = mapped_column(default=False)
elapsed_time: Mapped[float | None] = mapped_column(default=None)
config: Mapped[dict] = mapped_column(JSONB)
result: Mapped[dict] = mapped_column(JSONB)
created_at: Mapped[datetime]
deleted_at: Mapped[datetime | None] = mapped_column(default=None)

user = relationship("User")
file_info = relationship("FileInfo")
8 changes: 8 additions & 0 deletions app/domain/task/schema/ar/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from typing import Annotated
from pydantic import Field
from app.domain.task.schema.base_config import BaseTaskConfig


class ARTaskConfig(BaseTaskConfig):
min_support_ar: Annotated[float, Field(ge=0, le=1)]
min_confidence: Annotated[float, Field(ge=0, le=1)]
5 changes: 5 additions & 0 deletions app/domain/task/schema/ar/result.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from app.domain.task.schema.specific_with_deps_result import SpecificTaskWithDepsResult


class ARTaskResult(SpecificTaskWithDepsResult):
value_dictionary: dict[int, int] | None
17 changes: 17 additions & 0 deletions app/domain/task/schema/base_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from enum import StrEnum, auto
from pydantic import BaseModel


class DBTaskPrimitiveType(StrEnum):
AR = auto()
CFD = auto()
FD = auto()
TypoFD = auto()
TypoCluster = auto()
SpecificTypoCluster = auto()
Stats = auto()


class BaseTaskConfig(BaseModel):
algorithm_name: str
primitive_type: DBTaskPrimitiveType
7 changes: 7 additions & 0 deletions app/domain/task/schema/base_result.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from datetime import datetime
from pydantic import BaseModel


class BaseTaskResult(BaseModel):
created_at: datetime
deleted_at: datetime | None = None
9 changes: 9 additions & 0 deletions app/domain/task/schema/cfd/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from typing import Annotated
from pydantic import Field
from app.domain.task.schema.base_config import BaseTaskConfig


class CFDTaskConfig(BaseTaskConfig):
max_lhs: Annotated[int, Field(ge=1, le=10)]
min_support_cfd: Annotated[int, Field(ge=1, le=16)]
min_confidence: Annotated[float, Field(ge=0, le=1)]
8 changes: 8 additions & 0 deletions app/domain/task/schema/cfd/result.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from app.domain.task.schema.specific_with_deps_result import SpecificTaskWithDepsResult


class CFDTaskResult(SpecificTaskWithDepsResult):
pk_column_indices: list[int] | None
with_patterns: str | None
without_patterns: str | None
value_dictionary: dict[int, int] | None
9 changes: 9 additions & 0 deletions app/domain/task/schema/fd/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from typing import Annotated
from pydantic import Field
from app.domain.task.schema.base_config import BaseTaskConfig


class FDTaskConfig(BaseTaskConfig):
error_threshold: Annotated[float, Field(ge=0, le=1)]
max_lhs: Annotated[int, Field(ge=1, le=10)]
threads_count: Annotated[int, Field(ge=1, le=8)]
6 changes: 6 additions & 0 deletions app/domain/task/schema/fd/result.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from app.domain.task.schema.specific_with_deps_result import SpecificTaskWithDepsResult


class FDTaskResult(SpecificTaskWithDepsResult):
pk_column_indices: list[int] | None
without_patterns: str | None
24 changes: 24 additions & 0 deletions app/domain/task/schema/mfd/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from enum import StrEnum, auto
from app.domain.task.schema.base_config import BaseTaskConfig


class MFDMetrics(StrEnum):
EUCLIDEAN = auto()
LEVENSHTEIN = auto()
MODULUS_OF_DIFFERENCE = auto()


class MFDMetricAlgorithm(StrEnum):
BRUTE = auto()
APPROX = auto()
CALIPERS = auto()


class MFDTaskConfig(BaseTaskConfig):
tolerance_parametr: float
lhs_indices: list[int]
rhs_indices: list[int]
distance_to_null_is_infinity: bool
type_of_metric: MFDMetrics
q_gram_length: int
metric_algorithm: MFDMetricAlgorithm
5 changes: 5 additions & 0 deletions app/domain/task/schema/mfd/result.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from app.domain.task.schema.specific_with_deps_result import SpecificTaskWithDepsResult


class MFDTaskResult(SpecificTaskWithDepsResult):
is_holding: bool | None
7 changes: 7 additions & 0 deletions app/domain/task/schema/specific_typo_cluster/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from pydantic import UUID4
from app.domain.task.schema.base_config import BaseTaskConfig


class SpecificTypoClusterTaskConfig(BaseTaskConfig):
parent_task_id: UUID4
cluster_id: UUID4
15 changes: 15 additions & 0 deletions app/domain/task/schema/specific_typo_cluster/result.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from enum import StrEnum, auto
from app.domain.task.schema.base_result import BaseTaskResult


class SquashState(StrEnum):
SQUASHED = auto()
NOT_SQUASHED = auto()


class SpecificTypoClusterTaskResult(BaseTaskResult):
suspicious_indices: list[int] | None
sguash_state: SquashState
sorted_cluster: str | None
not_sorted_cluster: str | None
items_amount: int | None
6 changes: 6 additions & 0 deletions app/domain/task/schema/specific_with_deps_result.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from app.domain.task.schema.base_result import BaseTaskResult


class SpecificTaskWithDepsResult(BaseTaskResult):
deps: str | None
deps_amount: int | None
7 changes: 7 additions & 0 deletions app/domain/task/schema/stats/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from typing import Annotated
from pydantic import Field
from app.domain.task.schema.base_config import BaseTaskConfig


class StatsTaskConfig(BaseTaskConfig):
threads_count: Annotated[int, Field(ge=1, le=8)]
19 changes: 19 additions & 0 deletions app/domain/task/schema/stats/result.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from app.domain.task.schema.base_result import BaseTaskResult


class StatsTaskResult(BaseTaskResult):
column_index: int
type: str
distinct: int | None
is_categorical: bool | None
count: int | None
avg: str | None
std: str | None
skewness: str | None
kurtosis: str | None
min: str | None
max: str | None
sum: str | None
quantile25: str | None
quantile50: str | None
quantile75: str | None
18 changes: 18 additions & 0 deletions app/domain/task/schema/typo_cluster/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from dataclasses import Field
from typing import Annotated

from pydantic import UUID4, BaseModel

from app.domain.task.schema.base_config import BaseTaskConfig


class TypoFD(BaseModel):
left: list[int]
right: int


class TypoClusterTaskConfig(BaseTaskConfig):
parent_task_id: UUID4
typo_fd: TypoFD
radius: Annotated[float, Field(ge=1, le=10)]
ratio: Annotated[float, Field(ge=0, le=1)]
7 changes: 7 additions & 0 deletions app/domain/task/schema/typo_cluster/result.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from app.domain.task.schema.base_result import BaseTaskResult


class TypoClusterTaskResult(BaseTaskResult):
typo_clusters: str | None
suspicious_indices: list[int] | None
clusters_count: int | None
20 changes: 20 additions & 0 deletions app/domain/task/schema/typo_fd/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from enum import StrEnum, auto
from typing import Annotated
from pydantic import Field
from app.domain.task.schema.base_config import BaseTaskConfig


class MetricType(StrEnum):
LEVENSHTEIN = auto()
MODULUS_OF_DIFFERENCE = auto()


class TypoFDTaskConfig(BaseTaskConfig):
error_threshold: Annotated[float, Field(ge=0, le=1)]
max_lhs: Annotated[int, Field(ge=1, le=9)]
threads_count: Annotated[int, Field(ge=1, le=8)]
precise_algorithm: str
approximate_algorithm: str
type_of_metric: MetricType
default_radius: Annotated[float, Field(ge=1, le=10)]
default_ratio: Annotated[float, Field(ge=0, le=1)]
5 changes: 5 additions & 0 deletions app/domain/task/schema/typo_fd/result.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from app.domain.task.schema.specific_with_deps_result import SpecificTaskWithDepsResult


class TypoFDTaskResult(SpecificTaskWithDepsResult):
pk_column_indices: list[int] | None
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit b3e5e72

Please sign in to comment.