pandahub 0.3.9__zip → 0.3.10__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.
Files changed (49) hide show
  1. {pandahub-0.3.9 → pandahub-0.3.10}/CHANGELOG.md +4 -0
  2. {pandahub-0.3.9 → pandahub-0.3.10}/PKG-INFO +1 -1
  3. {pandahub-0.3.9 → pandahub-0.3.10}/pandahub/api/routers/variants.py +15 -5
  4. {pandahub-0.3.9 → pandahub-0.3.10}/pandahub/lib/PandaHub.py +45 -25
  5. {pandahub-0.3.9 → pandahub-0.3.10}/pandahub.egg-info/PKG-INFO +1 -1
  6. {pandahub-0.3.9 → pandahub-0.3.10}/pyproject.toml +1 -1
  7. {pandahub-0.3.9 → pandahub-0.3.10}/CONTRIBUTING.rst +0 -0
  8. {pandahub-0.3.9 → pandahub-0.3.10}/LICENSE +0 -0
  9. {pandahub-0.3.9 → pandahub-0.3.10}/MANIFEST.in +0 -0
  10. {pandahub-0.3.9 → pandahub-0.3.10}/README.md +0 -0
  11. {pandahub-0.3.9 → pandahub-0.3.10}/pandahub/__init__.py +0 -0
  12. {pandahub-0.3.9 → pandahub-0.3.10}/pandahub/api/__init__.py +0 -0
  13. {pandahub-0.3.9 → pandahub-0.3.10}/pandahub/api/dependencies.py +0 -0
  14. {pandahub-0.3.9 → pandahub-0.3.10}/pandahub/api/internal/__init__.py +0 -0
  15. {pandahub-0.3.9 → pandahub-0.3.10}/pandahub/api/internal/db.py +0 -0
  16. {pandahub-0.3.9 → pandahub-0.3.10}/pandahub/api/internal/schemas.py +0 -0
  17. {pandahub-0.3.9 → pandahub-0.3.10}/pandahub/api/internal/settings.py +0 -0
  18. {pandahub-0.3.9 → pandahub-0.3.10}/pandahub/api/internal/toolbox.py +0 -0
  19. {pandahub-0.3.9 → pandahub-0.3.10}/pandahub/api/internal/users.py +0 -0
  20. {pandahub-0.3.9 → pandahub-0.3.10}/pandahub/api/main.py +0 -0
  21. {pandahub-0.3.9 → pandahub-0.3.10}/pandahub/api/routers/__init__.py +0 -0
  22. {pandahub-0.3.9 → pandahub-0.3.10}/pandahub/api/routers/auth.py +0 -0
  23. {pandahub-0.3.9 → pandahub-0.3.10}/pandahub/api/routers/net.py +0 -0
  24. {pandahub-0.3.9 → pandahub-0.3.10}/pandahub/api/routers/projects.py +0 -0
  25. {pandahub-0.3.9 → pandahub-0.3.10}/pandahub/api/routers/timeseries.py +0 -0
  26. {pandahub-0.3.9 → pandahub-0.3.10}/pandahub/api/routers/users.py +0 -0
  27. {pandahub-0.3.9 → pandahub-0.3.10}/pandahub/lib/__init__.py +0 -0
  28. {pandahub-0.3.9 → pandahub-0.3.10}/pandahub/lib/database_toolbox.py +0 -0
  29. {pandahub-0.3.9 → pandahub-0.3.10}/pandahub/lib/datatypes.py +0 -0
  30. {pandahub-0.3.9 → pandahub-0.3.10}/pandahub/lib/mongodb_indexes.py +0 -0
  31. {pandahub-0.3.9 → pandahub-0.3.10}/pandahub/lib/timeseries/__init__.py +0 -0
  32. {pandahub-0.3.9 → pandahub-0.3.10}/pandahub/lib/timeseries/data_sources/__init__.py +0 -0
  33. {pandahub-0.3.9 → pandahub-0.3.10}/pandahub/lib/timeseries/data_sources/mongo_data.py +0 -0
  34. {pandahub-0.3.9 → pandahub-0.3.10}/pandahub/lib/timeseries/output_writer_mongodb.py +0 -0
  35. {pandahub-0.3.9 → pandahub-0.3.10}/pandahub.egg-info/SOURCES.txt +0 -0
  36. {pandahub-0.3.9 → pandahub-0.3.10}/pandahub.egg-info/dependency_links.txt +0 -0
  37. {pandahub-0.3.9 → pandahub-0.3.10}/pandahub.egg-info/requires.txt +0 -0
  38. {pandahub-0.3.9 → pandahub-0.3.10}/pandahub.egg-info/top_level.txt +0 -0
  39. {pandahub-0.3.9 → pandahub-0.3.10}/requirements.txt +0 -0
  40. {pandahub-0.3.9 → pandahub-0.3.10}/setup.cfg +0 -0
  41. {pandahub-0.3.9 → pandahub-0.3.10}/setup.py +0 -0
  42. {pandahub-0.3.9 → pandahub-0.3.10}/test/__init__.py +0 -0
  43. {pandahub-0.3.9 → pandahub-0.3.10}/test/conftest.py +0 -0
  44. {pandahub-0.3.9 → pandahub-0.3.10}/test/performance_test.py +0 -0
  45. {pandahub-0.3.9 → pandahub-0.3.10}/test/test_client.py +0 -0
  46. {pandahub-0.3.9 → pandahub-0.3.10}/test/test_networks.py +0 -0
  47. {pandahub-0.3.9 → pandahub-0.3.10}/test/test_projects.py +0 -0
  48. {pandahub-0.3.9 → pandahub-0.3.10}/test/test_timeseries.py +0 -0
  49. {pandahub-0.3.9 → pandahub-0.3.10}/tutorials/config.py +0 -0
