pandahub 0.3.14__zip → 0.3.16__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.14 → pandahub-0.3.16}/PKG-INFO +1 -1
  2. {pandahub-0.3.14 → pandahub-0.3.16}/pandahub/lib/PandaHub.py +29 -30
  3. {pandahub-0.3.14 → pandahub-0.3.16}/pandahub/lib/database_toolbox.py +19 -0
  4. {pandahub-0.3.14 → pandahub-0.3.16}/pandahub.egg-info/PKG-INFO +1 -1
  5. {pandahub-0.3.14 → pandahub-0.3.16}/pyproject.toml +1 -1
  6. {pandahub-0.3.14 → pandahub-0.3.16}/CHANGELOG.md +0 -0
  7. {pandahub-0.3.14 → pandahub-0.3.16}/CONTRIBUTING.rst +0 -0
  8. {pandahub-0.3.14 → pandahub-0.3.16}/LICENSE +0 -0
  9. {pandahub-0.3.14 → pandahub-0.3.16}/MANIFEST.in +0 -0
  10. {pandahub-0.3.14 → pandahub-0.3.16}/README.md +0 -0
  11. {pandahub-0.3.14 → pandahub-0.3.16}/pandahub/__init__.py +0 -0
  12. {pandahub-0.3.14 → pandahub-0.3.16}/pandahub/api/__init__.py +0 -0
  13. {pandahub-0.3.14 → pandahub-0.3.16}/pandahub/api/dependencies.py +0 -0
  14. {pandahub-0.3.14 → pandahub-0.3.16}/pandahub/api/internal/__init__.py +0 -0
  15. {pandahub-0.3.14 → pandahub-0.3.16}/pandahub/api/internal/db.py +0 -0
  16. {pandahub-0.3.14 → pandahub-0.3.16}/pandahub/api/internal/schemas.py +0 -0
  17. {pandahub-0.3.14 → pandahub-0.3.16}/pandahub/api/internal/settings.py +0 -0
  18. {pandahub-0.3.14 → pandahub-0.3.16}/pandahub/api/internal/toolbox.py +0 -0
  19. {pandahub-0.3.14 → pandahub-0.3.16}/pandahub/api/internal/users.py +0 -0
  20. {pandahub-0.3.14 → pandahub-0.3.16}/pandahub/api/main.py +0 -0
  21. {pandahub-0.3.14 → pandahub-0.3.16}/pandahub/api/routers/__init__.py +0 -0
  22. {pandahub-0.3.14 → pandahub-0.3.16}/pandahub/api/routers/auth.py +0 -0
  23. {pandahub-0.3.14 → pandahub-0.3.16}/pandahub/api/routers/net.py +0 -0
  24. {pandahub-0.3.14 → pandahub-0.3.16}/pandahub/api/routers/projects.py +0 -0
  25. {pandahub-0.3.14 → pandahub-0.3.16}/pandahub/api/routers/timeseries.py +0 -0
  26. {pandahub-0.3.14 → pandahub-0.3.16}/pandahub/api/routers/users.py +0 -0
  27. {pandahub-0.3.14 → pandahub-0.3.16}/pandahub/api/routers/variants.py +0 -0
  28. {pandahub-0.3.14 → pandahub-0.3.16}/pandahub/lib/__init__.py +0 -0
  29. {pandahub-0.3.14 → pandahub-0.3.16}/pandahub/lib/datatypes.py +0 -0
  30. {pandahub-0.3.14 → pandahub-0.3.16}/pandahub/lib/mongodb_indexes.py +0 -0
  31. {pandahub-0.3.14 → pandahub-0.3.16}/pandahub/lib/timeseries/__init__.py +0 -0
  32. {pandahub-0.3.14 → pandahub-0.3.16}/pandahub/lib/timeseries/data_sources/__init__.py +0 -0
  33. {pandahub-0.3.14 → pandahub-0.3.16}/pandahub/lib/timeseries/data_sources/mongo_data.py +0 -0
  34. {pandahub-0.3.14 → pandahub-0.3.16}/pandahub/lib/timeseries/output_writer_mongodb.py +0 -0
  35. {pandahub-0.3.14 → pandahub-0.3.16}/pandahub.egg-info/SOURCES.txt +0 -0
  36. {pandahub-0.3.14 → pandahub-0.3.16}/pandahub.egg-info/dependency_links.txt +0 -0
  37. {pandahub-0.3.14 → pandahub-0.3.16}/pandahub.egg-info/requires.txt +0 -0
  38. {pandahub-0.3.14 → pandahub-0.3.16}/pandahub.egg-info/top_level.txt +0 -0
  39. {pandahub-0.3.14 → pandahub-0.3.16}/requirements.txt +0 -0
  40. {pandahub-0.3.14 → pandahub-0.3.16}/setup.cfg +0 -0
  41. {pandahub-0.3.14 → pandahub-0.3.16}/setup.py +0 -0
  42. {pandahub-0.3.14 → pandahub-0.3.16}/test/__init__.py +0 -0
  43. {pandahub-0.3.14 → pandahub-0.3.16}/test/conftest.py +0 -0
  44. {pandahub-0.3.14 → pandahub-0.3.16}/test/performance_test.py +0 -0
  45. {pandahub-0.3.14 → pandahub-0.3.16}/test/test_client.py +0 -0
  46. {pandahub-0.3.14 → pandahub-0.3.16}/test/test_networks.py +0 -0
  47. {pandahub-0.3.14 → pandahub-0.3.16}/test/test_projects.py +0 -0
  48. {pandahub-0.3.14 → pandahub-0.3.16}/test/test_timeseries.py +0 -0
  49. {pandahub-0.3.14 → pandahub-0.3.16}/tutorials/config.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pandahub
