Skip to content

Commit 3013618

Browse files
committed
Generate a datapackage.json file
The foreign keys are not yet correctly built/linked
1 parent 627a703 commit 3013618

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

app/projects/management/commands/datapackage.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from projects.models import Scenario
33
from pathlib import Path
44
import shutil
5+
from oemof.tabular.datapackage import building
6+
import datapackage as dp
57

68

79
class Command(BaseCommand):
@@ -23,3 +25,20 @@ def handle(self, *args, **options):
2325
if scenario_folder.exists():
2426
shutil.rmtree(scenario_folder)
2527
scenario.to_datapackage(destination_path)
28+
29+
dp_json = scenario_folder / "datapackage.json"
30+
31+
if dp_json.exists():
32+
print("Only inferring metadata")
33+
p = dp.Package(dp_json)
34+
building.infer_package_foreign_keys(p)
35+
p.descriptor["resources"].sort(key=lambda x: (x["path"], x["name"]))
36+
p.commit()
37+
p.save(dp_json)
38+
39+
else:
40+
print("Creating datapackage.json")
41+
building.infer_metadata_from_data(
42+
package_name=f"scenario_{scen_id}",
43+
path=scenario_folder,
44+
)

app/requirements/base.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Django==4.2.4
22
django-bootstrap-modal-forms==2.0.0
33
django-compressor==4.1
44
django-crispy-forms==1.9.2
5+
django-environ
56
django-extensions==3.0.9
67
django-jsonview==2.0.0
78
django-q==1.3.4
@@ -12,12 +13,11 @@ httpx==0.23.0
1213
jsonschema==4.4.0
1314
libsass==0.21.0
1415
numpy>=1.22.4
15-
oemof-solph==0.4.4
16+
oemof-tabular==0.0.6.dev0
1617
oemof-thermal==0.0.5
1718
openpyxl==3.0.10
1819
plotly==5.6.0
1920
psycopg2-binary==2.9.3
2021
requests==2.24.0
21-
XlsxWriter==1.3.9
22-
django-environ
2322
whitenoise==6.9.0
23+
XlsxWriter==1.3.9

0 commit comments

Comments
 (0)