@@ -1,5 +1,9 @@
1
1
  # Change Log
2
2
 
3
+ ## [0.3.10]
4
+
5
+ - BREAKING: changed signatures of create_variant function and route
6
+
3
7
  ## [0.3.9]
4
8
 
5
9
  - 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.9
3
+ Version: 0.3.10
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
- variant_data: dict
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
- project_id = data.project_id
38
- ph.set_active_project_by_id(project_id)
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
@@ -91,6 +92,7 @@ class PandaHub:
91
92
  user_id=None,
92
93
  datatypes=DATATYPES,
93
94
  mongodb_indexes=MONGODB_INDEXES,
95
+ elements_without_vars = None,
94
96
  ):
95
97
  mongo_client_args = {
96
98
  "host": connection_url,
@@ -115,6 +117,7 @@ class PandaHub:
115
117
  {"var_type": np.nan},
116
118
  ]
117
119
  }
120
+ self._elements_without_vars = ["variant"] if elements_without_vars is None else elements_without_vars
118
121
  if check_server_available:
119
122
  self.server_is_available()
120
123
 
@@ -1150,10 +1153,13 @@ class PandaHub:
1150
1153
  if element_data.empty:
1151
1154
  continue
1152
1155
  element_data = element_data.copy(deep=True)
1153
- if "var_type" in element_data:
1154
- element_data["var_type"] = element_data["var_type"].fillna("base")
1155
- else:
1156
- element_data["var_type"] = "base"
1156
+ if element not in self._elements_without_vars:
1157
+ if "var_type" in element_data:
1158
+ element_data["var_type"] = element_data["var_type"].fillna("base")
1159
+ else:
1160
+ element_data["var_type"] = "base"
1161
+ element_data["not_in_var"] = np.empty((len(element_data.index), 0)).tolist()
1162
+ element_data["variant"] = None
1157
1163
  element_data = convert_element_to_dict(element_data, net_id, self._datatypes.get(element))
1158
1164
  self._write_element_to_db(db, element, element_data)
1159
1165
 
@@ -1228,9 +1234,12 @@ class PandaHub:
1228
1234
  def _network_with_name_exists(self, name, db):
1229
1235
  return self._get_net_id_from_name(name, db) is not None
1230
1236
 
1237
+ def _get_net_collections(self, db, with_areas=True):
1238
+ return self.get_net_collections(db, with_areas)
1239
+
1231
1240
  def get_net_collections(self, db=None, with_areas=True):
1232
1241
  if db is None:
1233
- db = self._get_project_database()
1242
+ db = self.get_project_database()
1234
1243
  if with_areas:
1235
1244
  collection_filter = {"name": {"$regex": "^net_"}}
1236
1245
  else:
