-
Notifications
You must be signed in to change notification settings - Fork 0
/
translation-test.py
54 lines (45 loc) · 1.59 KB
/
translation-test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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)