@datagrok/compute 0.7.1 → 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 +12 -4
- 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 +96 -44
- package/src/outliers-selection/outliers-selection-viewer.ts +37 -28
- package/src/package.ts +33 -20
- package/src/view-samples/computation-test-view.ts +8 -0
- package/.eslintrc.json +0 -35
- package/src/export-funccall.ts +0 -200
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datagrok/compute",
|
|
3
3
|
"friendlyName": "Compute",
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.2",
|
|
5
5
|
"description": "",
|
|
6
6
|
"dependencies": {
|
|
7
|
+
"@datagrok-libraries/utils": "^0.2.4",
|
|
7
8
|
"cash-dom": "latest",
|
|
8
9
|
"codemirror": "^5.64.0",
|
|
9
|
-
"datagrok-api": "
|
|
10
|
+
"datagrok-api": "^0.148.1",
|
|
10
11
|
"dayjs": "latest",
|
|
11
12
|
"exceljs": "^4.3.0",
|
|
12
13
|
"file-saver": "^2.0.5",
|
|
@@ -30,10 +31,13 @@
|
|
|
30
31
|
},
|
|
31
32
|
"scripts": {
|
|
32
33
|
"link-api": "npm link datagrok-api",
|
|
34
|
+
"link-utils": "npm link @datagrok-libraries/utils",
|
|
35
|
+
"link-all": "npm link datagrok-api @datagrok-libraries/utils",
|
|
33
36
|
"debug-compute": "webpack & grok publish dev --release",
|
|
34
37
|
"release-compute": "grok publish --rebuild --release",
|
|
35
38
|
"build-compute": "webpack",
|
|
36
39
|
"build": "webpack",
|
|
40
|
+
"build-compute-local": "npm --prefix ./../../js-api run build && npm --prefix ./../../libraries/utils run build && npm run build",
|
|
37
41
|
"debug-compute-dev": "webpack && grok publish dev --rebuild",
|
|
38
42
|
"release-compute-dev": "grok publish dev --release",
|
|
39
43
|
"debug-compute-local": "grok publish local --rebuild",
|
|
@@ -43,6 +47,10 @@
|
|
|
43
47
|
"debug-compute-compose": "grok publish compose --rebuild",
|
|
44
48
|
"release-compute-compose": "grok publish compose --rebuild --release"
|
|
45
49
|
},
|
|
46
|
-
"canEdit": [
|
|
47
|
-
|
|
50
|
+
"canEdit": [
|
|
51
|
+
"Developers"
|
|
52
|
+
],
|
|
53
|
+
"canView": [
|
|
54
|
+
"All users"
|
|
55
|
+
]
|
|
48
56
|
}
|
package/scripts/vmax.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
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: model, filtration
|
|
5
|
+
//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")}
|
|
6
|
+
//input: dataframe reportingParameters {caption: Reporting parameters; viewer: Grid()}
|
|
7
|
+
//input: double testFilterArea = 3.5 {caption: Test filter area; units: cm²} [Test filter area]
|
|
8
|
+
//input: double desiredVolumeOfBatch = 25 {caption: Desired batch volume; units: L} [Desired batch volume]
|
|
9
|
+
//input: double desiredProcessTime = 0.5 {caption: Desired process time; units: hr} [Desired process time]
|
|
10
|
+
//input: double sf = 1.5 {caption: Safety factor} [Safety factor]
|
|
11
|
+
//help-url: https://github.com/datagrok-ai/public/blob/master/packages/Compute/src/help.md
|
|
12
|
+
//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}
|
|
13
|
+
//output: dataframe trialData {caption: Trial data; viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); category: OUTPUT}
|
|
14
|
+
//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}
|
|
15
|
+
//output: dataframe experimentalResultsSummary {viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); caption: Experimental results summary; category: OUTPUT}
|
|
16
|
+
//output: dataframe recommendations {viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); caption: Recommendations; category: OUTPUT}
|
|
17
|
+
//output: dataframe sampleCharacteristics {viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); caption: Sample characteristics; category: OUTPUT}
|
|
18
|
+
//output: dataframe filter {viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); caption: Filter; category: OUTPUT}
|
|
19
|
+
|
|
20
|
+
// inputTable = grok.shell.tables[0]; reportingParameters = grok.shell.tables[1];
|
|
21
|
+
// testFilterArea = 3.5; desiredVolumeOfBatch = 25; desiredProcessTime = 0.5; sf = 1.5;
|
|
22
|
+
|
|
23
|
+
const COL_NAMES = {
|
|
24
|
+
INPUT_TIME_IN_MINUTES: "time (min)",
|
|
25
|
+
INPUT_VOLUME_IN_MILLILITERS: "filtrate volume (mL)",
|
|
26
|
+
INPUT_IS_OUTLIER: "isOutlier",
|
|
27
|
+
TIME_IN_HOURS: "Time [hr]",
|
|
28
|
+
TRIAL_THROUGHPUT: "Throughput [L/m²]",
|
|
29
|
+
T_V: "Time/volume/area [hr/L/m²]",
|
|
30
|
+
FLOW_RATE: "Flow rate",
|
|
31
|
+
FLUX: "Flux",
|
|
32
|
+
RELATIVE_FLUX: "Rel Flux"
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const PARAM_NAMES = {
|
|
36
|
+
FILTER_FAMILY: "Filter family",
|
|
37
|
+
FILTER_NAME: "Filter name",
|
|
38
|
+
PORE_RATING: "Pore rating (μm)",
|
|
39
|
+
EFFECTIVE_MEMBR_AREA: "Effective membr. area (cm^2)",
|
|
40
|
+
MEMBR_MATERIAL: "Membr material",
|
|
41
|
+
CATALOG_NR: "Catalog nr",
|
|
42
|
+
DATE: "Date",
|
|
43
|
+
PRIOR_STEP: "Prior step",
|
|
44
|
+
PROT_CONC: "Prot conc. (mg/mL)",
|
|
45
|
+
DENSITY: "Density (g/L)",
|
|
46
|
+
TURBIDITY: "Turbidity (NTU)",
|
|
47
|
+
INSTALLED_DEVICE: "Installed device",
|
|
48
|
+
PROJECT_NAME: "Project name", // PARAMETERS BELOW ARE NOT USED
|
|
49
|
+
FILTRATION_STAGE: "Filtration stage",
|
|
50
|
+
ELN_REFERENCE: "ELN reference",
|
|
51
|
+
BIOREACTOR_ID: "Bioreactor ID",
|
|
52
|
+
BIOREACTOR_PCV: "Bioreactor PCV (%)",
|
|
53
|
+
BIOREACTOR_TURBIDITY: "Bioreactor turbidity (NTU)",
|
|
54
|
+
FILTER_FEED_TURBIDITY: "Filter feed turbidity (NTU)",
|
|
55
|
+
FILTER_FEED_PCV: "Filter feed PCV (%)",
|
|
56
|
+
FILTER_FEED_PH: "Filter feed pH",
|
|
57
|
+
FILTER_FEED_LDH: "Filter feed LDH (U/L)",
|
|
58
|
+
FILTER_FEED_CONDUCTIVITY: "Filter feed conductivity (mS/cm)"
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
function linearRegression(x, y) {
|
|
62
|
+
let sum_x = 0, sum_y = 0, sum_xy = 0, sum_xx = 0;
|
|
63
|
+
for (let i = 0; i < y.length; i++) {
|
|
64
|
+
sum_x += x[i];
|
|
65
|
+
sum_y += y[i];
|
|
66
|
+
sum_xy += x[i] * y[i];
|
|
67
|
+
sum_xx += x[i] * x[i];
|
|
68
|
+
}
|
|
69
|
+
const slope = (y.length * sum_xy - sum_x * sum_y) / (y.length * sum_xx - sum_x * sum_x);
|
|
70
|
+
const intercept = (sum_y - slope * sum_x) / y.length;
|
|
71
|
+
return { slope: slope, intercept: intercept };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const timeInMinutes = inputTable.col(COL_NAMES.INPUT_TIME_IN_MINUTES);
|
|
75
|
+
const volumeInMilliliters = inputTable.col(COL_NAMES.INPUT_VOLUME_IN_MILLILITERS);
|
|
76
|
+
const isOutlier = inputTable.col(COL_NAMES.INPUT_IS_OUTLIER);
|
|
77
|
+
|
|
78
|
+
let df = DG.DataFrame.fromColumns([timeInMinutes, volumeInMilliliters, isOutlier]);
|
|
79
|
+
|
|
80
|
+
df.columns.addNewFloat(COL_NAMES.TIME_IN_HOURS).init((i) => timeInMinutes.get(i) / 60);
|
|
81
|
+
const timeInHours = df.col(COL_NAMES.TIME_IN_HOURS);
|
|
82
|
+
|
|
83
|
+
df.columns.addNewFloat(COL_NAMES.TRIAL_THROUGHPUT).init((i) => 10 * volumeInMilliliters.get(i) / testFilterArea);
|
|
84
|
+
const trialThroughputCol = df.col(COL_NAMES.TRIAL_THROUGHPUT);
|
|
85
|
+
|
|
86
|
+
df.columns.addNewFloat(COL_NAMES.T_V).init((i) => timeInHours.get(i) / trialThroughputCol.get(i));
|
|
87
|
+
const tv = df.col(COL_NAMES.T_V);
|
|
88
|
+
|
|
89
|
+
df.columns.addNewFloat(COL_NAMES.FLOW_RATE).init((i) => (i > 0) ?
|
|
90
|
+
0.06 * (volumeInMilliliters.get(i) - volumeInMilliliters.get(i - 1)) / (timeInMinutes.get(i) - timeInMinutes.get(i - 1)) : 0
|
|
91
|
+
);
|
|
92
|
+
const flowRate = df.col(COL_NAMES.FLOW_RATE);
|
|
93
|
+
|
|
94
|
+
df.columns.addNewFloat(COL_NAMES.FLUX).init((i) => 10000 * flowRate.get(i) / testFilterArea);
|
|
95
|
+
const flux = df.col(COL_NAMES.FLUX);
|
|
96
|
+
|
|
97
|
+
df.columns.addNewFloat(COL_NAMES.RELATIVE_FLUX).init((i) => flux.get(i) / flux.get(1));
|
|
98
|
+
const relativeFlux = df.col(COL_NAMES.RELATIVE_FLUX);
|
|
99
|
+
|
|
100
|
+
fluxDecayDf = DG.DataFrame.fromColumns([
|
|
101
|
+
DG.Column.fromFloat32Array(COL_NAMES.TRIAL_THROUGHPUT, df.col(COL_NAMES.TRIAL_THROUGHPUT).toList().slice(1)),
|
|
102
|
+
DG.Column.fromFloat32Array(COL_NAMES.FLUX, df.col(COL_NAMES.FLUX).toList().slice(1)),
|
|
103
|
+
DG.Column.fromFloat32Array(COL_NAMES.RELATIVE_FLUX, df.col(COL_NAMES.RELATIVE_FLUX).toList().slice(1)),
|
|
104
|
+
DG.Column.fromList(DG.COLUMN_TYPE.BOOL, isOutlier.name, isOutlier.toList().slice(1))
|
|
105
|
+
]);
|
|
106
|
+
|
|
107
|
+
filtrationKinetics = DG.DataFrame.fromColumns([
|
|
108
|
+
timeInHours,
|
|
109
|
+
df.col(COL_NAMES.T_V),
|
|
110
|
+
volumeInMilliliters,
|
|
111
|
+
isOutlier
|
|
112
|
+
]);
|
|
113
|
+
|
|
114
|
+
df.col(COL_NAMES.INPUT_IS_OUTLIER).markers.assign('true', DG.MARKER_TYPE.OUTLIER);
|
|
115
|
+
filtrationKinetics.col(COL_NAMES.INPUT_IS_OUTLIER).markers.assign('true', DG.MARKER_TYPE.OUTLIER);
|
|
116
|
+
|
|
117
|
+
for (let i = df.rowCount - 1; i > -1; i--)
|
|
118
|
+
if (isOutlier.get(i))
|
|
119
|
+
df.rows.removeAt(i, 1, false);
|
|
120
|
+
|
|
121
|
+
const coefficients = linearRegression(df.col(COL_NAMES.TIME_IN_HOURS).toList(), df.col(COL_NAMES.T_V).toList());
|
|
122
|
+
const vmax = 1 / coefficients.slope;
|
|
123
|
+
const j0 = 1 / coefficients.intercept;
|
|
124
|
+
const flux0 = flux.get(1);
|
|
125
|
+
const amin = desiredVolumeOfBatch / vmax + desiredVolumeOfBatch / desiredProcessTime / j0;
|
|
126
|
+
const installedArea = sf * amin;
|
|
127
|
+
const processLoading = desiredVolumeOfBatch / installedArea;
|
|
128
|
+
const trialThroughput = df.col(COL_NAMES.TRIAL_THROUGHPUT).get(df.rowCount - 1);
|
|
129
|
+
const fluxDecay = (1 - df.col(COL_NAMES.RELATIVE_FLUX).get(df.rowCount - 1)) * 100;
|
|
130
|
+
const initialFlowRate = flowRate.get(1);
|
|
131
|
+
const meanFlux = flux.stats.avg * df.rowCount / (df.rowCount - 1); // exclude zero from calculation
|
|
132
|
+
|
|
133
|
+
const names = reportingParameters.col('Parameter name').toList();
|
|
134
|
+
const values = reportingParameters.col('Parameter value').toList();
|
|
135
|
+
|
|
136
|
+
experimentalResultsSummary = DG.DataFrame.fromObjects([
|
|
137
|
+
{ Name: 'Run', Value: '1' },
|
|
138
|
+
{ Name: 'Filter', Value: values[names.indexOf(PARAM_NAMES.FILTER_FAMILY)] },
|
|
139
|
+
{ Name: 'Trial Throughput [L/m²]', Value: Math.round(1000 * trialThroughput) / 1000 },
|
|
140
|
+
{ Name: 'Flux0 [LMH]', Value: Math.round(1000 * flux0) / 1000 },
|
|
141
|
+
{ Name: 'Mean Flux [LMH]', Value: Math.round(1000 * meanFlux) / 1000 },
|
|
142
|
+
{ Name: 'Vmax [L/m²]', Value: Math.round(1000 * vmax) / 1000 },
|
|
143
|
+
{ Name: 'Flux Decay [%]', Value: Math.round(1000 * fluxDecay) / 1000 }
|
|
144
|
+
]);
|
|
145
|
+
|
|
146
|
+
recommendations = DG.DataFrame.fromObjects([
|
|
147
|
+
{ Name: 'Volume [L]', Value: desiredVolumeOfBatch },
|
|
148
|
+
{ Name: 'Time [h]', Value: desiredProcessTime },
|
|
149
|
+
{ Name: 'Amin [m²]', Value: Math.round(1000 * amin) / 1000 },
|
|
150
|
+
{ Name: 'Safety Factor', Value: sf },
|
|
151
|
+
{ Name: 'Installed Area', Value: Math.round(1000 * installedArea) / 1000 },
|
|
152
|
+
{ Name: 'Process Loading [L/m²]', Value: Math.round(1000 * processLoading) / 1000 },
|
|
153
|
+
{ Name: PARAM_NAMES.FILTER_FAMILY, Value: values[names.indexOf(PARAM_NAMES.FILTER_FAMILY)] },
|
|
154
|
+
{ Name: PARAM_NAMES.INSTALLED_DEVICE, Value: values[names.indexOf(PARAM_NAMES.INSTALLED_DEVICE)] }
|
|
155
|
+
]);
|
|
156
|
+
|
|
157
|
+
trialData = DG.DataFrame.fromObjects([
|
|
158
|
+
{ Name: 'Test Filter Area [cm²]', Value: testFilterArea },
|
|
159
|
+
{ Name: 'Initial Flow Rate [L/h]', Value: Math.round(1000 * initialFlowRate) / 1000 },
|
|
160
|
+
{ Name: 'Vmax [L/m²]', Value: Math.round(1000 * vmax) / 1000 }
|
|
161
|
+
]);
|
|
162
|
+
|
|
163
|
+
filter = DG.DataFrame.fromObjects([
|
|
164
|
+
{ Name: PARAM_NAMES.FILTER_FAMILY, Value: values[names.indexOf(PARAM_NAMES.FILTER_FAMILY)] },
|
|
165
|
+
{ Name: PARAM_NAMES.FILTER_NAME, Value: values[names.indexOf(PARAM_NAMES.FILTER_NAME)] },
|
|
166
|
+
{ Name: PARAM_NAMES.PORE_RATING, Value: values[names.indexOf(PARAM_NAMES.PORE_RATING)] },
|
|
167
|
+
{ Name: PARAM_NAMES.EFFECTIVE_MEMBR_AREA, Value: values[names.indexOf(PARAM_NAMES.EFFECTIVE_MEMBR_AREA)] },
|
|
168
|
+
{ Name: PARAM_NAMES.MEMBR_MATERIAL, Value: values[names.indexOf(PARAM_NAMES.MEMBR_MATERIAL)] },
|
|
169
|
+
{ Name: PARAM_NAMES.CATALOG_NR, Value: values[names.indexOf(PARAM_NAMES.CATALOG_NR)] }
|
|
170
|
+
]);
|
|
171
|
+
|
|
172
|
+
sampleCharacteristics = DG.DataFrame.fromObjects([
|
|
173
|
+
{ Name: PARAM_NAMES.DATE, Value: values[names.indexOf(PARAM_NAMES.DATE)].slice(0, 10) },
|
|
174
|
+
{ Name: PARAM_NAMES.PRIOR_STEP, Value: values[names.indexOf(PARAM_NAMES.PRIOR_STEP)] },
|
|
175
|
+
{ Name: PARAM_NAMES.PROT_CONC, Value: values[names.indexOf(PARAM_NAMES.PROT_CONC)] },
|
|
176
|
+
{ Name: PARAM_NAMES.DENSITY, Value: values[names.indexOf(PARAM_NAMES.DENSITY)].slice(0, 5) },
|
|
177
|
+
{ Name: PARAM_NAMES.TURBIDITY, Value: values[names.indexOf(PARAM_NAMES.TURBIDITY)] }
|
|
178
|
+
]);
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import * as grok from 'datagrok-api/grok';
|
|
2
|
+
import * as rxjs from 'rxjs';
|
|
3
|
+
import * as ui from 'datagrok-api/ui';
|
|
4
|
+
import * as DG from 'datagrok-api/dg';
|
|
5
|
+
import {DataFrame, FuncCall, FuncCallParam, Grid, TYPE} from 'datagrok-api/dg';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Base class for handling Compute models (see https://github.com/datagrok-ai/public/blob/master/help/compute/compute.md).
|
|
9
|
+
* In most cases, the computation is a simple {@link Func}
|
|
10
|
+
* Extend it in cases where a behavior or UI not supported by the {@link FunctionView} is needed.
|
|
11
|
+
*
|
|
12
|
+
* It provides the following functionality out-of-the-box, where each section could be customized:
|
|
13
|
+
* - a structured way to represent input and output parameters: {@link parameters}
|
|
14
|
+
* - generic way to generate UI for inputs, outputs, and interactivity (running the model, etc)
|
|
15
|
+
* - persisting historical results to the db (via {@link parameters})
|
|
16
|
+
* - export (to Excel and PDF): {@link export}
|
|
17
|
+
* - easy loading of historical runs
|
|
18
|
+
* - routing
|
|
19
|
+
* - entering the real, measured (as opposed to predicted) values manually
|
|
20
|
+
* - notifications for changing inputs, completion of computations, etc: {@link onInputChanged}
|
|
21
|
+
* */
|
|
22
|
+
export class ComputeView extends DG.ViewBase {
|
|
23
|
+
|
|
24
|
+
func: DG.Func;
|
|
25
|
+
call: DG.FuncCall; // what is being currently edited
|
|
26
|
+
lastCall?: DG.FuncCall;
|
|
27
|
+
_inputFields: Map<string, DG.InputBase> = new Map<string, DG.InputBase>();
|
|
28
|
+
_inputBlock?: HTMLDivElement;
|
|
29
|
+
_outputBlock?: HTMLDivElement;
|
|
30
|
+
|
|
31
|
+
onViewInitialized: rxjs.Subject<void> = new rxjs.Subject();
|
|
32
|
+
onInputChanged: rxjs.Subject<void> = new rxjs.Subject();
|
|
33
|
+
onComputationStarted: rxjs.Subject<FuncCall> = new rxjs.Subject();
|
|
34
|
+
onComputationCompleted: rxjs.Subject<FuncCall> = new rxjs.Subject();
|
|
35
|
+
onComputationSucceeded: rxjs.Subject<FuncCall> = new rxjs.Subject();
|
|
36
|
+
onComputationError: rxjs.Subject<FuncCall> = new rxjs.Subject();
|
|
37
|
+
|
|
38
|
+
constructor(func: DG.Func) {
|
|
39
|
+
super();
|
|
40
|
+
|
|
41
|
+
this.func = func;
|
|
42
|
+
this.name = func.friendlyName;
|
|
43
|
+
this.call = func.prepare();
|
|
44
|
+
|
|
45
|
+
this.initTopMenu();
|
|
46
|
+
this.initRibbonPanels();
|
|
47
|
+
|
|
48
|
+
this.init().then((_) => {
|
|
49
|
+
this.root.appendChild(this.build());
|
|
50
|
+
return this.onViewInitialized.next();
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** All inputs that are bound to fields */
|
|
55
|
+
get inputFields(): Map<string, DG.InputBase> { return this._inputFields; }
|
|
56
|
+
|
|
57
|
+
/** Saves the computation results to the historical results, returns its id. See also {@link loadRun}. */
|
|
58
|
+
async saveRun(call: FuncCall): Promise<string> { return 'xxx'; }
|
|
59
|
+
|
|
60
|
+
/** Loads the specified historical results. See also {@link saveRun}. */
|
|
61
|
+
async loadRun(runId: string): Promise<void> { }
|
|
62
|
+
|
|
63
|
+
/** The actual computation function. */
|
|
64
|
+
async compute(call: FuncCall): Promise<void> { await call.call(); }
|
|
65
|
+
|
|
66
|
+
/** Maps inputs to parameters, computes, and maps output parameters to the UI. */
|
|
67
|
+
async run(): Promise<void> {
|
|
68
|
+
this.lastCall = this.call.clone();
|
|
69
|
+
this.inputFieldsToParameters(this.lastCall);
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
await this.compute(this.lastCall);
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
this.onComputationError.next(this.lastCall);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
this.outputParametersToView(this.lastCall);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Override to provide custom initialization. {@link onViewInitialized} gets fired after that. */
|
|
82
|
+
async init(): Promise<void> {}
|
|
83
|
+
|
|
84
|
+
/** Override to customize top menu*/
|
|
85
|
+
initTopMenu() {
|
|
86
|
+
this.ribbonMenu = DG.Menu.create()
|
|
87
|
+
.group(this.func.friendlyName)
|
|
88
|
+
.item('Run', () => this.run());
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Override to customize ribbon panels */
|
|
92
|
+
initRibbonPanels() {
|
|
93
|
+
this.setRibbonPanels([[
|
|
94
|
+
ui.icons.play(() => this.run(), 'RUN'),
|
|
95
|
+
ui.comboPopup(
|
|
96
|
+
ui.icons.save(null, 'Export'),
|
|
97
|
+
this.supportedExportFormats,
|
|
98
|
+
async (format) => DG.Utils.download('output.csv', await this.export(format)),
|
|
99
|
+
),
|
|
100
|
+
]]);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Builds the complete view. Override it if completely custom implementation is needed,
|
|
104
|
+
* otherwise consider overriding {@link buildInputBlock} and/or {@link buildOutputBlock} */
|
|
105
|
+
build(): HTMLElement { return ui.splitH([this.buildInputBlock(), this.buildOutputBlock()]); }
|
|
106
|
+
|
|
107
|
+
/** Override to build completely custom input block (the one with inputs, usually on the left).
|
|
108
|
+
* If only specific field, consider overriding {@link buildCustomInputs}. */
|
|
109
|
+
buildInputBlock(): HTMLElement {
|
|
110
|
+
for (const p of this.func.inputs)
|
|
111
|
+
this._inputFields.set(p.name, DG.InputBase.forProperty(p, this.call.dart));
|
|
112
|
+
|
|
113
|
+
return this._inputBlock = ui.inputs(this._inputFields.values())
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Custom inputs for the specified fields. Inputs for these fields will not be created by {@link buildInputBlock}. */
|
|
117
|
+
buildCustomInputs(): Map<String, DG.InputBase> { return new Map(); }
|
|
118
|
+
|
|
119
|
+
/** Override to create output block. */
|
|
120
|
+
buildOutputBlock(): HTMLElement { return this._outputBlock = ui.div(); }
|
|
121
|
+
|
|
122
|
+
/** Override to create a custom input control. */
|
|
123
|
+
buildRibbonPanel(): HTMLElement { return ui.divH([
|
|
124
|
+
ui.button('RUN', () => {}),
|
|
125
|
+
ui.comboPopup('Export', this.supportedExportFormats, (format) => this.export(format))]);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Creates function parameters based on the data entered by the user. */
|
|
129
|
+
inputFieldsToParameters(call: FuncCall): void { }
|
|
130
|
+
|
|
131
|
+
/** Visualizes computation results. Requires _outputBlock. */
|
|
132
|
+
outputParametersToView(call: FuncCall | null): void {
|
|
133
|
+
ui.empty(this._outputBlock!);
|
|
134
|
+
|
|
135
|
+
if (call == null)
|
|
136
|
+
return;
|
|
137
|
+
|
|
138
|
+
for (let p of this.func.outputs)
|
|
139
|
+
this._outputBlock?.appendChild(this.renderOutputParameter(call, call?.outputParams[p.name]));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
renderOutputParameter(call: FuncCall, param: FuncCallParam): HTMLElement {
|
|
143
|
+
if (param.property.propertyType == TYPE.DATA_FRAME)
|
|
144
|
+
return Grid.grid(call.outputParams[param.name]).root;
|
|
145
|
+
else
|
|
146
|
+
return ui.divText(`Unknown type: ${param.property.propertyType}`);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Override to provide custom computation error handling. */
|
|
150
|
+
processComputationError(call: FuncCall) { grok.shell.error(call.errorMessage!); }
|
|
151
|
+
|
|
152
|
+
/** Override to provide supported export formats.
|
|
153
|
+
* These formats are available under the "Export" popup on the ribbon panel. */
|
|
154
|
+
get supportedExportFormats(): string[] { return ['Excel', 'PDF', 'CSV']; }
|
|
155
|
+
|
|
156
|
+
/** Override to provide custom export. */
|
|
157
|
+
async export(format: string): Promise<Blob> {
|
|
158
|
+
if (format == 'CSV')
|
|
159
|
+
return new Blob([(this.lastCall?.getOutputParamValue() as DataFrame).toCsv()]);
|
|
160
|
+
throw `Format "${format}" is not supported.`;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
@@ -3,14 +3,13 @@ import * as ui from 'datagrok-api/ui';
|
|
|
3
3
|
import * as DG from 'datagrok-api/dg';
|
|
4
4
|
import {ModelHandler} from './model-handler';
|
|
5
5
|
import {onboardModel} from './onboard-model';
|
|
6
|
-
const api = <any>window;
|
|
7
6
|
|
|
8
7
|
/* eslint-disable */
|
|
9
8
|
|
|
10
|
-
export class ModelCatalogView extends DG.
|
|
9
|
+
export class ModelCatalogView extends DG.CustomCardView {
|
|
11
10
|
|
|
12
11
|
constructor() {
|
|
13
|
-
super(
|
|
12
|
+
super({dataSource: grok.dapi.functions, permanentFilter: '#model'});
|
|
14
13
|
|
|
15
14
|
this.meta = new ModelHandler();
|
|
16
15
|
this.name = 'Models';
|
package/src/model-handler.ts
CHANGED
|
@@ -2,18 +2,20 @@ import * as grok from 'datagrok-api/grok';
|
|
|
2
2
|
import * as ui from 'datagrok-api/ui';
|
|
3
3
|
import * as DG from 'datagrok-api/dg';
|
|
4
4
|
import {ModelCatalogView} from "./model-catalog-view";
|
|
5
|
+
import {TYPE} from "datagrok-api/dg";
|
|
6
|
+
import {FunctionView} from '@datagrok-libraries/utils/src/function-view';
|
|
5
7
|
|
|
6
8
|
export class ModelHandler extends DG.ObjectHandler {
|
|
7
9
|
get type() {
|
|
8
10
|
return 'Model';
|
|
9
11
|
}
|
|
10
12
|
|
|
11
|
-
async getById(id: string): Promise<DG.
|
|
13
|
+
async getById(id: string): Promise<DG.Func> {
|
|
12
14
|
console.log('id:', id);
|
|
13
|
-
return await grok.dapi.
|
|
15
|
+
return await grok.dapi.functions.find(id);
|
|
14
16
|
}
|
|
15
17
|
|
|
16
|
-
async refresh(x: DG.Script): Promise<DG.
|
|
18
|
+
async refresh(x: DG.Script): Promise<DG.Func> {
|
|
17
19
|
let script = await this.getById(x.id);
|
|
18
20
|
console.log('script:', script);
|
|
19
21
|
return script;
|
|
@@ -27,18 +29,18 @@ export class ModelHandler extends DG.ObjectHandler {
|
|
|
27
29
|
|
|
28
30
|
// Checks whether this is the handler for [x]
|
|
29
31
|
isApplicable(x: any) {
|
|
30
|
-
return x instanceof DG.
|
|
32
|
+
return x instanceof DG.Func && x.hasTag('model');
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
renderIcon(x: DG.
|
|
34
|
-
return this.getLanguageIcon(x.language);
|
|
35
|
+
renderIcon(x: DG.Func, context: any = null): HTMLElement {
|
|
36
|
+
return x instanceof DG.Script ? this.getLanguageIcon(x.language) : ui.iconFA('lightning');
|
|
35
37
|
}
|
|
36
38
|
|
|
37
|
-
renderMarkup(x: DG.
|
|
39
|
+
renderMarkup(x: DG.Func): HTMLElement {
|
|
38
40
|
return ui.span([this.renderIcon(x), ui.label(x.friendlyName, {style: {marginLeft: '4px'}})], {style: {display: 'inline-flex'}});
|
|
39
41
|
}
|
|
40
42
|
|
|
41
|
-
renderProperties(x: DG.
|
|
43
|
+
renderProperties(x: DG.Func) {
|
|
42
44
|
const a = ui.accordion();
|
|
43
45
|
a.context = x;
|
|
44
46
|
a.addTitle(ui.span([this.renderIcon(x), ui.label(x.friendlyName), ui.contextActions(x), ui.star(x.id)]));
|
|
@@ -52,34 +54,34 @@ export class ModelHandler extends DG.ObjectHandler {
|
|
|
52
54
|
return a.root;
|
|
53
55
|
}
|
|
54
56
|
|
|
55
|
-
renderDetails(x: DG.
|
|
57
|
+
renderDetails(x: DG.Func) {
|
|
56
58
|
return ui.divV([ui.render(x.author), ui.render(x.createdOn)], {style: {lineHeight: '150%'}});
|
|
57
59
|
}
|
|
58
60
|
|
|
59
|
-
renderTooltip(x: DG.
|
|
61
|
+
renderTooltip(x: DG.Func) {
|
|
60
62
|
return ui.divText(`${x.friendlyName}`);
|
|
61
63
|
}
|
|
62
64
|
|
|
63
|
-
renderCard(x: DG.
|
|
65
|
+
renderCard(x: DG.Func, context?: any): HTMLElement {
|
|
64
66
|
let card = ui.bind(x, ui.divV([
|
|
65
67
|
ui.h2(this.renderMarkup(x)),
|
|
66
68
|
ui.divText(x.description, 'ui-description'),
|
|
67
69
|
this.renderDetails(x),
|
|
68
70
|
], 'd4-gallery-item'), {contextMenu: false});
|
|
71
|
+
let c = grok.functions.getCurrentCall();
|
|
69
72
|
card.ondblclick = (e) => {
|
|
70
|
-
ModelHandler.openModel(x);
|
|
73
|
+
ModelHandler.openModel(x, c);
|
|
71
74
|
}
|
|
72
75
|
return card;
|
|
73
76
|
}
|
|
74
77
|
|
|
75
|
-
static openModel(x: DG.
|
|
76
|
-
let
|
|
77
|
-
|
|
78
|
+
static openModel(x: DG.Func, parentCall?: DG.FuncCall) {
|
|
79
|
+
let fc = x.prepare();
|
|
80
|
+
if (parentCall != null)
|
|
81
|
+
fc.parentCall = parentCall;
|
|
82
|
+
fc.edit();
|
|
78
83
|
}
|
|
79
84
|
|
|
80
85
|
init() {
|
|
81
|
-
this.registerParamFunc('Open', async (t: DG.Script) => {
|
|
82
|
-
|
|
83
|
-
});
|
|
84
86
|
}
|
|
85
87
|
}
|
package/src/models-widget.ts
CHANGED
|
@@ -1,67 +1,119 @@
|
|
|
1
1
|
import * as grok from 'datagrok-api/grok';
|
|
2
2
|
import * as DG from "datagrok-api/dg";
|
|
3
3
|
import * as ui from "datagrok-api/ui";
|
|
4
|
+
import {ModelHandler} from './model-handler';
|
|
5
|
+
import {TYPE} from "datagrok-api/dg";
|
|
4
6
|
import $ from 'cash-dom';
|
|
7
|
+
import {FunctionView} from "@datagrok-libraries/utils/src/function-view";
|
|
8
|
+
const api = <any>window;
|
|
9
|
+
|
|
5
10
|
|
|
6
11
|
export class ModelsWidget extends DG.Widget {
|
|
7
12
|
caption: string;
|
|
8
13
|
order: string;
|
|
14
|
+
meta: ModelHandler;
|
|
15
|
+
name: string;
|
|
16
|
+
permanentFilter: string;
|
|
17
|
+
objectType: string;
|
|
18
|
+
modelsList: HTMLDivElement;
|
|
9
19
|
|
|
10
20
|
constructor() {
|
|
11
|
-
super(ui.
|
|
12
|
-
|
|
21
|
+
super(ui.box());
|
|
22
|
+
|
|
23
|
+
this.meta = new ModelHandler();
|
|
24
|
+
this.name = 'Models';
|
|
25
|
+
this.permanentFilter = '#model';
|
|
26
|
+
this.objectType = 'Script';
|
|
27
|
+
|
|
28
|
+
this.caption = super.addProperty('caption', DG.TYPE.STRING, 'Models');
|
|
13
29
|
this.order = super.addProperty('order', DG.TYPE.STRING, '0');
|
|
14
|
-
|
|
30
|
+
|
|
31
|
+
let topbar = ui.divH([
|
|
32
|
+
ui.choiceInput('', 'Recent', ['Recent','Newest','Oldest'], (v:string) => {
|
|
33
|
+
this.modelsList.innerHTML = '';
|
|
34
|
+
this.getModels(v);
|
|
35
|
+
}).root,
|
|
36
|
+
ui.link('Open Model Catalog', ()=>{
|
|
37
|
+
grok.functions.call("Compute:ModelCatalog");
|
|
38
|
+
setTimeout(() => {
|
|
39
|
+
for (let v of grok.shell.views)
|
|
40
|
+
if (v.name === 'Models')
|
|
41
|
+
grok.shell.v = v;
|
|
42
|
+
}, 500);
|
|
43
|
+
})
|
|
44
|
+
]);
|
|
45
|
+
topbar.style.justifyContent = 'space-between';
|
|
46
|
+
topbar.style.margin = '0 12px';
|
|
47
|
+
topbar.style.alignItems = 'center';
|
|
48
|
+
|
|
49
|
+
this.modelsList = ui.divV([]);
|
|
50
|
+
this.modelsList.style.marginLeft = '12px';
|
|
51
|
+
|
|
52
|
+
this.root.appendChild(ui.splitV([
|
|
53
|
+
ui.box(topbar, {style:{maxHeight:'40px'}}),
|
|
54
|
+
this.modelsList
|
|
55
|
+
]));
|
|
56
|
+
|
|
57
|
+
DG.ObjectHandler.register(new ModelHandler());
|
|
58
|
+
|
|
59
|
+
this.getModels('updatedOn');
|
|
15
60
|
}
|
|
16
61
|
|
|
17
|
-
|
|
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
|
-
}
|
|
62
|
+
|
|
27
63
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
64
|
+
async getModels(order:string){
|
|
65
|
+
let b = true;
|
|
66
|
+
let v = order;
|
|
67
|
+
|
|
68
|
+
switch(order){
|
|
69
|
+
case 'Recent':
|
|
70
|
+
v = 'updatedOn';
|
|
71
|
+
break;
|
|
72
|
+
case 'Newest':
|
|
73
|
+
v = 'createdOn';
|
|
74
|
+
break;
|
|
75
|
+
case 'Oldest':
|
|
76
|
+
v = 'createdOn';
|
|
77
|
+
b = false;
|
|
78
|
+
break;
|
|
79
|
+
default:
|
|
80
|
+
v = 'updatedOn';
|
|
81
|
+
}
|
|
34
82
|
|
|
35
83
|
grok.dapi.scripts
|
|
36
84
|
.filter('#model')
|
|
85
|
+
.order(v, b)
|
|
37
86
|
.list()
|
|
38
87
|
.then((scripts) => scripts.map((p) => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
88
|
+
let d = this.meta.renderMarkup(p);
|
|
89
|
+
d.ondblclick = (e) => {
|
|
90
|
+
ModelsWidget.openModel(p);
|
|
91
|
+
}
|
|
92
|
+
d.style.color = 'var(--blue-1)';
|
|
93
|
+
d.style.margin = '4px 0';
|
|
94
|
+
$(d).find('.ui-label').addClass('ui-link');
|
|
95
|
+
|
|
96
|
+
this.modelsList.append(d)
|
|
48
97
|
}));
|
|
98
|
+
}
|
|
49
99
|
|
|
50
|
-
|
|
100
|
+
static openModel(x: DG.Script, parentCall?: DG.FuncCall) {
|
|
101
|
+
let views = []
|
|
102
|
+
for (let v of grok.shell.views)
|
|
103
|
+
views.push(v.name)
|
|
104
|
+
|
|
105
|
+
if (views.includes('Models')){
|
|
106
|
+
let view = new FunctionView(x);
|
|
107
|
+
view.parentCall = parentCall!;
|
|
108
|
+
grok.shell.addView(view);
|
|
109
|
+
}else{
|
|
110
|
+
grok.functions.call("Compute:ModelCatalog");
|
|
111
|
+
setTimeout(() => {
|
|
112
|
+
let view = new FunctionView(x);
|
|
113
|
+
view.parentCall = parentCall!;
|
|
114
|
+
grok.shell.addView(view);
|
|
115
|
+
}, 500)
|
|
116
|
+
}
|
|
51
117
|
}
|
|
52
|
-
}
|
|
53
118
|
|
|
54
|
-
|
|
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
|
-
}
|
|
119
|
+
}
|