@datagrok/compute 1.16.1 → 1.17.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/CHANGELOG.md +14 -0
- package/dist/package.js +1 -1
- package/dist/package.js.map +1 -1
- package/package.json +2 -2
- package/src/css/model-card.css +1 -1
- package/src/package.ts +19 -118
- package/files/default_data.csv +0 -2425
- package/scripts/trig.js +0 -15
- package/scripts/vmax.js +0 -179
- package/scripts/wrapper.js +0 -8
- package/src/function-parameters-grid.ts +0 -63
- package/src/import-script-generator/store.ts +0 -12
- package/src/import-script-generator/view.ts +0 -185
- package/src/model-catalog-view.ts +0 -84
- package/src/model-handler.ts +0 -165
- package/src/models-widget.ts +0 -118
package/scripts/trig.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
//name: trig
|
|
2
|
-
//description: Returns sin, cos, and tan
|
|
3
|
-
//language: javascript
|
|
4
|
-
//input: double x
|
|
5
|
-
//output: double sin
|
|
6
|
-
//output: double cos
|
|
7
|
-
//output: double tan
|
|
8
|
-
//meta.domain: math
|
|
9
|
-
//meta.runOnOpen: true
|
|
10
|
-
//meta.runOnInput: true
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
sin = Math.sin(x);
|
|
14
|
-
cos = Math.cos(x);
|
|
15
|
-
tan = Math.tan(x);
|
package/scripts/vmax.js
DELETED
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
//name: Vmax
|
|
2
|
-
//description: Predict the minimum filter size required for the separation of effluent from bioreactors, given the constraints of batch size and total batch time based on a training dataset of time vs filtrate volume for a given filter type, filter area and pressure
|
|
3
|
-
//language: javascript
|
|
4
|
-
//tags: filtration, scale-up, model
|
|
5
|
-
//meta.status: Upstream
|
|
6
|
-
//input: dataframe inputTable {caption: Input table; viewer: OutliersSelectionViewer(block: 25) | Scatter Plot(y: "t/V (hr/(L/m²))", block: 75, filter: "!${isOutlier}", showFilteredOutPoints: "true", filteredOutRowsColor: 4293991195, showRegressionLine: "true", markers: "isOutlier", lassoTool: "true", legendVisibility: "Never", filterByZoom: "false")}
|
|
7
|
-
//input: dataframe reportingParameters {caption: Reporting parameters; viewer: Grid()}
|
|
8
|
-
//input: double testFilterArea = 3.5 {caption: Test filter area; units: cm²} [Test filter area]
|
|
9
|
-
//input: double desiredVolumeOfBatch = 25 {caption: Desired batch volume; units: L} [Desired batch volume]
|
|
10
|
-
//input: double desiredProcessTime = 0.5 {caption: Desired process time; units: hr} [Desired process time]
|
|
11
|
-
//input: double sf = 1.5 {caption: Safety factor} [Safety factor]
|
|
12
|
-
//help-url: https://github.com/datagrok-ai/public/blob/master/packages/Compute/src/help.md
|
|
13
|
-
//output: dataframe filtrationKinetics {caption: Filtration kinetics; viewer: Scatter Plot(block: 75, filter: "!${isOutlier}", markers: "isOutlier", showFilteredOutPoints: "true", filteredOutRowsColor: 4293991195, showRegressionLine: "true", legendVisibility: "Never"); category: OUTPUT}
|
|
14
|
-
//output: dataframe trialData {caption: Trial data; viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); category: OUTPUT}
|
|
15
|
-
//output: dataframe fluxDecayDf {caption: Flux decay experimental results; viewer: Scatter Plot(description: "Absolute flux decay", y: "Flux", block: 50, filter: "!${isOutlier}", markers: "isOutlier", showFilteredOutPoints: "true", filteredOutRowsColor: 4293991195, legendVisibility: "Never") | Scatter Plot(description: "Relative flux decay", y: "Rel Flux", block: 50, filter: "!${isOutlier}", markers: "isOutlier", showFilteredOutPoints: "true", filteredOutRowsColor: 4293991195, legendVisibility: "Never"); category: OUTPUT}
|
|
16
|
-
//output: dataframe experimentalResultsSummary {viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); caption: Experimental results summary; category: OUTPUT}
|
|
17
|
-
//output: dataframe recommendations {viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); caption: Recommendations; category: OUTPUT}
|
|
18
|
-
//output: dataframe sampleCharacteristics {viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); caption: Sample characteristics; category: OUTPUT}
|
|
19
|
-
//output: dataframe filter {viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); caption: Filter; category: OUTPUT}
|
|
20
|
-
//editor: Compute:ComputationView
|
|
21
|
-
//meta.runOnOpen: true
|
|
22
|
-
//meta.runOnInput: true
|
|
23
|
-
|
|
24
|
-
const COL_NAMES = {
|
|
25
|
-
INPUT_TIME_IN_MINUTES: "time (min)",
|
|
26
|
-
INPUT_VOLUME_IN_MILLILITERS: "filtrate volume (mL)",
|
|
27
|
-
INPUT_IS_OUTLIER: "isOutlier",
|
|
28
|
-
TIME_IN_HOURS: "Time [hr]",
|
|
29
|
-
TRIAL_THROUGHPUT: "Throughput [L/m²]",
|
|
30
|
-
T_V: "Time/volume/area [hr/L/m²]",
|
|
31
|
-
FLOW_RATE: "Flow rate",
|
|
32
|
-
FLUX: "Flux",
|
|
33
|
-
RELATIVE_FLUX: "Rel Flux"
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const PARAM_NAMES = {
|
|
37
|
-
FILTER_FAMILY: "Filter family",
|
|
38
|
-
FILTER_NAME: "Filter name",
|
|
39
|
-
PORE_RATING: "Pore rating (μm)",
|
|
40
|
-
EFFECTIVE_MEMBR_AREA: "Effective membr. area (cm^2)",
|
|
41
|
-
MEMBR_MATERIAL: "Membr material",
|
|
42
|
-
CATALOG_NR: "Catalog nr",
|
|
43
|
-
DATE: "Date",
|
|
44
|
-
PRIOR_STEP: "Prior step",
|
|
45
|
-
PROT_CONC: "Prot conc. (mg/mL)",
|
|
46
|
-
DENSITY: "Density (g/L)",
|
|
47
|
-
TURBIDITY: "Turbidity (NTU)",
|
|
48
|
-
INSTALLED_DEVICE: "Installed device",
|
|
49
|
-
PROJECT_NAME: "Project name", // PARAMETERS BELOW ARE NOT USED
|
|
50
|
-
FILTRATION_STAGE: "Filtration stage",
|
|
51
|
-
ELN_REFERENCE: "ELN reference",
|
|
52
|
-
BIOREACTOR_ID: "Bioreactor ID",
|
|
53
|
-
BIOREACTOR_PCV: "Bioreactor PCV (%)",
|
|
54
|
-
BIOREACTOR_TURBIDITY: "Bioreactor turbidity (NTU)",
|
|
55
|
-
FILTER_FEED_TURBIDITY: "Filter feed turbidity (NTU)",
|
|
56
|
-
FILTER_FEED_PCV: "Filter feed PCV (%)",
|
|
57
|
-
FILTER_FEED_PH: "Filter feed pH",
|
|
58
|
-
FILTER_FEED_LDH: "Filter feed LDH (U/L)",
|
|
59
|
-
FILTER_FEED_CONDUCTIVITY: "Filter feed conductivity (mS/cm)"
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
function linearRegression(x, y) {
|
|
63
|
-
let sum_x = 0, sum_y = 0, sum_xy = 0, sum_xx = 0;
|
|
64
|
-
for (let i = 0; i < y.length; i++) {
|
|
65
|
-
sum_x += x[i];
|
|
66
|
-
sum_y += y[i];
|
|
67
|
-
sum_xy += x[i] * y[i];
|
|
68
|
-
sum_xx += x[i] * x[i];
|
|
69
|
-
}
|
|
70
|
-
const slope = (y.length * sum_xy - sum_x * sum_y) / (y.length * sum_xx - sum_x * sum_x);
|
|
71
|
-
const intercept = (sum_y - slope * sum_x) / y.length;
|
|
72
|
-
return { slope: slope, intercept: intercept };
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const timeInMinutes = inputTable.col(COL_NAMES.INPUT_TIME_IN_MINUTES);
|
|
76
|
-
const volumeInMilliliters = inputTable.col(COL_NAMES.INPUT_VOLUME_IN_MILLILITERS);
|
|
77
|
-
const isOutlier = inputTable.col(COL_NAMES.INPUT_IS_OUTLIER);
|
|
78
|
-
|
|
79
|
-
let df = DG.DataFrame.fromColumns([timeInMinutes, volumeInMilliliters, isOutlier]);
|
|
80
|
-
|
|
81
|
-
df.columns.addNewFloat(COL_NAMES.TIME_IN_HOURS).init((i) => timeInMinutes.get(i) / 60);
|
|
82
|
-
const timeInHours = df.col(COL_NAMES.TIME_IN_HOURS);
|
|
83
|
-
|
|
84
|
-
df.columns.addNewFloat(COL_NAMES.TRIAL_THROUGHPUT).init((i) => 10 * volumeInMilliliters.get(i) / testFilterArea);
|
|
85
|
-
const trialThroughputCol = df.col(COL_NAMES.TRIAL_THROUGHPUT);
|
|
86
|
-
|
|
87
|
-
df.columns.addNewFloat(COL_NAMES.T_V).init((i) => timeInHours.get(i) / trialThroughputCol.get(i));
|
|
88
|
-
const tv = df.col(COL_NAMES.T_V);
|
|
89
|
-
|
|
90
|
-
df.columns.addNewFloat(COL_NAMES.FLOW_RATE).init((i) => (i > 0) ?
|
|
91
|
-
0.06 * (volumeInMilliliters.get(i) - volumeInMilliliters.get(i - 1)) / (timeInMinutes.get(i) - timeInMinutes.get(i - 1)) : 0
|
|
92
|
-
);
|
|
93
|
-
const flowRate = df.col(COL_NAMES.FLOW_RATE);
|
|
94
|
-
|
|
95
|
-
df.columns.addNewFloat(COL_NAMES.FLUX).init((i) => 10000 * flowRate.get(i) / testFilterArea);
|
|
96
|
-
const flux = df.col(COL_NAMES.FLUX);
|
|
97
|
-
|
|
98
|
-
df.columns.addNewFloat(COL_NAMES.RELATIVE_FLUX).init((i) => flux.get(i) / flux.get(1));
|
|
99
|
-
const relativeFlux = df.col(COL_NAMES.RELATIVE_FLUX);
|
|
100
|
-
|
|
101
|
-
fluxDecayDf = DG.DataFrame.fromColumns([
|
|
102
|
-
DG.Column.fromFloat32Array(COL_NAMES.TRIAL_THROUGHPUT, df.col(COL_NAMES.TRIAL_THROUGHPUT).toList().slice(1)),
|
|
103
|
-
DG.Column.fromFloat32Array(COL_NAMES.FLUX, df.col(COL_NAMES.FLUX).toList().slice(1)),
|
|
104
|
-
DG.Column.fromFloat32Array(COL_NAMES.RELATIVE_FLUX, df.col(COL_NAMES.RELATIVE_FLUX).toList().slice(1)),
|
|
105
|
-
DG.Column.fromList(DG.COLUMN_TYPE.BOOL, isOutlier.name, isOutlier.toList().slice(1))
|
|
106
|
-
]);
|
|
107
|
-
|
|
108
|
-
filtrationKinetics = DG.DataFrame.fromColumns([
|
|
109
|
-
timeInHours,
|
|
110
|
-
df.col(COL_NAMES.T_V),
|
|
111
|
-
volumeInMilliliters,
|
|
112
|
-
isOutlier
|
|
113
|
-
]);
|
|
114
|
-
|
|
115
|
-
df.col(COL_NAMES.INPUT_IS_OUTLIER).markers.assign('true', DG.MARKER_TYPE.OUTLIER);
|
|
116
|
-
filtrationKinetics.col(COL_NAMES.INPUT_IS_OUTLIER).markers.assign('true', DG.MARKER_TYPE.OUTLIER);
|
|
117
|
-
|
|
118
|
-
for (let i = df.rowCount - 1; i > -1; i--)
|
|
119
|
-
if (isOutlier.get(i))
|
|
120
|
-
df.rows.removeAt(i, 1, false);
|
|
121
|
-
|
|
122
|
-
const coefficients = linearRegression(df.col(COL_NAMES.TIME_IN_HOURS).toList(), df.col(COL_NAMES.T_V).toList());
|
|
123
|
-
const vmax = 1 / coefficients.slope;
|
|
124
|
-
const j0 = 1 / coefficients.intercept;
|
|
125
|
-
const flux0 = flux.get(1);
|
|
126
|
-
const amin = desiredVolumeOfBatch / vmax + desiredVolumeOfBatch / desiredProcessTime / j0;
|
|
127
|
-
const installedArea = sf * amin;
|
|
128
|
-
const processLoading = desiredVolumeOfBatch / installedArea;
|
|
129
|
-
const trialThroughput = df.col(COL_NAMES.TRIAL_THROUGHPUT).get(df.rowCount - 1);
|
|
130
|
-
const fluxDecay = (1 - df.col(COL_NAMES.RELATIVE_FLUX).get(df.rowCount - 1)) * 100;
|
|
131
|
-
const initialFlowRate = flowRate.get(1);
|
|
132
|
-
const meanFlux = flux.stats.avg * df.rowCount / (df.rowCount - 1); // exclude zero from calculation
|
|
133
|
-
|
|
134
|
-
const names = reportingParameters.col('Parameter name').toList();
|
|
135
|
-
const values = reportingParameters.col('Parameter value').toList();
|
|
136
|
-
|
|
137
|
-
experimentalResultsSummary = DG.DataFrame.fromObjects([
|
|
138
|
-
{ Name: 'Run', Value: '1' },
|
|
139
|
-
{ Name: 'Filter', Value: values[names.indexOf(PARAM_NAMES.FILTER_FAMILY)] },
|
|
140
|
-
{ Name: 'Trial Throughput [L/m²]', Value: Math.round(1000 * trialThroughput) / 1000 },
|
|
141
|
-
{ Name: 'Flux0 [LMH]', Value: Math.round(1000 * flux0) / 1000 },
|
|
142
|
-
{ Name: 'Mean Flux [LMH]', Value: Math.round(1000 * meanFlux) / 1000 },
|
|
143
|
-
{ Name: 'Vmax [L/m²]', Value: Math.round(1000 * vmax) / 1000 },
|
|
144
|
-
{ Name: 'Flux Decay [%]', Value: Math.round(1000 * fluxDecay) / 1000 }
|
|
145
|
-
]);
|
|
146
|
-
|
|
147
|
-
recommendations = DG.DataFrame.fromObjects([
|
|
148
|
-
{ Name: 'Volume [L]', Value: desiredVolumeOfBatch },
|
|
149
|
-
{ Name: 'Time [h]', Value: desiredProcessTime },
|
|
150
|
-
{ Name: 'Amin [m²]', Value: Math.round(1000 * amin) / 1000 },
|
|
151
|
-
{ Name: 'Safety Factor', Value: sf },
|
|
152
|
-
{ Name: 'Installed Area', Value: Math.round(1000 * installedArea) / 1000 },
|
|
153
|
-
{ Name: 'Process Loading [L/m²]', Value: Math.round(1000 * processLoading) / 1000 },
|
|
154
|
-
{ Name: PARAM_NAMES.FILTER_FAMILY, Value: values[names.indexOf(PARAM_NAMES.FILTER_FAMILY)] },
|
|
155
|
-
{ Name: PARAM_NAMES.INSTALLED_DEVICE, Value: values[names.indexOf(PARAM_NAMES.INSTALLED_DEVICE)] }
|
|
156
|
-
]);
|
|
157
|
-
|
|
158
|
-
trialData = DG.DataFrame.fromObjects([
|
|
159
|
-
{ Name: 'Test Filter Area [cm²]', Value: testFilterArea },
|
|
160
|
-
{ Name: 'Initial Flow Rate [L/h]', Value: Math.round(1000 * initialFlowRate) / 1000 },
|
|
161
|
-
{ Name: 'Vmax [L/m²]', Value: Math.round(1000 * vmax) / 1000 }
|
|
162
|
-
]);
|
|
163
|
-
|
|
164
|
-
filter = DG.DataFrame.fromObjects([
|
|
165
|
-
{ Name: PARAM_NAMES.FILTER_FAMILY, Value: values[names.indexOf(PARAM_NAMES.FILTER_FAMILY)] },
|
|
166
|
-
{ Name: PARAM_NAMES.FILTER_NAME, Value: values[names.indexOf(PARAM_NAMES.FILTER_NAME)] },
|
|
167
|
-
{ Name: PARAM_NAMES.PORE_RATING, Value: values[names.indexOf(PARAM_NAMES.PORE_RATING)] },
|
|
168
|
-
{ Name: PARAM_NAMES.EFFECTIVE_MEMBR_AREA, Value: values[names.indexOf(PARAM_NAMES.EFFECTIVE_MEMBR_AREA)] },
|
|
169
|
-
{ Name: PARAM_NAMES.MEMBR_MATERIAL, Value: values[names.indexOf(PARAM_NAMES.MEMBR_MATERIAL)] },
|
|
170
|
-
{ Name: PARAM_NAMES.CATALOG_NR, Value: values[names.indexOf(PARAM_NAMES.CATALOG_NR)] }
|
|
171
|
-
]);
|
|
172
|
-
|
|
173
|
-
sampleCharacteristics = DG.DataFrame.fromObjects([
|
|
174
|
-
{ Name: PARAM_NAMES.DATE, Value: values[names.indexOf(PARAM_NAMES.DATE)].slice(0, 10) },
|
|
175
|
-
{ Name: PARAM_NAMES.PRIOR_STEP, Value: values[names.indexOf(PARAM_NAMES.PRIOR_STEP)] },
|
|
176
|
-
{ Name: PARAM_NAMES.PROT_CONC, Value: values[names.indexOf(PARAM_NAMES.PROT_CONC)] },
|
|
177
|
-
{ Name: PARAM_NAMES.DENSITY, Value: values[names.indexOf(PARAM_NAMES.DENSITY)].slice(0, 5) },
|
|
178
|
-
{ Name: PARAM_NAMES.TURBIDITY, Value: values[names.indexOf(PARAM_NAMES.TURBIDITY)] }
|
|
179
|
-
]);
|
package/scripts/wrapper.js
DELETED
|
@@ -1,63 +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
|
-
|
|
5
|
-
//description: A spreadsheet that lets you interactively edit parameters and evaluate functions
|
|
6
|
-
//tags: functionAnalysis
|
|
7
|
-
//input: func f
|
|
8
|
-
//output: view result
|
|
9
|
-
export function _functionParametersGrid(f: DG.Func): DG.View {
|
|
10
|
-
|
|
11
|
-
let view = DG.View.create();
|
|
12
|
-
let gridHost = ui.div();
|
|
13
|
-
let functionName = ui.stringInput('Function', f.name);
|
|
14
|
-
|
|
15
|
-
view.root.appendChild(functionName.root);
|
|
16
|
-
view.root.appendChild(gridHost);
|
|
17
|
-
|
|
18
|
-
function init() {
|
|
19
|
-
view.name = f.name;
|
|
20
|
-
ui.empty(gridHost);
|
|
21
|
-
|
|
22
|
-
let table = DG.DataFrame.fromProperties(f.inputs.concat(f.outputs), 5);
|
|
23
|
-
let grid = DG.Grid.create(table);
|
|
24
|
-
let calculating: boolean = false;
|
|
25
|
-
|
|
26
|
-
function refreshRow(row: number) {
|
|
27
|
-
for (let i = 0; i < f.inputs.length; i++)
|
|
28
|
-
if (table.columns.byIndex(i).isNone(row))
|
|
29
|
-
return;
|
|
30
|
-
|
|
31
|
-
let params: any = {};
|
|
32
|
-
for (let p of f.inputs)
|
|
33
|
-
params[p.name] = table.col(p.name)!.get(row);
|
|
34
|
-
|
|
35
|
-
calculating = true;
|
|
36
|
-
let call = f.prepare(params);
|
|
37
|
-
call.call().then(c => {
|
|
38
|
-
for (let p of f.outputs)
|
|
39
|
-
table.col(p.name)!.set(row, call.outputs[p.name]);
|
|
40
|
-
calculating = false;
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
grid.onCellValueEdited.subscribe(gc => refreshRow(gc.tableRow?.idx!));
|
|
45
|
-
gridHost.appendChild(grid.root);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
init();
|
|
49
|
-
functionName.onChanged(() => {
|
|
50
|
-
DG.Func
|
|
51
|
-
.findAll({name: functionName.value})
|
|
52
|
-
.then(funcs => {
|
|
53
|
-
if (funcs.length == 1) {
|
|
54
|
-
f = funcs[0];
|
|
55
|
-
init();
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
// ;
|
|
59
|
-
// if (f !== null)
|
|
60
|
-
// init();
|
|
61
|
-
});
|
|
62
|
-
return view;
|
|
63
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import * as rxjs from "rxjs";
|
|
2
|
-
|
|
3
|
-
export class ImportGeneratorStore {
|
|
4
|
-
scriptName: string = '';
|
|
5
|
-
description: string = '';
|
|
6
|
-
dfSheetsToSeek: string[] = [];
|
|
7
|
-
scalarsToSeek: string[] = []
|
|
8
|
-
|
|
9
|
-
scriptText = new rxjs.BehaviorSubject('');
|
|
10
|
-
infoText = new rxjs.BehaviorSubject('');
|
|
11
|
-
lastSavedScriptId = new rxjs.BehaviorSubject('');
|
|
12
|
-
}
|
|
@@ -1,185 +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 { ImportGeneratorStore } from './store';
|
|
5
|
-
|
|
6
|
-
export class ImportScriptGeneratorApp extends DG.ViewBase {
|
|
7
|
-
store = new ImportGeneratorStore();
|
|
8
|
-
scriptNameInput = ui.stringInput('Script name', '', (v: string) => this.store.scriptName = v);
|
|
9
|
-
descriptionInput = ui.stringInput('Description', '', (v: string) => this.store.description = v);
|
|
10
|
-
|
|
11
|
-
constructor() {
|
|
12
|
-
super();
|
|
13
|
-
|
|
14
|
-
const runButton = ui.bigButton('Generate script', async () => await this.generate());
|
|
15
|
-
const saveButton = ui.bigButton('Save', async () => await this.save());
|
|
16
|
-
const openButton = ui.bigButton('Open', async () => this.open());
|
|
17
|
-
openButton.style.display = 'none';
|
|
18
|
-
|
|
19
|
-
this.store.lastSavedScriptId.subscribe((newId) => {
|
|
20
|
-
if (newId !== '') {
|
|
21
|
-
openButton.style.removeProperty('display');
|
|
22
|
-
}
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
const dynamicDFInput = (counter: number) => {
|
|
26
|
-
const deleteBtn = ui.button('Remove', () => {});
|
|
27
|
-
deleteBtn.style.width = deleteBtn.style.height;
|
|
28
|
-
deleteBtn.style.alignSelf = 'center';
|
|
29
|
-
|
|
30
|
-
this.store.dfSheetsToSeek.push('');
|
|
31
|
-
|
|
32
|
-
const containter = ui.divH([
|
|
33
|
-
ui.stringInput(`Sheet name #${counter}`, '', (v: string) => this.store.dfSheetsToSeek[counter] = v).root,
|
|
34
|
-
deleteBtn,
|
|
35
|
-
], {style: {'justify-content': 'space-between'}});
|
|
36
|
-
deleteBtn.addEventListener('click', () => {
|
|
37
|
-
this.store.dfSheetsToSeek.splice(counter, 1);
|
|
38
|
-
containter.remove();
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
return containter;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const dynamicScalarInput = (counter: number) => {
|
|
45
|
-
const deleteBtn = ui.button('Remove', () => {});
|
|
46
|
-
deleteBtn.style.width = deleteBtn.style.height;
|
|
47
|
-
deleteBtn.style.alignSelf = 'center';
|
|
48
|
-
|
|
49
|
-
this.store.scalarsToSeek.push('');
|
|
50
|
-
|
|
51
|
-
const containter = ui.divH([
|
|
52
|
-
ui.stringInput(`Scalar name #${counter}`, '', (v: string) => this.store.scalarsToSeek[counter] = v).root,
|
|
53
|
-
deleteBtn,
|
|
54
|
-
], {style: {'justify-content': 'space-between'}});
|
|
55
|
-
deleteBtn.addEventListener('click', () => {
|
|
56
|
-
this.store.scalarsToSeek.splice(counter, 1);
|
|
57
|
-
containter.remove();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
return containter;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const dfInputsDiv = ui.divV([]);
|
|
64
|
-
const dfInputAddBtn = ui.button('Add DF to search', () => {
|
|
65
|
-
dfInputsDiv.append(dynamicDFInput(this.store.dfSheetsToSeek.length))
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
const scalarsInputsDiv = ui.divV([]);
|
|
69
|
-
const scalarsInputAddBtn = ui.button('Add scalar to search', () => {
|
|
70
|
-
scalarsInputsDiv.append(dynamicScalarInput(this.store.scalarsToSeek.length))
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
const formDiv = ui.divV([
|
|
74
|
-
ui.h3('Script properties'),
|
|
75
|
-
this.scriptNameInput.root,
|
|
76
|
-
this.descriptionInput.root,
|
|
77
|
-
ui.h3('Dataframes to search'),
|
|
78
|
-
dfInputsDiv,
|
|
79
|
-
dfInputAddBtn,
|
|
80
|
-
ui.h3('Scalars to search'),
|
|
81
|
-
scalarsInputsDiv,
|
|
82
|
-
scalarsInputAddBtn,
|
|
83
|
-
ui.divH([runButton], {style: {'justify-content': 'flex-end'}})
|
|
84
|
-
], 'ui-form');
|
|
85
|
-
|
|
86
|
-
let scriptDiv = ui.divText(this.store.scriptText.value);
|
|
87
|
-
let infoDiv = ui.info(this.store.infoText.value);
|
|
88
|
-
|
|
89
|
-
const outputDiv = ui.panel([
|
|
90
|
-
ui.h3('Script text'),
|
|
91
|
-
scriptDiv,
|
|
92
|
-
infoDiv,
|
|
93
|
-
ui.divH([saveButton, openButton], {style: {'justify-content': 'flex-end'}})
|
|
94
|
-
], {style: {display: 'none'}})
|
|
95
|
-
this.store.scriptText.subscribe((newScriptText) => {
|
|
96
|
-
const newScriptDiv = ui.divText(newScriptText);
|
|
97
|
-
scriptDiv.replaceWith(newScriptDiv);
|
|
98
|
-
scriptDiv = newScriptDiv;
|
|
99
|
-
|
|
100
|
-
if (newScriptText !== '') outputDiv.style.removeProperty('display');
|
|
101
|
-
})
|
|
102
|
-
this.store.infoText.subscribe((newInfoText) => {
|
|
103
|
-
const newInfoDiv = (newInfoText === '') ? ui.div([]) : ui.info(newInfoText);
|
|
104
|
-
infoDiv.replaceWith(newInfoDiv);
|
|
105
|
-
infoDiv = newInfoDiv;
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
this.root.appendChild(ui.splitH([formDiv, outputDiv], {style: {height: '100%', width: '100%'}}, true));
|
|
109
|
-
|
|
110
|
-
ui.tools.handleResize(formDiv.parentElement!, (width) => {
|
|
111
|
-
if (width < 350)
|
|
112
|
-
formDiv.classList.add('ui-form-condensed');
|
|
113
|
-
else
|
|
114
|
-
formDiv.classList.remove('ui-form-condensed');
|
|
115
|
-
});
|
|
116
|
-
formDiv.parentElement!.style.maxWidth = '340px';
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
async generate() {
|
|
120
|
-
const dfOutputsLines = this.store.dfSheetsToSeek.map((dfName) => `//output: dataframe ${dfName.trim()} { viewer: Grid(); }`).join("\n");
|
|
121
|
-
const scalarsLines = this.store.scalarsToSeek.map((scalarName) => `//output: string ${scalarName.trim()}`).join("\n");
|
|
122
|
-
|
|
123
|
-
const fileParsingCode =
|
|
124
|
-
`
|
|
125
|
-
const wb = new ExcelJS.Workbook();
|
|
126
|
-
await wb.xlsx.load(await uploadedFile.arrayBuffer());
|
|
127
|
-
const dfSheetsToSeek = ["${this.store.dfSheetsToSeek.join(`","`)}"];`
|
|
128
|
-
|
|
129
|
-
const dfParsingCode = (dfName: string) =>
|
|
130
|
-
`
|
|
131
|
-
const ${dfName}_ws = wb.getWorksheet("${dfName}");
|
|
132
|
-
let ${dfName}_data = await ${dfName}_ws.workbook.csv.writeBuffer();
|
|
133
|
-
${dfName} = grok.data.parseCsv(${dfName}_data.toString());`
|
|
134
|
-
|
|
135
|
-
const getAllScalars = () =>
|
|
136
|
-
`
|
|
137
|
-
const scalarSheets = wb.worksheets.filter(ws => !dfSheetsToSeek.includes(ws.name));
|
|
138
|
-
const scalarNames = scalarSheets.flatMap((sheet) => sheet.getColumn(1).values);
|
|
139
|
-
const scalarValues = scalarSheets.flatMap((sheet) => sheet.getColumn(2).values);`
|
|
140
|
-
|
|
141
|
-
const scalarParsingCode = (searchName: string) =>
|
|
142
|
-
`
|
|
143
|
-
const ${searchName}_index = scalarNames.findIndex((scalarName) => scalarName === "${searchName}");
|
|
144
|
-
${searchName} = (${searchName}_index >= 0) ? scalarValues[${searchName}_index] : '';`
|
|
145
|
-
|
|
146
|
-
let scriptText = `//name: ${this.store.scriptName}` + "\n";
|
|
147
|
-
scriptText += `//description: ${this.store.description}` + "\n";
|
|
148
|
-
scriptText += `//language: javascript` + "\n";
|
|
149
|
-
scriptText += `//input: file uploadedFile` + "\n";
|
|
150
|
-
scriptText += scalarsLines + "\n";
|
|
151
|
-
scriptText += dfOutputsLines + "\n";
|
|
152
|
-
scriptText += `//editor: Compute:FunctionViewEditor` + "\n";
|
|
153
|
-
scriptText += fileParsingCode + "\n";
|
|
154
|
-
|
|
155
|
-
this.store.dfSheetsToSeek.forEach((dfName) => {
|
|
156
|
-
scriptText += dfParsingCode(dfName.trim()) + "\n";
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
scriptText += getAllScalars();
|
|
160
|
-
|
|
161
|
-
this.store.scalarsToSeek.forEach((scalarName) => {
|
|
162
|
-
scriptText += scalarParsingCode(scalarName) + "\n";
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
this.store.scriptText.next(scriptText);
|
|
166
|
-
|
|
167
|
-
const duplicates = await grok.dapi.scripts.filter(`name="${this.store.scriptName}"`).list();
|
|
168
|
-
if (duplicates.length > 0){
|
|
169
|
-
this.store.infoText.next(`Script named "${this.store.scriptName}" already exists`);
|
|
170
|
-
}else {
|
|
171
|
-
this.store.infoText.next(``);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
async save() {
|
|
176
|
-
const resultScript = DG.Script.create(this.store.scriptText.value);
|
|
177
|
-
const savedScript = await grok.dapi.scripts.save(resultScript);
|
|
178
|
-
this.store.lastSavedScriptId.next(savedScript.id);
|
|
179
|
-
grok.shell.info(`Script "${this.store.scriptName}" has been saved successfully`)
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
open() {
|
|
183
|
-
window.open(`${window.location.origin}/script/${this.store.lastSavedScriptId.value}`)
|
|
184
|
-
}
|
|
185
|
-
}
|
|
@@ -1,84 +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 * as rxjs from "rxjs";
|
|
5
|
-
import {ModelHandler} from './model-handler';
|
|
6
|
-
|
|
7
|
-
/* eslint-disable */
|
|
8
|
-
|
|
9
|
-
let propsSub: rxjs.Subscription;
|
|
10
|
-
|
|
11
|
-
export class ModelCatalogView extends DG.CustomCardView {
|
|
12
|
-
|
|
13
|
-
constructor() {
|
|
14
|
-
super({dataSource: grok.dapi.functions, permanentFilter: '#model'});
|
|
15
|
-
|
|
16
|
-
this.root.classList.add('model-catalog-view');
|
|
17
|
-
this.meta = new ModelHandler();
|
|
18
|
-
this.name = 'Models';
|
|
19
|
-
this.permanentFilter = '#model';
|
|
20
|
-
this.renderMode = DG.RENDER_MODE.BRIEF;
|
|
21
|
-
|
|
22
|
-
this.objectType = 'Func';
|
|
23
|
-
this.categoryFilters = {
|
|
24
|
-
'options.department': 'Department',
|
|
25
|
-
'options.HL_process': 'HL_process',
|
|
26
|
-
'options.process': 'Process',
|
|
27
|
-
'tag': 'Tags'
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
this.filters = {
|
|
31
|
-
'All': '',
|
|
32
|
-
'Favorites': 'starredBy = @current',
|
|
33
|
-
'Used by me': 'usedBy = @current'
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
this.hierarchy = [
|
|
37
|
-
'options.department',
|
|
38
|
-
'options.HL_process',
|
|
39
|
-
'options.process'
|
|
40
|
-
];
|
|
41
|
-
|
|
42
|
-
this.hierarchyProperties = {
|
|
43
|
-
'options.department': 'Department',
|
|
44
|
-
'options.HL_process': 'HL_process',
|
|
45
|
-
'options.process': 'Process'
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
this.showTree = true;
|
|
49
|
-
this.initRibbon();
|
|
50
|
-
this.initMenu();
|
|
51
|
-
this.currentCall = grok.functions.getCurrentCall();
|
|
52
|
-
if (propsSub == null && window.localStorage.getItem('ModelCatalogShowProperties') == null) { // @ts-ignore
|
|
53
|
-
propsSub = grok.events.onCurrentObjectChanged.subscribe((o) => {
|
|
54
|
-
if (new ModelHandler().isApplicable(o.sender)) {
|
|
55
|
-
grok.shell.windows.showProperties = true;
|
|
56
|
-
window.localStorage.setItem('ModelCatalogShowProperties', 'false');
|
|
57
|
-
propsSub.unsubscribe();
|
|
58
|
-
}
|
|
59
|
-
})
|
|
60
|
-
}
|
|
61
|
-
grok.shell.windows.showHelp = false;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
currentCall: DG.FuncCall;
|
|
65
|
-
|
|
66
|
-
initRibbon() {
|
|
67
|
-
this.setRibbonPanels([[ui.icons.sync(() => this.refresh())]]);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
initMenu() {
|
|
71
|
-
this.ribbonMenu
|
|
72
|
-
.group('Help')
|
|
73
|
-
.item('Compute Engine', () => window.open('https://github.com/datagrok-ai/public/tree/master/packages/Compute', '_blank'))
|
|
74
|
-
.item('Developing Models', () => window.open('https://datagrok.ai/help/compute/scripting', '_blank'))
|
|
75
|
-
.endGroup();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
setCurrentModel(model: DG.Script) {
|
|
79
|
-
let modelView = DG.View.forObject(model)!;
|
|
80
|
-
let host: HTMLDivElement = this.root.querySelector('.grok-gallery-grid')! as HTMLDivElement;
|
|
81
|
-
ui.empty(host);
|
|
82
|
-
host.appendChild(modelView.root);
|
|
83
|
-
}
|
|
84
|
-
}
|