-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import requests | ||
import json | ||
import glob | ||
|
||
metadata = {} | ||
for file in glob.glob("data/*/*/*.json"): | ||
_, model, version, fname = file.split("/") | ||
fname = fname.split(".json")[0] | ||
if model not in metadata: | ||
metadata[model] = {} | ||
if version not in metadata[model]: | ||
metadata[model][version] = {} | ||
|
||
metadata[model][version][fname] = json.load(open(file)) | ||
|
||
|
||
traser_uri = "http://localhost:3001/" | ||
headers = { | ||
"Content-Type": "application/json", | ||
} | ||
extra = { | ||
"id": "placeholder", | ||
"pid": "placeholder", | ||
"datasetType": "Healthdata", | ||
"publisherId": "123", | ||
"publisherName": "Tst Test", | ||
} | ||
|
||
|
||
def translate(input_model, input_version, output_model, output_version, metadata): | ||
|
||
response = requests.post( | ||
f"{traser_uri}translate?input_schema={input_model}&input_version={input_version}&output_schema={output_model}&output_version={output_version}", | ||
headers=headers, | ||
json={"metadata": metadata, "extra": extra}, | ||
) | ||
return response.status_code, response.json() | ||
|
||
|
||
for model, versions in metadata.items(): | ||
for version, metadatas in versions.items(): | ||
for name, metadata in metadatas.items(): | ||
for output_model, output_version in [ | ||
["GWDM", "1.0"], | ||
["GWDM", "1.1"], | ||
["GWDM", "1.2"], | ||
]: | ||
code, output = translate( | ||
model, version, output_model, output_version, metadata | ||
) | ||
print(model, version, name, code) | ||
if code != 200: | ||
print(json.dumps(output, indent=6)) | ||
exit(0) |