3
- Version: 0.3.14
3
+ Version: 0.3.16
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
@@ -38,6 +38,7 @@ from pandahub.lib.database_toolbox import (
38
38
  get_dtypes,
39
39
  decompress_timeseries_data,
40
40
  convert_geojsons,
41
+ get_metadata_for_timeseries_collections
41
42
  )
42
43
  from pandahub.lib.mongodb_indexes import MONGODB_INDEXES
43
44
 
@@ -2053,20 +2054,21 @@ class PandaHub:
2053
2054
  self.check_permission("write")
2054
2055
  db = self._get_project_database()
2055
2056
  if self.collection_is_timeseries(collection_name, project_id, global_database):
2056
- metadata = kwargs
2057
- if data_type is not None:
2058
- metadata["data_type"] = data_type
2059
- net_id = metadata.get('net_id', None)
2060
- if net_id is None:
2061
- net_ids = db["_networks"].distinct("_id")
2062
- if len(net_ids) == 1:
2063
- net_id = net_ids[0]
2064
- else:
2065
- raise ValueError(
2066
- "No net_id was provided and multiple networks exist in the database. "
2067
- "Please provide a net_id."
2068
- )
2069
- metadata["_id"] = f"{net_id}_{metadata.get('element_type', None)}_{metadata.get('element_index', None)}_{data_type}"
2057
+ # get metadata dictionary based on the input arguments
2058
+ metadata = get_metadata_for_timeseries_collections(db, data_type=data_type, **kwargs)
2059
+ _id = metadata["_id"]
2060
+
2061
+ # delete overlapping timeseries already in the database
2062
+ filter = {
2063
+ "metadata._id": _id,
2064
+ "timestamp": {
2065
+ "$gte": timeseries.index.min(),
2066
+ "$lte": timeseries.index.max()
2067
+ }
2068
+ }
2069
+ db.timeseries.delete_many(filter)
2070
+
2071
+ # create new timeseries documents
2070
2072
  if isinstance(timeseries, pd.Series):
2071
2073
  documents = [
2072
2074
  {"metadata": metadata, "timestamp": idx, "value": value}
@@ -2078,9 +2080,11 @@ class PandaHub:
2078
2080
  for idx, row in timeseries.iterrows()
2079
2081
  ]
2080
2082
  db[collection_name].insert_many(documents)
2083
+
2081
2084
  if kwargs.get("return_id"):
2082
- return metadata["_id"]
2085
+ return _id
2083
2086
  return None
