pandahub 0.3.7__zip → 0.3.8__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.7 → pandahub-0.3.8}/CHANGELOG.md +4 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/PKG-INFO +1 -1
- {pandahub-0.3.7 → pandahub-0.3.8}/pandahub/api/routers/variants.py +1 -4
- {pandahub-0.3.7 → pandahub-0.3.8}/pandahub/lib/PandaHub.py +56 -85
- {pandahub-0.3.7 → pandahub-0.3.8}/pandahub.egg-info/PKG-INFO +1 -1
- {pandahub-0.3.7 → pandahub-0.3.8}/pyproject.toml +1 -1
- {pandahub-0.3.7 → pandahub-0.3.8}/CONTRIBUTING.rst +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/LICENSE +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/MANIFEST.in +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/README.md +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/pandahub/__init__.py +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/pandahub/api/__init__.py +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/pandahub/api/dependencies.py +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/pandahub/api/internal/__init__.py +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/pandahub/api/internal/db.py +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/pandahub/api/internal/schemas.py +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/pandahub/api/internal/settings.py +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/pandahub/api/internal/toolbox.py +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/pandahub/api/internal/users.py +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/pandahub/api/main.py +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/pandahub/api/routers/__init__.py +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/pandahub/api/routers/auth.py +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/pandahub/api/routers/net.py +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/pandahub/api/routers/projects.py +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/pandahub/api/routers/timeseries.py +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/pandahub/api/routers/users.py +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/pandahub/lib/__init__.py +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/pandahub/lib/database_toolbox.py +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/pandahub/lib/datatypes.py +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/pandahub/lib/mongodb_indexes.py +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/pandahub/lib/timeseries/__init__.py +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/pandahub/lib/timeseries/data_sources/__init__.py +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/pandahub/lib/timeseries/data_sources/mongo_data.py +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/pandahub/lib/timeseries/output_writer_mongodb.py +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/pandahub.egg-info/SOURCES.txt +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/pandahub.egg-info/dependency_links.txt +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/pandahub.egg-info/requires.txt +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/pandahub.egg-info/top_level.txt +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/requirements.txt +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/setup.cfg +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/setup.py +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/test/__init__.py +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/test/conftest.py +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/test/performance_test.py +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/test/test_client.py +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/test/test_networks.py +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/test/test_projects.py +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/test/test_timeseries.py +0 -0
- {pandahub-0.3.7 → pandahub-0.3.8}/tutorials/config.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pandahub
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.8
|
|
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
|
|
@@ -25,10 +25,7 @@ def get_variants(data: GetVariantsModel, ph=Depends(pandahub)):
|
|
|
25
25
|
variants_collection = ph.get_project_database("variant")
|
|
26
26
|
|
|
27
27
|
variants = variants_collection.find({"net_id": data.net_id}, projection={"_id": 0})
|
|
28
|
-
|
|
29
|
-
for var in variants:
|
|
30
|
-
response[var.pop("index")] = var
|
|
31
|
-
return response
|
|
28
|
+
return {variant.pop("index"): variant for variant in variants}
|
|
32
29
|
|
|
33
30
|
|
|
34
31
|
class CreateVariantModel(BaseModel):
|
|
@@ -5,6 +5,7 @@ import logging
|
|
|
5
5
|
import warnings
|
|
6
6
|
from inspect import signature, _empty
|
|
7
7
|
from collections.abc import Callable
|
|
8
|
+
from types import NoneType
|
|
8
9
|
from typing import Optional, Union, TypeVar
|
|
9
10
|
|
|
10
11
|
import numpy as np
|
|
@@ -63,6 +64,13 @@ class PandaHubError(Exception):
|
|
|
63
64
|
ProjectID = TypeVar("ProjectID", str, int, ObjectId)
|
|
64
65
|
SettingsValue = TypeVar("SettingsValue", str, int, float, list, dict)
|
|
65
66
|
|
|
67
|
+
|
|
68
|
+
def validate_variant_type(variant: int | None):
|
|
69
|
+
"""Raise a ValueError if variant is not int | None."""
|
|
70
|
+
if not isinstance(variant, (int, NoneType)):
|
|
71
|
+
msg = f"variant must be int or None, but got {variant} of type {type(variant)}"
|
|
72
|
+
raise ValueError(msg)
|
|
73
|
+
|
|
66
74
|
class PandaHub:
|
|
67
75
|
permissions = {
|
|
68
76
|
"read": ["owner", "developer", "guest"],
|
|
@@ -706,7 +714,7 @@ class PandaHub:
|
|
|
706
714
|
only_tables=None,
|
|
707
715
|
project_id=None,
|
|
708
716
|
geo_mode="string",
|
|
709
|
-
|
|
717
|
+
variant=None,
|
|
710
718
|
convert=True,
|
|
711
719
|
):
|
|
712
720
|
if project_id:
|
|
@@ -717,7 +725,7 @@ class PandaHub:
|
|
|
717
725
|
if _id is None:
|
|
718
726
|
return None
|
|
719
727
|
return self.get_net_from_db_by_id(
|
|
720
|
-
_id, include_results, only_tables, geo_mode=geo_mode,
|
|
728
|
+
_id, include_results, only_tables, geo_mode=geo_mode, variant=variant, convert=convert
|
|
721
729
|
)
|
|
722
730
|
|
|
723
731
|
def get_net_from_db_by_id(
|
|
@@ -727,7 +735,7 @@ class PandaHub:
|
|
|
727
735
|
only_tables=None,
|
|
728
736
|
convert=True,
|
|
729
737
|
geo_mode="string",
|
|
730
|
-
|
|
738
|
+
variant=None,
|
|
731
739
|
):
|
|
732
740
|
self.check_permission("read")
|
|
733
741
|
return self._get_net_from_db_by_id(
|
|
@@ -736,7 +744,7 @@ class PandaHub:
|
|
|
736
744
|
only_tables,
|
|
737
745
|
convert=convert,
|
|
738
746
|
geo_mode=geo_mode,
|
|
739
|
-
|
|
747
|
+
variant=variant,
|
|
740
748
|
)
|
|
741
749
|
|
|
742
750
|
def _get_net_from_db_by_id(
|
|
@@ -746,7 +754,7 @@ class PandaHub:
|
|
|
746
754
|
only_tables=None,
|
|
747
755
|
convert=True,
|
|
748
756
|
geo_mode="string",
|
|
749
|
-
|
|
757
|
+
variant=None,
|
|
750
758
|
):
|
|
751
759
|
db = self._get_project_database()
|
|
752
760
|
meta = self._get_network_metadata(db, id_)
|
|
@@ -766,7 +774,7 @@ class PandaHub:
|
|
|
766
774
|
include_results=include_results,
|
|
767
775
|
only_tables=only_tables,
|
|
768
776
|
geo_mode=geo_mode,
|
|
769
|
-
|
|
777
|
+
variant=variant,
|
|
770
778
|
)
|
|
771
779
|
# add data that is not stored in dataframes
|
|
772
780
|
self.deserialize_and_update_data(net, meta)
|
|
@@ -796,7 +804,7 @@ class PandaHub:
|
|
|
796
804
|
include_results=True,
|
|
797
805
|
add_edge_branches=True,
|
|
798
806
|
geo_mode="string",
|
|
799
|
-
|
|
807
|
+
variant=None,
|
|
800
808
|
additional_filters: dict[
|
|
801
809
|
str, Callable[[pp.auxiliary.pandapowerNet], dict]
|
|
802
810
|
] = {},
|
|
@@ -812,7 +820,7 @@ class PandaHub:
|
|
|
812
820
|
include_results=include_results,
|
|
813
821
|
add_edge_branches=add_edge_branches,
|
|
814
822
|
geo_mode=geo_mode,
|
|
815
|
-
|
|
823
|
+
variant=variant,
|
|
816
824
|
additional_filters=additional_filters,
|
|
817
825
|
)
|
|
818
826
|
|
|
@@ -823,7 +831,7 @@ class PandaHub:
|
|
|
823
831
|
include_results=True,
|
|
824
832
|
add_edge_branches=True,
|
|
825
833
|
geo_mode="string",
|
|
826
|
-
|
|
834
|
+
variant=None,
|
|
827
835
|
ignore_elements=[],
|
|
828
836
|
additional_filters: dict[
|
|
829
837
|
str, Callable[[pp.auxiliary.pandapowerNet], dict]
|
|
@@ -847,7 +855,7 @@ class PandaHub:
|
|
|
847
855
|
net_id,
|
|
848
856
|
bus_filter,
|
|
849
857
|
geo_mode=geo_mode,
|
|
850
|
-
|
|
858
|
+
variant=variant,
|
|
851
859
|
dtypes=dtypes,
|
|
852
860
|
)
|
|
853
861
|
buses = net.bus.index.tolist()
|
|
@@ -873,7 +881,7 @@ class PandaHub:
|
|
|
873
881
|
]
|
|
874
882
|
},
|
|
875
883
|
geo_mode=geo_mode,
|
|
876
|
-
|
|
884
|
+
variant=variant,
|
|
877
885
|
dtypes=dtypes,
|
|
878
886
|
)
|
|
879
887
|
trafo_operator = "$or" if "trafo" in add_edge_branches else "$and"
|
|
@@ -884,7 +892,7 @@ class PandaHub:
|
|
|
884
892
|
net_id,
|
|
885
893
|
{trafo_operator: [{"hv_bus": {"$in": buses}}, {"lv_bus": {"$in": buses}}]},
|
|
886
894
|
geo_mode=geo_mode,
|
|
887
|
-
|
|
895
|
+
variant=variant,
|
|
888
896
|
dtypes=dtypes,
|
|
889
897
|
)
|
|
890
898
|
self._add_element_from_collection(
|
|
@@ -900,7 +908,7 @@ class PandaHub:
|
|
|
900
908
|
]
|
|
901
909
|
},
|
|
902
910
|
geo_mode=geo_mode,
|
|
903
|
-
|
|
911
|
+
variant=variant,
|
|
904
912
|
dtypes=dtypes,
|
|
905
913
|
)
|
|
906
914
|
switch_operator = "$or" if "switch" in add_edge_branches else "$and"
|
|
@@ -921,7 +929,7 @@ class PandaHub:
|
|
|
921
929
|
]
|
|
922
930
|
},
|
|
923
931
|
geo_mode=geo_mode,
|
|
924
|
-
|
|
932
|
+
variant=variant,
|
|
925
933
|
dtypes=dtypes,
|
|
926
934
|
)
|
|
927
935
|
if add_edge_branches:
|
|
@@ -944,7 +952,7 @@ class PandaHub:
|
|
|
944
952
|
"bus",
|
|
945
953
|
net_id,
|
|
946
954
|
geo_mode=geo_mode,
|
|
947
|
-
|
|
955
|
+
variant=variant,
|
|
948
956
|
filter={"index": {"$in": branch_buses_outside}},
|
|
949
957
|
dtypes=dtypes,
|
|
950
958
|
)
|
|
@@ -969,7 +977,7 @@ class PandaHub:
|
|
|
969
977
|
net_id,
|
|
970
978
|
switch_filter,
|
|
971
979
|
geo_mode=geo_mode,
|
|
972
|
-
|
|
980
|
+
variant=variant,
|
|
973
981
|
dtypes=dtypes,
|
|
974
982
|
)
|
|
975
983
|
|
|
@@ -1004,7 +1012,7 @@ class PandaHub:
|
|
|
1004
1012
|
filter=element_filter,
|
|
1005
1013
|
geo_mode=geo_mode,
|
|
1006
1014
|
include_results=include_results,
|
|
1007
|
-
|
|
1015
|
+
variant=variant,
|
|
1008
1016
|
dtypes=dtypes,
|
|
1009
1017
|
)
|
|
1010
1018
|
|
|
@@ -1021,7 +1029,7 @@ class PandaHub:
|
|
|
1021
1029
|
filter=element_filter,
|
|
1022
1030
|
geo_mode=geo_mode,
|
|
1023
1031
|
include_results=include_results,
|
|
1024
|
-
|
|
1032
|
+
variant=variant,
|
|
1025
1033
|
dtypes=dtypes,
|
|
1026
1034
|
)
|
|
1027
1035
|
|
|
@@ -1050,7 +1058,7 @@ class PandaHub:
|
|
|
1050
1058
|
filter=element_filter,
|
|
1051
1059
|
geo_mode=geo_mode,
|
|
1052
1060
|
include_results=include_results,
|
|
1053
|
-
|
|
1061
|
+
variant=variant,
|
|
1054
1062
|
dtypes=dtypes,
|
|
1055
1063
|
)
|
|
1056
1064
|
self.deserialize_and_update_data(net, meta)
|
|
@@ -1201,15 +1209,14 @@ class PandaHub:
|
|
|
1201
1209
|
include_results=True,
|
|
1202
1210
|
only_tables=None,
|
|
1203
1211
|
geo_mode="string",
|
|
1204
|
-
|
|
1212
|
+
variant=None,
|
|
1205
1213
|
dtypes=None,
|
|
1206
1214
|
):
|
|
1207
|
-
if only_tables is not None and not
|
|
1215
|
+
if only_tables is not None and element_type not in only_tables:
|
|
1208
1216
|
return
|
|
1209
1217
|
if not include_results and element_type.startswith("res_"):
|
|
1210
1218
|
return
|
|
1211
|
-
|
|
1212
|
-
filter_dict = {"net_id": net_id, **variants_filter}
|
|
1219
|
+
filter_dict = {"net_id": net_id, **self.get_variant_filter(variant)}
|
|
1213
1220
|
if filter is not None:
|
|
1214
1221
|
if "$or" in filter_dict.keys() and "$or" in filter.keys():
|
|
1215
1222
|
# if 'or' is in both filters create 'and' with
|
|
@@ -1263,13 +1270,11 @@ class PandaHub:
|
|
|
1263
1270
|
def get_net_value_from_db(
|
|
1264
1271
|
self, net, element_type, element_index, parameter, variant=None, project_id=None
|
|
1265
1272
|
):
|
|
1266
|
-
if variant is not None:
|
|
1267
|
-
variant = int(variant)
|
|
1268
1273
|
if project_id:
|
|
1269
1274
|
self.set_active_project_by_id(project_id)
|
|
1270
1275
|
self.check_permission("write")
|
|
1271
1276
|
db = self._get_project_database()
|
|
1272
|
-
if
|
|
1277
|
+
if isinstance(net, str):
|
|
1273
1278
|
net_id = self._get_id_from_name(net, db)
|
|
1274
1279
|
else:
|
|
1275
1280
|
net_id = net
|
|
@@ -1334,7 +1339,7 @@ class PandaHub:
|
|
|
1334
1339
|
net: Union[int, str],
|
|
1335
1340
|
element_type: str,
|
|
1336
1341
|
element_indexes: list[int],
|
|
1337
|
-
variant: Union[int,
|
|
1342
|
+
variant: Union[int, None] = None,
|
|
1338
1343
|
project_id: Union[str, None] = None,
|
|
1339
1344
|
**kwargs,
|
|
1340
1345
|
) -> list[dict]:
|
|
@@ -1360,9 +1365,7 @@ class PandaHub:
|
|
|
1360
1365
|
"""
|
|
1361
1366
|
if not isinstance(element_indexes, list):
|
|
1362
1367
|
raise TypeError("Parameter element_indexes must be a list of ints!")
|
|
1363
|
-
|
|
1364
|
-
if variant is not None:
|
|
1365
|
-
variant = int(variant)
|
|
1368
|
+
validate_variant_type(variant)
|
|
1366
1369
|
if project_id:
|
|
1367
1370
|
self.set_active_project_by_id(project_id)
|
|
1368
1371
|
|
|
@@ -1370,7 +1373,7 @@ class PandaHub:
|
|
|
1370
1373
|
db = self._get_project_database()
|
|
1371
1374
|
collection = self._collection_name_of_element(element_type)
|
|
1372
1375
|
|
|
1373
|
-
if
|
|
1376
|
+
if isinstance(net, str):
|
|
1374
1377
|
net_id = self._get_id_from_name(net, db)
|
|
1375
1378
|
else:
|
|
1376
1379
|
net_id = net
|
|
@@ -1385,7 +1388,7 @@ class PandaHub:
|
|
|
1385
1388
|
if not deletion_targets:
|
|
1386
1389
|
return []
|
|
1387
1390
|
|
|
1388
|
-
if variant:
|
|
1391
|
+
if variant is not None:
|
|
1389
1392
|
delete_ids_variant, delete_ids = [], []
|
|
1390
1393
|
for target in deletion_targets:
|
|
1391
1394
|
delete_ids_variant.append(target["_id"]) if target[
|
|
@@ -1411,8 +1414,7 @@ class PandaHub:
|
|
|
1411
1414
|
project_id=None,
|
|
1412
1415
|
**kwargs,
|
|
1413
1416
|
):
|
|
1414
|
-
|
|
1415
|
-
variant = int(variant)
|
|
1417
|
+
validate_variant_type(variant)
|
|
1416
1418
|
if project_id:
|
|
1417
1419
|
self.set_active_project_by_id(project_id)
|
|
1418
1420
|
self.check_permission("write")
|
|
@@ -1421,7 +1423,7 @@ class PandaHub:
|
|
|
1421
1423
|
if value is not None and dtypes is not None and parameter in dtypes:
|
|
1422
1424
|
value = dtypes[parameter](value)
|
|
1423
1425
|
collection = self._collection_name_of_element(element_type)
|
|
1424
|
-
if
|
|
1426
|
+
if isinstance(net, str):
|
|
1425
1427
|
net_id = self._get_id_from_name(net, db)
|
|
1426
1428
|
else:
|
|
1427
1429
|
net_id = net
|
|
@@ -1484,6 +1486,7 @@ class PandaHub:
|
|
|
1484
1486
|
variant=None,
|
|
1485
1487
|
project_id=None,
|
|
1486
1488
|
):
|
|
1489
|
+
validate_variant_type(variant)
|
|
1487
1490
|
if project_id:
|
|
1488
1491
|
self.set_active_project_by_id(project_id)
|
|
1489
1492
|
self.check_permission("write")
|
|
@@ -1492,7 +1495,7 @@ class PandaHub:
|
|
|
1492
1495
|
if dtypes is not None and parameter in dtypes:
|
|
1493
1496
|
value = dtypes[parameter](value)
|
|
1494
1497
|
collection = self._collection_name_of_element(element_type)
|
|
1495
|
-
if
|
|
1498
|
+
if isinstance(net, str):
|
|
1496
1499
|
net_id = self._get_id_from_name(net, db)
|
|
1497
1500
|
else:
|
|
1498
1501
|
net_id = net
|
|
@@ -1518,7 +1521,6 @@ class PandaHub:
|
|
|
1518
1521
|
{"$set": {"object._object": obj.to_json()}},
|
|
1519
1522
|
)
|
|
1520
1523
|
else:
|
|
1521
|
-
variant = int(variant)
|
|
1522
1524
|
element_filter = {**element_filter, **self.get_variant_filter(variant)}
|
|
1523
1525
|
document = db[collection].find_one({**element_filter})
|
|
1524
1526
|
if not document:
|
|
@@ -1586,7 +1588,7 @@ class PandaHub:
|
|
|
1586
1588
|
net: Union[int, str],
|
|
1587
1589
|
element_type: str,
|
|
1588
1590
|
elements_data: list[dict],
|
|
1589
|
-
variant: int = None,
|
|
1591
|
+
variant: int | None = None,
|
|
1590
1592
|
project_id: str = None,
|
|
1591
1593
|
**kwargs,
|
|
1592
1594
|
) -> list[dict]:
|
|
@@ -1610,15 +1612,16 @@ class PandaHub:
|
|
|
1610
1612
|
list
|
|
1611
1613
|
A list of the created elements (elements_data with added _id fields)
|
|
1612
1614
|
"""
|
|
1615
|
+
validate_variant_type(variant)
|
|
1613
1616
|
if project_id:
|
|
1614
1617
|
self.set_active_project_by_id(project_id)
|
|
1615
1618
|
self.check_permission("write")
|
|
1616
1619
|
db = self._get_project_database()
|
|
1617
|
-
if
|
|
1618
|
-
var_data = {"var_type": "base", "not_in_var": []}
|
|
1620
|
+
if variant is None:
|
|
1621
|
+
var_data = {"var_type": "base", "not_in_var": [], "variant": None}
|
|
1619
1622
|
else:
|
|
1620
|
-
var_data = {"var_type": "addition", "variant":
|
|
1621
|
-
if
|
|
1623
|
+
var_data = {"var_type": "addition", "not_in_var": [], "variant": variant}
|
|
1624
|
+
if isinstance(net, str):
|
|
1622
1625
|
net_id = self._get_id_from_name(net, db)
|
|
1623
1626
|
else:
|
|
1624
1627
|
net_id = net
|
|
@@ -1730,7 +1733,7 @@ class PandaHub:
|
|
|
1730
1733
|
for coll in self._get_net_collections(db):
|
|
1731
1734
|
db[coll].update_many(
|
|
1732
1735
|
{"$or": [{"var_type": None}, {"var_type": np.nan}]},
|
|
1733
|
-
{"$set": {"var_type": "base", "not_in_var": []}}
|
|
1736
|
+
{"$set": {"var_type": "base", "not_in_var": [], "variant": None}},
|
|
1734
1737
|
)
|
|
1735
1738
|
return data
|
|
1736
1739
|
|
|
@@ -1758,58 +1761,26 @@ class PandaHub:
|
|
|
1758
1761
|
db = self._get_project_database()
|
|
1759
1762
|
db["variant"].update_one({"net_id": net_id, "index": index}, {"$set": data})
|
|
1760
1763
|
|
|
1761
|
-
def get_variant_filter(self,
|
|
1764
|
+
def get_variant_filter(self, variant: int | None) -> dict:
|
|
1762
1765
|
"""
|
|
1763
1766
|
Creates a mongodb query filter to retrieve pandapower elements for the given variant(s).
|
|
1764
1767
|
|
|
1765
1768
|
Parameters
|
|
1766
1769
|
----------
|
|
1767
|
-
|
|
1768
|
-
None
|
|
1770
|
+
variant : int or None
|
|
1771
|
+
None represent the base variant, ints specify variant indices.
|
|
1769
1772
|
|
|
1770
1773
|
Returns
|
|
1771
1774
|
-------
|
|
1772
1775
|
dict
|
|
1773
|
-
mongodb query filter for the given variant
|
|
1776
|
+
mongodb query filter for the given variant
|
|
1774
1777
|
"""
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
f"Passing variants as list is deprecated, use None or int instead (variants: {variants})",
|
|
1778
|
-
DeprecationWarning,
|
|
1779
|
-
stacklevel=2,
|
|
1780
|
-
)
|
|
1781
|
-
if len(variants) == 0:
|
|
1782
|
-
variants = None
|
|
1783
|
-
elif len(variants) == 1:
|
|
1784
|
-
variants = variants[0]
|
|
1785
|
-
elif len(variants) > 1:
|
|
1786
|
-
warnings.warn(
|
|
1787
|
-
f"Passing multiple variants is deprecated, use None or int instead (variants: {variants})",
|
|
1788
|
-
DeprecationWarning,
|
|
1789
|
-
stacklevel=2,
|
|
1790
|
-
)
|
|
1791
|
-
variants = [
|
|
1792
|
-
int(var) for var in variants
|
|
1793
|
-
] # make sure variants are of type int
|
|
1794
|
-
return {
|
|
1795
|
-
"$or": [
|
|
1796
|
-
{"var_type": "base", "not_in_var": {"$nin": variants}},
|
|
1797
|
-
{
|
|
1798
|
-
"var_type": {"$in": ["change", "addition"]},
|
|
1799
|
-
"variant": {"$in": variants},
|
|
1800
|
-
},
|
|
1801
|
-
]
|
|
1802
|
-
}
|
|
1803
|
-
if variants:
|
|
1804
|
-
variants = int(variants)
|
|
1805
|
-
return {
|
|
1806
|
-
"$or": [
|
|
1807
|
-
{"var_type": "base", "not_in_var": {"$ne": variants}},
|
|
1808
|
-
{"var_type": {"$in": ["change", "addition"]}, "variant": variants},
|
|
1809
|
-
]
|
|
1810
|
-
}
|
|
1811
|
-
else:
|
|
1778
|
+
validate_variant_type(variant)
|
|
1779
|
+
if variant is None:
|
|
1812
1780
|
return self.base_variant_filter
|
|
1781
|
+
return {"$or": [{"var_type": "base", "not_in_var": {"$ne": variant}},
|
|
1782
|
+
{"var_type": {"$in": ["change", "addition"]}, "variant": variant}, ]}
|
|
1783
|
+
|
|
1813
1784
|
|
|
1814
1785
|
# -------------------------
|
|
1815
1786
|
# Bulk operations
|
|
@@ -3019,7 +2990,7 @@ class PandaHub:
|
|
|
3019
2990
|
element_type: str,
|
|
3020
2991
|
elements_data: list[dict],
|
|
3021
2992
|
project_id: str = None,
|
|
3022
|
-
variant: int = None,
|
|
2993
|
+
variant: int | None = None,
|
|
3023
2994
|
):
|
|
3024
2995
|
warnings.warn(
|
|
3025
2996
|
"ph.create_elements_in_db was renamed - use ph.create_elements instead! "
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pandahub
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.8
|
|
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.8" # 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
|
|
File without changes
|