pandahub 0.3.13__zip → 0.3.14__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.13 → pandahub-0.3.14}/PKG-INFO +1 -1
- {pandahub-0.3.13 → pandahub-0.3.14}/pandahub/lib/PandaHub.py +73 -31
- {pandahub-0.3.13 → pandahub-0.3.14}/pandahub.egg-info/PKG-INFO +1 -1
- {pandahub-0.3.13 → pandahub-0.3.14}/pyproject.toml +1 -1
- {pandahub-0.3.13 → pandahub-0.3.14}/CHANGELOG.md +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/CONTRIBUTING.rst +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/LICENSE +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/MANIFEST.in +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/README.md +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/pandahub/__init__.py +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/pandahub/api/__init__.py +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/pandahub/api/dependencies.py +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/pandahub/api/internal/__init__.py +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/pandahub/api/internal/db.py +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/pandahub/api/internal/schemas.py +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/pandahub/api/internal/settings.py +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/pandahub/api/internal/toolbox.py +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/pandahub/api/internal/users.py +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/pandahub/api/main.py +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/pandahub/api/routers/__init__.py +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/pandahub/api/routers/auth.py +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/pandahub/api/routers/net.py +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/pandahub/api/routers/projects.py +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/pandahub/api/routers/timeseries.py +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/pandahub/api/routers/users.py +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/pandahub/api/routers/variants.py +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/pandahub/lib/__init__.py +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/pandahub/lib/database_toolbox.py +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/pandahub/lib/datatypes.py +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/pandahub/lib/mongodb_indexes.py +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/pandahub/lib/timeseries/__init__.py +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/pandahub/lib/timeseries/data_sources/__init__.py +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/pandahub/lib/timeseries/data_sources/mongo_data.py +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/pandahub/lib/timeseries/output_writer_mongodb.py +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/pandahub.egg-info/SOURCES.txt +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/pandahub.egg-info/dependency_links.txt +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/pandahub.egg-info/requires.txt +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/pandahub.egg-info/top_level.txt +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/requirements.txt +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/setup.cfg +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/setup.py +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/test/__init__.py +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/test/conftest.py +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/test/performance_test.py +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/test/test_client.py +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/test/test_networks.py +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/test/test_projects.py +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/test/test_timeseries.py +0 -0
- {pandahub-0.3.13 → pandahub-0.3.14}/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.14
|
|
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
|
|
@@ -1674,21 +1674,22 @@ class PandaHub:
|
|
|
1674
1674
|
var_data = {"var_type": "base", "not_in_var": [], "variant": None}
|
|
1675
1675
|
else:
|
|
1676
1676
|
var_data = {"var_type": "addition", "not_in_var": [], "variant": variant}
|
|
1677
|
-
|
|
1677
|
+
net_doc = db["_networks"].find_one({"_id": net_id})
|
|
1678
1678
|
data = []
|
|
1679
1679
|
for elm_data in elements_data:
|
|
1680
|
-
self._add_missing_defaults(
|
|
1680
|
+
self._add_missing_defaults(element_type, elm_data, net_doc)
|
|
1681
1681
|
self._ensure_dtypes(element_type, elm_data)
|
|
1682
1682
|
data.append({**elm_data, **var_data, "net_id": net_id})
|
|
1683
1683
|
collection = self._collection_name_of_element(element_type)
|
|
1684
1684
|
db[collection].insert_many(data, ordered=False)
|
|
1685
1685
|
return data
|
|
1686
1686
|
|
|
1687
|
-
def _add_missing_defaults(self,
|
|
1687
|
+
def _add_missing_defaults(self, element_type, element_data, net_doc):
|
|
1688
1688
|
func_str = f"create_{element_type}"
|
|
1689
|
-
|
|
1689
|
+
package = pp if net_doc['sector'] == 'power' else pps
|
|
1690
|
+
if not hasattr(package, func_str):
|
|
1690
1691
|
return
|
|
1691
|
-
create_func = getattr(
|
|
1692
|
+
create_func = getattr(package, func_str)
|
|
1692
1693
|
sig = signature(create_func)
|
|
1693
1694
|
params = sig.parameters
|
|
1694
1695
|
|
|
@@ -1704,7 +1705,6 @@ class PandaHub:
|
|
|
1704
1705
|
if element_type in ["line", "trafo", "trafo3w"]:
|
|
1705
1706
|
# add standard type values
|
|
1706
1707
|
std_type = element_data["std_type"]
|
|
1707
|
-
net_doc = db["_networks"].find_one({"_id": net_id})
|
|
1708
1708
|
if net_doc is not None:
|
|
1709
1709
|
# std_types = json.loads(net_doc["data"]["std_types"], cls=io_pp.PPJSONDecoder)[element_type]
|
|
1710
1710
|
std_types = net_doc["data"]["std_types"]
|
|
@@ -1715,6 +1715,9 @@ class PandaHub:
|
|
|
1715
1715
|
if element_type == "line":
|
|
1716
1716
|
if "g_us_per_km" not in element_data:
|
|
1717
1717
|
element_data["g_us_per_km"] = 0
|
|
1718
|
+
if element_type in ['sink', 'source']:
|
|
1719
|
+
if not 'mdot_kg_per_s' in element_data:
|
|
1720
|
+
element_data["mdot_kg_per_s"] = None
|
|
1718
1721
|
|
|
1719
1722
|
def _ensure_dtypes(self, element_type, data):
|
|
1720
1723
|
dtypes = self._datatypes.get(element_type)
|
|
@@ -2053,6 +2056,17 @@ class PandaHub:
|
|
|
2053
2056
|
metadata = kwargs
|
|
2054
2057
|
if data_type is not None:
|
|
2055
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}"
|
|
2056
2070
|
if isinstance(timeseries, pd.Series):
|
|
2057
2071
|
documents = [
|
|
2058
2072
|
{"metadata": metadata, "timestamp": idx, "value": value}
|
|
@@ -2063,7 +2077,10 @@ class PandaHub:
|
|
|
2063
2077
|
{"metadata": metadata, "timestamp": idx, **row.to_dict()}
|
|
2064
2078
|
for idx, row in timeseries.iterrows()
|
|
2065
2079
|
]
|
|
2066
|
-
|
|
2080
|
+
db[collection_name].insert_many(documents)
|
|
2081
|
+
if kwargs.get("return_id"):
|
|
2082
|
+
return metadata["_id"]
|
|
2083
|
+
return None
|
|
2067
2084
|
document = create_timeseries_document(
|
|
2068
2085
|
timeseries=timeseries,
|
|
2069
2086
|
data_type=data_type,
|
|
@@ -2335,12 +2352,17 @@ class PandaHub:
|
|
|
2335
2352
|
pipeline.append({"$match": meta_filter})
|
|
2336
2353
|
pipeline.append({"$project": {"_id": 0, "metadata": 0}})
|
|
2337
2354
|
timeseries = db[collection_name].aggregate_pandas_all(pipeline)
|
|
2355
|
+
if len(timeseries) == 0:
|
|
2356
|
+
raise PandaHubError("no documents matching the provided filter found", 404)
|
|
2338
2357
|
timeseries.set_index("timestamp", inplace=True)
|
|
2339
2358
|
if include_metadata:
|
|
2340
2359
|
raise NotImplementedError(
|
|
2341
2360
|
"Not implemented yet for timeseries collections"
|
|
2342
2361
|
)
|
|
2343
|
-
|
|
2362
|
+
if len(timeseries.columns) == 1:
|
|
2363
|
+
return timeseries[timeseries.columns[0]]
|
|
2364
|
+
else:
|
|
2365
|
+
return timeseries
|
|
2344
2366
|
filter_document = {**filter_document, **kwargs}
|
|
2345
2367
|
pipeline = [{"$match": filter_document}]
|
|
2346
2368
|
if not compressed_ts_data:
|
|
@@ -2427,6 +2449,7 @@ class PandaHub:
|
|
|
2427
2449
|
collection_name="timeseries",
|
|
2428
2450
|
global_database=False,
|
|
2429
2451
|
project_id=None,
|
|
2452
|
+
timestamp_range=None,
|
|
2430
2453
|
):
|
|
2431
2454
|
"""
|
|
2432
2455
|
Returns a DataFrame, containing all metadata matching the provided filter.
|
|
@@ -2467,10 +2490,17 @@ class PandaHub:
|
|
|
2467
2490
|
pipeline.append({"$match": document_filter})
|
|
2468
2491
|
else:
|
|
2469
2492
|
document_filter = {}
|
|
2493
|
+
if timestamp_range is not None:
|
|
2494
|
+
document_filter["timestamp"] = {
|
|
2495
|
+
"$gte": timestamp_range[0],
|
|
2496
|
+
"$lt": timestamp_range[1],
|
|
2497
|
+
}
|
|
2470
2498
|
document = db[collection_name].find_one(
|
|
2471
2499
|
document_filter, projection={"timestamp": 0, "_id": 0}
|
|
2472
2500
|
)
|
|
2473
|
-
|
|
2501
|
+
if document is None:
|
|
2502
|
+
return pd.DataFrame()
|
|
2503
|
+
value_fields = ["$%s" % field for field in document.keys() if field != "metadata"]
|
|
2474
2504
|
group_dict = {
|
|
2475
2505
|
"_id": "$metadata._id",
|
|
2476
2506
|
"max_value": {"$max": {"$max": value_fields}},
|
|
@@ -2595,27 +2625,30 @@ class PandaHub:
|
|
|
2595
2625
|
document_filter,
|
|
2596
2626
|
projection={"timestamp": 0, "metadata": 0, "_id": 0},
|
|
2597
2627
|
)
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
"
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2628
|
+
if document is None:
|
|
2629
|
+
meta_data = {}
|
|
2630
|
+
else:
|
|
2631
|
+
meta_pipeline = []
|
|
2632
|
+
meta_pipeline.append({"$match": document_filter})
|
|
2633
|
+
value_fields = ["$%s" % field for field in document.keys()]
|
|
2634
|
+
group_dict = {
|
|
2635
|
+
"_id": "$metadata._id",
|
|
2636
|
+
"max_value": {"$max": {"$max": value_fields}},
|
|
2637
|
+
"min_value": {"$min": {"$min": value_fields}},
|
|
2638
|
+
"first_timestamp": {"$min": "$timestamp"},
|
|
2639
|
+
"last_timestamp": {"$max": "$timestamp"},
|
|
2640
|
+
}
|
|
2641
|
+
document = db[collection_name].find_one(document_filter)
|
|
2642
|
+
metadata_fields = {
|
|
2643
|
+
metadata_field: {"$first": "$metadata.%s" % metadata_field}
|
|
2644
|
+
for metadata_field in document["metadata"].keys()
|
|
2645
|
+
if metadata_field != "_id"
|
|
2646
|
+
}
|
|
2647
|
+
group_dict.update(metadata_fields)
|
|
2648
|
+
meta_pipeline.append({"$group": group_dict})
|
|
2649
|
+
meta_data = {
|
|
2650
|
+
d["_id"]: d for d in db[collection_name].aggregate(meta_pipeline)
|
|
2651
|
+
}
|
|
2619
2652
|
timeseries = []
|
|
2620
2653
|
ts_all = db[collection_name].aggregate_pandas_all(pipeline)
|
|
2621
2654
|
if len(ts_all) == 0:
|
|
@@ -2961,7 +2994,16 @@ class PandaHub:
|
|
|
2961
2994
|
"""
|
|
2962
2995
|
self.check_permission("write")
|
|
2963
2996
|
db = self._get_project_database()
|
|
2964
|
-
|
|
2997
|
+
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)
|
|
2965
3007
|
filter_document = {"element_type": element_type, "data_type": data_type}
|
|
2966
3008
|
if netname is not None:
|
|
2967
3009
|
filter_document["netname"] = netname
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pandahub
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.14
|
|
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.14" # 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
|
|
File without changes
|
|
File without changes
|