Skip to content

Commit

Permalink
make dataid of an artifact downlable
Browse files Browse the repository at this point in the history
  • Loading branch information
koubaa-hmc committed Dec 18, 2024
1 parent 786240f commit da890cc
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 5 deletions.
15 changes: 11 additions & 4 deletions databusclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,12 @@ def __handle_databus_collection__(endpoint, uri: str) -> str:
return requests.get(uri, headers=headers).text


def __handle_databus_artefact__(endpoint, uri: str) -> str:
headers = {"Accept": "application/ld+json"}
resp = requests.get(uri, headers=headers).text
return resp


def __download_list__(urls: List[str], local_dir: str):
for url in urls:
__download_file__(url=url, filename=local_dir+"/"+wsha256(url))
Expand All @@ -474,7 +480,7 @@ def download(
"""
Download datasets to local storage from databus registry
------
localDir: the local directory
local_dir: the local directory
databus_uris: identifiers to access databus registered datasets
"""
for databus_uri in databus_uris:
Expand All @@ -483,14 +489,15 @@ def download(
# databus collection
if "/collections/" in databus_uri: # TODO "in" is not safe! there could be an artifact named collections, need to check for the correct part position in the URI
query = __handle_databus_collection__(endpoint, databus_uri)
res = __handle__databus_file_query__(endpoint, query)
response = __handle__databus_file_query__(endpoint, query)
else:
print("dataId not supported yet") # TODO add support for other DatabusIds here (artifact, group, etc.)
response = __handle_databus_artefact__(endpoint, databus_uri)
# print("dataId not supported yet") # TODO add support for other DatabusIds here (artifact, group, etc.)
# query in local file
elif databus_uri.startswith("file://"):
print("query in file not supported yet")
# query as argument
else:
print("QUERY {}", databus_uri.replace("\n", " "))
res = __handle__databus_file_query__(endpoint, databus_uri)
response = __handle__databus_file_query__(endpoint, databus_uri)
__download_list__(res, local_dir)
3 changes: 2 additions & 1 deletion databusclient/consume/download.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# All kind of download functionalities for Databus ###

class Downloder:

class Downloader:
pass
67 changes: 67 additions & 0 deletions tests/data/file_0001.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"name": "iai_photovoltaic_active_power_data_202303",
"title": "Active power generation through a photovoltaic installation in March 2023",
"id": "https://openenergy-platform.org/dataedit/view/model_draft/iai_active_power_pv_202303",
"description": "Measured active power produced",
"publicationDate": "2023-03-13",
"context": {
"contact": "[email protected]",
"fundingAgency": "Helmholtz Metadata Collaboration"
},
"temporal": {
"referenceDate": "2023-02-13",
"timeseries": [
{
"start": "2023-02-13",
"end": "2023-03-13",
"resolution": "1h",
"alignment": "right",
"aggregationType": "mean"
}
]
},
"resources": [
{
"name": "iai_active_power_pv_202303",
"schema": {
"foreignKeys": [],
"fields": [
{
"name": "id",
"description": "unique identifier like generated for the panda data frame",
"type": "bigint"
},
{
"name": "datetime",
"description": "Date and time in yyyy-MM-dd hh:mm:ss",
"type": "timestamp"
},
{
"name": "active_power",
"description": "Active power generated by the photovoltaic installation",
"type": "float",
"unit": "KW"
}
]
}
}
],
"metaMetadata": {
"metadataVersion": "OEP-1.5.2",
"metadataLicense": {
"name": "CC0-1.0",
"title": "Creative Commons Zero v1.0 Universal",
"path": "https://creativecommons.org/publicdomain/zero/1.0/"
}
},
"_comment": {
"metadata": "Metadata documentation and explanation (https://github.com/OpenEnergyPlatform/oemetadata)",
"dates": "Dates and time must follow the ISO8601 including time zone (YYYY-MM-DD or YYYY-MM-DDThh:mm:ss±hh)",
"units": "Use a space between numbers and units (100 m)",
"languages": "Languages must follow the IETF (BCP47) format (en-GB, en-US, de-DE)",
"licenses": "License name must follow the SPDX License List (https://spdx.org/licenses/)",
"review": "Following the OEP Data Review (https://github.com/OpenEnergyPlatform/data-preprocessing/blob/master/data-review/manual/review_manual.md)",
"null": "If not applicable use: null",
"todo": "If a value is not yet available, use: todo"
}
}
5 changes: 5 additions & 0 deletions tests/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
} LIMIT 10
"""
TEST_COLLECTION = "https://databus.openenergyplatform.org/koubaa-hmc/collections/sandbox"
TEST_ARTEFACT = "https://databus.openenergyplatform.org/koubaa-hmc/active_photovoltaic/01-2022"


def test_with_query():
Expand All @@ -17,3 +18,7 @@ def test_with_query():

def test_with_collection():
cl.download("tmp", DEFAULT_ENDPOINT, [TEST_COLLECTION])


def test_with_artefact():
cl.download("tmp", DEFAULT_ENDPOINT, [TEST_ARTEFACT])

0 comments on commit da890cc

Please sign in to comment.