@datagrok/compute 0.7.1 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -4
- package/dist/package.js +1518 -0
- package/package.json +20 -7
- package/scripts/Fab Arm Exchange.py +4 -3
- package/scripts/Heat Exchange.js +2 -2
- package/scripts/IntervalsFromECG.py +0 -1
- package/scripts/Logistic Map.js +1 -1
- package/scripts/Lorenz Attractor.js +1 -1
- package/scripts/Lotka-Volterra.js +2 -1
- package/scripts/Maximal Volume.R +0 -1
- package/scripts/pkpd.R +0 -1
- package/scripts/popPK.R +0 -1
- package/scripts/trig.js +0 -1
- package/scripts/vmax.js +180 -0
- package/scripts/wrapper.js +8 -0
- package/src/css/model-card.css +61 -0
- package/src/function-views/compute-view.ts +162 -0
- package/src/model-catalog-view.ts +23 -13
- package/src/model-handler.ts +52 -38
- package/src/models-widget.ts +97 -44
- package/src/outliers-selection/outliers-selection-viewer.ts +37 -28
- package/src/package.ts +60 -23
- package/src/view-samples/computation-test-view.ts +8 -0
- package/.eslintrc.json +0 -35
- package/src/export-funccall.ts +0 -200
package/package.json
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datagrok/compute",
|
|
3
3
|
"friendlyName": "Compute",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"description": "",
|
|
4
|
+
"version": "0.8.3",
|
|
5
|
+
"description": "Provides additional analytical and UI blocks for [Datagrok scientific computing](../../help/compute/compute.md)",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/datagrok-ai/public.git",
|
|
9
|
+
"directory": "packages/Compute"
|
|
10
|
+
},
|
|
6
11
|
"dependencies": {
|
|
12
|
+
"@datagrok-libraries/utils": "^0.4.0",
|
|
7
13
|
"cash-dom": "latest",
|
|
8
14
|
"codemirror": "^5.64.0",
|
|
9
|
-
"datagrok-api": "
|
|
15
|
+
"datagrok-api": "^1.0.0",
|
|
10
16
|
"dayjs": "latest",
|
|
11
17
|
"exceljs": "^4.3.0",
|
|
12
18
|
"file-saver": "^2.0.5",
|
|
@@ -30,10 +36,13 @@
|
|
|
30
36
|
},
|
|
31
37
|
"scripts": {
|
|
32
38
|
"link-api": "npm link datagrok-api",
|
|
33
|
-
"
|
|
34
|
-
"
|
|
39
|
+
"link-utils": "npm link @datagrok-libraries/utils",
|
|
40
|
+
"link-all": "npm link datagrok-api @datagrok-libraries/utils",
|
|
41
|
+
"debug-compute": "webpack & grok publish localhost --release",
|
|
42
|
+
"release-compute": "webpack && grok publish localhost --release",
|
|
35
43
|
"build-compute": "webpack",
|
|
36
44
|
"build": "webpack",
|
|
45
|
+
"build-compute-local": "npm --prefix ./../../js-api run build && npm --prefix ./../../libraries/utils run build && npm run build",
|
|
37
46
|
"debug-compute-dev": "webpack && grok publish dev --rebuild",
|
|
38
47
|
"release-compute-dev": "grok publish dev --release",
|
|
39
48
|
"debug-compute-local": "grok publish local --rebuild",
|
|
@@ -43,6 +52,10 @@
|
|
|
43
52
|
"debug-compute-compose": "grok publish compose --rebuild",
|
|
44
53
|
"release-compute-compose": "grok publish compose --rebuild --release"
|
|
45
54
|
},
|
|
46
|
-
"canEdit": [
|
|
47
|
-
|
|
55
|
+
"canEdit": [
|
|
56
|
+
"Developers"
|
|
57
|
+
],
|
|
58
|
+
"canView": [
|
|
59
|
+
"All users"
|
|
60
|
+
]
|
|
48
61
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
#name: Fab Arm Exchange
|
|
2
2
|
#language: python
|
|
3
|
-
#tags:
|
|
4
|
-
#meta.
|
|
5
|
-
#meta.
|
|
3
|
+
#tags: antibody-eng
|
|
4
|
+
#meta.department: BTDS
|
|
5
|
+
#meta.status: Upstream
|
|
6
|
+
#meta.group: Bioengineering process
|
|
6
7
|
#input: double meaConcentration = 60 {category:FAE Reaction Parameters; units:mM; caption:2-MEA Concentration} [2-MEA Concentration]
|
|
7
8
|
#input: double phOfFaeReaction = 7.5 {category:FAE Reaction Parameters; caption:pH of FAE Reaction} [pH of FAE Reaction]
|
|
8
9
|
#input: double faeReactionTime = 3 {category:FAE Reaction Parameters; units:hr; caption:FAE Reaction Time} [FAE Reaction Time]
|
package/scripts/Heat Exchange.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
//name: Heat Exchange
|
|
2
2
|
//language: javascript
|
|
3
|
-
//tags:
|
|
4
|
-
//meta.modality: Small molecule
|
|
3
|
+
//tags: simulation
|
|
5
4
|
//input: int len = 1000
|
|
6
5
|
//input: double k = 1.2
|
|
7
6
|
//output: dataframe simulation {viewer: Line Chart(multiAxis: "true")}
|
|
@@ -9,6 +8,7 @@
|
|
|
9
8
|
//output: double finalSaturation
|
|
10
9
|
//output: double finalConcentration
|
|
11
10
|
//meta.domain: Manufacturing
|
|
11
|
+
//meta.modality: Small molecule
|
|
12
12
|
|
|
13
13
|
function sigmoid(z) {
|
|
14
14
|
return 1 / (1 + Math.exp(-z));
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
#name: IntervalsFromECG
|
|
2
2
|
#description: Identify the beats in an ECG signal and compute the IBIs
|
|
3
3
|
#language: python
|
|
4
|
-
#tags: model
|
|
5
4
|
#input: double samplingFrequency = 2048
|
|
6
5
|
#input: int bpmMax = 120 [Maximal expected heart rate (in beats per minute): (1 < bpm_max <= 400)]
|
|
7
6
|
#input: double delta = 0 [Threshold for the peak detection. By default it is computed from the signal (adaptive thresholding)]
|
package/scripts/Logistic Map.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//name: Logistic Map
|
|
2
|
-
//tags:
|
|
2
|
+
//tags: simulation
|
|
3
3
|
//description: Archetypal example of how complex, chaotic behaviour can arise from very simple non-linear dynamical equations.
|
|
4
4
|
//language: javascript
|
|
5
5
|
//input: int iterations = 1000 [Number of iterations per point]
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//name: Lorenz Attractor
|
|
2
|
-
//tags:
|
|
2
|
+
//tags: simulation
|
|
3
3
|
//meta.domain: Nonlinear dynamics
|
|
4
4
|
//description: Set of chaotic solutions of the system for weather prediction. It illustrates the phenomenon known as the Butterfly effect or (more technically) sensitive dependence on initial conditions
|
|
5
5
|
//language: javascript
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//name: Lotka-Volterra
|
|
2
|
-
//tags:
|
|
2
|
+
//tags: simulation
|
|
3
3
|
//meta.domain: Nonlinear dynamics
|
|
4
4
|
//description: Model describes the dynamics of biological systems in which two species interact, one as a predator and the other as prey.
|
|
5
5
|
//language: javascript
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
//input: double timeStop = 18
|
|
15
15
|
//output: dataframe df {viewer: Line Chart(x: "Time", multiAxis: "true", title: "Lotka-Volterra Model")}
|
|
16
16
|
|
|
17
|
+
|
|
17
18
|
function sumArrays(...arrays) {
|
|
18
19
|
return Array.from({ length: 2 })
|
|
19
20
|
.map((_, i) => arrays
|
package/scripts/Maximal Volume.R
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
#name: Vmax
|
|
2
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
3
|
#language: r
|
|
4
|
-
#tags: model
|
|
5
4
|
#input: dataframe test_data {editor: Compute:manualOutlierSelectionDialog; editor-button: Outliers...}
|
|
6
5
|
#input: double test_area = 3.5 {caption: Filter Area; units: cm²} [Filter area]
|
|
7
6
|
#input: double vbatch = 25 {caption: VBatch; units: L} [Desired batch size to process]
|
package/scripts/pkpd.R
CHANGED
package/scripts/popPK.R
CHANGED
package/scripts/trig.js
CHANGED
package/scripts/vmax.js
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
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
|
|
5
|
+
//meta.department: BTDS
|
|
6
|
+
//meta.status: Upstream
|
|
7
|
+
//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")}
|
|
8
|
+
//input: dataframe reportingParameters {caption: Reporting parameters; viewer: Grid()}
|
|
9
|
+
//input: double testFilterArea = 3.5 {caption: Test filter area; units: cm²} [Test filter area]
|
|
10
|
+
//input: double desiredVolumeOfBatch = 25 {caption: Desired batch volume; units: L} [Desired batch volume]
|
|
11
|
+
//input: double desiredProcessTime = 0.5 {caption: Desired process time; units: hr} [Desired process time]
|
|
12
|
+
//input: double sf = 1.5 {caption: Safety factor} [Safety factor]
|
|
13
|
+
//help-url: https://github.com/datagrok-ai/public/blob/master/packages/Compute/src/help.md
|
|
14
|
+
//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}
|
|
15
|
+
//output: dataframe trialData {caption: Trial data; viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); category: OUTPUT}
|
|
16
|
+
//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}
|
|
17
|
+
//output: dataframe experimentalResultsSummary {viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); caption: Experimental results summary; category: OUTPUT}
|
|
18
|
+
//output: dataframe recommendations {viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); caption: Recommendations; category: OUTPUT}
|
|
19
|
+
//output: dataframe sampleCharacteristics {viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); caption: Sample characteristics; category: OUTPUT}
|
|
20
|
+
//output: dataframe filter {viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); caption: Filter; category: OUTPUT}
|
|
21
|
+
//editor: Compute:ComputationView
|
|
22
|
+
// inputTable = grok.shell.tables[0]; reportingParameters = grok.shell.tables[1];
|
|
23
|
+
// testFilterArea = 3.5; desiredVolumeOfBatch = 25; desiredProcessTime = 0.5; sf = 1.5;
|
|
24
|
+
|
|
25
|
+
const COL_NAMES = {
|
|
26
|
+
INPUT_TIME_IN_MINUTES: "time (min)",
|
|
27
|
+
INPUT_VOLUME_IN_MILLILITERS: "filtrate volume (mL)",
|
|
28
|
+
INPUT_IS_OUTLIER: "isOutlier",
|
|
29
|
+
TIME_IN_HOURS: "Time [hr]",
|
|
30
|
+
TRIAL_THROUGHPUT: "Throughput [L/m²]",
|
|
31
|
+
T_V: "Time/volume/area [hr/L/m²]",
|
|
32
|
+
FLOW_RATE: "Flow rate",
|
|
33
|
+
FLUX: "Flux",
|
|
34
|
+
RELATIVE_FLUX: "Rel Flux"
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const PARAM_NAMES = {
|
|
38
|
+
FILTER_FAMILY: "Filter family",
|
|
39
|
+
FILTER_NAME: "Filter name",
|
|
40
|
+
PORE_RATING: "Pore rating (μm)",
|
|
41
|
+
EFFECTIVE_MEMBR_AREA: "Effective membr. area (cm^2)",
|
|
42
|
+
MEMBR_MATERIAL: "Membr material",
|
|
43
|
+
CATALOG_NR: "Catalog nr",
|
|
44
|
+
DATE: "Date",
|
|
45
|
+
PRIOR_STEP: "Prior step",
|
|
46
|
+
PROT_CONC: "Prot conc. (mg/mL)",
|
|
47
|
+
DENSITY: "Density (g/L)",
|
|
48
|
+
TURBIDITY: "Turbidity (NTU)",
|
|
49
|
+
INSTALLED_DEVICE: "Installed device",
|
|
50
|
+
PROJECT_NAME: "Project name", // PARAMETERS BELOW ARE NOT USED
|
|
51
|
+
FILTRATION_STAGE: "Filtration stage",
|
|
52
|
+
ELN_REFERENCE: "ELN reference",
|
|
53
|
+
BIOREACTOR_ID: "Bioreactor ID",
|
|
54
|
+
BIOREACTOR_PCV: "Bioreactor PCV (%)",
|
|
55
|
+
BIOREACTOR_TURBIDITY: "Bioreactor turbidity (NTU)",
|
|
56
|
+
FILTER_FEED_TURBIDITY: "Filter feed turbidity (NTU)",
|
|
57
|
+
FILTER_FEED_PCV: "Filter feed PCV (%)",
|
|
58
|
+
FILTER_FEED_PH: "Filter feed pH",
|
|
59
|
+
FILTER_FEED_LDH: "Filter feed LDH (U/L)",
|
|
60
|
+
FILTER_FEED_CONDUCTIVITY: "Filter feed conductivity (mS/cm)"
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
function linearRegression(x, y) {
|
|
64
|
+
let sum_x = 0, sum_y = 0, sum_xy = 0, sum_xx = 0;
|
|
65
|
+
for (let i = 0; i < y.length; i++) {
|
|
66
|
+
sum_x += x[i];
|
|
67
|
+
sum_y += y[i];
|
|
68
|
+
sum_xy += x[i] * y[i];
|
|
69
|
+
sum_xx += x[i] * x[i];
|
|
70
|
+
}
|
|
71
|
+
const slope = (y.length * sum_xy - sum_x * sum_y) / (y.length * sum_xx - sum_x * sum_x);
|
|
72
|
+
const intercept = (sum_y - slope * sum_x) / y.length;
|
|
73
|
+
return { slope: slope, intercept: intercept };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const timeInMinutes = inputTable.col(COL_NAMES.INPUT_TIME_IN_MINUTES);
|
|
77
|
+
const volumeInMilliliters = inputTable.col(COL_NAMES.INPUT_VOLUME_IN_MILLILITERS);
|
|
78
|
+
const isOutlier = inputTable.col(COL_NAMES.INPUT_IS_OUTLIER);
|
|
79
|
+
|
|
80
|
+
let df = DG.DataFrame.fromColumns([timeInMinutes, volumeInMilliliters, isOutlier]);
|
|
81
|
+
|
|
82
|
+
df.columns.addNewFloat(COL_NAMES.TIME_IN_HOURS).init((i) => timeInMinutes.get(i) / 60);
|
|
83
|
+
const timeInHours = df.col(COL_NAMES.TIME_IN_HOURS);
|
|
84
|
+
|
|
85
|
+
df.columns.addNewFloat(COL_NAMES.TRIAL_THROUGHPUT).init((i) => 10 * volumeInMilliliters.get(i) / testFilterArea);
|
|
86
|
+
const trialThroughputCol = df.col(COL_NAMES.TRIAL_THROUGHPUT);
|
|
87
|
+
|
|
88
|
+
df.columns.addNewFloat(COL_NAMES.T_V).init((i) => timeInHours.get(i) / trialThroughputCol.get(i));
|
|
89
|
+
const tv = df.col(COL_NAMES.T_V);
|
|
90
|
+
|
|
91
|
+
df.columns.addNewFloat(COL_NAMES.FLOW_RATE).init((i) => (i > 0) ?
|
|
92
|
+
0.06 * (volumeInMilliliters.get(i) - volumeInMilliliters.get(i - 1)) / (timeInMinutes.get(i) - timeInMinutes.get(i - 1)) : 0
|
|
93
|
+
);
|
|
94
|
+
const flowRate = df.col(COL_NAMES.FLOW_RATE);
|
|
95
|
+
|
|
96
|
+
df.columns.addNewFloat(COL_NAMES.FLUX).init((i) => 10000 * flowRate.get(i) / testFilterArea);
|
|
97
|
+
const flux = df.col(COL_NAMES.FLUX);
|
|
98
|
+
|
|
99
|
+
df.columns.addNewFloat(COL_NAMES.RELATIVE_FLUX).init((i) => flux.get(i) / flux.get(1));
|
|
100
|
+
const relativeFlux = df.col(COL_NAMES.RELATIVE_FLUX);
|
|
101
|
+
|
|
102
|
+
fluxDecayDf = DG.DataFrame.fromColumns([
|
|
103
|
+
DG.Column.fromFloat32Array(COL_NAMES.TRIAL_THROUGHPUT, df.col(COL_NAMES.TRIAL_THROUGHPUT).toList().slice(1)),
|
|
104
|
+
DG.Column.fromFloat32Array(COL_NAMES.FLUX, df.col(COL_NAMES.FLUX).toList().slice(1)),
|
|
105
|
+
DG.Column.fromFloat32Array(COL_NAMES.RELATIVE_FLUX, df.col(COL_NAMES.RELATIVE_FLUX).toList().slice(1)),
|
|
106
|
+
DG.Column.fromList(DG.COLUMN_TYPE.BOOL, isOutlier.name, isOutlier.toList().slice(1))
|
|
107
|
+
]);
|
|
108
|
+
|
|
109
|
+
filtrationKinetics = DG.DataFrame.fromColumns([
|
|
110
|
+
timeInHours,
|
|
111
|
+
df.col(COL_NAMES.T_V),
|
|
112
|
+
volumeInMilliliters,
|
|
113
|
+
isOutlier
|
|
114
|
+
]);
|
|
115
|
+
|
|
116
|
+
df.col(COL_NAMES.INPUT_IS_OUTLIER).markers.assign('true', DG.MARKER_TYPE.OUTLIER);
|
|
117
|
+
filtrationKinetics.col(COL_NAMES.INPUT_IS_OUTLIER).markers.assign('true', DG.MARKER_TYPE.OUTLIER);
|
|
118
|
+
|
|
119
|
+
for (let i = df.rowCount - 1; i > -1; i--)
|
|
120
|
+
if (isOutlier.get(i))
|
|
121
|
+
df.rows.removeAt(i, 1, false);
|
|
122
|
+
|
|
123
|
+
const coefficients = linearRegression(df.col(COL_NAMES.TIME_IN_HOURS).toList(), df.col(COL_NAMES.T_V).toList());
|
|
124
|
+
const vmax = 1 / coefficients.slope;
|
|
125
|
+
const j0 = 1 / coefficients.intercept;
|
|
126
|
+
const flux0 = flux.get(1);
|
|
127
|
+
const amin = desiredVolumeOfBatch / vmax + desiredVolumeOfBatch / desiredProcessTime / j0;
|
|
128
|
+
const installedArea = sf * amin;
|
|
129
|
+
const processLoading = desiredVolumeOfBatch / installedArea;
|
|
130
|
+
const trialThroughput = df.col(COL_NAMES.TRIAL_THROUGHPUT).get(df.rowCount - 1);
|
|
131
|
+
const fluxDecay = (1 - df.col(COL_NAMES.RELATIVE_FLUX).get(df.rowCount - 1)) * 100;
|
|
132
|
+
const initialFlowRate = flowRate.get(1);
|
|
133
|
+
const meanFlux = flux.stats.avg * df.rowCount / (df.rowCount - 1); // exclude zero from calculation
|
|
134
|
+
|
|
135
|
+
const names = reportingParameters.col('Parameter name').toList();
|
|
136
|
+
const values = reportingParameters.col('Parameter value').toList();
|
|
137
|
+
|
|
138
|
+
experimentalResultsSummary = DG.DataFrame.fromObjects([
|
|
139
|
+
{ Name: 'Run', Value: '1' },
|
|
140
|
+
{ Name: 'Filter', Value: values[names.indexOf(PARAM_NAMES.FILTER_FAMILY)] },
|
|
141
|
+
{ Name: 'Trial Throughput [L/m²]', Value: Math.round(1000 * trialThroughput) / 1000 },
|
|
142
|
+
{ Name: 'Flux0 [LMH]', Value: Math.round(1000 * flux0) / 1000 },
|
|
143
|
+
{ Name: 'Mean Flux [LMH]', Value: Math.round(1000 * meanFlux) / 1000 },
|
|
144
|
+
{ Name: 'Vmax [L/m²]', Value: Math.round(1000 * vmax) / 1000 },
|
|
145
|
+
{ Name: 'Flux Decay [%]', Value: Math.round(1000 * fluxDecay) / 1000 }
|
|
146
|
+
]);
|
|
147
|
+
|
|
148
|
+
recommendations = DG.DataFrame.fromObjects([
|
|
149
|
+
{ Name: 'Volume [L]', Value: desiredVolumeOfBatch },
|
|
150
|
+
{ Name: 'Time [h]', Value: desiredProcessTime },
|
|
151
|
+
{ Name: 'Amin [m²]', Value: Math.round(1000 * amin) / 1000 },
|
|
152
|
+
{ Name: 'Safety Factor', Value: sf },
|
|
153
|
+
{ Name: 'Installed Area', Value: Math.round(1000 * installedArea) / 1000 },
|
|
154
|
+
{ Name: 'Process Loading [L/m²]', Value: Math.round(1000 * processLoading) / 1000 },
|
|
155
|
+
{ Name: PARAM_NAMES.FILTER_FAMILY, Value: values[names.indexOf(PARAM_NAMES.FILTER_FAMILY)] },
|
|
156
|
+
{ Name: PARAM_NAMES.INSTALLED_DEVICE, Value: values[names.indexOf(PARAM_NAMES.INSTALLED_DEVICE)] }
|
|
157
|
+
]);
|
|
158
|
+
|
|
159
|
+
trialData = DG.DataFrame.fromObjects([
|
|
160
|
+
{ Name: 'Test Filter Area [cm²]', Value: testFilterArea },
|
|
161
|
+
{ Name: 'Initial Flow Rate [L/h]', Value: Math.round(1000 * initialFlowRate) / 1000 },
|
|
162
|
+
{ Name: 'Vmax [L/m²]', Value: Math.round(1000 * vmax) / 1000 }
|
|
163
|
+
]);
|
|
164
|
+
|
|
165
|
+
filter = DG.DataFrame.fromObjects([
|
|
166
|
+
{ Name: PARAM_NAMES.FILTER_FAMILY, Value: values[names.indexOf(PARAM_NAMES.FILTER_FAMILY)] },
|
|
167
|
+
{ Name: PARAM_NAMES.FILTER_NAME, Value: values[names.indexOf(PARAM_NAMES.FILTER_NAME)] },
|
|
168
|
+
{ Name: PARAM_NAMES.PORE_RATING, Value: values[names.indexOf(PARAM_NAMES.PORE_RATING)] },
|
|
169
|
+
{ Name: PARAM_NAMES.EFFECTIVE_MEMBR_AREA, Value: values[names.indexOf(PARAM_NAMES.EFFECTIVE_MEMBR_AREA)] },
|
|
170
|
+
{ Name: PARAM_NAMES.MEMBR_MATERIAL, Value: values[names.indexOf(PARAM_NAMES.MEMBR_MATERIAL)] },
|
|
171
|
+
{ Name: PARAM_NAMES.CATALOG_NR, Value: values[names.indexOf(PARAM_NAMES.CATALOG_NR)] }
|
|
172
|
+
]);
|
|
173
|
+
|
|
174
|
+
sampleCharacteristics = DG.DataFrame.fromObjects([
|
|
175
|
+
{ Name: PARAM_NAMES.DATE, Value: values[names.indexOf(PARAM_NAMES.DATE)].slice(0, 10) },
|
|
176
|
+
{ Name: PARAM_NAMES.PRIOR_STEP, Value: values[names.indexOf(PARAM_NAMES.PRIOR_STEP)] },
|
|
177
|
+
{ Name: PARAM_NAMES.PROT_CONC, Value: values[names.indexOf(PARAM_NAMES.PROT_CONC)] },
|
|
178
|
+
{ Name: PARAM_NAMES.DENSITY, Value: values[names.indexOf(PARAM_NAMES.DENSITY)].slice(0, 5) },
|
|
179
|
+
{ Name: PARAM_NAMES.TURBIDITY, Value: values[names.indexOf(PARAM_NAMES.TURBIDITY)] }
|
|
180
|
+
]);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
.model-catalog-view .d4-gallery-card.entity-model i {
|
|
2
|
+
height: 64px;
|
|
3
|
+
width: 64px;
|
|
4
|
+
position: initial;
|
|
5
|
+
flex-shrink: 0;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.model-catalog-view .d4-gallery-card.entity-model .d4-link-label i.grok-icon + label {
|
|
9
|
+
margin-left: 6px;
|
|
10
|
+
align-items: center;
|
|
11
|
+
display: inline-flex;
|
|
12
|
+
white-space: normal;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.model-catalog-view .d4-gallery-card.entity-model {
|
|
16
|
+
padding: 0 8px;
|
|
17
|
+
align-items: center;
|
|
18
|
+
display: flex;
|
|
19
|
+
margin: 0;
|
|
20
|
+
height: 94px;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.model-catalog-view .grok-gallery-grid[mode="Brief"] .grok-gallery-grid {
|
|
24
|
+
flex-direction: row!important;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.model-catalog-view .grok-gallery-grid[mode="Brief"] .d4-link-label i.grok-icon {
|
|
28
|
+
width: 32px;
|
|
29
|
+
height: 32px;
|
|
30
|
+
position: initial;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.model-catalog-view .grok-gallery-grid[mode="Brief"] .d4-link-label label {
|
|
34
|
+
margin-left: 8px;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.model-catalog-view .grok-gallery-grid[mode="Brief"] .grok-gallery-grid .d4-link-label {
|
|
38
|
+
min-width: 250px;
|
|
39
|
+
margin-bottom: 9px;
|
|
40
|
+
color: var(--grey-6);
|
|
41
|
+
padding: 10px;
|
|
42
|
+
width: initial;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.model-catalog-view .d4-tree-view-root > .d4-tree-view-group-host > .d4-tree-view-group > .d4-tree-view-node {
|
|
46
|
+
font-size: 20px;
|
|
47
|
+
padding: 4px 0;
|
|
48
|
+
color: var(--grey-6);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.model-catalog-view .d4-tree-view-root > .d4-tree-view-group-host > .d4-tree-view-group > .d4-tree-view-group-host > .d4-tree-view-group > .d4-tree-view-node {
|
|
52
|
+
font-size: 16px;
|
|
53
|
+
padding: 4px 0;
|
|
54
|
+
color: var(--grey-6);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.model-catalog-view .d4-tree-view-root > .d4-tree-view-group-host > .d4-tree-view-group > .d4-tree-view-group-host > .d4-tree-view-group > .d4-tree-view-group-host > .d4-tree-view-group .d4-tree-view-node {
|
|
58
|
+
font-size: 14px;
|
|
59
|
+
padding: 4px 0;
|
|
60
|
+
color: var(--grey-6);
|
|
61
|
+
}
|
|
@@ -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,39 +3,49 @@ 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
|
|
|
14
|
+
this.root.classList.add('model-catalog-view');
|
|
15
15
|
this.meta = new ModelHandler();
|
|
16
16
|
this.name = 'Models';
|
|
17
17
|
this.permanentFilter = '#model';
|
|
18
|
+
this.renderMode = DG.RENDER_MODE.BRIEF;
|
|
19
|
+
|
|
20
|
+
this.objectType = 'Func';
|
|
21
|
+
this.categoryFilters = {
|
|
22
|
+
'options.department': 'Department',
|
|
23
|
+
'options.group': 'Group',
|
|
24
|
+
'options.process': 'Process',
|
|
25
|
+
'tag': 'Tags'
|
|
26
|
+
};
|
|
18
27
|
|
|
19
|
-
this.
|
|
20
|
-
|
|
21
|
-
'
|
|
22
|
-
'
|
|
23
|
-
'createdOn': 'Created',
|
|
24
|
-
'author.id': 'Author'
|
|
28
|
+
this.filters = {
|
|
29
|
+
'All': '',
|
|
30
|
+
'Favorites': 'starredBy = @current',
|
|
31
|
+
'Used by me': 'usedBy = @current'
|
|
25
32
|
};
|
|
33
|
+
this.hierarchy = [
|
|
34
|
+
'options.department',
|
|
35
|
+
'options.group',
|
|
36
|
+
'options.process'
|
|
37
|
+
];
|
|
38
|
+
this.showTree = true;
|
|
26
39
|
this.initRibbon();
|
|
27
40
|
this.initMenu();
|
|
28
41
|
}
|
|
29
42
|
|
|
30
43
|
initRibbon() {
|
|
31
|
-
this.setRibbonPanels([[ui.icons.
|
|
44
|
+
this.setRibbonPanels([[ui.icons.sync(() => this.refresh())]]);
|
|
32
45
|
}
|
|
33
46
|
|
|
34
47
|
initMenu() {
|
|
35
48
|
this.ribbonMenu
|
|
36
|
-
.group('Models')
|
|
37
|
-
.item('Add New...', () => onboardModel())
|
|
38
|
-
.endGroup()
|
|
39
49
|
.group('Help')
|
|
40
50
|
.item('Compute Engine', () => window.open('https://github.com/datagrok-ai/public/tree/master/packages/Compute', '_blank'))
|
|
41
51
|
.item('Developing Models', () => window.open('https://datagrok.ai/help/compute/scripting', '_blank'))
|