@datagrok/compute 0.7.1 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -4
- package/dist/package.js +1518 -0
- package/package.json +20 -7
- package/scripts/Fab Arm Exchange.py +4 -3
- package/scripts/Heat Exchange.js +2 -2
- package/scripts/IntervalsFromECG.py +0 -1
- package/scripts/Logistic Map.js +1 -1
- package/scripts/Lorenz Attractor.js +1 -1
- package/scripts/Lotka-Volterra.js +2 -1
- package/scripts/Maximal Volume.R +0 -1
- package/scripts/pkpd.R +0 -1
- package/scripts/popPK.R +0 -1
- package/scripts/trig.js +0 -1
- package/scripts/vmax.js +180 -0
- package/scripts/wrapper.js +8 -0
- package/src/css/model-card.css +61 -0
- package/src/function-views/compute-view.ts +162 -0
- package/src/model-catalog-view.ts +23 -13
- package/src/model-handler.ts +52 -38
- package/src/models-widget.ts +97 -44
- package/src/outliers-selection/outliers-selection-viewer.ts +37 -28
- package/src/package.ts +60 -23
- package/src/view-samples/computation-test-view.ts +8 -0
- package/.eslintrc.json +0 -35
- package/src/export-funccall.ts +0 -200
package/src/export-funccall.ts
DELETED
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
import * as grok from 'datagrok-api/grok';
|
|
2
|
-
import * as ui from 'datagrok-api/ui';
|
|
3
|
-
import * as DG from 'datagrok-api/dg';
|
|
4
|
-
import ExcelJS from 'exceljs';
|
|
5
|
-
import {saveAs} from 'file-saver';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const getSheetName = (name: string, direction: DIRECTION) => {
|
|
9
|
-
const idealName = `${direction} - ${name}`;
|
|
10
|
-
return (idealName.length > 31) ? name.substring(0, 32) : idealName;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
enum DIRECTION {
|
|
14
|
-
INPUT = 'Input',
|
|
15
|
-
OUTPUT = 'Output'
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export async function exportFuncCall(call: DG.FuncCall) {
|
|
19
|
-
//todo: check status
|
|
20
|
-
// if (call.status != FuncCall.STATUS_COMPLETED) ...
|
|
21
|
-
|
|
22
|
-
const BLOB_TYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8';
|
|
23
|
-
const exportWorkbook = new ExcelJS.Workbook();
|
|
24
|
-
|
|
25
|
-
const isScalarType = (type: DG.TYPE) => {
|
|
26
|
-
return DG.TYPES_SCALAR.has(type);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const isDataFrame = (type: DG.TYPE) => (type === DG.TYPE.DATA_FRAME);
|
|
30
|
-
|
|
31
|
-
const dfInputs = call.func.inputs.filter((input) => isDataFrame(input.propertyType));
|
|
32
|
-
const scalarInputs = call.func.inputs.filter((input) => isScalarType(input.propertyType));
|
|
33
|
-
const dfOutputs = call.func.outputs.filter((output) => isDataFrame(output.propertyType));
|
|
34
|
-
const scalarOutputs = call.func.outputs.filter((output) => isScalarType(output.propertyType));
|
|
35
|
-
|
|
36
|
-
const realNames: Record<string, string> = {};
|
|
37
|
-
|
|
38
|
-
dfInputs.forEach((dfInput) => {
|
|
39
|
-
const visibleTitle = dfInput.options.caption || dfInput.name;
|
|
40
|
-
const currentDfSheet = exportWorkbook.addWorksheet(getSheetName(visibleTitle, DIRECTION.INPUT));
|
|
41
|
-
realNames[visibleTitle] = dfInput.name;
|
|
42
|
-
const currentDf = (call.inputs[dfInput.name] as DG.DataFrame);
|
|
43
|
-
currentDfSheet.addRow((currentDf.columns as DG.ColumnList).names());
|
|
44
|
-
for (let i = 0; i < currentDf.rowCount; i++) {
|
|
45
|
-
currentDfSheet.addRow([...currentDf.row(i).cells].map((cell: DG.Cell) => cell.value));
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
if (scalarInputs.length) {
|
|
50
|
-
const inputScalarsSheet = exportWorkbook.addWorksheet('Input scalars');
|
|
51
|
-
scalarInputs.forEach((scalarInput) => {
|
|
52
|
-
inputScalarsSheet.addRow([scalarInput.options['caption'] || scalarInput.name, call.inputs[scalarInput.name], scalarInput.options['units'] || '']);
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
dfOutputs.forEach((dfOutput) => {
|
|
57
|
-
const visibleTitle = dfOutput.options.caption || dfOutput.name;
|
|
58
|
-
const currentDfSheet = exportWorkbook.addWorksheet(getSheetName(visibleTitle, DIRECTION.OUTPUT));
|
|
59
|
-
realNames[visibleTitle] = dfOutput.name;
|
|
60
|
-
const currentDf = (call.outputs[dfOutput.name] as DG.DataFrame);
|
|
61
|
-
currentDfSheet.addRow((currentDf.columns as DG.ColumnList).names());
|
|
62
|
-
for (let i = 0; i < currentDf.rowCount; i++) {
|
|
63
|
-
currentDfSheet.addRow([...currentDf.row(i).cells].map((cell: DG.Cell) => cell.value));
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
const addToFile = (imageId: number, visibleTitle: string, width: number, height: number, plotCount?: number) => {
|
|
68
|
-
if (imageId === null || imageId === undefined) return;
|
|
69
|
-
|
|
70
|
-
const worksheet = exportWorkbook.getWorksheet(getSheetName(visibleTitle, DIRECTION.INPUT)) ||
|
|
71
|
-
exportWorkbook.getWorksheet(getSheetName(visibleTitle, DIRECTION.OUTPUT));
|
|
72
|
-
if (worksheet) {
|
|
73
|
-
const columnForImage = (
|
|
74
|
-
((call.inputs[realNames[visibleTitle]] ||
|
|
75
|
-
call.outputs[realNames[visibleTitle]]) as DG.DataFrame)
|
|
76
|
-
.columns as DG.ColumnList)
|
|
77
|
-
.length + 1 + (plotCount ? plotCount * (Math.ceil(width / 64.0) + 1): 0);
|
|
78
|
-
worksheet.addImage(imageId, {
|
|
79
|
-
tl: {col: columnForImage, row: 0},
|
|
80
|
-
ext: {width, height},
|
|
81
|
-
});
|
|
82
|
-
} else {
|
|
83
|
-
const newWorksheet = exportWorkbook.addWorksheet(`Output - Plot - ${visibleTitle}`);
|
|
84
|
-
newWorksheet.addImage(imageId, {
|
|
85
|
-
tl: {col: 0, row: 0},
|
|
86
|
-
ext: {width, height},
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
const exportImage = async (imageDiv: Element, visibleTitle: string) => {
|
|
92
|
-
const regex = /background-image: url\(.*\)/;
|
|
93
|
-
const urlAttr = imageDiv.outerHTML.match(regex)?.[0];
|
|
94
|
-
if (!urlAttr) return;
|
|
95
|
-
const url = urlAttr.substring(23, urlAttr?.length - 2);
|
|
96
|
-
const pic = (await(await fetch(url)).arrayBuffer());
|
|
97
|
-
const imageId = exportWorkbook.addImage({
|
|
98
|
-
buffer: pic,
|
|
99
|
-
extension: 'png',
|
|
100
|
-
});
|
|
101
|
-
addToFile(imageId, visibleTitle, imageDiv.clientWidth, imageDiv.clientHeight);
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
const exportPlot = async (plotDiv: ChildNode | null | undefined,
|
|
105
|
-
blockDiv: Element, visibleTitle: string, plotCount? : number) => {
|
|
106
|
-
const titleDiv = blockDiv.firstChild as HTMLElement;
|
|
107
|
-
if (!titleDiv) return;
|
|
108
|
-
|
|
109
|
-
if (plotDiv && !titleDiv.getElementsByClassName('svg-table').length &&
|
|
110
|
-
(plotDiv as HTMLElement).getAttribute('name') === 'viewer-Grid') return;
|
|
111
|
-
|
|
112
|
-
if (plotDiv && titleDiv.getElementsByClassName('svg-table').length) {
|
|
113
|
-
if ((plotDiv as HTMLElement).getAttribute('name') === 'viewer-OutliersSelectionViewer') {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
if ((plotDiv as HTMLElement).getAttribute('name') === 'viewer-Grid') {
|
|
117
|
-
(titleDiv.getElementsByClassName('svg-table')[0] as HTMLElement).click();
|
|
118
|
-
await new Promise((r) => setTimeout(r, 150));
|
|
119
|
-
plotDiv = titleDiv.nextSibling;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (plotDiv) {
|
|
124
|
-
const plot = (plotDiv as HTMLElement).getElementsByClassName('d4-layout-middle')[0];
|
|
125
|
-
const canvas = await DG.HtmlUtils.renderToCanvas(plot as HTMLElement);
|
|
126
|
-
const dataUrl = canvas.toDataURL('image/png');
|
|
127
|
-
|
|
128
|
-
const imageId = exportWorkbook.addImage({
|
|
129
|
-
base64: dataUrl,
|
|
130
|
-
extension: 'png',
|
|
131
|
-
});
|
|
132
|
-
addToFile(imageId, visibleTitle, canvas.width, canvas.height, plotCount);
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
const exportTab = async (tab: HTMLElement) => {
|
|
137
|
-
const blockDivs = document.getElementsByClassName('ui-div ui-block');
|
|
138
|
-
let visibleTitle: string = '';
|
|
139
|
-
let plotCount: number = 0;
|
|
140
|
-
|
|
141
|
-
for (let i = 0; i < blockDivs.length; i++) {
|
|
142
|
-
const blockDiv = blockDivs[i];
|
|
143
|
-
|
|
144
|
-
if ((blockDiv as HTMLElement).style.display === 'none') continue;
|
|
145
|
-
|
|
146
|
-
if (blockDiv.firstChild?.firstChild?.textContent) {
|
|
147
|
-
visibleTitle = blockDiv.firstChild?.firstChild?.textContent;
|
|
148
|
-
plotCount = 0;
|
|
149
|
-
} else {
|
|
150
|
-
plotCount++;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if ((blockDiv.firstChild?.nextSibling as HTMLElement).getAttribute('name') === 'viewer-OutliersSelectionViewer') {
|
|
154
|
-
plotCount--;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const imageDiv = blockDiv.getElementsByClassName('grok-scripting-image-container')[0];
|
|
158
|
-
if (imageDiv) {
|
|
159
|
-
await exportImage(imageDiv, visibleTitle);
|
|
160
|
-
} else {
|
|
161
|
-
const plotDiv: ChildNode | null | undefined = blockDiv.firstChild?.nextSibling;
|
|
162
|
-
await exportPlot(plotDiv, blockDiv, visibleTitle, plotCount);
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
// UWAGA: very fragile solution
|
|
168
|
-
const funcView = document.getElementsByClassName('grok-view grok-view-func ui-box')[0];
|
|
169
|
-
const resultView = funcView.getElementsByClassName('d4-tab-host ui-box')[0];
|
|
170
|
-
if (resultView) {
|
|
171
|
-
const tabs = resultView.getElementsByClassName('d4-tab-header-stripe')[0].children;
|
|
172
|
-
const selectedByUser = resultView.getElementsByClassName('d4-tab-header selected')[0];
|
|
173
|
-
for (let i=0; i< tabs.length; i++) {
|
|
174
|
-
const tab = tabs[i] as HTMLElement;
|
|
175
|
-
tab.click();
|
|
176
|
-
await new Promise((r) => setTimeout(r, 150));
|
|
177
|
-
await exportTab(tab);
|
|
178
|
-
}
|
|
179
|
-
(selectedByUser as HTMLElement).click();
|
|
180
|
-
} else {
|
|
181
|
-
const resultView = document.getElementsByClassName('ui-panel grok-func-results')[0];
|
|
182
|
-
await exportTab(resultView as HTMLElement);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if (scalarOutputs.length) {
|
|
186
|
-
const outputScalarsSheet = exportWorkbook.addWorksheet('Output scalars');
|
|
187
|
-
scalarOutputs.forEach((scalarOutput) => {
|
|
188
|
-
outputScalarsSheet.addRow([scalarOutput.name, call.outputs[scalarOutput.name]]);
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
const metadataSheet = exportWorkbook.addWorksheet('Function run metadata');
|
|
193
|
-
metadataSheet.addRow(['Author', `${call.func.author.lastName} ${call.func.author.firstName}`]);
|
|
194
|
-
metadataSheet.addRow(['Login', call.func.author.toString()]);
|
|
195
|
-
|
|
196
|
-
exportWorkbook.xlsx.writeBuffer().then((data) => {
|
|
197
|
-
const blob = new Blob([data], {type: BLOB_TYPE});
|
|
198
|
-
saveAs(blob, `${call.func.name} - ${new Date().toLocaleString()}`);
|
|
199
|
-
});
|
|
200
|
-
}
|