@@ -1402,7 +1411,7 @@ class PandaHub:
1402
1411
  """
1403
1412
  if not isinstance(element_indexes, list):
1404
1413
  raise TypeError("Parameter element_indexes must be a list of ints!")
1405
- validate_variant_type(variant)
1414
+ self.validate_variant(variant, element_type)
1406
1415
  if project_id:
1407
1416
  self.set_active_project_by_id(project_id)
1408
1417
 
@@ -1446,7 +1455,7 @@ class PandaHub:
1446
1455
  project_id=None,
1447
1456
  **kwargs,
1448
1457
  ):
1449
- validate_variant_type(variant)
1458
+ self.validate_variant(variant, element_type)
1450
1459
  if project_id:
1451
1460
  self.set_active_project_by_id(project_id)
1452
1461
  self.check_permission("write")
@@ -1514,7 +1523,7 @@ class PandaHub:
1514
1523
  variant=None,
1515
1524
  project_id=None,
1516
1525
  ):
1517
- validate_variant_type(variant)
1526
+ self.validate_variant(variant, element_type)
1518
1527
  if project_id:
1519
1528
  self.set_active_project_by_id(project_id)
1520
1529
  self.check_permission("write")
@@ -1636,7 +1645,7 @@ class PandaHub:
1636
1645
  list
1637
1646
  A list of the created elements (elements_data with added _id fields)
1638
1647
  """
1639
- validate_variant_type(variant)
1648
+ self.validate_variant(variant, element_type)
1640
1649
  if project_id:
1641
1650
  self.set_active_project_by_id(project_id)
1642
1651
  self.check_permission("write")
@@ -1771,24 +1780,30 @@ class PandaHub:
1771
1780
  # Variants
1772
1781
  # -------------------------
1773
1782
 
1774
- def create_variant(self, data, index: Optional[int] = None):
1783
+ def create_variant(
1784
+ self,
1785
+ net_id: int,
1786
+ name: str | None = None,
1787
+ default_name: str = "Variant",
1788
+ index: int | None = None,
1789
+ ) -> dict:
1775
1790
  db = self._get_project_database()
1776
- net_id = int(data["net_id"])
1777
1791
  if index is None:
1778
1792
  index = self._get_int_index("variant", index_field="index", query_filter={"net_id": net_id})
1779
- data["index"] = index
1780
- if data.get("default_name") is not None and data.get("name") is None:
1781
- data["name"] = data.pop("default_name") + " " + str(index)
1782
- db["variant"].insert_one(data)
1783
- del data["_id"]
1784
-
1785
- if index == 1:
1786
- for coll in self.get_net_collections(db):
1787
- db[coll].update_many(
1788
- {"$or": [{"var_type": None}, {"var_type": np.nan}]},
1789
- {"$set": {"var_type": "base", "not_in_var": [], "variant": None}},
1790
- )
1791
- return data
1793
+
1794
+ if name is None:
1795
+ name = f"{default_name} {index + 1}"
1796
+ now = int(time.time())
1797
+ variant = {
1798
+ "net_id": net_id,
1799
+ "index": index,
1800
+ "name": name,
1801
+ "date_created": now,
1802
+ "date_changed": now,
1803
+ }
1804
+ db["variant"].insert_one(variant)
1805
+ del variant["_id"]
1806
+ return variant
1792
1807
 
1793
1808
  def delete_variant(self, net_id, index):
1794
1809
  db = self._get_project_database()
@@ -1828,12 +1843,17 @@ class PandaHub:
1828
1843
  dict
1829
1844
  mongodb query filter for the given variant
1830
1845
  """
1831
- validate_variant_type(variant)
1846
+ self.validate_variant(variant)
1832
1847
  if variant is None:
1833
1848
  return self.base_variant_filter
1834
1849
  return {"$or": [{"var_type": "base", "not_in_var": {"$ne": variant}},
1835
1850
  {"var_type": {"$in": ["change", "addition"]}, "variant": variant}, ]}
1836
1851
 
1852
+ def validate_variant(self, variant: int | None, element_type: str | None = None):
1853
+ """Raise a ValueError if variant is not int | None or element_type does not support variants."""
1854
+ validate_variant_type(variant)
1855
+ if element_type is not None and variant is not None and element_type in self._elements_without_vars:
1856
+ raise ValueError(f"{element_type} does not support variants")
1837
1857
 
1838
1858
  # -------------------------
1839
1859
  # Bulk operations
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pandahub
3
- Version: 0.3.9
3
+ Version: 0.3.10
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.9" # File format version '__format_version__' is tracked in __init__.py
7
+ version = "0.3.10" # 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