pandahub 0.3.9__zip → 0.3.11__zip
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.
- {pandahub-0.3.9 → pandahub-0.3.11}/CHANGELOG.md +8 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/PKG-INFO +1 -1
- {pandahub-0.3.9 → pandahub-0.3.11}/pandahub/api/routers/variants.py +15 -5
- {pandahub-0.3.9 → pandahub-0.3.11}/pandahub/lib/PandaHub.py +48 -36
- {pandahub-0.3.9 → pandahub-0.3.11}/pandahub/lib/database_toolbox.py +17 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/pandahub.egg-info/PKG-INFO +1 -1
- {pandahub-0.3.9 → pandahub-0.3.11}/pyproject.toml +1 -1
- {pandahub-0.3.9 → pandahub-0.3.11}/CONTRIBUTING.rst +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/LICENSE +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/MANIFEST.in +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/README.md +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/pandahub/__init__.py +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/pandahub/api/__init__.py +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/pandahub/api/dependencies.py +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/pandahub/api/internal/__init__.py +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/pandahub/api/internal/db.py +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/pandahub/api/internal/schemas.py +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/pandahub/api/internal/settings.py +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/pandahub/api/internal/toolbox.py +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/pandahub/api/internal/users.py +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/pandahub/api/main.py +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/pandahub/api/routers/__init__.py +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/pandahub/api/routers/auth.py +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/pandahub/api/routers/net.py +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/pandahub/api/routers/projects.py +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/pandahub/api/routers/timeseries.py +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/pandahub/api/routers/users.py +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/pandahub/lib/__init__.py +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/pandahub/lib/datatypes.py +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/pandahub/lib/mongodb_indexes.py +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/pandahub/lib/timeseries/__init__.py +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/pandahub/lib/timeseries/data_sources/__init__.py +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/pandahub/lib/timeseries/data_sources/mongo_data.py +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/pandahub/lib/timeseries/output_writer_mongodb.py +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/pandahub.egg-info/SOURCES.txt +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/pandahub.egg-info/dependency_links.txt +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/pandahub.egg-info/requires.txt +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/pandahub.egg-info/top_level.txt +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/requirements.txt +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/setup.cfg +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/setup.py +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/test/__init__.py +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/test/conftest.py +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/test/performance_test.py +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/test/test_client.py +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/test/test_networks.py +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/test/test_projects.py +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/test/test_timeseries.py +0 -0
- {pandahub-0.3.9 → pandahub-0.3.11}/tutorials/config.py +0 -0
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## [0.3.11]
|
|
4
|
+
|
|
5
|
+
- IMPROVED: add lib.database_toolbox.get_mongo_client function
|
|
6
|
+
|
|
7
|
+
## [0.3.10]
|
|
8
|
+
|
|
9
|
+
- BREAKING: changed signatures of create_variant function and route
|
|
10
|
+
|
|
3
11
|
## [0.3.9]
|
|
4
12
|
|
|
5
13
|
- BREAKING: inserting multiple networks with the same name does not represent an error anymore, networks are only unique by their net_id (_id field of the collection)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pandahub
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.11
|
|
4
4
|
Summary: Data hub for pandapower and pandapipes networks based on MongoDB
|
|
5
5
|
Author-email: Jan Ulffers <jan.ulffers@iee.fraunhofer.de>, Leon Thurner <leon.thurner@retoflow.de>, Jannis Kupka <jannis.kupka@retoflow.de>, Mike Vogt <mike.vogt@iee.fraunhofer.de>, Joschka Thurner <joschka.thurner@retoflow.de>, Alexander Scheidler <alexander.scheidler@iee.fraunhofer.de>
|
|
6
6
|
License: Copyright (c) 2022 by University of Kassel, Fraunhofer Institute for Energy Economics
|
|
@@ -30,13 +30,23 @@ def get_variants(data: GetVariantsModel, ph=Depends(pandahub)):
|
|
|
30
30
|
|
|
31
31
|
class CreateVariantModel(BaseModel):
|
|
32
32
|
project_id: str
|
|
33
|
-
|
|
33
|
+
net_id: int
|
|
34
|
+
name: str | None = None
|
|
35
|
+
default_name: str | None = None
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class CreateVariantResponseModel(BaseModel):
|
|
39
|
+
net_id: int
|
|
40
|
+
index: int
|
|
41
|
+
name: str | None = None
|
|
42
|
+
date_created: int
|
|
43
|
+
date_changed: int
|
|
44
|
+
|
|
34
45
|
|
|
35
46
|
@router.post("/create_variant")
|
|
36
|
-
def create_variant(data: CreateVariantModel, ph=Depends(pandahub)):
|
|
37
|
-
|
|
38
|
-
ph.
|
|
39
|
-
return ph.create_variant(data.variant_data)
|
|
47
|
+
def create_variant(data: CreateVariantModel, ph=Depends(pandahub)) -> CreateVariantResponseModel:
|
|
48
|
+
ph.set_active_project_by_id(data.project_id)
|
|
49
|
+
return ph.create_variant(net_id=data.net_id, name=data.name, default_name=data.default_name)
|
|
40
50
|
|
|
41
51
|
class DeleteVariantModel(BaseModel):
|
|
42
52
|
project_id: str
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import builtins
|
|
3
3
|
import json
|
|
4
4
|
import logging
|
|
5
|
+
import time
|
|
5
6
|
import warnings
|
|
6
7
|
from inspect import signature, _empty
|
|
7
8
|
from collections.abc import Callable
|
|
@@ -22,12 +23,14 @@ import pandapipes as pps
|
|
|
22
23
|
from pandapipes import from_json_string as from_json_pps, FromSerializableRegistryPpipe
|
|
23
24
|
import pandapower as pp
|
|
24
25
|
import pandapower.io_utils as io_pp
|
|
26
|
+
|
|
25
27
|
from pandahub.api.internal.settings import MONGODB_URL, MONGODB_USER, MONGODB_PASSWORD, MONGODB_GLOBAL_DATABASE_URL, \
|
|
26
28
|
MONGODB_GLOBAL_DATABASE_USER, MONGODB_GLOBAL_DATABASE_PASSWORD, CREATE_INDEXES_WITH_PROJECT
|
|
27
29
|
from pandahub.lib.database_toolbox import (
|
|
28
30
|
create_timeseries_document,
|
|
29
31
|
convert_timeseries_to_subdocuments,
|
|
30
32
|
convert_element_to_dict,
|
|
33
|
+
get_mongo_client,
|
|
31
34
|
json_to_object,
|
|
32
35
|
serialize_object_data,
|
|
33
36
|
get_dtypes,
|
|
@@ -91,20 +94,11 @@ class PandaHub:
|
|
|
91
94
|
user_id=None,
|
|
92
95
|
datatypes=DATATYPES,
|
|
93
96
|
mongodb_indexes=MONGODB_INDEXES,
|
|
97
|
+
elements_without_vars = None,
|
|
94
98
|
):
|
|
95
|
-
mongo_client_args = {
|
|
96
|
-
"host": connection_url,
|
|
97
|
-
"uuidRepresentation": "standard",
|
|
98
|
-
"connect": False,
|
|
99
|
-
}
|
|
100
|
-
if connection_user:
|
|
101
|
-
mongo_client_args |= {
|
|
102
|
-
"username": connection_user,
|
|
103
|
-
"password": connection_password,
|
|
104
|
-
}
|
|
105
99
|
self._datatypes = datatypes
|
|
106
100
|
self.mongodb_indexes = mongodb_indexes
|
|
107
|
-
self.mongo_client =
|
|
101
|
+
self.mongo_client = get_mongo_client(connection_url, connection_user, connection_password)
|
|
108
102
|
self.mongo_client_global_db = None
|
|
109
103
|
self.active_project = None
|
|
110
104
|
self.user_id = user_id
|
|
@@ -115,6 +109,7 @@ class PandaHub:
|
|
|
115
109
|
{"var_type": np.nan},
|
|
116
110
|
]
|
|
117
111
|
}
|
|
112
|
+
self._elements_without_vars = ["variant"] if elements_without_vars is None else elements_without_vars
|
|
118
113
|
if check_server_available:
|
|
119
114
|
self.server_is_available()
|
|
120
115
|
|
|
@@ -1150,10 +1145,13 @@ class PandaHub:
|
|
|
1150
1145
|
if element_data.empty:
|
|
1151
1146
|
continue
|
|
1152
1147
|
element_data = element_data.copy(deep=True)
|
|
1153
|
-
if
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1148
|
+
if element not in self._elements_without_vars:
|
|
1149
|
+
if "var_type" in element_data:
|
|
1150
|
+
element_data["var_type"] = element_data["var_type"].fillna("base")
|
|
1151
|
+
else:
|
|
1152
|
+
element_data["var_type"] = "base"
|
|
1153
|
+
element_data["not_in_var"] = np.empty((len(element_data.index), 0)).tolist()
|
|
1154
|
+
element_data["variant"] = None
|
|
1157
1155
|
element_data = convert_element_to_dict(element_data, net_id, self._datatypes.get(element))
|
|
1158
1156
|
self._write_element_to_db(db, element, element_data)
|
|
1159
1157
|
|
|
@@ -1228,9 +1226,12 @@ class PandaHub:
|
|
|
1228
1226
|
def _network_with_name_exists(self, name, db):
|
|
1229
1227
|
return self._get_net_id_from_name(name, db) is not None
|
|
1230
1228
|
|
|
1229
|
+
def _get_net_collections(self, db, with_areas=True):
|
|
1230
|
+
return self.get_net_collections(db, with_areas)
|
|
1231
|
+
|
|
1231
1232
|
def get_net_collections(self, db=None, with_areas=True):
|
|
1232
1233
|
if db is None:
|
|
1233
|
-
db = self.
|
|
1234
|
+
db = self.get_project_database()
|
|
1234
1235
|
if with_areas:
|
|
1235
1236
|
collection_filter = {"name": {"$regex": "^net_"}}
|
|
1236
1237
|
else:
|
|
@@ -1402,7 +1403,7 @@ class PandaHub:
|
|
|
1402
1403
|
"""
|
|
1403
1404
|
if not isinstance(element_indexes, list):
|
|
1404
1405
|
raise TypeError("Parameter element_indexes must be a list of ints!")
|
|
1405
|
-
|
|
1406
|
+
self.validate_variant(variant, element_type)
|
|
1406
1407
|
if project_id:
|
|
1407
1408
|
self.set_active_project_by_id(project_id)
|
|
1408
1409
|
|
|
@@ -1446,7 +1447,7 @@ class PandaHub:
|
|
|
1446
1447
|
project_id=None,
|
|
1447
1448
|
**kwargs,
|
|
1448
1449
|
):
|
|
1449
|
-
|
|
1450
|
+
self.validate_variant(variant, element_type)
|
|
1450
1451
|
if project_id:
|
|
1451
1452
|
self.set_active_project_by_id(project_id)
|
|
1452
1453
|
self.check_permission("write")
|
|
@@ -1514,7 +1515,7 @@ class PandaHub:
|
|
|
1514
1515
|
variant=None,
|
|
1515
1516
|
project_id=None,
|
|
1516
1517
|
):
|
|
1517
|
-
|
|
1518
|
+
self.validate_variant(variant, element_type)
|
|
1518
1519
|
if project_id:
|
|
1519
1520
|
self.set_active_project_by_id(project_id)
|
|
1520
1521
|
self.check_permission("write")
|
|
@@ -1636,7 +1637,7 @@ class PandaHub:
|
|
|
1636
1637
|
list
|
|
1637
1638
|
A list of the created elements (elements_data with added _id fields)
|
|
1638
1639
|
"""
|
|
1639
|
-
|
|
1640
|
+
self.validate_variant(variant, element_type)
|
|
1640
1641
|
if project_id:
|
|
1641
1642
|
self.set_active_project_by_id(project_id)
|
|
1642
1643
|
self.check_permission("write")
|
|
@@ -1771,24 +1772,30 @@ class PandaHub:
|
|
|
1771
1772
|
# Variants
|
|
1772
1773
|
# -------------------------
|
|
1773
1774
|
|
|
1774
|
-
def create_variant(
|
|
1775
|
+
def create_variant(
|
|
1776
|
+
self,
|
|
1777
|
+
net_id: int,
|
|
1778
|
+
name: str | None = None,
|
|
1779
|
+
default_name: str = "Variant",
|
|
1780
|
+
index: int | None = None,
|
|
1781
|
+
) -> dict:
|
|
1775
1782
|
db = self._get_project_database()
|
|
1776
|
-
net_id = int(data["net_id"])
|
|
1777
1783
|
if index is None:
|
|
1778
1784
|
index = self._get_int_index("variant", index_field="index", query_filter={"net_id": net_id})
|
|
1779
|
-
|
|
1780
|
-
if
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1785
|
+
|
|
1786
|
+
if name is None:
|
|
1787
|
+
name = f"{default_name} {index + 1}"
|
|
1788
|
+
now = int(time.time())
|
|
1789
|
+
variant = {
|
|
1790
|
+
"net_id": net_id,
|
|
1791
|
+
"index": index,
|
|
1792
|
+
"name": name,
|
|
1793
|
+
"date_created": now,
|
|
1794
|
+
"date_changed": now,
|
|
1795
|
+
}
|
|
1796
|
+
db["variant"].insert_one(variant)
|
|
1797
|
+
del variant["_id"]
|
|
1798
|
+
return variant
|
|
1792
1799
|
|
|
1793
1800
|
def delete_variant(self, net_id, index):
|
|
1794
1801
|
db = self._get_project_database()
|
|
@@ -1828,12 +1835,17 @@ class PandaHub:
|
|
|
1828
1835
|
dict
|
|
1829
1836
|
mongodb query filter for the given variant
|
|
1830
1837
|
"""
|
|
1831
|
-
|
|
1838
|
+
self.validate_variant(variant)
|
|
1832
1839
|
if variant is None:
|
|
1833
1840
|
return self.base_variant_filter
|
|
1834
1841
|
return {"$or": [{"var_type": "base", "not_in_var": {"$ne": variant}},
|
|
1835
1842
|
{"var_type": {"$in": ["change", "addition"]}, "variant": variant}, ]}
|
|
1836
1843
|
|
|
1844
|
+
def validate_variant(self, variant: int | None, element_type: str | None = None):
|
|
1845
|
+
"""Raise a ValueError if variant is not int | None or element_type does not support variants."""
|
|
1846
|
+
validate_variant_type(variant)
|
|
1847
|
+
if element_type is not None and variant is not None and element_type in self._elements_without_vars:
|
|
1848
|
+
raise ValueError(f"{element_type} does not support variants")
|
|
1837
1849
|
|
|
1838
1850
|
# -------------------------
|
|
1839
1851
|
# Bulk operations
|
|
@@ -3,6 +3,9 @@ from typing import Optional
|
|
|
3
3
|
|
|
4
4
|
import numpy as np
|
|
5
5
|
import pandas as pd
|
|
6
|
+
from pymongo import MongoClient
|
|
7
|
+
|
|
8
|
+
from pandahub.api.internal.settings import MONGODB_URL, MONGODB_USER, MONGODB_PASSWORD
|
|
6
9
|
from pandahub.lib.datatypes import DATATYPES
|
|
7
10
|
import base64
|
|
8
11
|
import hashlib
|
|
@@ -421,3 +424,17 @@ def migrate_userdb_to_beanie(ph):
|
|
|
421
424
|
{'$unset': 'id'},
|
|
422
425
|
{'$out': 'users'}]
|
|
423
426
|
userdb.aggregate(migration)
|
|
427
|
+
|
|
428
|
+
def get_mongo_client(connection_url=MONGODB_URL, connection_user=MONGODB_USER,
|
|
429
|
+
connection_password=MONGODB_PASSWORD) -> MongoClient:
|
|
430
|
+
mongo_client_args = {
|
|
431
|
+
"host": connection_url,
|
|
432
|
+
"uuidRepresentation": "standard",
|
|
433
|
+
"connect": False,
|
|
434
|
+
}
|
|
435
|
+
if connection_user:
|
|
436
|
+
mongo_client_args |= {
|
|
437
|
+
"username": connection_user,
|
|
438
|
+
"password": connection_password,
|
|
439
|
+
}
|
|
440
|
+
return MongoClient(**mongo_client_args)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pandahub
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.11
|
|
4
4
|
Summary: Data hub for pandapower and pandapipes networks based on MongoDB
|
|
5
5
|
Author-email: Jan Ulffers <jan.ulffers@iee.fraunhofer.de>, Leon Thurner <leon.thurner@retoflow.de>, Jannis Kupka <jannis.kupka@retoflow.de>, Mike Vogt <mike.vogt@iee.fraunhofer.de>, Joschka Thurner <joschka.thurner@retoflow.de>, Alexander Scheidler <alexander.scheidler@iee.fraunhofer.de>
|
|
6
6
|
License: Copyright (c) 2022 by University of Kassel, Fraunhofer Institute for Energy Economics
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "pandahub"
|
|
7
|
-
version = "0.3.
|
|
7
|
+
version = "0.3.11" # File format version '__format_version__' is tracked in __init__.py
|
|
8
8
|
authors=[
|
|
9
9
|
{ name = "Jan Ulffers", email = "jan.ulffers@iee.fraunhofer.de" },
|
|
10
10
|
{ name = "Leon Thurner", email = "leon.thurner@retoflow.de" },
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|