...
First of all we have to know which routes we need to use. For this it is recommended to take a look at the query builder or swagger ui (http://localhost:8002/ui/). Under the Edit tab there are all routes which can be used to insert or update data of the property service.
For this tutorial we are using just two of them. One to add new provenances datasets and one to add new regions to the property service.
- /provenancedataset/bulk
- /region/{provenancedataset}
Requests
These two routes are both POST routes which requires them to be called with a POST request. To create simple post requests we recommend the python package requests.
...
Code Block | ||
---|---|---|
| ||
# define data to store ml_provenancedatasets = '[ { "name": "ml-algorithms' ", "responsible": "John Doe", "type": "algorithm", "description": "no comment!" } ] ml_result = { 'time_end': '2016-01-22T17:27:59.001Z', 'lat_hg': '2016-01-22T17:27:59.001Z', 'long_hg': '2016-01-22T17:27:59.001Z', 'algorithm_name': 'LassoCV', 'algorithm_parameters': { 'store': 'what you want', 'also here': [1, 2, 3, 4] } } |
...
- Every region needs at least a time_start, lat_hg and long_hg attribute.
- Every specific data has to be added to the data attribute and has to be a key-value pair.
This would then look like this:
Code Block | ||
---|---|---|
| ||
# define data to store post_data = { 'time_start': '2016-01-21T17:27:59.001Z', 'datalat_hg': ml_result }12, 'long_hg': 4.2, 'data': { "LassoCV": { 'store': 'what you want', 'also here': [1, 2, 3, 4] } } } |
Ingest
Now the ingest of this post_data is very simple. We first have to add the new provenance dataset to the property service and then add a new region.
Code Block | ||
---|---|---|
| ||
# add provenance print('creating provenance...') requests.post("http://localhost:8002/provenancedataset/bulk", json=ml_provenancedatasets) # add region print('storing data...') requests.post("http://localhost:8002/region/%s" % ml_provenancedatasets[0]['name'], json=post_data) |
The addresses of the routes are the same we looked up before.
...
Now to check if everything worked we should retrieve all the properties regions which are stored under this provenancedataset. This can be done with a GET request.
Code Block | ||
---|---|---|
| ||
# retrieving data print('downloading all properties...') ml_propertiesregions = requests.get("http://localhost:8002/propertyregion/%s/list" % ml_provenancedatasets[0]['name']).json() print(ml_propertiesregions) |
Source Code
Here you can download the full python source code.
...