@datagrok/compute 0.6.6 → 0.7.2
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/dist/package.js +1455 -0
- package/package.json +13 -3
- package/scripts/vmax.js +178 -0
- package/scripts/wrapper.js +8 -0
- package/src/function-views/compute-view.ts +162 -0
- package/src/model-catalog-view.ts +2 -3
- package/src/model-handler.ts +20 -18
- package/src/models-widget.ts +119 -0
- package/src/outliers-selection/outliers-selection-viewer.ts +44 -45
- package/src/package.ts +38 -92
- package/src/view-samples/computation-test-view.ts +8 -0
- package/.eslintrc.json +0 -35
- package/detectors.js +0 -9
- package/src/export-funccall.ts +0 -263
- package/src/function-editor/function-editor.ts +0 -615
|
@@ -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,24 +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
|
-
|
|
39
|
-
if (!inputData.columns.byName(IS_OUTLIER_COL_LABEL)) {
|
|
40
|
-
inputData.columns
|
|
41
|
-
.add(DG.Column.fromBitSet(IS_OUTLIER_COL_LABEL, DG.BitSet.create(inputData.rowCount, () => false)));
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (!inputData.columns.byName(OUTLIER_RATIONALE_COL_LABEL)) {
|
|
45
|
-
inputData.columns
|
|
46
|
-
.add(DG.Column.fromStrings(OUTLIER_RATIONALE_COL_LABEL, Array.from({length: inputData.rowCount}, () => '')));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (!inputData.columns.byName(FLUX)) {
|
|
50
|
-
(inputData.columns as DG.ColumnList).addNew(FLUX, 'double').init((index) => (inputData.cell(index, 'time (min)').value/60.0) / ((inputData.cell(index, 'filtrate volume (mL)').value/1000.0) / (DEFAULT_TEST_AREA / 10000.0)));
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const initialData = inputData.clone();
|
|
54
30
|
|
|
55
31
|
const clearTable = () => {
|
|
56
32
|
return DG.DataFrame.fromColumns([
|
|
@@ -75,6 +51,19 @@ export class OutliersSelectionViewer extends DG.JsViewer {
|
|
|
75
51
|
ui.iconFA('check', () => {
|
|
76
52
|
if (!groupsListGrid.dataFrame) return;
|
|
77
53
|
|
|
54
|
+
if (!inputData.columns.byName(IS_OUTLIER_COL_LABEL)) {
|
|
55
|
+
inputData.columns
|
|
56
|
+
.add(DG.Column.fromBitSet(IS_OUTLIER_COL_LABEL, DG.BitSet.create(inputData.rowCount, () => false)));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (!inputData.columns.byName(OUTLIER_RATIONALE_COL_LABEL)) {
|
|
60
|
+
inputData.columns
|
|
61
|
+
.add(DG.Column.fromStrings(OUTLIER_RATIONALE_COL_LABEL, Array.from({length: inputData.rowCount}, () => '')));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
//@ts-ignore
|
|
65
|
+
inputData.col(IS_OUTLIER_COL_LABEL)?.markers.assign('true', DG.MARKER_TYPE.OUTLIER);
|
|
66
|
+
|
|
78
67
|
const newRationale =
|
|
79
68
|
groupsListGrid.dataFrame?.cell(groupsListGrid.dataFrame.rowCount-1, OUTLIER_RATIONALE_COL_LABEL).value;
|
|
80
69
|
|
|
@@ -142,14 +131,30 @@ export class OutliersSelectionViewer extends DG.JsViewer {
|
|
|
142
131
|
});
|
|
143
132
|
|
|
144
133
|
const updateGroupsTable = () => {
|
|
134
|
+
if ((inputData.columns as DG.ColumnList).byName(OUTLIER_RATIONALE_COL_LABEL)) {
|
|
135
|
+
for (let i = 0; i < inputData.rowCount; i++) {
|
|
136
|
+
if (inputData.columns.byName(IS_OUTLIER_COL_LABEL).get(i)) {
|
|
137
|
+
if (inputData.columns.byName(OUTLIER_RATIONALE_COL_LABEL).get(i) === '') {
|
|
138
|
+
(inputData.columns as DG.ColumnList).byName(OUTLIER_RATIONALE_COL_LABEL).set(i, "Manual", false)
|
|
139
|
+
}
|
|
140
|
+
} else {
|
|
141
|
+
if (inputData.columns.byName(OUTLIER_RATIONALE_COL_LABEL).get(i) !== '') {
|
|
142
|
+
(inputData.columns as DG.ColumnList).byName(OUTLIER_RATIONALE_COL_LABEL).set(i, '', false)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
145
148
|
const uniqueValues: {[key:string]: number} = {};
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
149
|
+
if ((inputData.columns as DG.ColumnList).byName(OUTLIER_RATIONALE_COL_LABEL)) {
|
|
150
|
+
for (let i = 0; i < inputData.rowCount; i++) {
|
|
151
|
+
const record = inputData.columns.byName(OUTLIER_RATIONALE_COL_LABEL).get(i);
|
|
152
|
+
const count = uniqueValues[record];
|
|
153
|
+
if (record != '') {
|
|
154
|
+
count ?
|
|
155
|
+
uniqueValues[record]++ :
|
|
156
|
+
uniqueValues[record] = 1;
|
|
157
|
+
}
|
|
153
158
|
}
|
|
154
159
|
}
|
|
155
160
|
groupsListGrid.dataFrame = clearTable();
|
|
@@ -183,14 +188,8 @@ export class OutliersSelectionViewer extends DG.JsViewer {
|
|
|
183
188
|
|
|
184
189
|
updateGroupsTable();
|
|
185
190
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
// ui.p('Hold the “SHIFT” key and start to draw a freehand selection on the plot area'),
|
|
189
|
-
// ], {style: {'white-space': 'pre-wrap'}}),
|
|
190
|
-
// );
|
|
191
|
-
// info.style.marginBottom = '0px';
|
|
192
|
-
|
|
193
|
-
this.root.replaceWith(
|
|
191
|
+
this.root.innerHTML = '';
|
|
192
|
+
this.root.appendChild(
|
|
194
193
|
ui.divV([
|
|
195
194
|
ui.divV([
|
|
196
195
|
groupsListGrid.root,
|
package/src/package.ts
CHANGED
|
@@ -3,21 +3,19 @@ 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 {exportFuncCall} from './export-funccall';
|
|
7
6
|
import {_functionParametersGrid} from './function-views/function-parameters-grid';
|
|
8
7
|
import {ModelCatalogView} from './model-catalog-view';
|
|
9
8
|
import wu from 'wu';
|
|
10
|
-
import {_functionEditor} from './function-editor/function-editor';
|
|
11
9
|
import {OutliersSelectionViewer} from './outliers-selection/outliers-selection-viewer';
|
|
10
|
+
import {ModelsWidget} from './models-widget'
|
|
11
|
+
import {FunctionView} from "@datagrok-libraries/utils/src/function-view";
|
|
12
|
+
import {delay} from "@datagrok-libraries/utils/src/test";
|
|
13
|
+
import {ComputationView} from "@datagrok-libraries/utils/src/computation-view";
|
|
14
|
+
import {ComputeView} from "./function-views/compute-view";
|
|
12
15
|
|
|
13
16
|
let initCompleted: boolean = false;
|
|
14
17
|
export const _package = new DG.Package();
|
|
15
18
|
|
|
16
|
-
//name: test
|
|
17
|
-
export function test() {
|
|
18
|
-
grok.shell.info(_package.webRoot);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
19
|
//name: OutliersSelectionViewer
|
|
22
20
|
//description: Creates an outliers selection viewer
|
|
23
21
|
//tags: viewer
|
|
@@ -26,80 +24,11 @@ export function OutliersSelection() {
|
|
|
26
24
|
return new OutliersSelectionViewer();
|
|
27
25
|
}
|
|
28
26
|
|
|
29
|
-
//name: Export to Excel
|
|
30
|
-
//input: funccall call
|
|
31
|
-
//tags: export
|
|
32
|
-
export function exportToExcel(call: DG.FuncCall) {
|
|
33
|
-
exportFuncCall(call);
|
|
34
|
-
}
|
|
35
27
|
|
|
36
|
-
//
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
#description: Chemical space using t-distributed Stochastic Neighbor Embedding
|
|
41
|
-
#help-url: https://datagrok.ai/help/domains/chem/functions/tsne
|
|
42
|
-
#language: python
|
|
43
|
-
#sample: chem/smiles_coordinates.csv
|
|
44
|
-
#tags: demo, chem, rdkit
|
|
45
|
-
#input: dataframe t1 {columns: numerical; category: test} [first input data table]
|
|
46
|
-
#input: dataframe t2 {columns: numerical} [second input data table]
|
|
47
|
-
#input: column x {type: numerical; table: t1} [x axis column name]
|
|
48
|
-
#input: column y {type: numerical} [y axis column name]
|
|
49
|
-
#input: column date {type: datetime; format: mm/dd/yyyy} [date column name]
|
|
50
|
-
#input: column_list numdata {type :numerical; table:t1} [numerical columns names]
|
|
51
|
-
#input: int numcomp = 2 {min: 2; max: 7; units: mm} [number of components]
|
|
52
|
-
#input: bool center = true [number of components]
|
|
53
|
-
#input: string type = high {choices: ["high", "low"]} [type of filter]
|
|
54
|
-
#output: dataframe result {action: join(t1)} [pca components]
|
|
55
|
-
#output: graphics scatter [scatter plot]
|
|
56
|
-
|
|
57
|
-
import numba
|
|
58
|
-
import hdbscan
|
|
59
|
-
import numpy as np
|
|
60
|
-
import matplotlib.pyplot as plt
|
|
61
|
-
from sklearn.manifold import TSNE
|
|
62
|
-
from rdkit import Chem
|
|
63
|
-
from rdkit.Chem import AllChem
|
|
64
|
-
from rdkit.Chem import Draw
|
|
65
|
-
from rdkit.Chem import DataStructs
|
|
66
|
-
|
|
67
|
-
smiles = data[smiles]
|
|
68
|
-
mols = [Chem.MolFromSmiles(mol) for mol in smiles]
|
|
69
|
-
mols = [mol for mol in mols if mol is not None]
|
|
70
|
-
for mol in mols:
|
|
71
|
-
AllChem.Compute2DCoords(mol)
|
|
72
|
-
X = []
|
|
73
|
-
for mol in mols:
|
|
74
|
-
arr = np.zeros((0,))
|
|
75
|
-
fp = AllChem.GetMorganFingerprintAsBitVect(mol, 2)
|
|
76
|
-
DataStructs.ConvertToNumpyArray(fp, arr)
|
|
77
|
-
X.append(arr)
|
|
78
|
-
|
|
79
|
-
@numba.njit()
|
|
80
|
-
def tanimoto_dist(a, b):
|
|
81
|
-
dotprod = np.dot(a, b)
|
|
82
|
-
tc = dotprod / (np.sum(a) + np.sum(b) - dotprod)
|
|
83
|
-
return 1.0 - tc
|
|
84
|
-
|
|
85
|
-
tsne = TSNE(n_components=components, metric=tanimoto_dist)
|
|
86
|
-
tsne_X = tsne.fit_transform(X)
|
|
87
|
-
cluster_tsne = hdbscan.HDBSCAN(min_cluster_size=minClusterSize, gen_min_span_tree=True)
|
|
88
|
-
cluster_tsne.fit(tsne_X)
|
|
89
|
-
|
|
90
|
-
plt.figure(0)
|
|
91
|
-
cluster_tsne.minimum_spanning_tree_.plot(
|
|
92
|
-
edge_cmap='viridis', edge_alpha=0.6,
|
|
93
|
-
node_size=90, edge_linewidth=2)
|
|
94
|
-
|
|
95
|
-
plt.figure(1)
|
|
96
|
-
cluster_tsne.single_linkage_tree_.plot(cmap='viridis', colorbar=True)
|
|
97
|
-
|
|
98
|
-
plt.figure(2)
|
|
99
|
-
plt.scatter(tsne_X.T[0], tsne_X.T[1], c=cluster_tsne.labels_, cmap='plasma')
|
|
100
|
-
plt.title('Chemical space')
|
|
101
|
-
`;
|
|
102
|
-
_functionEditor(sampleScript);
|
|
28
|
+
//output: widget result
|
|
29
|
+
//tags: dashboard
|
|
30
|
+
export function modelsWidget(): DG.Widget {
|
|
31
|
+
return new ModelsWidget();
|
|
103
32
|
}
|
|
104
33
|
|
|
105
34
|
/* eslint-disable */
|
|
@@ -200,8 +129,8 @@ export function init() {
|
|
|
200
129
|
}).root;
|
|
201
130
|
});
|
|
202
131
|
|
|
203
|
-
grok.events.onViewAdding.subscribe((v: DG.
|
|
204
|
-
if (v
|
|
132
|
+
grok.events.onViewAdding.subscribe((v: DG.ViewBase) => {
|
|
133
|
+
if (v.type == 'function' && (v as FunctionView).func?.hasTag("model")) {
|
|
205
134
|
let modelsView = wu(grok.shell.views).find((v) => v.parentCall?.func.name == 'modelCatalog');
|
|
206
135
|
if (modelsView != undefined) {
|
|
207
136
|
v.parentCall = modelsView!.parentCall;
|
|
@@ -215,14 +144,31 @@ export function init() {
|
|
|
215
144
|
}
|
|
216
145
|
|
|
217
146
|
//name: Model Catalog
|
|
218
|
-
//
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
147
|
+
// export function modelCatalog() {
|
|
148
|
+
// /* let view = new DG.MultiView({
|
|
149
|
+
// viewFactories: {
|
|
150
|
+
// 'Models': {factory: () => new ModelCatalogView(), allowClose: false}
|
|
151
|
+
// }
|
|
152
|
+
// });*/
|
|
153
|
+
// let view = new ModelCatalogView();
|
|
154
|
+
// view.name = 'Models';
|
|
155
|
+
// grok.shell.addView(view);
|
|
156
|
+
// }
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
//name: computationTest
|
|
160
|
+
//input: int delayMs {description: Wait time; units: ms}
|
|
161
|
+
//input: string error {description: When specified, throws this error}
|
|
162
|
+
//output: dataframe result
|
|
163
|
+
export async function computationTest(delayMs: number, error: string): Promise<DG.DataFrame> {
|
|
164
|
+
await delay(delayMs);
|
|
165
|
+
if (error != null || error != '')
|
|
166
|
+
throw error;
|
|
167
|
+
return grok.data.demo.demog();
|
|
228
168
|
}
|
|
169
|
+
|
|
170
|
+
//name: testComputationView();
|
|
171
|
+
export function testComputationView() {
|
|
172
|
+
let f = DG.Func.find({name: 'computationTest'})[0];
|
|
173
|
+
grok.shell.addView(new ComputeView(f));
|
|
174
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
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 {ComputationView} from "@datagrok-libraries/utils/src/computation-view";
|
|
5
|
+
|
|
6
|
+
export class ComputationTestView extends ComputationView {
|
|
7
|
+
|
|
8
|
+
}
|
package/.eslintrc.json
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"env": {
|
|
3
|
-
"browser": true,
|
|
4
|
-
"es2021": true
|
|
5
|
-
},
|
|
6
|
-
"extends": [
|
|
7
|
-
"google"
|
|
8
|
-
],
|
|
9
|
-
"parserOptions": {
|
|
10
|
-
"ecmaVersion": 12,
|
|
11
|
-
"sourceType": "module"
|
|
12
|
-
},
|
|
13
|
-
"rules": {
|
|
14
|
-
"indent": [
|
|
15
|
-
"error",
|
|
16
|
-
2
|
|
17
|
-
],
|
|
18
|
-
"max-len": [
|
|
19
|
-
"error",
|
|
20
|
-
120,
|
|
21
|
-
{ "ignoreStrings": true }
|
|
22
|
-
],
|
|
23
|
-
"require-jsdoc": "off",
|
|
24
|
-
"spaced-comment": "off",
|
|
25
|
-
"valid-jsdoc": [
|
|
26
|
-
"error",
|
|
27
|
-
{ "requireParamType": false,
|
|
28
|
-
"requireReturnType": false }
|
|
29
|
-
]
|
|
30
|
-
},
|
|
31
|
-
"parser": "@typescript-eslint/parser",
|
|
32
|
-
"plugins": [
|
|
33
|
-
"@typescript-eslint"
|
|
34
|
-
]
|
|
35
|
-
}
|
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
|
-
}
|
package/src/export-funccall.ts
DELETED
|
@@ -1,263 +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
|
-
// UWAGA: very fragile solution
|
|
68
|
-
const funcView = document.getElementsByClassName('grok-view grok-view-func ui-box')[0];
|
|
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));
|
|
76
|
-
|
|
77
|
-
const titleDivs = document.getElementsByClassName('grok-func-results-header');
|
|
78
|
-
if (!titleDivs.length) continue;
|
|
79
|
-
let skipNext = false;
|
|
80
|
-
|
|
81
|
-
for (let i = 0; i < titleDivs.length; i++) {
|
|
82
|
-
if (skipNext) {
|
|
83
|
-
skipNext = false;
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
const titleDiv = titleDivs[i];
|
|
87
|
-
if (titleDiv.parentElement?.style.display === 'none') continue;
|
|
88
|
-
|
|
89
|
-
const visibleTitle = titleDiv.firstChild?.textContent;
|
|
90
|
-
if (visibleTitle === null || visibleTitle === undefined) continue;
|
|
91
|
-
|
|
92
|
-
let imageId;
|
|
93
|
-
let width = 0;
|
|
94
|
-
let height = 0;
|
|
95
|
-
|
|
96
|
-
const imageDiv = titleDiv.parentElement?.getElementsByClassName('grok-scripting-image-container')[0];
|
|
97
|
-
if (imageDiv) {
|
|
98
|
-
const regex = /background-image: url\(.*\)/;
|
|
99
|
-
const urlAttr = imageDiv.outerHTML.match(regex)?.[0];
|
|
100
|
-
if (!urlAttr) continue;
|
|
101
|
-
const url = urlAttr.substring(23, urlAttr?.length - 2);
|
|
102
|
-
const pic = (await (await fetch(url)).arrayBuffer());
|
|
103
|
-
imageId = exportWorkbook.addImage({
|
|
104
|
-
buffer: pic,
|
|
105
|
-
extension: 'png',
|
|
106
|
-
});
|
|
107
|
-
width = imageDiv.clientWidth;
|
|
108
|
-
height = imageDiv.clientHeight;
|
|
109
|
-
} else {
|
|
110
|
-
let plotDiv: ChildNode | null | undefined = titleDiv.nextSibling;
|
|
111
|
-
|
|
112
|
-
if (plotDiv && !titleDiv.getElementsByClassName('svg-table').length && (plotDiv as HTMLElement).getAttribute('name') === 'viewer-Grid') continue;
|
|
113
|
-
|
|
114
|
-
if (plotDiv && titleDiv.getElementsByClassName('svg-table').length) {
|
|
115
|
-
if ((plotDiv as HTMLElement).getAttribute('name') === 'viewer-OutliersSelectionViewer') {
|
|
116
|
-
plotDiv = titleDiv.parentElement?.nextSibling?.firstChild?.nextSibling;
|
|
117
|
-
skipNext = true;
|
|
118
|
-
}
|
|
119
|
-
if ((plotDiv as HTMLElement).getAttribute('name') === 'viewer-Grid') {
|
|
120
|
-
(titleDiv.getElementsByClassName('svg-table')[0] as HTMLElement).click();
|
|
121
|
-
await new Promise((r) => setTimeout(r, 150));
|
|
122
|
-
plotDiv = titleDiv.nextSibling;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
console.log(plotDiv);
|
|
126
|
-
|
|
127
|
-
if (plotDiv) {
|
|
128
|
-
const plot = (plotDiv as HTMLElement).getElementsByClassName('d4-layout-middle')[0];
|
|
129
|
-
const canvas = await DG.HtmlUtils.renderToCanvas(plot as HTMLElement);
|
|
130
|
-
const dataUrl = canvas.toDataURL('image/png');
|
|
131
|
-
|
|
132
|
-
imageId = exportWorkbook.addImage({
|
|
133
|
-
base64: dataUrl,
|
|
134
|
-
extension: 'png',
|
|
135
|
-
});
|
|
136
|
-
width = canvas.width;
|
|
137
|
-
height = canvas.height;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
if (imageId === null || imageId === undefined) continue;
|
|
142
|
-
|
|
143
|
-
const worksheet = exportWorkbook.getWorksheet(getSheetName(visibleTitle, DIRECTION.INPUT)) ||
|
|
144
|
-
exportWorkbook.getWorksheet(getSheetName(visibleTitle, DIRECTION.OUTPUT));
|
|
145
|
-
if (worksheet) {
|
|
146
|
-
console.log(visibleTitle);
|
|
147
|
-
console.log(realNames[visibleTitle]);
|
|
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
|
-
}
|
|
164
|
-
}
|
|
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
|
-
|
|
172
|
-
for (let i=0; i< titleDivs.length; i++) {
|
|
173
|
-
if (skipNext) {
|
|
174
|
-
skipNext = false;
|
|
175
|
-
continue;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
const titleDiv = titleDivs[i];
|
|
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];
|
|
187
|
-
if (imageDiv) {
|
|
188
|
-
const regex = /background-image: url\(.*\)/;
|
|
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;
|
|
199
|
-
} else {
|
|
200
|
-
let plotDiv: ChildNode | null | undefined = titleDiv.nextSibling;
|
|
201
|
-
if (plotDiv &&
|
|
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
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
if (imageId === null || imageId === undefined) continue;
|
|
227
|
-
|
|
228
|
-
const worksheet = exportWorkbook.getWorksheet(getSheetName(visibleTitle, DIRECTION.OUTPUT));
|
|
229
|
-
if (worksheet) {
|
|
230
|
-
const columnForImage = ((call
|
|
231
|
-
.outputs[realNames[visibleTitle]] as DG.DataFrame)
|
|
232
|
-
.columns as DG.ColumnList)
|
|
233
|
-
.length + 1;
|
|
234
|
-
worksheet.addImage(imageId, {
|
|
235
|
-
tl: {col: columnForImage, row: 0},
|
|
236
|
-
ext: {width, height},
|
|
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
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
if (scalarOutputs.length) {
|
|
249
|
-
const outputScalarsSheet = exportWorkbook.addWorksheet('Output scalars');
|
|
250
|
-
scalarOutputs.forEach((scalarOutput) => {
|
|
251
|
-
outputScalarsSheet.addRow([scalarOutput.name, call.outputs[scalarOutput.name]]);
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
const metadataSheet = exportWorkbook.addWorksheet('Function run metadata');
|
|
256
|
-
metadataSheet.addRow(['Author', `${call.func.author.lastName} ${call.func.author.firstName}`]);
|
|
257
|
-
metadataSheet.addRow(['Login', call.func.author.toString()]);
|
|
258
|
-
|
|
259
|
-
exportWorkbook.xlsx.writeBuffer().then((data) => {
|
|
260
|
-
const blob = new Blob([data], {type: BLOB_TYPE});
|
|
261
|
-
saveAs(blob, `${call.func.name} - ${new Date().toLocaleString()}`);
|
|
262
|
-
});
|
|
263
|
-
}
|