-
Notifications
You must be signed in to change notification settings - Fork 3
Architecture refactoring #56
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
Changes from 13 commits
ca6afa9
2a37304
3ab94fd
f61bafd
abcde64
64a71d6
ad585f6
0b6923c
33a9c84
c0780ab
65ddee7
cf19800
499b73d
6dd4e37
80674f5
ad7c987
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| from dataclasses import dataclass | ||
|
|
||
| from stattest.configuration.experiment_config.experiment_config import ExperimentConfig | ||
|
|
||
|
|
||
| @dataclass | ||
| class CriticalValueExperimentConfig(ExperimentConfig): | ||
| """ | ||
| Critical value experiment configuration. | ||
| """ | ||
|
|
||
| significance_levels: list[float] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| from dataclasses import dataclass | ||
|
|
||
| from stattest.configuration.model.criterion.criterion import Criterion | ||
| from stattest.configuration.model.experiment_type.experiment_type import ExperimentType | ||
| from stattest.configuration.model.hypothesis.hypothesis import Hypothesis | ||
| from stattest.configuration.model.run_mode.run_mode import RunMode | ||
| from stattest.configuration.model.step_type.step_type import StepType | ||
|
|
||
|
|
||
| @dataclass | ||
| class ExperimentConfig: | ||
| """ | ||
| Experiment configuration. | ||
| """ | ||
|
|
||
| experiment_type: ExperimentType | ||
| storage_connection: str | ||
| run_mode: RunMode | ||
| hypothesis: Hypothesis | ||
| data_generator_type: StepType | ||
| executor_type: StepType | ||
| report_builder_type: StepType | ||
| sample_sizes: list[int] | ||
| monte_carlo_count: int | ||
| criteria: list[Criterion] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| from dataclasses import dataclass | ||
|
|
||
| from stattest.configuration.experiment_config.experiment_config import ExperimentConfig | ||
| from stattest.configuration.model.alternative.alternative import Alternative | ||
|
|
||
|
|
||
| @dataclass | ||
| class PowerExperimentConfig(ExperimentConfig): | ||
| """ | ||
| Power experiment configuration. | ||
| """ | ||
|
|
||
| alternatives: list[Alternative] | ||
| significance_levels: list[float] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| from dataclasses import dataclass | ||
|
|
||
| from stattest.configuration.experiment_config.experiment_config import ExperimentConfig | ||
|
|
||
|
|
||
| @dataclass | ||
| class TimeComplexityExperimentConfig(ExperimentConfig): | ||
| """ | ||
| Time complexity experiment configuration. | ||
| """ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| from dataclasses import dataclass | ||
|
|
||
|
|
||
| @dataclass | ||
| class Alternative: | ||
| """ | ||
| Alternative configuration (generator code + parameters). | ||
| """ | ||
|
|
||
| generator_code: str | ||
| parameters: list[float] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| from dataclasses import dataclass | ||
|
|
||
|
|
||
| @dataclass | ||
| class Criterion: | ||
| """ | ||
| Criterion configuration (criterion code + parameters). | ||
| """ | ||
|
|
||
| criterion_code: str | ||
| parameters: list[float] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| from enum import Enum | ||
|
|
||
|
|
||
| class ExperimentType(Enum): | ||
| """ | ||
| Experiment type. | ||
| """ | ||
|
|
||
| CRITICAL_VALUE = "critical_value" | ||
| POWER = "power" | ||
| TIME_COMPLEXITY = "time_complexity" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| from enum import Enum | ||
|
|
||
|
|
||
| class Hypothesis(Enum): | ||
| """ | ||
| Hypothesis. | ||
| """ | ||
|
|
||
| NORMAL = "normal" | ||
| EXPONENTIAL = "exponential" | ||
| WEIBULL = "weibull" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| from enum import Enum | ||
|
|
||
|
|
||
| class RunMode(Enum): | ||
| """ | ||
| Run mode (use existing data in DB or overwrite). | ||
| """ | ||
|
|
||
| REUSE = "reuse" | ||
| OVERWRITE = "overwrite" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| from enum import Enum | ||
|
|
||
|
|
||
| class StepType(Enum): | ||
| """ | ||
| Step type (standard or custom). | ||
| """ | ||
|
|
||
| STANDARD = "standard" | ||
| CUSTOM = "custom" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| from dataclasses import dataclass | ||
|
|
||
| from stattest.experiment_new.model.experiment_step.experiment_step import IExperimentStep | ||
|
|
||
|
|
||
| @dataclass | ||
| class ExperimentSteps: | ||
| """ | ||
| Experiment steps dataclass. | ||
| """ | ||
|
|
||
| generation_step: IExperimentStep | ||
| execution_step: IExperimentStep | ||
| report_building_step: IExperimentStep |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| from stattest.experiment_new.experiment_steps.experiment_steps import ExperimentSteps | ||
| from stattest.experiment_new.model.experiment_step.experiment_step import IExperimentStep | ||
|
|
||
|
|
||
| class Experiment: | ||
| """ | ||
| Experiment. | ||
| """ | ||
|
|
||
| def __init__(self, experiment_steps: ExperimentSteps): | ||
| self.experiment_steps = experiment_steps | ||
|
|
||
| def run_experiment(self) -> None: | ||
| """ | ||
| Run experiment. | ||
| """ | ||
| generation_step: IExperimentStep = self.experiment_steps.generation_step | ||
| execution_step: IExperimentStep = self.experiment_steps.execution_step | ||
| report_building_step: IExperimentStep = self.experiment_steps.report_building_step | ||
|
|
||
| print("Running generation step...") | ||
| generation_step.run() | ||
| print("Generation step finished") | ||
|
|
||
| print("Running execution step...") | ||
| execution_step.run() | ||
| print("Execution step finished") | ||
|
|
||
| print("Running report building step...") | ||
| report_building_step.run() | ||
| print("Report building step finished") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| from typing import Protocol | ||
|
|
||
|
|
||
| class IExperimentStep(Protocol): | ||
| """ | ||
| Interface for experiment step. | ||
| """ | ||
|
|
||
| def run(self) -> None: | ||
| pass |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| from dataclasses import dataclass | ||
|
|
||
| from pysatl_criterion.statistics.goodness_of_fit import AbstractGoodnessOfFitStatistic | ||
|
|
||
|
|
||
| @dataclass | ||
| class ExecutionStepData: | ||
| """ | ||
| Data for execution step. | ||
| """ | ||
|
|
||
| criterion: AbstractGoodnessOfFitStatistic | ||
| sample_size: int |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| from dataclasses import dataclass | ||
|
|
||
| from pysatl_criterion.persistence.model.limit_distribution.limit_distribution import ( | ||
| ILimitDistributionStorage, | ||
| ) | ||
|
|
||
| from stattest.experiment_new.step.execution.common.execution_step_data.execution_step_data import ( | ||
| ExecutionStepData, | ||
| ) | ||
| from stattest.persistence.model.random_values.random_values import IRandomValuesStorage | ||
| from stattest.worker.critical_value.critical_value import CriticalValueWorker | ||
|
|
||
|
|
||
| @dataclass | ||
| class CriticalValueStepData(ExecutionStepData): | ||
| """ | ||
| Data for execution step in critical value experiment. | ||
| """ | ||
|
|
||
|
|
||
| class CriticalValueExecutionStep: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Не нужно ли добавить общий ExecutionStep?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Он есть, это IExperimentStep. Он объявлен как Protocol, в котором задан метод run() c определенной сигнатурой. CriticalValueExecutionStep реализует данный метод с такой же сигнатурой, что означает, что он является подклассом IExperimentStep (duck typing). Можно было бы явно указать, но это не требуется. |
||
| """ | ||
| Standard critical value experiment execution step. | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| worker: CriticalValueWorker, | ||
| step_data: list[CriticalValueStepData], | ||
| monte_carlo_count: int, | ||
| data_storage: IRandomValuesStorage, | ||
| result_storage: ILimitDistributionStorage, | ||
| ): | ||
| self.worker = worker | ||
| self.step_data = step_data | ||
| self.monte_carlo_count = monte_carlo_count | ||
| self.data_storage = data_storage | ||
| self.result_storage = result_storage | ||
|
|
||
| def run(self) -> None: | ||
| """ | ||
| Run standard critical value execution step. | ||
| """ | ||
| raise NotImplementedError("Method is not yet implemented") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Аналогично для других шагов.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Да, для них работает то же самое правило. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| from dataclasses import dataclass | ||
|
|
||
| from stattest.experiment.generator import AbstractRVSGenerator | ||
| from stattest.experiment_new.step.execution.common.execution_step_data.execution_step_data import ( | ||
| ExecutionStepData, | ||
| ) | ||
| from stattest.persistence.model.power.power import IPowerStorage | ||
| from stattest.persistence.model.random_values.random_values import IRandomValuesStorage | ||
| from stattest.worker.power.power import PowerWorker | ||
|
|
||
|
|
||
| @dataclass | ||
| class PowerStepData(ExecutionStepData): | ||
| """ | ||
| Data for execution step in power experiment. | ||
| """ | ||
|
|
||
| alternative: AbstractRVSGenerator | ||
| significance_level: float | ||
|
|
||
|
|
||
| class PowerExecutionStep: | ||
| """ | ||
| Standard power experiment execution step. | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| worker: PowerWorker, | ||
| step_data: list[PowerStepData], | ||
| monte_carlo_count: int, | ||
| data_storage: IRandomValuesStorage, | ||
| result_storage: IPowerStorage, | ||
| ): | ||
| self.worker = worker | ||
| self.step_data = step_data | ||
| self.monte_carlo_count = monte_carlo_count | ||
| self.data_storage = data_storage | ||
| self.result_storage = result_storage | ||
|
|
||
| def run(self) -> None: | ||
| """ | ||
| Run standard power execution step. | ||
| """ | ||
| raise NotImplementedError("Method is not yet implemented") |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Мб какой-то коммент на будущее оставить для расширения?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Для остальных перечислений так же.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не понял, Дим, что ты имеешь в виду.