2087
+
2084
2088
  document = create_timeseries_document(
2085
2089
  timeseries=timeseries,
2086
2090
  data_type=data_type,
@@ -2345,11 +2349,9 @@ class PandaHub:
2345
2349
  self.check_permission("read")
2346
2350
  db = self._get_project_database()
2347
2351
  if self.collection_is_timeseries(collection_name, project_id, global_database):
2348
- meta_filter = {
2349
- "metadata." + key: value for key, value in filter_document.items()
2350
- }
2352
+ metadata = get_metadata_for_timeseries_collections(db, **kwargs)
2351
2353
  pipeline = []
2352
- pipeline.append({"$match": meta_filter})
2354
+ pipeline.append({"$match": {"metadata._id": metadata["_id"]}})
2353
2355
  pipeline.append({"$project": {"_id": 0, "metadata": 0}})
2354
2356
  timeseries = db[collection_name].aggregate_pandas_all(pipeline)
2355
2357
  if len(timeseries) == 0:
@@ -2995,15 +2997,8 @@ class PandaHub:
2995
2997
  self.check_permission("write")
2996
2998
  db = self._get_project_database()
2997
2999
  if self.collection_is_timeseries(collection_name):
2998
- meta_filter = {
2999
- "metadata.element_type": element_type,
3000
- "metadata.data_type": data_type,
3001
- }
3002
- if netname is not None:
3003
- meta_filter["metadata.netname"] = netname
3004
- if element_index is not None:
3005
- meta_filter["metadata.element_index"] = element_index
3006
- return db[collection_name].delete_many(meta_filter)
3000
+ metadata = get_metadata_for_timeseries_collections(db, data_type, **kwargs)
3001
+ return db[collection_name].delete_many({"metadata._id": metadata["_id"]})
3007
3002
  filter_document = {"element_type": element_type, "data_type": data_type}
3008
3003
  if netname is not None:
3009
3004
  filter_document["netname"] = netname
@@ -3062,8 +3057,11 @@ class PandaHub:
3062
3057
  del_res = db[collection_name].delete_many(match_filter)
3063
3058
  return del_res
3064
3059
 
3065
- def create_timeseries_collection(self, collection_name, overwrite=False):
3066
- db = self._get_project_database()
3060
+ def create_timeseries_collection(self, collection_name, overwrite=False, project_id=None):
3061
+ if project_id is None:
3062
+ db = self._get_project_database()
3063
+ else:
3064
+ db = self.mongo_client[str(project_id)]
3067
3065
  collection_exists = collection_name in db.list_collection_names()
3068
3066
  if collection_exists:
3069
3067
  if overwrite:
@@ -3196,6 +3194,7 @@ class PandaHub:
3196
3194
  return self.get_net_collections(db, with_areas)
3197
3195
 
3198
3196
 
3197
+
3199
3198
  if __name__ == "__main__":
3200
3199
  self = PandaHub()
3201
3200
  project_name = "test_project"
@@ -478,3 +478,22 @@ def mongo_client(database: str | None = None, collection: str | None = None, con
478
478
  client.close()
479
479
 
480
480
 
481
+ def get_metadata_for_timeseries_collections(db, data_type=None, net_id=None, element_type=None, element_index=None, **kwargs):
482
+ if element_type is None:
483
+ raise ValueError("element_type needs to be defined for timeseries collections")
484
+ if element_index is None:
485
+ raise ValueError("element_index needs to be defined for timeseries collections")
486
+ if data_type is None:
487
+ raise ValueError("data_type needs to be defined for timeseries collections")
488
+ if net_id is None:
489
+ net_ids = db["_networks"].distinct("_id")
490
+ if len(net_ids) == 1:
491
+ net_id = net_ids[0]
492
+ else:
493
+ raise ValueError(
494
+ "No net_id was provided and multiple networks exist in the database. "
495
+ "Please provide a net_id."
496
+ )
497
+ metadata = {"data_type": data_type, "net_id": net_id, "element_type": element_type, "element_index": element_index, **kwargs}
498
+ metadata["_id"] = f"{net_id}_{element_type}_{element_index}_{data_type}"
499
+ return metadata
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pandahub
3
- Version: 0.3.14
3
+ Version: 0.3.16
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.14" # File format version '__format_version__' is tracked in __init__.py
7
+ version = "0.3.16" # 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