@datagrok/compute 0.6.5 → 0.7.1
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/package.json +4 -2
- package/src/export-funccall.ts +102 -161
- package/src/models-widget.ts +67 -0
- package/src/outliers-selection/outliers-selection-viewer.ts +10 -20
- package/src/package.ts +8 -104
- package/detectors.js +0 -9
- package/src/function-editor/function-editor.ts +0 -615
- package/src/outliers-selection/outliers-selection.ts +0 -281
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datagrok/compute",
|
|
3
3
|
"friendlyName": "Compute",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.7.1",
|
|
5
5
|
"description": "",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"cash-dom": "latest",
|
|
@@ -42,5 +42,7 @@
|
|
|
42
42
|
"release-compute-localhost": "grok publish localhost --rebuild --release",
|
|
43
43
|
"debug-compute-compose": "grok publish compose --rebuild",
|
|
44
44
|
"release-compute-compose": "grok publish compose --rebuild --release"
|
|
45
|
-
}
|
|
45
|
+
},
|
|
46
|
+
"canEdit": [ "Developers" ],
|
|
47
|
+
"canView": [ "All users" ]
|
|
46
48
|
}
|
package/src/export-funccall.ts
CHANGED
|
@@ -49,7 +49,7 @@ export async function exportFuncCall(call: DG.FuncCall) {
|
|
|
49
49
|
if (scalarInputs.length) {
|
|
50
50
|
const inputScalarsSheet = exportWorkbook.addWorksheet('Input scalars');
|
|
51
51
|
scalarInputs.forEach((scalarInput) => {
|
|
52
|
-
inputScalarsSheet.addRow([scalarInput.name, call.inputs[scalarInput.name]]);
|
|
52
|
+
inputScalarsSheet.addRow([scalarInput.options['caption'] || scalarInput.name, call.inputs[scalarInput.name], scalarInput.options['units'] || '']);
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
|
|
@@ -64,185 +64,122 @@ export async function exportFuncCall(call: DG.FuncCall) {
|
|
|
64
64
|
}
|
|
65
65
|
});
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const resultView = funcView.getElementsByClassName('d4-tab-host ui-box')[0];
|
|
70
|
-
if (resultView) {
|
|
71
|
-
const tabs = resultView.getElementsByClassName('d4-tab-header-stripe')[0].children;
|
|
72
|
-
const selectedByUser = resultView.getElementsByClassName('d4-tab-header selected')[0];
|
|
73
|
-
for (let i=0; i< tabs.length; i++) {
|
|
74
|
-
(tabs[i] as HTMLElement).click();
|
|
75
|
-
await new Promise((r) => setTimeout(r, 150));
|
|
67
|
+
const addToFile = (imageId: number, visibleTitle: string, width: number, height: number, plotCount?: number) => {
|
|
68
|
+
if (imageId === null || imageId === undefined) return;
|
|
76
69
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
+
};
|
|
80
90
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
+
};
|
|
88
103
|
|
|
89
|
-
|
|
90
|
-
|
|
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;
|
|
91
108
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
let height = 0;
|
|
109
|
+
if (plotDiv && !titleDiv.getElementsByClassName('svg-table').length &&
|
|
110
|
+
(plotDiv as HTMLElement).getAttribute('name') === 'viewer-Grid') return;
|
|
95
111
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
});
|
|
107
|
-
width = imageDiv.clientWidth;
|
|
108
|
-
height = imageDiv.clientHeight;
|
|
109
|
-
} else {
|
|
110
|
-
let plotDiv: ChildNode | null | undefined = titleDiv.nextSibling;
|
|
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
|
+
}
|
|
111
122
|
|
|
112
|
-
|
|
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');
|
|
113
127
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
await new Promise((r) => setTimeout(r, 150));
|
|
122
|
-
plotDiv = titleDiv.nextSibling;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
console.log(plotDiv);
|
|
128
|
+
const imageId = exportWorkbook.addImage({
|
|
129
|
+
base64: dataUrl,
|
|
130
|
+
extension: 'png',
|
|
131
|
+
});
|
|
132
|
+
addToFile(imageId, visibleTitle, canvas.width, canvas.height, plotCount);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
126
135
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
136
|
+
const exportTab = async (tab: HTMLElement) => {
|
|
137
|
+
const blockDivs = document.getElementsByClassName('ui-div ui-block');
|
|
138
|
+
let visibleTitle: string = '';
|
|
139
|
+
let plotCount: number = 0;
|
|
131
140
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
extension: 'png',
|
|
135
|
-
});
|
|
136
|
-
width = canvas.width;
|
|
137
|
-
height = canvas.height;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
141
|
+
for (let i = 0; i < blockDivs.length; i++) {
|
|
142
|
+
const blockDiv = blockDivs[i];
|
|
140
143
|
|
|
141
|
-
|
|
144
|
+
if ((blockDiv as HTMLElement).style.display === 'none') continue;
|
|
142
145
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const columnForImage = (((call
|
|
149
|
-
.inputs[realNames[visibleTitle]] || call
|
|
150
|
-
.outputs[realNames[visibleTitle]]) as DG.DataFrame)
|
|
151
|
-
.columns as DG.ColumnList)
|
|
152
|
-
.length + 1;
|
|
153
|
-
worksheet.addImage(imageId, {
|
|
154
|
-
tl: {col: columnForImage, row: 0},
|
|
155
|
-
ext: {width, height},
|
|
156
|
-
});
|
|
157
|
-
} else {
|
|
158
|
-
const newWorksheet = exportWorkbook.addWorksheet(`Output - Plot - ${visibleTitle}`);
|
|
159
|
-
newWorksheet.addImage(imageId, {
|
|
160
|
-
tl: {col: 0, row: 0},
|
|
161
|
-
ext: {width, height},
|
|
162
|
-
});
|
|
163
|
-
}
|
|
146
|
+
if (blockDiv.firstChild?.firstChild?.textContent) {
|
|
147
|
+
visibleTitle = blockDiv.firstChild?.firstChild?.textContent;
|
|
148
|
+
plotCount = 0;
|
|
149
|
+
} else {
|
|
150
|
+
plotCount++;
|
|
164
151
|
}
|
|
165
|
-
}
|
|
166
|
-
(selectedByUser as HTMLElement).click();
|
|
167
|
-
} else {
|
|
168
|
-
const resultView = document.getElementsByClassName('ui-panel grok-func-results')[0];
|
|
169
|
-
const titleDivs = resultView.getElementsByClassName('grok-func-results-header');
|
|
170
|
-
let skipNext = false;
|
|
171
152
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
skipNext = false;
|
|
175
|
-
continue;
|
|
153
|
+
if ((blockDiv.firstChild?.nextSibling as HTMLElement).getAttribute('name') === 'viewer-OutliersSelectionViewer') {
|
|
154
|
+
plotCount--;
|
|
176
155
|
}
|
|
177
156
|
|
|
178
|
-
const
|
|
179
|
-
const visibleTitle = titleDiv.firstChild?.textContent;
|
|
180
|
-
if (visibleTitle === null || visibleTitle === undefined) continue;
|
|
181
|
-
|
|
182
|
-
let imageId;
|
|
183
|
-
let width = 0;
|
|
184
|
-
let height = 0;
|
|
185
|
-
|
|
186
|
-
const imageDiv = titleDiv.parentElement?.getElementsByClassName('grok-scripting-image-container')[0];
|
|
157
|
+
const imageDiv = blockDiv.getElementsByClassName('grok-scripting-image-container')[0];
|
|
187
158
|
if (imageDiv) {
|
|
188
|
-
|
|
189
|
-
const urlAttr = imageDiv.outerHTML.match(regex)?.[0];
|
|
190
|
-
if (!urlAttr) continue;
|
|
191
|
-
const url = urlAttr.substring(23, urlAttr?.length - 2);
|
|
192
|
-
const pic = (await (await fetch(url)).arrayBuffer());
|
|
193
|
-
imageId = exportWorkbook.addImage({
|
|
194
|
-
buffer: pic,
|
|
195
|
-
extension: 'png',
|
|
196
|
-
});
|
|
197
|
-
width = imageDiv.clientWidth;
|
|
198
|
-
height = imageDiv.clientHeight;
|
|
159
|
+
await exportImage(imageDiv, visibleTitle);
|
|
199
160
|
} else {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
((plotDiv as HTMLElement).getAttribute('name') === 'viewer-Grid' ||
|
|
203
|
-
(plotDiv as HTMLElement).getAttribute('name') === 'viewer-OutliersSelectionViewer')) {
|
|
204
|
-
if (titleDiv.getElementsByClassName('svg-table').length) {
|
|
205
|
-
plotDiv = titleDiv.parentElement?.nextSibling?.firstChild?.nextSibling;
|
|
206
|
-
skipNext = true;
|
|
207
|
-
} else {
|
|
208
|
-
continue;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
if (plotDiv) {
|
|
213
|
-
const plot = (plotDiv as HTMLElement).getElementsByClassName('d4-layout-middle')[0];
|
|
214
|
-
const canvas = await DG.HtmlUtils.renderToCanvas(plot as HTMLElement);
|
|
215
|
-
const dataUrl = canvas.toDataURL('image/png');
|
|
216
|
-
|
|
217
|
-
imageId = exportWorkbook.addImage({
|
|
218
|
-
base64: dataUrl,
|
|
219
|
-
extension: 'png',
|
|
220
|
-
});
|
|
221
|
-
width = canvas.width;
|
|
222
|
-
height = canvas.height;
|
|
223
|
-
}
|
|
161
|
+
const plotDiv: ChildNode | null | undefined = blockDiv.firstChild?.nextSibling;
|
|
162
|
+
await exportPlot(plotDiv, blockDiv, visibleTitle, plotCount);
|
|
224
163
|
}
|
|
164
|
+
};
|
|
165
|
+
};
|
|
225
166
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
});
|
|
238
|
-
} else {
|
|
239
|
-
const newWorksheet = exportWorkbook.addWorksheet(`Output - Plot - ${visibleTitle}`);
|
|
240
|
-
newWorksheet.addImage(imageId, {
|
|
241
|
-
tl: {col: 0, row: 0},
|
|
242
|
-
ext: {width, height},
|
|
243
|
-
});
|
|
244
|
-
}
|
|
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);
|
|
245
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);
|
|
246
183
|
}
|
|
247
184
|
|
|
248
185
|
if (scalarOutputs.length) {
|
|
@@ -252,8 +189,12 @@ export async function exportFuncCall(call: DG.FuncCall) {
|
|
|
252
189
|
});
|
|
253
190
|
}
|
|
254
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
|
+
|
|
255
196
|
exportWorkbook.xlsx.writeBuffer().then((data) => {
|
|
256
197
|
const blob = new Blob([data], {type: BLOB_TYPE});
|
|
257
|
-
saveAs(blob, call.func.name);
|
|
198
|
+
saveAs(blob, `${call.func.name} - ${new Date().toLocaleString()}`);
|
|
258
199
|
});
|
|
259
200
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import * as grok from 'datagrok-api/grok';
|
|
2
|
+
import * as DG from "datagrok-api/dg";
|
|
3
|
+
import * as ui from "datagrok-api/ui";
|
|
4
|
+
import $ from 'cash-dom';
|
|
5
|
+
|
|
6
|
+
export class ModelsWidget extends DG.Widget {
|
|
7
|
+
caption: string;
|
|
8
|
+
order: string;
|
|
9
|
+
|
|
10
|
+
constructor() {
|
|
11
|
+
super(ui.panel());
|
|
12
|
+
this.caption = super.addProperty('caption', DG.TYPE.STRING, 'Model catalog');
|
|
13
|
+
this.order = super.addProperty('order', DG.TYPE.STRING, '0');
|
|
14
|
+
this.getModels();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async getModels(){
|
|
18
|
+
let count = (await grok.dapi.scripts.filter('#model').list()).length;
|
|
19
|
+
let titles = [ui.h3('Simulation'), ui.h3('Other')];
|
|
20
|
+
for (let i in titles){
|
|
21
|
+
titles[i].style.color = 'var(--grey-3)';
|
|
22
|
+
titles[i].style.fontSize = '12px';
|
|
23
|
+
titles[i].style.textTransform = 'uppercase';
|
|
24
|
+
titles[i].style.letterSpacing = '1px';
|
|
25
|
+
titles[i].style.margin = '5px 0';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let modelsList = ui.divV([
|
|
29
|
+
titles[0],
|
|
30
|
+
ui.divV([],'models-widget-group'),
|
|
31
|
+
titles[1],
|
|
32
|
+
ui.divV([],'models-widget-group'),
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
grok.dapi.scripts
|
|
36
|
+
.filter('#model')
|
|
37
|
+
.list()
|
|
38
|
+
.then((scripts) => scripts.map((p) => {
|
|
39
|
+
if(p.tags.includes("simulation")){
|
|
40
|
+
let div = ui.link('', p.path, undefined, null);
|
|
41
|
+
div.append(modelData(p))
|
|
42
|
+
$(modelsList).find('.models-widget-group')[0]?.append(div);
|
|
43
|
+
}else{
|
|
44
|
+
let div = ui.link('', p.path, undefined, null);
|
|
45
|
+
div.append(modelData(p))
|
|
46
|
+
$(modelsList).find('.models-widget-group')[1]?.append(div);
|
|
47
|
+
}
|
|
48
|
+
}));
|
|
49
|
+
|
|
50
|
+
this.root.appendChild(modelsList);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function modelData(p: any){
|
|
55
|
+
let img = ui.iconImage('logo', `/images/entities/${p.language}.png`);
|
|
56
|
+
img.style.width = '30px';
|
|
57
|
+
img.style.height = '30px';
|
|
58
|
+
img.style.border = 'none';
|
|
59
|
+
let card = ui.cards.summary(
|
|
60
|
+
img,
|
|
61
|
+
[
|
|
62
|
+
ui.div(ui.link(p.friendlyName, p, undefined, null)),
|
|
63
|
+
ui.div([p.updatedOn], {style:{color:'var(--grey-4)'}})
|
|
64
|
+
]);
|
|
65
|
+
ui.tooltip.bind(card, p);
|
|
66
|
+
return card;
|
|
67
|
+
}
|
|
@@ -7,23 +7,17 @@ export class OutliersSelectionViewer extends DG.JsViewer {
|
|
|
7
7
|
super();
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
onFrameAttached(dataFrame: DG.DataFrame): void {
|
|
11
|
+
this.dataFrame = dataFrame;
|
|
12
|
+
this.render();
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
onTableAttached() {
|
|
16
|
-
|
|
17
|
-
this.initialRender();
|
|
18
|
-
}
|
|
15
|
+
onTableAttached(): void {
|
|
16
|
+
this.render();
|
|
19
17
|
}
|
|
20
18
|
|
|
21
19
|
render() {
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
initialRender() {
|
|
26
|
-
if (!this.dataFrame) {
|
|
20
|
+
if (!this.dataFrame || this.dataFrame.rowCount <= 0) {
|
|
27
21
|
this.root.innerHTML = '';
|
|
28
22
|
return;
|
|
29
23
|
}
|
|
@@ -33,8 +27,6 @@ export class OutliersSelectionViewer extends DG.JsViewer {
|
|
|
33
27
|
const OUTLIER_RATIONALE_COL_LABEL = 'Rationale';
|
|
34
28
|
const OUTLIER_COUNT_COL_LABEL = 'Count';
|
|
35
29
|
const IS_GROUP_CONFIRMED_LABEL = 'isConfirmed';
|
|
36
|
-
const FLUX = 't/V (hr/(L/m²))';
|
|
37
|
-
const DEFAULT_TEST_AREA = 3.5;
|
|
38
30
|
|
|
39
31
|
if (!inputData.columns.byName(IS_OUTLIER_COL_LABEL)) {
|
|
40
32
|
inputData.columns
|
|
@@ -46,11 +38,8 @@ export class OutliersSelectionViewer extends DG.JsViewer {
|
|
|
46
38
|
.add(DG.Column.fromStrings(OUTLIER_RATIONALE_COL_LABEL, Array.from({length: inputData.rowCount}, () => '')));
|
|
47
39
|
}
|
|
48
40
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const initialData = inputData.clone();
|
|
41
|
+
//@ts-ignore
|
|
42
|
+
inputData.col(IS_OUTLIER_COL_LABEL)?.markers.assign('true', DG.MARKER_TYPE.OUTLIER);
|
|
54
43
|
|
|
55
44
|
const clearTable = () => {
|
|
56
45
|
return DG.DataFrame.fromColumns([
|
|
@@ -190,7 +179,8 @@ export class OutliersSelectionViewer extends DG.JsViewer {
|
|
|
190
179
|
// );
|
|
191
180
|
// info.style.marginBottom = '0px';
|
|
192
181
|
|
|
193
|
-
this.root.
|
|
182
|
+
this.root.innerHTML = '';
|
|
183
|
+
this.root.append(
|
|
194
184
|
ui.divV([
|
|
195
185
|
ui.divV([
|
|
196
186
|
groupsListGrid.root,
|
package/src/package.ts
CHANGED
|
@@ -3,50 +3,16 @@ import * as grok from 'datagrok-api/grok';
|
|
|
3
3
|
import * as ui from 'datagrok-api/ui';
|
|
4
4
|
import * as DG from 'datagrok-api/dg';
|
|
5
5
|
import {ModelHandler} from './model-handler';
|
|
6
|
-
import {selectOutliersManually} from './outliers-selection/outliers-selection';
|
|
7
6
|
import {exportFuncCall} from './export-funccall';
|
|
8
7
|
import {_functionParametersGrid} from './function-views/function-parameters-grid';
|
|
9
8
|
import {ModelCatalogView} from './model-catalog-view';
|
|
10
9
|
import wu from 'wu';
|
|
11
|
-
import {_functionEditor} from './function-editor/function-editor';
|
|
12
10
|
import {OutliersSelectionViewer} from './outliers-selection/outliers-selection-viewer';
|
|
11
|
+
import {ModelsWidget} from './models-widget'
|
|
13
12
|
|
|
14
13
|
let initCompleted: boolean = false;
|
|
15
14
|
export const _package = new DG.Package();
|
|
16
15
|
|
|
17
|
-
//name: test
|
|
18
|
-
export function test() {
|
|
19
|
-
grok.shell.info(_package.webRoot);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
//name: manualOutlierDetectionDialog
|
|
23
|
-
//input: dataframe inputData
|
|
24
|
-
//output: dataframe augmentedInput
|
|
25
|
-
//output: dataframe editedInput
|
|
26
|
-
export async function manualOutlierSelectionDialog(inputData: DG.DataFrame) {
|
|
27
|
-
const call = grok.functions.getCurrentCall();
|
|
28
|
-
|
|
29
|
-
const IS_OUTLIER_COL_LABEL = 'isOutlier';
|
|
30
|
-
const OUTLIER_REASON_COL_LABEL = 'Rationale';
|
|
31
|
-
|
|
32
|
-
if (call.options['interactive']) {
|
|
33
|
-
const {augmentedInput, editedInput} = await selectOutliersManually(inputData);
|
|
34
|
-
return {augmentedInput, editedInput};
|
|
35
|
-
}
|
|
36
|
-
return new Promise<{augmentedInput: DG.DataFrame, editedInput: DG.DataFrame}>((resolve, reject) => {
|
|
37
|
-
if (!inputData.columns.byName(IS_OUTLIER_COL_LABEL)) {
|
|
38
|
-
inputData.columns
|
|
39
|
-
.add(DG.Column.fromBitSet(IS_OUTLIER_COL_LABEL, DG.BitSet.create(inputData.rowCount, () => false)));
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (!inputData.columns.byName(OUTLIER_REASON_COL_LABEL)) {
|
|
43
|
-
inputData.columns
|
|
44
|
-
.add(DG.Column.fromStrings(OUTLIER_REASON_COL_LABEL, Array.from({length: inputData.rowCount}, () => '')));
|
|
45
|
-
}
|
|
46
|
-
resolve({augmentedInput: inputData, editedInput: inputData});
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
16
|
//name: OutliersSelectionViewer
|
|
51
17
|
//description: Creates an outliers selection viewer
|
|
52
18
|
//tags: viewer
|
|
@@ -55,6 +21,13 @@ export function OutliersSelection() {
|
|
|
55
21
|
return new OutliersSelectionViewer();
|
|
56
22
|
}
|
|
57
23
|
|
|
24
|
+
|
|
25
|
+
//output: widget result
|
|
26
|
+
//tags: dashboard
|
|
27
|
+
export function modelsWidget(): DG.Widget {
|
|
28
|
+
return new ModelsWidget();
|
|
29
|
+
}
|
|
30
|
+
|
|
58
31
|
//name: Export to Excel
|
|
59
32
|
//input: funccall call
|
|
60
33
|
//tags: export
|
|
@@ -62,75 +35,6 @@ export function exportToExcel(call: DG.FuncCall) {
|
|
|
62
35
|
exportFuncCall(call);
|
|
63
36
|
}
|
|
64
37
|
|
|
65
|
-
//name: Function Editor
|
|
66
|
-
export function functionEditor() {
|
|
67
|
-
const sampleScript = `
|
|
68
|
-
#name: Chemical Space Using tSNE
|
|
69
|
-
#description: Chemical space using t-distributed Stochastic Neighbor Embedding
|
|
70
|
-
#help-url: https://datagrok.ai/help/domains/chem/functions/tsne
|
|
71
|
-
#language: python
|
|
72
|
-
#sample: chem/smiles_coordinates.csv
|
|
73
|
-
#tags: demo, chem, rdkit
|
|
74
|
-
#input: dataframe t1 {columns: numerical; category: test} [first input data table]
|
|
75
|
-
#input: dataframe t2 {columns: numerical} [second input data table]
|
|
76
|
-
#input: column x {type: numerical; table: t1} [x axis column name]
|
|
77
|
-
#input: column y {type: numerical} [y axis column name]
|
|
78
|
-
#input: column date {type: datetime; format: mm/dd/yyyy} [date column name]
|
|
79
|
-
#input: column_list numdata {type :numerical; table:t1} [numerical columns names]
|
|
80
|
-
#input: int numcomp = 2 {min: 2; max: 7; units: mm} [number of components]
|
|
81
|
-
#input: bool center = true [number of components]
|
|
82
|
-
#input: string type = high {choices: ["high", "low"]} [type of filter]
|
|
83
|
-
#output: dataframe result {action: join(t1)} [pca components]
|
|
84
|
-
#output: graphics scatter [scatter plot]
|
|
85
|
-
|
|
86
|
-
import numba
|
|
87
|
-
import hdbscan
|
|
88
|
-
import numpy as np
|
|
89
|
-
import matplotlib.pyplot as plt
|
|
90
|
-
from sklearn.manifold import TSNE
|
|
91
|
-
from rdkit import Chem
|
|
92
|
-
from rdkit.Chem import AllChem
|
|
93
|
-
from rdkit.Chem import Draw
|
|
94
|
-
from rdkit.Chem import DataStructs
|
|
95
|
-
|
|
96
|
-
smiles = data[smiles]
|
|
97
|
-
mols = [Chem.MolFromSmiles(mol) for mol in smiles]
|
|
98
|
-
mols = [mol for mol in mols if mol is not None]
|
|
99
|
-
for mol in mols:
|
|
100
|
-
AllChem.Compute2DCoords(mol)
|
|
101
|
-
X = []
|
|
102
|
-
for mol in mols:
|
|
103
|
-
arr = np.zeros((0,))
|
|
104
|
-
fp = AllChem.GetMorganFingerprintAsBitVect(mol, 2)
|
|
105
|
-
DataStructs.ConvertToNumpyArray(fp, arr)
|
|
106
|
-
X.append(arr)
|
|
107
|
-
|
|
108
|
-
@numba.njit()
|
|
109
|
-
def tanimoto_dist(a, b):
|
|
110
|
-
dotprod = np.dot(a, b)
|
|
111
|
-
tc = dotprod / (np.sum(a) + np.sum(b) - dotprod)
|
|
112
|
-
return 1.0 - tc
|
|
113
|
-
|
|
114
|
-
tsne = TSNE(n_components=components, metric=tanimoto_dist)
|
|
115
|
-
tsne_X = tsne.fit_transform(X)
|
|
116
|
-
cluster_tsne = hdbscan.HDBSCAN(min_cluster_size=minClusterSize, gen_min_span_tree=True)
|
|
117
|
-
cluster_tsne.fit(tsne_X)
|
|
118
|
-
|
|
119
|
-
plt.figure(0)
|
|
120
|
-
cluster_tsne.minimum_spanning_tree_.plot(
|
|
121
|
-
edge_cmap='viridis', edge_alpha=0.6,
|
|
122
|
-
node_size=90, edge_linewidth=2)
|
|
123
|
-
|
|
124
|
-
plt.figure(1)
|
|
125
|
-
cluster_tsne.single_linkage_tree_.plot(cmap='viridis', colorbar=True)
|
|
126
|
-
|
|
127
|
-
plt.figure(2)
|
|
128
|
-
plt.scatter(tsne_X.T[0], tsne_X.T[1], c=cluster_tsne.labels_, cmap='plasma')
|
|
129
|
-
plt.title('Chemical space')
|
|
130
|
-
`;
|
|
131
|
-
_functionEditor(sampleScript);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
38
|
/* eslint-disable */
|
|
135
39
|
|
|
136
40
|
//description: A spreadsheet that lets you interactively edit parameters and evaluate functions
|
package/detectors.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The class contains semantic type detectors.
|
|
3
|
-
* Detectors are functions tagged with `DG.FUNC_TYPES.SEM_TYPE_DETECTOR`.
|
|
4
|
-
* See also: https://datagrok.ai/help/develop/how-to/define-semantic-type-detectors
|
|
5
|
-
* The class name is comprised of <PackageName> and the `PackageDetectors` suffix.
|
|
6
|
-
* Follow this naming convention to ensure that your detectors are properly loaded.
|
|
7
|
-
*/
|
|
8
|
-
class ComputePackageDetectors extends DG.Package {
|
|
9
|
-
}
|