Skip to content

Commit 07725b7

Browse files
authored
Refactor (#70)
* Refactor * Fix tests
1 parent 721fcc3 commit 07725b7

File tree

32 files changed

+905
-238
lines changed

32 files changed

+905
-238
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,23 @@ You're all set! You can now import and use the statistical tests in your Python
2424

2525
## PySATL Criterion module usage example:
2626

27+
Statistic calculation example:
2728
```python
2829
# import needed criterion from pysatl_criterion
29-
from pysatl_criterion import KolmogorovSmirnovNormalityGofStatistic
30+
from pysatl_criterion.statistics import KolmogorovSmirnovNormalityGofStatistic
31+
3032

3133
# make a criterion object
32-
criterion = KolmogorovSmirnovNormalityGofStatistic(mean=0, var=1)
34+
statistic = KolmogorovSmirnovNormalityGofStatistic(mean=0, var=1)
3335

3436
# initialize test data
3537
x = [0.1, 0.7, 0.5, 0.3]
3638

3739
# then run algorithm
38-
statistic = criterion.execute_statistic(x)
40+
result = statistic.execute_statistic(x)
3941

4042
# print the results
41-
print(f"Statistic result: {statistic}")
43+
print(f"Statistic result: {result}")
4244
# output:
4345
# Statistic result: 0.539827837277029
4446
```

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ dependencies = [
1313
"scipy>=1.11.2",
1414
"pandas>=2.2.1",
1515
"typing-extensions>=4.12.2",
16-
"networkx ==3.4.2"
16+
"networkx == 3.4.2",
17+
"sqlalchemy == 2.0.41"
1718
]
1819

1920
[project.urls]
@@ -48,7 +49,6 @@ ruff = "0.7.4"
4849
pytest-mock = "3.14.0"
4950
pre-commit = "4.0.1"
5051
mypy = "1.15.0"
51-
sqlalchemy = "2.0.41"
5252

5353
[tool.isort]
5454
line_length = 100

pysatl_criterion/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
LOCAL_LIMIT_DISTRIBUTION_URL = "sqlite:///limit_distributions.sqlite"
2+
REMOTE_LIMIT_DISTRIBUTION_URL = "postgresql://postgres:postgres@localhost/pysatl"
File renamed without changes.
File renamed without changes.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from dataclasses import dataclass
2+
3+
from pysatl_criterion.critical_value.critical_area.model import CriticalArea
4+
5+
6+
@dataclass
7+
class LeftCriticalArea(CriticalArea):
8+
critical_value: float
9+
10+
def __init__(self, critical_value: float):
11+
self.critical_value = critical_value
12+
13+
def contains(self, value: float) -> bool:
14+
return value >= self.critical_value
15+
16+
17+
@dataclass
18+
class RightCriticalArea(CriticalArea):
19+
critical_value: float
20+
21+
def __init__(self, critical_value: float):
22+
self.critical_value = critical_value
23+
24+
def contains(self, value: float) -> bool:
25+
return value <= self.critical_value
26+
27+
28+
@dataclass
29+
class TwoSidedCriticalArea(CriticalArea):
30+
left_cv: float
31+
right_cv: float
32+
33+
def __init__(self, left_cv: float, right_cv: float):
34+
self.left_cv = left_cv
35+
self.right_cv = right_cv
36+
37+
def contains(self, value: float) -> bool:
38+
return self.left_cv <= value <= self.right_cv
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from abc import ABC, abstractmethod
2+
3+
4+
class CriticalArea(ABC):
5+
@abstractmethod
6+
def contains(self, value: float) -> bool:
7+
"""
8+
Check critical area contains value.
9+
:param value: true, if critical area contains value, false otherwise
10+
"""
11+
pass

pysatl_criterion/cv_calculator/cv_calculator/cv_calculator.py renamed to pysatl_criterion/critical_value/cv_calculator/cv_calculator.py

File renamed without changes.

pysatl_criterion/critical_value/loader/__init__.py

Whitespace-only changes.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import logging
2+
3+
from pysatl_criterion.persistence.model.limit_distribution.limit_distribution import (
4+
CriticalValueQuery,
5+
ILimitDistributionStorage,
6+
)
7+
8+
9+
class CriticalValueLoader:
10+
def __init__(
11+
self, local_storage: ILimitDistributionStorage, remote_storage: ILimitDistributionStorage
12+
):
13+
self.__local_storage = local_storage
14+
self.__remote_storage = remote_storage
15+
16+
def load(self, criterion_code: str, sample_size: int, sample_size_error: int = 0):
17+
"""
18+
Load data from remote distribution storage to local distribution storage.
19+
20+
:param criterion_code: criterion code
21+
:param sample_size: sample size
22+
:param sample_size_error: sample size error.
23+
Get sample_size - sample_size_error <= sample_size <= sample_size + sample_size_error
24+
"""
25+
26+
logging.info(f"Load criterion {criterion_code} with size {sample_size} from remote")
27+
query = CriticalValueQuery(criterion_code, sample_size, sample_size_error)
28+
remote_data = self.__remote_storage.get_data_for_cv(query)
29+
30+
if remote_data is not None:
31+
self.__local_storage.insert_data(remote_data)
32+
else:
33+
logging.warning(
34+
f"Remote data for criterion {criterion_code} " f"with size {sample_size} not found"
35+
)

0 commit comments

Comments
 (0)