Model execution with dashboard output
Notebook execution can output to some dashboard with a little configuration. This dashboard is the same for any execution but it has “id_ejec” param in order to show data of one particular execution output of the output of the model saved in some ontology.
The first step is to create a notebook with an input identifier per execution that can receive this id_ejec param. For this example, we are going to develop a simple notebook with two parameter, focus on understand the id_ejec parameter:
id_ejec → mandatory param with identification and ontology output writting. The model service autogenerates this parameter so we only need to use it.
data → array of json with two fields: name (string) and value (number).
We need an output ontology that connect the output of the notebook with input of the dashboard so we need to create a new ontology with the id_ejec field for execution identification:
That ontology will be the data output of the notebook so we create a client for this ontology and start writing the new notebook.
First, we create the input paragraph:
%python
id_ejec = z.input("id_ejec");
data = z.input("params"); |
Second we transform our new data, appending the id_ejec field with the same structure of the ontology instance:
%python
import json
jsondata = json.loads(json.loads(data)["data"])
arrayoutput = []
for inst in jsondata:
inst["id_ejec"] = id_ejec
arrayoutput.append({"dashboardOutput": inst})
data_id_ejec = json.dumps(arrayoutput)
print data_id_ejec
z.z.put("insert",data_id_ejec) |
Then we only need to initiate the connection and insert the generated data into the ontology.
%onesaitplatform
initConnection("client","tokenid")
The second step is to create the dashboard using this ontology and using this id_ejec like a parameter. So we create a simple pie using data for this id_ejec.
We drag the icon of pie gadget and drop it over the canvas.
We select “New Gadget”.
We type all the info: a name, the ontology we created before and the query.
Now it’s neccesary to use name as X Axis and value as Y Axis and click in new to create it.
With this gadget we can add the new special “id_ejec“ param and link it to this gadget to the same field. So we go to the params menu and we add it.
Finally we save our new dashboard.
If we open this dashboard and add the query param “id_ejec“ to the url, we can filter this dashboard with it, showing the gadget for one execution.
After all this, we can create our new model linked with the dashboard. We set a name and a description, and we select our notebook and the first paragraph (the input paragraph).
We need to add the data parameter. For this, id_ejec is implicit.
On the output source we need to select our dashboard and that’s all.
We can execute this model with the API for it and when the execution is finished we can go to the dashboard with the id_ejec parameter (output of execution) as query param and see all the data for that execution.