perfact-api-dg 0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- perfact_api_dg-0.1/PKG-INFO +24 -0
- perfact_api_dg-0.1/README.md +7 -0
- perfact_api_dg-0.1/pyproject.toml +44 -0
- perfact_api_dg-0.1/setup.cfg +4 -0
- perfact_api_dg-0.1/src/perfact/api/dg/__init__.py +0 -0
- perfact_api_dg-0.1/src/perfact/api/dg/model/__init__.py +7 -0
- perfact_api_dg-0.1/src/perfact/api/dg/model/dgkpi.py +22 -0
- perfact_api_dg-0.1/src/perfact/api/dg/model/dgval.py +45 -0
- perfact_api_dg-0.1/src/perfact/api/dg/model/py.typed +0 -0
- perfact_api_dg-0.1/src/perfact/api/dg/py.typed +0 -0
- perfact_api_dg-0.1/src/perfact/api/dg/services/.gitkeep +0 -0
- perfact_api_dg-0.1/src/perfact_api_dg.egg-info/PKG-INFO +24 -0
- perfact_api_dg-0.1/src/perfact_api_dg.egg-info/SOURCES.txt +18 -0
- perfact_api_dg-0.1/src/perfact_api_dg.egg-info/dependency_links.txt +1 -0
- perfact_api_dg-0.1/src/perfact_api_dg.egg-info/requires.txt +5 -0
- perfact_api_dg-0.1/src/perfact_api_dg.egg-info/top_level.txt +1 -0
- perfact_api_dg-0.1/tests/__init__.py +0 -0
- perfact_api_dg-0.1/tests/conftest.py +40 -0
- perfact_api_dg-0.1/tests/test_models.py +43 -0
- perfact_api_dg-0.1/tox.ini +27 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: perfact-api-dg
|
|
3
|
+
Version: 0.1
|
|
4
|
+
Summary: PerFact API - dg
|
|
5
|
+
Author-email: Viktor Dick <viktor.dick@perfact.de>
|
|
6
|
+
License: GPL-2.0-or-later
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Programming Language :: SQL
|
|
9
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
Requires-Dist: psycopg[binary]
|
|
13
|
+
Requires-Dist: sqlalchemy
|
|
14
|
+
Requires-Dist: perfact-api-base
|
|
15
|
+
Requires-Dist: perfact-api-app
|
|
16
|
+
Requires-Dist: pydantic-settings
|
|
17
|
+
|
|
18
|
+
# PerFact API - dg - model
|
|
19
|
+
|
|
20
|
+
This package contains the domain models and services for the dg module of the PerFact software.
|
|
21
|
+
|
|
22
|
+
## getting started
|
|
23
|
+
As this package does not contain an own main entrypoint, you have to install it into the base and run that one.
|
|
24
|
+
Please refer to the documentation of the *API Base* to get more information about how the discovery works and how to include this module to your app bundle.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# PerFact API - dg - model
|
|
2
|
+
|
|
3
|
+
This package contains the domain models and services for the dg module of the PerFact software.
|
|
4
|
+
|
|
5
|
+
## getting started
|
|
6
|
+
As this package does not contain an own main entrypoint, you have to install it into the base and run that one.
|
|
7
|
+
Please refer to the documentation of the *API Base* to get more information about how the discovery works and how to include this module to your app bundle.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.2", "setuptools-scm>=8.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "perfact-api-dg"
|
|
7
|
+
authors = [
|
|
8
|
+
{name="Viktor Dick", email="viktor.dick@perfact.de"},
|
|
9
|
+
]
|
|
10
|
+
description = "PerFact API - dg"
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
license = {text = "GPL-2.0-or-later"}
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"Programming Language :: SQL",
|
|
16
|
+
"Operating System :: POSIX :: Linux",
|
|
17
|
+
]
|
|
18
|
+
dependencies = [
|
|
19
|
+
"psycopg[binary]",
|
|
20
|
+
"sqlalchemy",
|
|
21
|
+
"perfact-api-base",
|
|
22
|
+
"perfact-api-app",
|
|
23
|
+
"pydantic-settings",
|
|
24
|
+
]
|
|
25
|
+
dynamic = ["version"]
|
|
26
|
+
requires-python = ">=3.10"
|
|
27
|
+
|
|
28
|
+
[project.scripts]
|
|
29
|
+
|
|
30
|
+
[tool.distutils.bdist_wheel]
|
|
31
|
+
universal = 1
|
|
32
|
+
|
|
33
|
+
[tool.setuptools]
|
|
34
|
+
include-package-data = true
|
|
35
|
+
|
|
36
|
+
[tool.setuptools.packages.find]
|
|
37
|
+
where = ["src"]
|
|
38
|
+
|
|
39
|
+
[tool.setuptools_scm]
|
|
40
|
+
root = ".."
|
|
41
|
+
fallback_version = "0.0.0"
|
|
42
|
+
|
|
43
|
+
[tool.mypy]
|
|
44
|
+
plugins = ["sqlalchemy.ext.mypy.plugin"]
|
|
File without changes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
|
|
3
|
+
from perfact.api.base.model import Base, Mapped
|
|
4
|
+
from sqlalchemy import DateTime
|
|
5
|
+
from sqlalchemy.orm import mapped_column
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class DgKpi(Base):
|
|
9
|
+
# COLS
|
|
10
|
+
name: Mapped[str | None]
|
|
11
|
+
description: Mapped[str | None]
|
|
12
|
+
plugin: Mapped[str | None]
|
|
13
|
+
lastcheck: Mapped[datetime] = mapped_column(DateTime(timezone=True))
|
|
14
|
+
maxage: Mapped[str | None]
|
|
15
|
+
updateactive: Mapped[bool | None]
|
|
16
|
+
thresholdmin: Mapped[float | None]
|
|
17
|
+
thresholdmax: Mapped[float | None]
|
|
18
|
+
deviationmax: Mapped[float | None]
|
|
19
|
+
|
|
20
|
+
# FKS
|
|
21
|
+
# mtunit_id: Mapped[int | None] = mapped_column(ForeignKey("mtunit.id"))
|
|
22
|
+
# RELATIONSHIPS
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
from perfact.api.base.model import Base, ForeignKey, Mapped
|
|
5
|
+
from sqlalchemy import DateTime, func, select
|
|
6
|
+
from sqlalchemy.dialects.postgresql import JSONB
|
|
7
|
+
from sqlalchemy.orm import mapped_column
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class DgVal(Base):
|
|
11
|
+
# COLS
|
|
12
|
+
value: Mapped[float | None]
|
|
13
|
+
name: Mapped[str | None]
|
|
14
|
+
refid: Mapped[int | None]
|
|
15
|
+
createtime: Mapped[datetime] = mapped_column(
|
|
16
|
+
DateTime(timezone=True), default=func.now()
|
|
17
|
+
)
|
|
18
|
+
reftime: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
|
|
19
|
+
reftable: Mapped[str | None]
|
|
20
|
+
identstring: Mapped[str | None]
|
|
21
|
+
data: Mapped[dict[str, Any] | None] = mapped_column(JSONB)
|
|
22
|
+
sortkey: Mapped[str | None]
|
|
23
|
+
|
|
24
|
+
# FKS
|
|
25
|
+
dgkpi_id: Mapped[int] = mapped_column(ForeignKey("dgkpi.id"))
|
|
26
|
+
# mtunit_id: Mapped[int | None] = mapped_column(ForeignKey("mtunit.id"))
|
|
27
|
+
# RELATIONSHIPS
|
|
28
|
+
|
|
29
|
+
@classmethod
|
|
30
|
+
def get_newest_dgval(
|
|
31
|
+
cls,
|
|
32
|
+
reftable: str,
|
|
33
|
+
refid: int,
|
|
34
|
+
identstring: str,
|
|
35
|
+
/,
|
|
36
|
+
):
|
|
37
|
+
"""SQL-level: newest matching dgval row for table/ref/day."""
|
|
38
|
+
return (
|
|
39
|
+
select(cls)
|
|
40
|
+
.where(cls.reftable == reftable)
|
|
41
|
+
.where(cls.refid == refid)
|
|
42
|
+
.where(cls.identstring == identstring)
|
|
43
|
+
.order_by(cls.id.desc())
|
|
44
|
+
.limit(1)
|
|
45
|
+
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: perfact-api-dg
|
|
3
|
+
Version: 0.1
|
|
4
|
+
Summary: PerFact API - dg
|
|
5
|
+
Author-email: Viktor Dick <viktor.dick@perfact.de>
|
|
6
|
+
License: GPL-2.0-or-later
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Programming Language :: SQL
|
|
9
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
Requires-Dist: psycopg[binary]
|
|
13
|
+
Requires-Dist: sqlalchemy
|
|
14
|
+
Requires-Dist: perfact-api-base
|
|
15
|
+
Requires-Dist: perfact-api-app
|
|
16
|
+
Requires-Dist: pydantic-settings
|
|
17
|
+
|
|
18
|
+
# PerFact API - dg - model
|
|
19
|
+
|
|
20
|
+
This package contains the domain models and services for the dg module of the PerFact software.
|
|
21
|
+
|
|
22
|
+
## getting started
|
|
23
|
+
As this package does not contain an own main entrypoint, you have to install it into the base and run that one.
|
|
24
|
+
Please refer to the documentation of the *API Base* to get more information about how the discovery works and how to include this module to your app bundle.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
tox.ini
|
|
4
|
+
src/perfact/api/dg/__init__.py
|
|
5
|
+
src/perfact/api/dg/py.typed
|
|
6
|
+
src/perfact/api/dg/model/__init__.py
|
|
7
|
+
src/perfact/api/dg/model/dgkpi.py
|
|
8
|
+
src/perfact/api/dg/model/dgval.py
|
|
9
|
+
src/perfact/api/dg/model/py.typed
|
|
10
|
+
src/perfact/api/dg/services/.gitkeep
|
|
11
|
+
src/perfact_api_dg.egg-info/PKG-INFO
|
|
12
|
+
src/perfact_api_dg.egg-info/SOURCES.txt
|
|
13
|
+
src/perfact_api_dg.egg-info/dependency_links.txt
|
|
14
|
+
src/perfact_api_dg.egg-info/requires.txt
|
|
15
|
+
src/perfact_api_dg.egg-info/top_level.txt
|
|
16
|
+
tests/__init__.py
|
|
17
|
+
tests/conftest.py
|
|
18
|
+
tests/test_models.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
perfact
|
|
File without changes
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from perfact.api.base.model import Base
|
|
3
|
+
from perfact.api.dg.model import (
|
|
4
|
+
DgKpi,
|
|
5
|
+
DgVal,
|
|
6
|
+
)
|
|
7
|
+
from pytest_postgresql import factories
|
|
8
|
+
from sqlalchemy import create_engine, text
|
|
9
|
+
from sqlalchemy.orm import Session
|
|
10
|
+
|
|
11
|
+
postgresql_proc = factories.postgresql_proc()
|
|
12
|
+
postgresql = factories.postgresql("postgresql_proc")
|
|
13
|
+
|
|
14
|
+
_TABLES = [
|
|
15
|
+
DgVal.__table__,
|
|
16
|
+
DgKpi.__table__,
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@pytest.fixture
|
|
21
|
+
def db_engine(postgresql):
|
|
22
|
+
info = postgresql.info
|
|
23
|
+
url = f"postgresql+psycopg://{info.user}@{info.host}:{info.port}/{info.dbname}"
|
|
24
|
+
engine = create_engine(url)
|
|
25
|
+
with engine.begin() as conn:
|
|
26
|
+
conn.execute(
|
|
27
|
+
text(
|
|
28
|
+
"CREATE OR REPLACE FUNCTION db_username() RETURNS text "
|
|
29
|
+
"LANGUAGE SQL AS 'SELECT current_user'"
|
|
30
|
+
)
|
|
31
|
+
)
|
|
32
|
+
Base.metadata.create_all(engine, tables=_TABLES)
|
|
33
|
+
yield engine
|
|
34
|
+
engine.dispose()
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@pytest.fixture
|
|
38
|
+
def db_session(db_engine):
|
|
39
|
+
with Session(db_engine) as session:
|
|
40
|
+
yield session
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from datetime import datetime, timezone
|
|
2
|
+
|
|
3
|
+
from perfact.api.dg.model import DgKpi, DgVal
|
|
4
|
+
from sqlalchemy.orm import Session
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def test_dgval_get_newest_dgval_returns_latest_matching_row(
|
|
8
|
+
db_session: Session,
|
|
9
|
+
) -> None:
|
|
10
|
+
kpi = DgKpi(lastcheck=datetime.now(timezone.utc))
|
|
11
|
+
db_session.add(kpi)
|
|
12
|
+
db_session.flush()
|
|
13
|
+
|
|
14
|
+
older = DgVal(
|
|
15
|
+
dgkpi_id=kpi.id,
|
|
16
|
+
reftable="pdunit",
|
|
17
|
+
refid=10,
|
|
18
|
+
identstring="12-12-2012",
|
|
19
|
+
value=1.0,
|
|
20
|
+
)
|
|
21
|
+
newest = DgVal(
|
|
22
|
+
dgkpi_id=kpi.id,
|
|
23
|
+
reftable="pdunit",
|
|
24
|
+
refid=10,
|
|
25
|
+
identstring="12-12-2012",
|
|
26
|
+
value=2.0,
|
|
27
|
+
)
|
|
28
|
+
ignored = DgVal(
|
|
29
|
+
dgkpi_id=kpi.id,
|
|
30
|
+
reftable="other",
|
|
31
|
+
refid=10,
|
|
32
|
+
identstring="12-12-2012",
|
|
33
|
+
value=99.0,
|
|
34
|
+
)
|
|
35
|
+
db_session.add_all([older, newest, ignored])
|
|
36
|
+
db_session.flush()
|
|
37
|
+
|
|
38
|
+
stmt = DgVal.get_newest_dgval("pdunit", 10, "12-12-2012")
|
|
39
|
+
selected = db_session.scalar(stmt)
|
|
40
|
+
|
|
41
|
+
assert selected is not None
|
|
42
|
+
assert selected.id == newest.id
|
|
43
|
+
assert selected.value == 2.0
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[tox]
|
|
2
|
+
envlist = py3
|
|
3
|
+
isolated_build = true
|
|
4
|
+
|
|
5
|
+
[testenv]
|
|
6
|
+
passenv = SSH_AUTH_SOCK, PYTHONPATH, HTTP_PROXY, HTTPS_PROXY
|
|
7
|
+
setenv =
|
|
8
|
+
GIT_SSH_VARIANT=ssh
|
|
9
|
+
GIT_SSH_COMMAND=ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no
|
|
10
|
+
|
|
11
|
+
deps =
|
|
12
|
+
ruff
|
|
13
|
+
pytest
|
|
14
|
+
coverage
|
|
15
|
+
psycopg[binary]
|
|
16
|
+
pytest-postgresql
|
|
17
|
+
pytest-cov
|
|
18
|
+
pytest-typing
|
|
19
|
+
bandit
|
|
20
|
+
mypy
|
|
21
|
+
|
|
22
|
+
commands =
|
|
23
|
+
ruff format --check
|
|
24
|
+
ruff check
|
|
25
|
+
bandit --configfile {toxinidir}/../bandit.yml -r src
|
|
26
|
+
mypy -p perfact.api.dg
|
|
27
|
+
pytest --cov-branch --cov=perfact.api.dg --cov-report=term-missing --cov-fail-under=100 {posargs:tests}
|