Customize the experimental data upload
You may customize the data upload using Datagrok functions and meta.uploadFunc
tag.
The function mentioned in this tag will be called on clicking button instead of the basic data upload.
You may use it to extract the experimental data from the external resource (e.g., a database).
Extracted data could be saved to the history or could be used directly to compare the computed and experimental results.
- Enabling custom data upload
- Widget generator
- Data extractor
Your script header
//meta.uploadFunc: Compute:CustomUploader
package.ts
//name: CustomUploader
//input: object params
//output: widget uploadWidget
//output: funccall uploadFuncCall
export async function CustomUploader(params: {func: DG.Func}) {
const uploadFunc = await grok.functions.eval('Compute:DataExtractor') as DG.Func;
const uploadFuncCall = uploadFunc.prepare({func: params.func})
const uploadBtn = ui.bigButton('Click me to get mock calls', () => uploadFuncCall.call());
const dummyWidget = DG.Widget.fromRoot(ui.panel([ui.divV([
ui.label('This part of dialog comes from my custom data uploader'),
ui.divH([uploadBtn], {style: {'justify-content': 'center'}})
])]));
const setLoadingSub = grok.functions.onBeforeRunAction.pipe(
filter((call) => call.id === uploadFuncCall.id)
).subscribe(() => {
ui.setUpdateIndicator(uploadBtn, true);
})
const unsetLoadingSub = grok.functions.onAfterRunAction.pipe(
filter((call) => call.id === uploadFuncCall.id)
).subscribe(() => {
ui.setUpdateIndicator(uploadBtn, false);
})
dummyWidget.subs.push(setLoadingSub, unsetLoadingSub)
return {uploadWidget: dummyWidget, uploadFuncCall};
}
package.ts
//name: DataExtractor
//input: func func
//output: object uploadedCalls
export async function DataExtractor(func: DG.Func) {
await new Promise((r) => setTimeout(r, 1000));
const dummyFunccall = await func.prepare({
'ambTemp': 22,
'initTemp': 100,
'desiredTemp': 30,
'area': 0.06,
'heatCap': 4200,
'heatTransferCoeff': 8.3,
'simTime': 21600,
}).call();
return [dummyFunccall]
}
info
The custom upload funcion should return uploadWidget
(of type DG.Widget) and uploadFuncCall
(of type DG.FuncCall).
uploadWidget
will be shown on the UI; uploadFuncCall
, in turn, should return the experimental runs typed as array of DG.FuncCalls.