Skip to content

Commit da890cc

Browse files
committed
make dataid of an artifact downlable
1 parent 786240f commit da890cc

File tree

4 files changed

+85
-5
lines changed

4 files changed

+85
-5
lines changed

databusclient/client.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,12 @@ def __handle_databus_collection__(endpoint, uri: str) -> str:
461461
return requests.get(uri, headers=headers).text
462462

463463

464+
def __handle_databus_artefact__(endpoint, uri: str) -> str:
465+
headers = {"Accept": "application/ld+json"}
466+
resp = requests.get(uri, headers=headers).text
467+
return resp
468+
469+
464470
def __download_list__(urls: List[str], local_dir: str):
465471
for url in urls:
466472
__download_file__(url=url, filename=local_dir+"/"+wsha256(url))
@@ -474,7 +480,7 @@ def download(
474480
"""
475481
Download datasets to local storage from databus registry
476482
------
477-
localDir: the local directory
483+
local_dir: the local directory
478484
databus_uris: identifiers to access databus registered datasets
479485
"""
480486
for databus_uri in databus_uris:
@@ -483,14 +489,15 @@ def download(
483489
# databus collection
484490
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
485491
query = __handle_databus_collection__(endpoint, databus_uri)
486-
res = __handle__databus_file_query__(endpoint, query)
492+
response = __handle__databus_file_query__(endpoint, query)
487493
else:
488-
print("dataId not supported yet") # TODO add support for other DatabusIds here (artifact, group, etc.)
494+
response = __handle_databus_artefact__(endpoint, databus_uri)
495+
# print("dataId not supported yet") # TODO add support for other DatabusIds here (artifact, group, etc.)
489496
# query in local file
490497
elif databus_uri.startswith("file://"):
491498
print("query in file not supported yet")
492499
# query as argument
493500
else:
494501
print("QUERY {}", databus_uri.replace("\n", " "))
495-
res = __handle__databus_file_query__(endpoint, databus_uri)
502+
response = __handle__databus_file_query__(endpoint, databus_uri)
496503
__download_list__(res, local_dir)

databusclient/consume/download.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# All kind of download functionalities for Databus ###
22

3-
class Downloder:
3+
4+
class Downloader:
45
pass

tests/data/file_0001.json

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"name": "iai_photovoltaic_active_power_data_202303",
3+
"title": "Active power generation through a photovoltaic installation in March 2023",
4+
"id": "https://openenergy-platform.org/dataedit/view/model_draft/iai_active_power_pv_202303",
5+
"description": "Measured active power produced",
6+
"publicationDate": "2023-03-13",
7+
"context": {
8+
"contact": "mohamed.koubaa@kit.edu",
9+
"fundingAgency": "Helmholtz Metadata Collaboration"
10+
},
11+
"temporal": {
12+
"referenceDate": "2023-02-13",
13+
"timeseries": [
14+
{
15+
"start": "2023-02-13",
16+
"end": "2023-03-13",
17+
"resolution": "1h",
18+
"alignment": "right",
19+
"aggregationType": "mean"
20+
}
21+
]
22+
},
23+
"resources": [
24+
{
25+
"name": "iai_active_power_pv_202303",
26+
"schema": {
27+
"foreignKeys": [],
28+
"fields": [
29+
{
30+
"name": "id",
31+
"description": "unique identifier like generated for the panda data frame",
32+
"type": "bigint"
33+
},
34+
{
35+
"name": "datetime",
36+
"description": "Date and time in yyyy-MM-dd hh:mm:ss",
37+
"type": "timestamp"
38+
},
39+
{
40+
"name": "active_power",
41+
"description": "Active power generated by the photovoltaic installation",
42+
"type": "float",
43+
"unit": "KW"
44+
}
45+
]
46+
}
47+
}
48+
],
49+
"metaMetadata": {
50+
"metadataVersion": "OEP-1.5.2",
51+
"metadataLicense": {
52+
"name": "CC0-1.0",
53+
"title": "Creative Commons Zero v1.0 Universal",
54+
"path": "https://creativecommons.org/publicdomain/zero/1.0/"
55+
}
56+
},
57+
"_comment": {
58+
"metadata": "Metadata documentation and explanation (https://github.com/OpenEnergyPlatform/oemetadata)",
59+
"dates": "Dates and time must follow the ISO8601 including time zone (YYYY-MM-DD or YYYY-MM-DDThh:mm:ss±hh)",
60+
"units": "Use a space between numbers and units (100 m)",
61+
"languages": "Languages must follow the IETF (BCP47) format (en-GB, en-US, de-DE)",
62+
"licenses": "License name must follow the SPDX License List (https://spdx.org/licenses/)",
63+
"review": "Following the OEP Data Review (https://github.com/OpenEnergyPlatform/data-preprocessing/blob/master/data-review/manual/review_manual.md)",
64+
"null": "If not applicable use: null",
65+
"todo": "If a value is not yet available, use: todo"
66+
}
67+
}

tests/test_download.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
} LIMIT 10
1010
"""
1111
TEST_COLLECTION = "https://databus.openenergyplatform.org/koubaa-hmc/collections/sandbox"
12+
TEST_ARTEFACT = "https://databus.openenergyplatform.org/koubaa-hmc/active_photovoltaic/01-2022"
1213

1314

1415
def test_with_query():
@@ -17,3 +18,7 @@ def test_with_query():
1718

1819
def test_with_collection():
1920
cl.download("tmp", DEFAULT_ENDPOINT, [TEST_COLLECTION])
21+
22+
23+
def test_with_artefact():
24+
cl.download("tmp", DEFAULT_ENDPOINT, [TEST_ARTEFACT])

0 commit comments

Comments
 (0)