openstef-dbc
Advanced tools
@@ -1,4 +0,4 @@ | ||
| Metadata-Version: 2.2 | ||
| Metadata-Version: 2.4 | ||
| Name: openstef_dbc | ||
| Version: 3.7.21 | ||
| Version: 3.8.1 | ||
| Summary: Database Connection for OpenSTEF | ||
@@ -39,2 +39,3 @@ Home-page: https://github.com/openstef/openstef-dbc | ||
| Dynamic: license | ||
| Dynamic: license-file | ||
| Dynamic: requires-dist | ||
@@ -41,0 +42,0 @@ Dynamic: requires-python |
@@ -12,3 +12,3 @@ # SPDX-FileCopyrightText: 2017-2022 Contributors to the OpenSTEF project <korte.termijn.prognoses@alliander.com> | ||
| import sqlalchemy | ||
| from sqlalchemy import text, bindparam | ||
| from openstef_dbc import Singleton | ||
@@ -46,3 +46,4 @@ from openstef_dbc.ktp_api import KtpApi | ||
| proxies Union[dict[str, str], None]: Proxies. | ||
| sql_db_type (str, optional): SQL Database type engine to use('mysql' or 'postgresql'), if not defined mysql is used by default. | ||
| sql_db_type (str, optional): SQL Database type engine to use('mysql', 'postgresql' or 'none'), if not defined mysql is used by default. | ||
| Note: 'none' will result in no SQL engine being created. Hence all functionality that requires a SQL engine will not work. | ||
| """ | ||
@@ -70,2 +71,4 @@ | ||
| ) | ||
| elif self.sql_db_type == SupportedSqlTypes.NONE.name: | ||
| self.sql_engine = None | ||
| else: | ||
@@ -272,3 +275,3 @@ self.sql_engine = self._create_mysql_engine( | ||
| params = {} | ||
| cursor = connection.execute(query, **params) | ||
| cursor = connection.execute(text(query).bindparams(**params)) | ||
| if cursor.cursor is not None: | ||
@@ -295,4 +298,4 @@ return pd.DataFrame(cursor.fetchall()) | ||
| with self.sql_engine.connect() as connection: | ||
| response = connection.execute(statement, params=params) | ||
| response = connection.execute(text(statement).bindparams(**params)) | ||
| connection.commit() | ||
| self.logger.info( | ||
@@ -334,1 +337,2 @@ f"Added {response.rowcount} new systems to the systems table in the {self.sql_db_type} database" | ||
| POSTGRESQL = "postgresql" | ||
| NONE = "none" |
@@ -243,4 +243,2 @@ #!/usr/bin/env python | ||
| def get_logger(name=__name__): | ||
| global __loggers | ||
| # if logging is not yet configures | ||
@@ -247,0 +245,0 @@ if __configured is False: |
@@ -258,3 +258,3 @@ # SPDX-FileCopyrightText: 2017-2022 Contributors to the OpenSTEF project <korte.termijn.prognoses@alliander.com> | ||
| bind_params = {"turbine_type": turbine_type} | ||
| query = "SELECT * FROM genericpowercurves WHERE name = %(turbine_type)s" | ||
| query = "SELECT * FROM genericpowercurves WHERE name = :turbine_type" | ||
@@ -261,0 +261,0 @@ result = _DataInterface.get_instance().exec_sql_query(query, bind_params) |
@@ -217,3 +217,3 @@ # SPDX-FileCopyrightText: 2017-2022 Contributors to the OpenSTEF project <korte.termijn.prognoses@alliander.com> | ||
| LEFT JOIN `predictions` as p ON p.id = cp.prediction_id | ||
| WHERE cak.api_key = %(apiKey)s | ||
| WHERE cak.apiKey = :apiKey | ||
| """ | ||
@@ -268,3 +268,3 @@ result = _DataInterface.get_instance().exec_sql_query(query, bind_params) | ||
| FROM `predictions` as p | ||
| WHERE p.id = %(pid)s | ||
| WHERE p.id = :pid | ||
| """ | ||
@@ -271,0 +271,0 @@ result = _DataInterface.get_instance().exec_sql_query(query, bind_params) |
@@ -39,3 +39,3 @@ # SPDX-FileCopyrightText: 2017-2022 Contributors to the OpenSTEF project <korte.termijn.prognoses@alliander.com> | ||
| "SELECT ec.coef_name, AVG(ec.coef_value) FROM energy_split_coefs as ec " | ||
| "WHERE ec.pid = %(pid)s AND ec.created > %(dstart)s GROUP BY ec.coef_name " | ||
| "WHERE ec.pid = :pid AND ec.created > :dstart GROUP BY ec.coef_name " | ||
| ) | ||
@@ -46,5 +46,5 @@ # Retrieve latest coefficients otherwise | ||
| query = ( | ||
| "SELECT ec.coef_name,ec.coef_value FROM energy_split_coefs as ec WHERE ec.pid = %(pid)s " | ||
| "SELECT ec.coef_name,ec.coef_value FROM energy_split_coefs as ec WHERE ec.pid = :pid " | ||
| "AND ec.created = (SELECT max(energy_split_coefs.created) from energy_split_coefs " | ||
| "WHERE energy_split_coefs.pid = %(pid)s)" | ||
| "WHERE energy_split_coefs.pid = :pid)" | ||
| ) | ||
@@ -55,3 +55,3 @@ # Execute query | ||
| # Make output dict | ||
| if result is not None: | ||
| if not result.empty: | ||
| result = result.set_index("coef_name") | ||
@@ -58,0 +58,0 @@ if mean: |
@@ -43,7 +43,7 @@ # SPDX-FileCopyrightText: 2017-2022 Contributors to the OpenSTEF project <korte.termijn.prognoses@alliander.com> | ||
| query = """ | ||
| SELECT `sid`, `lat`, `lon`,`region`, ( 6371 * acos( cos( radians(%(lat)s) ) \ | ||
| * cos( radians( lat ) ) * cos( radians( lon ) - radians(%(lon)s) ) + sin( radians(%(lat)s) ) \ | ||
| SELECT `sid`, `lat`, `lon`,`region`, ( 6371 * acos( cos( radians(:lat) ) \ | ||
| * cos( radians( lat ) ) * cos( radians( lon ) - radians(:lon) ) + sin( radians(:lat) ) \ | ||
| * sin( radians( lat ) ) ) ) AS `distance` \ | ||
| FROM `systems` | ||
| WHERE `qual` > '%(quality)s' | ||
| WHERE `qual` > ':quality' | ||
| """ | ||
@@ -54,8 +54,8 @@ | ||
| bind_params["freq"] = str(freq) | ||
| query += """ AND `freq` <= %(freq)s""" | ||
| query += """ AND `freq` <= :freq""" | ||
| if lag_systems is not None: | ||
| query += """ AND `lagSystems` <= %(quality)s""" | ||
| query += """ AND `lagSystems` <= :quality""" | ||
| # Limit radius to given input radius | ||
| query += """ HAVING `distance` < %(radius)s ORDER BY `distance`;""" | ||
| query += """ HAVING `distance` < :radius ORDER BY `distance`;""" | ||
@@ -87,3 +87,3 @@ result = _DataInterface.get_instance().exec_sql_query(query, bind_params) | ||
| ON predictions_systems.system_id=systems.sid | ||
| WHERE predictions_systems.prediction_id=%(pid)s | ||
| WHERE predictions_systems.prediction_id=:pid | ||
| """ | ||
@@ -117,3 +117,3 @@ | ||
| bind_params["limit"] = limit | ||
| limit_query = f"LIMIT %(limit)s" | ||
| limit_query = f"LIMIT :limit" | ||
@@ -123,3 +123,3 @@ query = f""" | ||
| FROM systems | ||
| WHERE left(sid, 3) = 'pv_' AND autoupdate = %(autoupdate)s | ||
| WHERE left(sid, 3) = 'pv_' AND autoupdate = :autoupdate | ||
| ORDER BY RAND() {limit_query} | ||
@@ -146,3 +146,3 @@ """ | ||
| LEFT JOIN `systemsApiKeys` as sa ON s.measurements_customer_api_key_id = sa.id | ||
| WHERE s.sid = %(system)s; | ||
| WHERE s.sid = :system; | ||
| """ | ||
@@ -149,0 +149,0 @@ |
@@ -46,3 +46,3 @@ # SPDX-FileCopyrightText: 2017-2022 Contributors to the OpenSTEF project <korte.termijn.prognoses@alliander.com> | ||
| FROM weatherforecastlocations | ||
| WHERE country = %(country)s AND active = %(active)s | ||
| WHERE country = :country AND active = :active | ||
| """ | ||
@@ -140,3 +140,3 @@ result = _DataInterface.get_instance().exec_sql_query(query, bind_params) | ||
| binding_params = {"city": location_name} | ||
| query = "SELECT lat, lon from NameToLatLon where regionInput = %(city)s" | ||
| query = "SELECT lat, lon from NameToLatLon where regionInput = :city" | ||
| location = _DataInterface.get_instance().exec_sql_query(query, binding_params) | ||
@@ -283,7 +283,2 @@ | ||
| # Get data from an hour earlier to correct for radiation shift later | ||
| datetime_start_original = datetime_start.tz_localize("UTC") | ||
| datetime_start -= timedelta(hours=1) | ||
| location_name = self._get_nearest_weather_locations( | ||
@@ -376,13 +371,2 @@ location=location, country=country, number_locations=number_locations | ||
| # Shift radiation by 30 minutes if resolution allows it | ||
| if "radiation" in result.columns: | ||
| shift_delta = -timedelta(minutes=30) | ||
| if shift_delta % pd.Timedelta(resolution) == timedelta(0): | ||
| result["radiation"] = result.groupby(grouping_indices)[ | ||
| "radiation" | ||
| ].shift(1, shift_delta) | ||
| # Drop extra rows not neccesary | ||
| result = result[result.index >= datetime_start_original] | ||
| if number_locations == 1: | ||
@@ -389,0 +373,0 @@ result = result.drop(columns="input_city") |
@@ -24,3 +24,2 @@ # SPDX-FileCopyrightText: 2017-2022 Contributors to the OpenSTEF project <korte.termijn.prognoses@alliander.com> | ||
| bind_params = { | ||
| "table_name": "NameToLatLon", | ||
| "loc": location_name, | ||
@@ -31,3 +30,5 @@ "lat": location[0], | ||
| statement = "INSERT INTO %(table_name)s (regionInput, lat,lon) VALUES (%(loc)s, %(lat)s, %(lon)s)" | ||
| statement = ( | ||
| "INSERT INTO NameToLatLon (regionInput, lat,lon) VALUES (:loc, :lat, :lon)" | ||
| ) | ||
@@ -34,0 +35,0 @@ _DataInterface.get_instance().exec_sql_write(statement, params=bind_params) |
+3
-2
@@ -1,4 +0,4 @@ | ||
| Metadata-Version: 2.2 | ||
| Metadata-Version: 2.4 | ||
| Name: openstef_dbc | ||
| Version: 3.7.21 | ||
| Version: 3.8.1 | ||
| Summary: Database Connection for OpenSTEF | ||
@@ -39,2 +39,3 @@ Home-page: https://github.com/openstef/openstef-dbc | ||
| Dynamic: license | ||
| Dynamic: license-file | ||
| Dynamic: requires-dist | ||
@@ -41,0 +42,0 @@ Dynamic: requires-python |
+1
-1
@@ -32,3 +32,3 @@ # SPDX-FileCopyrightText: 2017-2022 Contributors to the OpenSTEF project <korte.termijn.prognoses@alliander.com> # noqa E501> | ||
| name="openstef_dbc", | ||
| version="3.7.21", | ||
| version="3.8.1", | ||
| packages=find_packages(include=["openstef_dbc", "openstef_dbc.*"]), | ||
@@ -35,0 +35,0 @@ description="Database Connection for OpenSTEF", |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
199452
-0.19%3943
-0.15%