Skip to content

Commit

Permalink
Merge pull request #54 from PrediktorAS/1192-remove-db-class-from-pyp…
Browse files Browse the repository at this point in the history
…rediktormapclient-and-use-dwh-from-pyprediktorutilites

1192 remove db class from pyprediktormapclient and use dwh from pyprediktorutilites
  • Loading branch information
jNormaster authored Feb 2, 2024
2 parents 5afe9d9 + 89becaf commit 65c652a
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 1,126 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10']
python-version: ['3.9', '3.10', '3.11']
defaults:
run:
working-directory: /home/runner/work/pyPrediktorMapClient/pyPrediktorMapClient
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ formats:
- pdf

python:
version: 3.8
version: 3.9
install:
- requirements: docs/requirements.txt
- {path: ., method: pip}
2 changes: 2 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@
# If this is True, todo emits a warning for each TODO entries. The default is False.
todo_emit_warnings = True

# Since the documentation build process doesn't need to make actual database connections, we can mock the pyodbc module during the documentation build.
autodoc_mock_imports = ["pyodbc"]

# -- Options for HTML output -------------------------------------------------

Expand Down
13 changes: 8 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ package_dir =
=src

# Require a min/specific Python version (comma-separated conditions)
python_requires = >=3.8
python_requires = >=3.9

# Add here dependencies of your project (line-separated), e.g. requests>=2.2,<3.0.
# Version specifiers like >=2.2,<3.0 avoid problems due to API changes in
Expand All @@ -53,7 +53,8 @@ install_requires =
aiohttp >= 3.8.1
pydantic >= 2.0
pandas >= 1.4.4
pyodbc >= 4.0.39
pyodbc
pyPrediktorUtilities >= 0.3.2

[options.packages.find]
where = src
Expand All @@ -70,6 +71,8 @@ testing =
setuptools
pytest
pytest-cov
pyPrediktorUtilities >= 0.3.2
pyodbc

[options.entry_points]

Expand Down Expand Up @@ -118,10 +121,10 @@ version = 4.3
package = pyprediktormapclient

[tox:tox]
envlist = py38, py39, py310, mypy
envlist = py39, py310, py311, mypy

[gh-actions]
python =
3.8: py38
3.9: py39
3.10: py310, mypy
3.10: py310, mypy
3.11: py311
2 changes: 1 addition & 1 deletion src/pyprediktormapclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .opc_ua import *

if sys.version_info[:2] >= (3, 8):
# TODO: Import directly (no need for conditional) when `python_requires = >= 3.8`
# TODO: Import directly (no need for conditional) when `python_requires = >= 3.9`
from importlib.metadata import PackageNotFoundError, version # pragma: no cover
else:
from importlib_metadata import PackageNotFoundError, version # pragma: no cover
Expand Down
8 changes: 4 additions & 4 deletions src/pyprediktormapclient/dwh/context/enercast.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
from pydantic import validate_call
from typing import List, Dict, Any, Union
from typing import List, Dict, Union

from ..idwh import IDWH

Expand All @@ -10,19 +10,19 @@ def __init__(self, dwh: IDWH) -> None:
self.dwh = dwh

@validate_call
def get_plants_to_update(self) -> List[Any]:
def get_plants_to_update(self) -> List:
query = "SET NOCOUNT ON; EXEC dwetl.GetEnercastPlantsToUpdate"
return self.dwh.fetch(query)

@validate_call
def get_live_meter_data(self, asset_name: str) -> List[Any]:
def get_live_meter_data(self, asset_name: str) -> List:
query = f"SET NOCOUNT ON; EXEC dwetl.GetEnercastLiveMeterData '{asset_name}'"
return self.dwh.fetch(query)

@validate_call
def upsert_forecast_data(
self, enercast_forecast_data: Dict, forecast_type_key: Union[int, None] = None
) -> List[Any]:
) -> List:
enercast_forecast_data_json = json.dumps({"results": enercast_forecast_data})

query = "EXEC dwetl.UpsertEnercastForecastData ?, ?"
Expand Down
8 changes: 4 additions & 4 deletions src/pyprediktormapclient/dwh/context/plant.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
from pydantic import validate_call
from typing import List, Dict, Any
from typing import List, Dict

from ..idwh import IDWH

Expand All @@ -10,15 +10,15 @@ def __init__(self, dwh: IDWH) -> None:
self.dwh = dwh

@validate_call
def get_optimal_tracker_angles(self, facility_name: str) -> List[Any]:
def get_optimal_tracker_angles(self, facility_name: str) -> List:
query = (
f"SET NOCOUNT ON; EXEC dwetl.GetOptimalTrackerAngleParameters "
+ f"@FacilityName = N'{facility_name}'"
)
return self.dwh.fetch(query)

@validate_call
def upsert_optimal_tracker_angles(self, facility_data: Dict) -> List[Any]:
def upsert_optimal_tracker_angles(self, facility_data: Dict) -> List:
facility_data_json = json.dumps(facility_data)
facility_data_json.replace("'", '"')

Expand All @@ -33,7 +33,7 @@ def insert_log(
data_type: str,
has_thrown_error: bool = False,
message: str = "",
) -> List[Any]:
) -> List:
query = "EXEC dwetl.InsertExtDataUpdateLog @plantname = ?, @extkey = ?, @DataType = ?, @Message = ?, @Result = ?"
return self.dwh.execute(
query,
Expand Down
6 changes: 3 additions & 3 deletions src/pyprediktormapclient/dwh/context/solcast.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
from pydantic import validate_call
from typing import List, Dict, Any, Union
from typing import List, Dict, Union

from ..idwh import IDWH

Expand All @@ -10,7 +10,7 @@ def __init__(self, dwh: IDWH) -> None:
self.dwh = dwh

@validate_call
def get_plants_to_update(self) -> List[Any]:
def get_plants_to_update(self) -> List:
query = "SET NOCOUNT ON; EXEC dwetl.GetSolcastPlantsToUpdate"
return self.dwh.fetch(query)

Expand All @@ -20,7 +20,7 @@ def upsert_forecast_data(
plantname: str,
solcast_forecast_data: Dict,
forecast_type_key: Union[int, None] = None,
) -> List[Any]:
) -> List:
solcast_forecast_data_json = json.dumps(
{
"results": {
Expand Down
Loading

0 comments on commit 65c652a

Please sign in to comment.