@datagrok/compute 0.3.0 → 0.6.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/.eslintrc.json +6 -1
- package/package.json +4 -2
- package/scripts/pMax.js +64 -23
- package/scripts/vMaxJS.js +86 -69
- package/src/export-funccall.ts +76 -13
- package/src/function-editor/function-editor.ts +105 -11
- package/src/outliers-selection/outliers-selection-viewer.ts +262 -0
- package/src/{outliers-selection.ts → outliers-selection/outliers-selection.ts} +9 -3
- package/src/package.ts +21 -8
- package/webpack.config.js +5 -1
package/.eslintrc.json
CHANGED
|
@@ -21,7 +21,12 @@
|
|
|
21
21
|
{ "ignoreStrings": true }
|
|
22
22
|
],
|
|
23
23
|
"require-jsdoc": "off",
|
|
24
|
-
"spaced-comment": "off"
|
|
24
|
+
"spaced-comment": "off",
|
|
25
|
+
"valid-jsdoc": [
|
|
26
|
+
"error",
|
|
27
|
+
{ "requireParamType": false,
|
|
28
|
+
"requireReturnType": false }
|
|
29
|
+
]
|
|
25
30
|
},
|
|
26
31
|
"parser": "@typescript-eslint/parser",
|
|
27
32
|
"plugins": [
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datagrok/compute",
|
|
3
3
|
"friendlyName": "Compute",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.6.1",
|
|
5
5
|
"description": "",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"cash-dom": "latest",
|
|
8
8
|
"codemirror": "^5.64.0",
|
|
9
|
-
"datagrok-api": ">=0.
|
|
9
|
+
"datagrok-api": ">=0.99.0",
|
|
10
10
|
"dayjs": "latest",
|
|
11
11
|
"exceljs": "^4.3.0",
|
|
12
12
|
"file-saver": "^2.0.5",
|
|
@@ -20,8 +20,10 @@
|
|
|
20
20
|
"@types/wu": "latest",
|
|
21
21
|
"@typescript-eslint/eslint-plugin": "^5.1.0",
|
|
22
22
|
"@typescript-eslint/parser": "^5.1.0",
|
|
23
|
+
"css-loader": "^6.5.1",
|
|
23
24
|
"eslint": "^8.0.1",
|
|
24
25
|
"eslint-config-google": "^0.14.0",
|
|
26
|
+
"style-loader": "^3.3.1",
|
|
25
27
|
"webpack": "latest",
|
|
26
28
|
"webpack-cli": "latest"
|
|
27
29
|
},
|
package/scripts/pMax.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
//name:
|
|
1
|
+
//name: Pmax
|
|
2
2
|
//description: pMax Filtration Model
|
|
3
3
|
//language: javascript
|
|
4
|
-
//tags: model
|
|
5
|
-
//input: dataframe inputTable [Should contain columns Time (min), Vol (mL), P1 (psi), P2 (psi)]
|
|
6
|
-
//input: dataframe
|
|
4
|
+
//tags: model, filtration
|
|
5
|
+
//input: dataframe inputTable {caption: Input Table; viewer: Grid()} [Should contain columns Time (min), Vol (mL), P1 (psi), P2 (psi)]
|
|
6
|
+
//input: dataframe reportingParameters {caption: Reporting Parameters; viewer: Grid()}
|
|
7
7
|
//input: double batchVolume = 100 {units: L} [Batch Volume]
|
|
8
8
|
//input: double batchTime = 2 {units: hours} [Batch Time]
|
|
9
9
|
//input: double targetPressure = 20 {units: psi} [Target Pressure]
|
|
@@ -12,14 +12,12 @@
|
|
|
12
12
|
//input: double filterArea1 = 23 {units: m²; caption: A_trial Filter 1} [A_trial Filter 1]
|
|
13
13
|
//input: double filterArea2 = 23 {units: m²; caption: A_trial Filter 2} [A_trial Filter 2]
|
|
14
14
|
//input: double sf = 1.5 {caption: Safety Factor}
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
//output: dataframe
|
|
18
|
-
//output: dataframe
|
|
19
|
-
//output: dataframe
|
|
20
|
-
//output: dataframe
|
|
21
|
-
//output: dataframe t2 {category: OUTPUT}
|
|
22
|
-
//output: dataframe Guessed2 {category: OUTPUT}
|
|
15
|
+
//output: dataframe Filter1 {caption: Primary Filter; viewer: Scatter Plot(showDataframeFormulaLines: "true"); category: OUTPUT}
|
|
16
|
+
//output: dataframe t1 {caption: Primary Filter Results; category: OUTPUT}
|
|
17
|
+
//output: dataframe Guessed1 {caption: Guessed Primary Filter; category: OUTPUT}
|
|
18
|
+
//output: dataframe Filter2 {caption: Secondary Filter; viewer: Scatter Plot(showDataframeFormulaLines: "true"); category: OUTPUT}
|
|
19
|
+
//output: dataframe t2 {caption: Secondary Filter Results; category: OUTPUT}
|
|
20
|
+
//output: dataframe Guessed2 {caption: Guessed Secondary Filter; category: OUTPUT}
|
|
23
21
|
|
|
24
22
|
function gaussianElimination(input, orderOfPolynomialRegression) {
|
|
25
23
|
const n = input.length - 1, coefficients = [orderOfPolynomialRegression];
|
|
@@ -68,12 +66,24 @@ function polynomialRegressionCoefficients(xCol, yCol, orderOfPolynomialRegressio
|
|
|
68
66
|
}
|
|
69
67
|
|
|
70
68
|
function predictPolynomialRegression(coefficients, x) {
|
|
71
|
-
let
|
|
69
|
+
let y = coefficients[0];
|
|
72
70
|
for (let i = coefficients.length - 1; i > 0; i--)
|
|
73
|
-
|
|
74
|
-
return
|
|
71
|
+
y += coefficients[i] * Math.pow(x, i);
|
|
72
|
+
return y;
|
|
75
73
|
}
|
|
76
74
|
|
|
75
|
+
function equationString(xColName, yColName, coefficients) {
|
|
76
|
+
let s = '';
|
|
77
|
+
for (let [index, coefficient] of coefficients.slice(1).reverse().entries()) {
|
|
78
|
+
s += String(coefficient);
|
|
79
|
+
for (let i = 0; i < coefficients.length - index - 1; i++)
|
|
80
|
+
s += " * ${" + String(xColName) + "}";
|
|
81
|
+
s += " + ";
|
|
82
|
+
}
|
|
83
|
+
return "${" + yColName + "} = " + s + String(coefficients[0]);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const orderOfPolynomialRegression = 3;
|
|
77
87
|
const lengthOfSecondTable = 2985;
|
|
78
88
|
const colNames1 = {
|
|
79
89
|
'time': 'Time (min)',
|
|
@@ -110,6 +120,21 @@ Filter2 = DG.DataFrame.fromColumns([df1.col(colNames1['tp2']), df1.col(colNames1
|
|
|
110
120
|
const coefficients1 = polynomialRegressionCoefficients(df1.col(colNames1['tp1']), df1.col(colNames1['res1']), orderOfPolynomialRegression);
|
|
111
121
|
const coefficients2 = polynomialRegressionCoefficients(df1.col(colNames1['tp2']), df1.col(colNames1['res2']), orderOfPolynomialRegression);
|
|
112
122
|
|
|
123
|
+
Filter1.meta.addFormulaLine({
|
|
124
|
+
title: 'Third-order polynomial regression',
|
|
125
|
+
equation: equationString(colNames1['tp1'], colNames1['res1'], coefficients1),
|
|
126
|
+
zindex: -30,
|
|
127
|
+
color: '#ff0000',
|
|
128
|
+
width: 3
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
Filter2.meta.addFormulaLine({
|
|
132
|
+
title: 'Third-order polynomial regression',
|
|
133
|
+
equation: equationString(colNames1['tp2'], colNames1['res2'], coefficients2),
|
|
134
|
+
zindex: -30,
|
|
135
|
+
color: '#ff0000',
|
|
136
|
+
width: 3
|
|
137
|
+
});
|
|
113
138
|
|
|
114
139
|
const df2 = DG.DataFrame.create(lengthOfSecondTable);
|
|
115
140
|
df2.columns.addNewFloat(colNames2['area']).init((i) => (i > 0) ? batchVolume / i : 0);
|
|
@@ -143,21 +168,37 @@ guessedMaxP2 = predictPolynomialRegression(coefficients2, processLoading2) * pro
|
|
|
143
168
|
guessedProcessFlux1 = processFlow1 / aMinFilter1Guessed, guessedProcessFlux2 = processFlow2 / aMinFilter2Guessed;
|
|
144
169
|
|
|
145
170
|
t1 = DG.DataFrame.fromColumns([
|
|
146
|
-
DG.Column.
|
|
147
|
-
DG.Column.
|
|
171
|
+
DG.Column.fromFloat32Array('Amin (m²)', [amin1]),
|
|
172
|
+
DG.Column.fromFloat32Array('Amin w SF (m²)', [aminSF1]),
|
|
173
|
+
DG.Column.fromFloat32Array('Trial Loading (L/m²)', [trialLoading1]),
|
|
174
|
+
DG.Column.fromFloat32Array('Process Loading (L/m²)', [processLoading1]),
|
|
175
|
+
DG.Column.fromFloat32Array('Max P (psi)', [maxP1]),
|
|
176
|
+
DG.Column.fromFloat32Array('Trial Flux (LMH)', [trialFlux1]),
|
|
177
|
+
DG.Column.fromFloat32Array('Process Flux (LMH)', [processFlux1]),
|
|
178
|
+
DG.Column.fromFloat32Array('Process Flow (L/hr)', [processFlow1])
|
|
148
179
|
]);
|
|
149
180
|
|
|
150
181
|
t2 = DG.DataFrame.fromColumns([
|
|
151
|
-
DG.Column.
|
|
152
|
-
DG.Column.
|
|
182
|
+
DG.Column.fromFloat32Array('Amin (m²)', [amin2]),
|
|
183
|
+
DG.Column.fromFloat32Array('Amin w SF (m²)', [aminSF2]),
|
|
184
|
+
DG.Column.fromFloat32Array('Trial Loading (L/m²)', [trialLoading2]),
|
|
185
|
+
DG.Column.fromFloat32Array('Process Loading (L/m²)', [processLoading2]),
|
|
186
|
+
DG.Column.fromFloat32Array('Max P (psi)', [maxP2]),
|
|
187
|
+
DG.Column.fromFloat32Array('Trial Flux (LMH)', [trialFlux2]),
|
|
188
|
+
DG.Column.fromFloat32Array('Process Flux (LMH)', [processFlux2]),
|
|
189
|
+
DG.Column.fromFloat32Array('Process Flow (L/hr)', [processFlow2])
|
|
153
190
|
]);
|
|
154
191
|
|
|
155
192
|
Guessed1 = DG.DataFrame.fromColumns([
|
|
156
|
-
DG.Column.
|
|
157
|
-
DG.Column.
|
|
193
|
+
DG.Column.fromFloat32Array('Amin (m²)', [guessedAmin1]),
|
|
194
|
+
DG.Column.fromFloat32Array('Process Loading (L/m²)', [guessedProcessLoading1]),
|
|
195
|
+
DG.Column.fromFloat32Array('Max P (psi)', [guessedMaxP1]),
|
|
196
|
+
DG.Column.fromFloat32Array('Process Flux (LMH)', [guessedProcessFlux1]),
|
|
158
197
|
]);
|
|
159
198
|
|
|
160
199
|
Guessed2 = DG.DataFrame.fromColumns([
|
|
161
|
-
DG.Column.
|
|
162
|
-
DG.Column.
|
|
200
|
+
DG.Column.fromFloat32Array('Amin (m²)', [guessedAmin2]),
|
|
201
|
+
DG.Column.fromFloat32Array('Process Loading (L/m²)', [guessedProcessLoading2]),
|
|
202
|
+
DG.Column.fromFloat32Array('Max P (psi)', [guessedMaxP2]),
|
|
203
|
+
DG.Column.fromFloat32Array('Process Flux (LMH)', [guessedProcessFlux2]),
|
|
163
204
|
]);
|
package/scripts/vMaxJS.js
CHANGED
|
@@ -1,26 +1,22 @@
|
|
|
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: javascript
|
|
4
|
-
//tags: model
|
|
5
|
-
//input: dataframe inputTable {
|
|
6
|
-
//input:
|
|
7
|
-
//input: double
|
|
8
|
-
//input: double
|
|
4
|
+
//tags: model, filtration
|
|
5
|
+
//input: dataframe inputTable {viewer: OutliersSelectionViewer() | Scatter Plot(filter: "!${isOutlier}", showFilteredOutPoints: "true", filteredOutRowsColor: 4293991195, showRegressionLine: "true") | Grid()}
|
|
6
|
+
//input: dataframe reportingParameters {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]
|
|
9
10
|
//input: double sf = 1.5 {caption: Safety Factor} [Safety Factor]
|
|
10
|
-
//input: int orderOfPolynomialRegression = 2 {caption: Order Of Polynomial Regression} [Order Of Polynomial Regression]
|
|
11
|
-
//meta.showInputs: true
|
|
12
11
|
//help-url: https://github.com/datagrok-ai/public/blob/master/packages/Compute/src/help.md
|
|
13
|
-
//output: dataframe regressionTable {
|
|
14
|
-
//output: dataframe
|
|
15
|
-
//output: dataframe
|
|
16
|
-
//output: dataframe
|
|
17
|
-
//output: dataframe
|
|
18
|
-
//output: dataframe
|
|
19
|
-
//output: dataframe
|
|
20
|
-
//output: dataframe sampleCharacteristics {category: OUTPUT}
|
|
21
|
-
//output: dataframe filter {category: OUTPUT}
|
|
12
|
+
//output: dataframe regressionTable {caption: Regression Table; viewer: Scatter Plot(filter: "!${isOutlier}", showFilteredOutPoints: "true", filteredOutRowsColor: 4293991195, showRegressionLine: "true"); category: OUTPUT}
|
|
13
|
+
//output: dataframe trialData {caption: Trial Data; category: OUTPUT}
|
|
14
|
+
//output: dataframe fluxDecayDf {caption: Flux Decay Experimental Results; viewer: Scatter Plot(filter: "!${isOutlier}", showFilteredOutPoints: "true", filteredOutRowsColor: 4293991195) | Grid(); category: OUTPUT}
|
|
15
|
+
//output: dataframe experimentalResultsSummary {caption: Experimental Results Summary; category: OUTPUT}
|
|
16
|
+
//output: dataframe recommendations {caption: Recommendations; category: OUTPUT}
|
|
17
|
+
//output: dataframe sampleCharacteristics {caption: Sample Characteristics; category: OUTPUT}
|
|
18
|
+
//output: dataframe filter {caption: Filter; category: OUTPUT}
|
|
22
19
|
|
|
23
|
-
volume = vbatch;
|
|
24
20
|
function gaussianElimination(input, orderOfPolynomialRegression) {
|
|
25
21
|
const n = input.length - 1, coefficients = [orderOfPolynomialRegression];
|
|
26
22
|
for (let i = 0; i < n; i++) {
|
|
@@ -67,99 +63,120 @@ function polynomialRegressionCoefficients(xCol, yCol, orderOfPolynomialRegressio
|
|
|
67
63
|
return gaussianElimination(rhs, k);
|
|
68
64
|
}
|
|
69
65
|
|
|
66
|
+
const orderOfPolynomialRegression = 2;
|
|
70
67
|
const area = 0.00035;
|
|
71
|
-
const isOutlierCol = inputTable.col(
|
|
72
|
-
|
|
73
|
-
|
|
68
|
+
const isOutlierCol = inputTable.col('isOutlier');
|
|
69
|
+
const timeMin = [];
|
|
70
|
+
const vol = [];
|
|
74
71
|
for (let i = 0; i < isOutlierCol.length; i++) {
|
|
75
72
|
if (isOutlierCol.get(i) == false) {
|
|
76
|
-
timeMin.push(inputTable.col(
|
|
77
|
-
vol.push(inputTable.col(
|
|
73
|
+
timeMin.push(inputTable.col('time (min)').get(i));
|
|
74
|
+
vol.push(inputTable.col('filtrate volume (mL)').get(i));
|
|
78
75
|
}
|
|
79
76
|
}
|
|
80
|
-
dfWithoutOutliers =
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const
|
|
77
|
+
dfWithoutOutliers = inputTable;
|
|
78
|
+
// DG.DataFrame.fromColumns([
|
|
79
|
+
// DG.Column.fromList('double', 'time (min)', timeMin),
|
|
80
|
+
// DG.Column.fromList('double', 'filtrate volume (mL)', vol),
|
|
81
|
+
// ]);
|
|
82
|
+
const timeInMinutes = dfWithoutOutliers.col('time (min)');
|
|
83
|
+
const volumeInMilliliters = dfWithoutOutliers.col('filtrate volume (mL)');
|
|
86
84
|
dfWithoutOutliers.columns.addNewFloat('time (hr)').init((i) => timeInMinutes.get(i) / 60);
|
|
87
|
-
const timeInHours = dfWithoutOutliers.col(
|
|
85
|
+
const timeInHours = dfWithoutOutliers.col('time (hr)');
|
|
88
86
|
|
|
89
|
-
dfWithoutOutliers.columns.addNewFloat('V (L/m2)').init((i) => 10 * volumeInMilliliters.get(i) /
|
|
87
|
+
dfWithoutOutliers.columns.addNewFloat('V (L/m2)').init((i) => 10 * volumeInMilliliters.get(i) / testFilterArea);
|
|
90
88
|
const newVolume = dfWithoutOutliers.col('V (L/m2)');
|
|
91
89
|
|
|
92
|
-
dfWithoutOutliers.columns.addNewFloat(
|
|
90
|
+
dfWithoutOutliers.columns.addNewFloat('t/V (hr/(L/m2))').init((i) => 100 * timeInHours.get(i) / newVolume.get(i));
|
|
93
91
|
|
|
94
|
-
dfWithoutOutliers.columns.addNewFloat(
|
|
95
|
-
dfWithoutOutliers.columns.addNewFloat(
|
|
92
|
+
dfWithoutOutliers.columns.addNewFloat('Time (s)').init((i) => 60 * timeInMinutes.get(i));
|
|
93
|
+
dfWithoutOutliers.columns.addNewFloat('V (L)').init((i) => volumeInMilliliters.get(i) / 1000);
|
|
96
94
|
const volumeInLiters = dfWithoutOutliers.col('V (L)');
|
|
97
95
|
const timeInSeconds = dfWithoutOutliers.col('Time (s)');
|
|
98
96
|
dfWithoutOutliers.columns.addNewFloat('V/A (L/m2)').init((i) => volumeInLiters.get(i) / area);
|
|
99
97
|
const va = dfWithoutOutliers.col('V/A (L/m2)');
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
98
|
+
// const va = inputTable.
|
|
99
|
+
const ca = [], cb = [];
|
|
100
|
+
const windowLength = 3;
|
|
101
|
+
for (let i = 0; i < va.length - windowLength; i++) {
|
|
102
|
+
const xCol = DG.Column.fromList('double', 'name', timeInSeconds.toList().slice(i, i + windowLength));
|
|
103
|
+
const yCol = DG.Column.fromList('double', 'name', va.toList().slice(i, i + windowLength));
|
|
104
|
+
const coefficients = polynomialRegressionCoefficients(xCol, yCol, orderOfPolynomialRegression);
|
|
106
105
|
ca.push(coefficients[orderOfPolynomialRegression]);
|
|
107
106
|
cb.push(coefficients[orderOfPolynomialRegression - 1]);
|
|
108
107
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const j =
|
|
114
|
-
|
|
115
|
-
const jj0 =
|
|
116
|
-
|
|
117
|
-
|
|
108
|
+
let newDf = DG.DataFrame.create(dfWithoutOutliers.rowCount - windowLength);
|
|
109
|
+
newDf.columns.addNewFloat('a2').init((i) => (i > 0) ? 3600 * (2 * ca[i] * timeInSeconds.get(i) + cb[i]) : 0);
|
|
110
|
+
newDf.columns.addNewFloat('a1').init((i) => (i > 0) ? 3600 * (2 * ca[i] * timeInSeconds.get(i) + cb[i]) : 0);
|
|
111
|
+
newDf.columns.addNewFloat('J (LMH)').init((i) => (i > 0) ? 3600 * (2 * ca[i] * timeInSeconds.get(i) + cb[i]) : 0);
|
|
112
|
+
const j = newDf.col('J (LMH)');
|
|
113
|
+
newDf.columns.addNewFloat('J/Jo').init((i) => (i > 0) ? j.get(i) / (3600 * area) : 0);
|
|
114
|
+
const jj0 = newDf.col('J/Jo');
|
|
115
|
+
fluxDecayDf = DG.DataFrame.fromColumns([
|
|
116
|
+
DG.Column.fromStrings('Run', Array(jj0.length - 1).fill('1')),
|
|
117
|
+
DG.Column.fromFloat32Array(va.name, va.toList().slice(1, va.length - windowLength)),
|
|
118
|
+
DG.Column.fromFloat32Array(j.name, j.toList().slice(1, j.length)),
|
|
119
|
+
DG.Column.fromFloat32Array(jj0.name, jj0.toList().slice(1, jj0.length)),
|
|
120
|
+
DG.Column.fromList('bool', isOutlierCol.name, isOutlierCol.toList().slice(1, isOutlierCol.length - windowLength))
|
|
121
|
+
]);
|
|
118
122
|
|
|
119
123
|
regressionTable = inputTable;
|
|
120
124
|
coefficients = [1.8, 4.32];//[4.32, 1.8];//polynomialRegressionCoefficients(inputTable.col("time (min)"), dfWithoutOutliers.col("t/V (hr/(L/m2))"), 1);
|
|
121
125
|
const trialThroughput = va.max;
|
|
122
126
|
const flux = 9372.11;
|
|
123
127
|
const ff0 = flux / j.get(1);
|
|
124
|
-
experimentalResults = DG.DataFrame.fromColumns([
|
|
125
|
-
DG.Column.fromList('string', 'Parameter', ['Trial Throughput', 'Flux', 'Flux/Flux0']),
|
|
126
|
-
DG.Column.fromList('double', 'Value', [trialThroughput, flux, ff0]),
|
|
127
|
-
DG.Column.fromList('string', 'Unit', ["L/m²", "LMH", "LMH"])
|
|
128
|
-
]);
|
|
129
128
|
const meanFlux = j.stats.avg;
|
|
130
129
|
const vmax = 0.28;//Math.round(1 / coefficients[1]);
|
|
131
130
|
const instantaneousFlux = j.get(j.length - 1);
|
|
132
131
|
const initialFlux = j.get(1);
|
|
133
132
|
const fluxDecay = (1 - instantaneousFlux / initialFlux) * 100;
|
|
133
|
+
const names = reportingParameters.col('Parameter').toList();
|
|
134
|
+
const values = reportingParameters.col('Value').toList();
|
|
134
135
|
experimentalResultsSummary = DG.DataFrame.fromColumns([
|
|
135
|
-
DG.Column.
|
|
136
|
-
DG.Column.
|
|
137
|
-
DG.Column.
|
|
136
|
+
DG.Column.fromStrings('Run', ['1']),
|
|
137
|
+
DG.Column.fromStrings('Filter', [values[names.indexOf('Filter Name')]]),
|
|
138
|
+
DG.Column.fromFloat32Array('Trial Throughput (L/m²)', [trialThroughput]),
|
|
139
|
+
DG.Column.fromFloat32Array('Flux0 (LMH)', [j.get(1)]),
|
|
140
|
+
DG.Column.fromFloat32Array('Mean Flux (LMH)', [meanFlux]),
|
|
141
|
+
DG.Column.fromFloat32Array('Vmax (L/m²)', [vmax]),
|
|
142
|
+
DG.Column.fromFloat32Array('Flux Decay (%)', [fluxDecay]),
|
|
138
143
|
]);
|
|
139
144
|
const q0 = Math.round(1 / coefficients[0]);
|
|
140
|
-
const amin = (
|
|
145
|
+
const amin = (desiredVolumeOfBatch / vmax) + (desiredVolumeOfBatch / desiredProcessTime / q0);
|
|
141
146
|
const installedArea = sf * amin;
|
|
142
147
|
const processLoading = volumeInLiters.get(volumeInLiters.length - 1) / installedArea;
|
|
143
148
|
recommendations = DG.DataFrame.fromColumns([
|
|
144
|
-
DG.Column.
|
|
145
|
-
DG.Column.
|
|
146
|
-
DG.Column.
|
|
149
|
+
DG.Column.fromFloat32Array('Volume (L)', [desiredVolumeOfBatch]),
|
|
150
|
+
DG.Column.fromFloat32Array('Time (h)', [desiredProcessTime]),
|
|
151
|
+
DG.Column.fromFloat32Array('Amin (m²)', [amin]),
|
|
152
|
+
DG.Column.fromFloat32Array('Safety Factor', [sf]),
|
|
153
|
+
DG.Column.fromFloat32Array('Installed Area', [installedArea]),
|
|
154
|
+
DG.Column.fromFloat32Array('Process Loading (L/m²)', [processLoading]),
|
|
155
|
+
DG.Column.fromStrings('Filter', [values[names.indexOf('Filter Name')]]),
|
|
156
|
+
DG.Column.fromStrings('Installed Device', [values[names.indexOf('Installed Device')]]),
|
|
147
157
|
]);
|
|
148
158
|
|
|
149
159
|
const v90 = vmax * 0.68;
|
|
150
|
-
const
|
|
160
|
+
const initialFlowRate = coefficients[0];
|
|
151
161
|
trialData = DG.DataFrame.fromColumns([
|
|
152
|
-
DG.Column.
|
|
153
|
-
DG.Column.
|
|
154
|
-
DG.Column.
|
|
162
|
+
DG.Column.fromFloat32Array('Test Filter Area (m²)', [testFilterArea]),
|
|
163
|
+
DG.Column.fromFloat32Array('Initial Flow Rate (L/h)', [initialFlowRate]),
|
|
164
|
+
DG.Column.fromFloat32Array('Vmax (m²)', [vmax]),
|
|
165
|
+
DG.Column.fromFloat32Array('V90 (m²)', [v90]),
|
|
155
166
|
]);
|
|
156
167
|
|
|
157
168
|
filter = DG.DataFrame.fromColumns([
|
|
158
|
-
DG.Column.
|
|
159
|
-
DG.Column.
|
|
169
|
+
DG.Column.fromStrings('Filter Family', [values[names.indexOf('Filter Family')]]),
|
|
170
|
+
DG.Column.fromStrings('Filter Name', [values[names.indexOf('Filter Name')]]),
|
|
171
|
+
DG.Column.fromStrings('Pore Rating (μm)', [values[names.indexOf('Pore rating (μm)')]]),
|
|
172
|
+
DG.Column.fromStrings('Effective Membr. Area (cm^2)', [values[names.indexOf('Effective Membr. Area (cm^2)')]]),
|
|
173
|
+
DG.Column.fromStrings('Membr material', [values[names.indexOf('Membr material')]]),
|
|
174
|
+
DG.Column.fromStrings('Catalog Nr', [values[names.indexOf('Catalog Nr')]]),
|
|
160
175
|
]);
|
|
161
|
-
|
|
162
176
|
sampleCharacteristics = DG.DataFrame.fromColumns([
|
|
163
|
-
DG.Column.
|
|
164
|
-
DG.Column.
|
|
177
|
+
DG.Column.fromStrings('Date', [values[names.indexOf('date ')]]),
|
|
178
|
+
DG.Column.fromStrings('Prior Step', [values[names.indexOf('Prior Step')]]),
|
|
179
|
+
DG.Column.fromStrings('Prot conc. (mg/mL)', [values[names.indexOf('Prot conc. (mg/mL)')]]),
|
|
180
|
+
DG.Column.fromStrings('Density (g/L)', [values[names.indexOf('Density (g/L)')]]),
|
|
181
|
+
DG.Column.fromStrings('Turbidity (NTU)', [values[names.indexOf('Turbidity (NTU)')]]),
|
|
165
182
|
]);
|
package/src/export-funccall.ts
CHANGED
|
@@ -46,21 +46,85 @@ export async function exportFuncCall(call: DG.FuncCall) {
|
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
// UWAGA: very fragile solution
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
const funcView = document.getElementsByClassName('grok-view grok-view-func ui-box')[0];
|
|
50
|
+
const resultView = funcView.getElementsByClassName('d4-tab-host ui-box')[0];
|
|
51
|
+
if (resultView) {
|
|
52
|
+
const tabs = resultView.getElementsByClassName('d4-tab-header-stripe')[0].children;
|
|
53
|
+
const selectedByUser = resultView.getElementsByClassName('d4-tab-header selected')[0];
|
|
54
|
+
for (let i=0; i< tabs.length; i++) {
|
|
55
|
+
(tabs[i] as HTMLElement).click();
|
|
56
|
+
await new Promise((r) => setTimeout(r, 150));
|
|
57
|
+
|
|
58
|
+
const titleDivs = document.getElementsByClassName('grok-func-results-header');
|
|
59
|
+
if (!titleDivs.length) continue;
|
|
60
|
+
|
|
61
|
+
for (let i = 0; i < titleDivs.length; i++) {
|
|
62
|
+
const titleDiv = titleDivs[i];
|
|
63
|
+
|
|
64
|
+
const title = titleDiv.firstChild?.textContent;
|
|
65
|
+
if (title === null || title === undefined) continue;
|
|
66
|
+
|
|
67
|
+
let imageId;
|
|
68
|
+
let width = 0;
|
|
69
|
+
let height = 0;
|
|
70
|
+
|
|
71
|
+
const imageDiv = titleDiv.parentElement?.getElementsByClassName('grok-scripting-image-container')[0];
|
|
72
|
+
if (imageDiv) {
|
|
73
|
+
const regex = /background-image: url\(.*\)/;
|
|
74
|
+
const urlAttr = imageDiv.outerHTML.match(regex)?.[0];
|
|
75
|
+
if (!urlAttr) continue;
|
|
76
|
+
const url = urlAttr.substring(23, urlAttr?.length - 2);
|
|
77
|
+
const pic = (await (await fetch(url)).arrayBuffer());
|
|
78
|
+
imageId = exportWorkbook.addImage({
|
|
79
|
+
buffer: pic,
|
|
80
|
+
extension: 'png',
|
|
81
|
+
});
|
|
82
|
+
width = imageDiv.clientWidth;
|
|
83
|
+
height = imageDiv.clientHeight;
|
|
84
|
+
} else {
|
|
85
|
+
const plot = titleDiv.nextSibling;
|
|
86
|
+
// if plot does not exist or it is only grid, skip it
|
|
87
|
+
if (!plot || (plot.firstChild?.firstChild?.firstChild as HTMLElement).getAttribute('name') === 'viewer-Grid') continue;
|
|
88
|
+
|
|
89
|
+
if (plot) {
|
|
90
|
+
const canvas = await DG.HtmlUtils.renderToCanvas(plot as HTMLElement);
|
|
91
|
+
const dataUrl = canvas.toDataURL('image/png');
|
|
92
|
+
|
|
93
|
+
imageId = exportWorkbook.addImage({
|
|
94
|
+
base64: dataUrl,
|
|
95
|
+
extension: 'png',
|
|
96
|
+
});
|
|
97
|
+
width = canvas.width;
|
|
98
|
+
height = canvas.height;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
55
101
|
|
|
56
|
-
|
|
57
|
-
if (!titleDivs.length) continue;
|
|
102
|
+
if (imageId === null || imageId === undefined) continue;
|
|
58
103
|
|
|
59
|
-
|
|
104
|
+
const worksheet = exportWorkbook.getWorksheet(`Output - ${title}`);
|
|
105
|
+
if (worksheet) {
|
|
106
|
+
const columnForImage = ((call.outputs[title] as DG.DataFrame).columns as DG.ColumnList).length + 1;
|
|
107
|
+
worksheet.addImage(imageId, {
|
|
108
|
+
tl: {col: columnForImage, row: 0},
|
|
109
|
+
ext: {width, height},
|
|
110
|
+
});
|
|
111
|
+
} else {
|
|
112
|
+
const newWorksheet = exportWorkbook.addWorksheet(`Output - Plot - ${title}`);
|
|
113
|
+
newWorksheet.addImage(imageId, {
|
|
114
|
+
tl: {col: 0, row: 0},
|
|
115
|
+
ext: {width, height},
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
(selectedByUser as HTMLElement).click();
|
|
121
|
+
} else {
|
|
122
|
+
const resultView = document.getElementsByClassName('ui-panel grok-func-results')[0];
|
|
123
|
+
const titleDivs = resultView.getElementsByClassName('grok-func-results-header');
|
|
124
|
+
for (let i=0; i< titleDivs.length; i++) {
|
|
60
125
|
const titleDiv = titleDivs[i];
|
|
61
|
-
|
|
62
126
|
const title = titleDiv.firstChild?.textContent;
|
|
63
|
-
if (
|
|
127
|
+
if (title === null || title === undefined) continue;
|
|
64
128
|
|
|
65
129
|
let imageId;
|
|
66
130
|
let width = 0;
|
|
@@ -82,7 +146,7 @@ export async function exportFuncCall(call: DG.FuncCall) {
|
|
|
82
146
|
} else {
|
|
83
147
|
const plot = titleDiv.nextSibling;
|
|
84
148
|
// if plot does not exist or it is only grid, skip it
|
|
85
|
-
if (!plot || (plot.firstChild as HTMLElement).getAttribute('name') === 'viewer-Grid') continue;
|
|
149
|
+
if (!plot || (plot.firstChild?.firstChild?.firstChild as HTMLElement).getAttribute('name') === 'viewer-Grid') continue;
|
|
86
150
|
|
|
87
151
|
if (plot) {
|
|
88
152
|
const canvas = await DG.HtmlUtils.renderToCanvas(plot as HTMLElement);
|
|
@@ -115,7 +179,6 @@ export async function exportFuncCall(call: DG.FuncCall) {
|
|
|
115
179
|
}
|
|
116
180
|
}
|
|
117
181
|
}
|
|
118
|
-
(selectedByUser as HTMLElement).click();
|
|
119
182
|
|
|
120
183
|
const outputScalarsSheet = exportWorkbook.addWorksheet('Output scalars');
|
|
121
184
|
scalarOutputs.forEach((scalarOutput) => {
|
|
@@ -2,6 +2,7 @@ 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 CodeMirror from 'codemirror';
|
|
5
|
+
import 'codemirror/lib/codemirror.css';
|
|
5
6
|
import {_package} from '../package';
|
|
6
7
|
|
|
7
8
|
const enum FUNC_PROPS_FIELDS {
|
|
@@ -95,6 +96,102 @@ const functionParamsLabels = (key: FUNC_PARAM_FIELDS) => {
|
|
|
95
96
|
}
|
|
96
97
|
};
|
|
97
98
|
|
|
99
|
+
enum COMMON_TAG_NAME {
|
|
100
|
+
VALIDATORS = 'validators',
|
|
101
|
+
CAPTION = 'caption',
|
|
102
|
+
POSTFIX = 'postfix',
|
|
103
|
+
UNITS = 'units',
|
|
104
|
+
EDITOR = 'editor',
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
enum OPTIONAL_TAG_NAME {
|
|
108
|
+
COLUMNS = 'columns',
|
|
109
|
+
CATEGORICAL = 'categorical',
|
|
110
|
+
TYPE = 'type',
|
|
111
|
+
FORMAT = 'format',
|
|
112
|
+
ALLOW_NULLS = 'allowNulls',
|
|
113
|
+
ACTION = 'action',
|
|
114
|
+
CHOICES = 'choices',
|
|
115
|
+
SUGGESTIONS = 'suggestions',
|
|
116
|
+
SEM_TYPE = 'semType',
|
|
117
|
+
MIN = 'min',
|
|
118
|
+
MAX = 'max',
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
type DF_TAG_NAME = COMMON_TAG_NAME | OPTIONAL_TAG_NAME.COLUMNS | OPTIONAL_TAG_NAME.CATEGORICAL;
|
|
122
|
+
type COLUMN_TAG_NAME = COMMON_TAG_NAME |
|
|
123
|
+
OPTIONAL_TAG_NAME.COLUMNS | OPTIONAL_TAG_NAME.FORMAT |
|
|
124
|
+
OPTIONAL_TAG_NAME.ALLOW_NULLS | OPTIONAL_TAG_NAME.ACTION | OPTIONAL_TAG_NAME.SEM_TYPE
|
|
125
|
+
|
|
126
|
+
type STRING_TAG_NAME = COMMON_TAG_NAME |
|
|
127
|
+
OPTIONAL_TAG_NAME.CHOICES | OPTIONAL_TAG_NAME.SUGGESTIONS
|
|
128
|
+
|
|
129
|
+
type INT_TAG_NAME = COMMON_TAG_NAME | OPTIONAL_TAG_NAME.MIN | OPTIONAL_TAG_NAME.MAX
|
|
130
|
+
|
|
131
|
+
const COMMON_TAG_NAMES = [...Object.values(COMMON_TAG_NAME)];
|
|
132
|
+
const DF_TAG_NAMES = [
|
|
133
|
+
...Object.values(COMMON_TAG_NAME),
|
|
134
|
+
OPTIONAL_TAG_NAME.COLUMNS,
|
|
135
|
+
OPTIONAL_TAG_NAME.CATEGORICAL,
|
|
136
|
+
OPTIONAL_TAG_NAME.ACTION];
|
|
137
|
+
const COLUMN_TAG_NAMES = [...Object.values(COMMON_TAG_NAME), OPTIONAL_TAG_NAME.COLUMNS, OPTIONAL_TAG_NAME.FORMAT,
|
|
138
|
+
OPTIONAL_TAG_NAME.ALLOW_NULLS, OPTIONAL_TAG_NAME.ACTION, OPTIONAL_TAG_NAME.SEM_TYPE];
|
|
139
|
+
const STRING_TAG_NAMES = [...Object.values(COMMON_TAG_NAME), OPTIONAL_TAG_NAME.CHOICES, OPTIONAL_TAG_NAME.SUGGESTIONS];
|
|
140
|
+
const INT_TAG_NAMES = [...Object.values(COMMON_TAG_NAME), OPTIONAL_TAG_NAME.MIN, OPTIONAL_TAG_NAME.MAX];
|
|
141
|
+
|
|
142
|
+
type FuncParamBase = {
|
|
143
|
+
direction: DIRECTION,
|
|
144
|
+
name?: string,
|
|
145
|
+
defaultValue?: string,
|
|
146
|
+
description?: string
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
type FuncParam =
|
|
150
|
+
FuncParamBase & {
|
|
151
|
+
type: DG.TYPE.BOOL | DG.TYPE.DATE_TIME | DG.TYPE.FLOAT | DG.TYPE.GRAPHICS | DG.TYPE.INT
|
|
152
|
+
options?: {tag: COMMON_TAG_NAME, value: string}[]
|
|
153
|
+
} | FuncParamBase & {
|
|
154
|
+
type: DG.TYPE.INT
|
|
155
|
+
options?: {tag: COMMON_TAG_NAME, value: string}[]
|
|
156
|
+
} | FuncParamBase & {
|
|
157
|
+
type: DG.TYPE.DATA_FRAME,
|
|
158
|
+
options?: {tag: DF_TAG_NAME, value: string}[]
|
|
159
|
+
} | FuncParamBase & {
|
|
160
|
+
type: DG.TYPE.COLUMN_LIST | DG.TYPE.COLUMN,
|
|
161
|
+
options?: {tag: COLUMN_TAG_NAME, value: string}[]
|
|
162
|
+
} | FuncParamBase & {
|
|
163
|
+
type: DG.TYPE.STRING
|
|
164
|
+
options?: {tag: STRING_TAG_NAME, value: string}[]
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const generateParamLine = (param: DG.Property, direction: string) => {
|
|
168
|
+
const optionTags = (() => {
|
|
169
|
+
switch (param.propertyType) {
|
|
170
|
+
case DG.TYPE.INT:
|
|
171
|
+
return INT_TAG_NAMES;
|
|
172
|
+
case DG.TYPE.DATA_FRAME:
|
|
173
|
+
return DF_TAG_NAMES;
|
|
174
|
+
case DG.TYPE.COLUMN_LIST:
|
|
175
|
+
case DG.TYPE.COLUMN:
|
|
176
|
+
return COLUMN_TAG_NAMES;
|
|
177
|
+
case DG.TYPE.STRING:
|
|
178
|
+
return STRING_TAG_NAMES;
|
|
179
|
+
default:
|
|
180
|
+
return COMMON_TAG_NAMES;
|
|
181
|
+
}
|
|
182
|
+
})();
|
|
183
|
+
const optionTagsPreview = optionTags
|
|
184
|
+
.map((tag) => {
|
|
185
|
+
// console.log(param.name, tag, JSON.stringify(param.options), param.options[tag]);
|
|
186
|
+
return {tag: tag, val: param.options[tag]};
|
|
187
|
+
})
|
|
188
|
+
.filter((value) => !!value.val)
|
|
189
|
+
.map(({tag, val}) => `${tag}:${val}`)
|
|
190
|
+
.join('; ');
|
|
191
|
+
const result =`#${direction}: ${param.propertyType} ${param.name? `${param.name} ` : ''}${param.defaultValue ? `= ${param.defaultValue} ` : ''}${!!optionTagsPreview.length ? `{${optionTagsPreview}} ` : ''}${param.description ? `[${param.description}]` : ''}\n`;
|
|
192
|
+
return result;
|
|
193
|
+
};
|
|
194
|
+
|
|
98
195
|
export function _functionEditor(functionCode: string) {
|
|
99
196
|
const inputScript = DG.Script.create(functionCode);
|
|
100
197
|
|
|
@@ -148,7 +245,9 @@ export function _functionEditor(functionCode: string) {
|
|
|
148
245
|
addButton.replaceWith(newAddButton);
|
|
149
246
|
addButton = newAddButton;
|
|
150
247
|
};
|
|
151
|
-
const menu = DG.Menu.popup().items(getNewProps()
|
|
248
|
+
const menu = DG.Menu.popup().items(getNewProps().map(
|
|
249
|
+
(propName) => functionPropsLabels(propName as FUNC_PROPS_FIELDS),
|
|
250
|
+
), onItemClick);
|
|
152
251
|
|
|
153
252
|
const shevron = ui.iconFA('chevron-down');
|
|
154
253
|
const button = ui.button([ui.icons.add(()=>{}), shevron], () => {
|
|
@@ -276,15 +375,10 @@ export function _functionEditor(functionCode: string) {
|
|
|
276
375
|
return ui.div(result);
|
|
277
376
|
});
|
|
278
377
|
|
|
279
|
-
acc.addPane('
|
|
378
|
+
acc.addPane('Tags', ()=> {
|
|
280
379
|
return ui.div();
|
|
281
380
|
});
|
|
282
381
|
|
|
283
|
-
acc.addPane('Viewers', ()=> {
|
|
284
|
-
return ui.div();
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
|
|
288
382
|
grok.shell.o = ui.divV([ui.h1(`Param: ${paramName}`), acc.root]);
|
|
289
383
|
};
|
|
290
384
|
|
|
@@ -351,9 +445,9 @@ export function _functionEditor(functionCode: string) {
|
|
|
351
445
|
);
|
|
352
446
|
|
|
353
447
|
const area = ui.textInput('', '');
|
|
354
|
-
const myCM = CodeMirror.fromTextArea((area.input as HTMLTextAreaElement)
|
|
448
|
+
const myCM = CodeMirror.fromTextArea((area.input as HTMLTextAreaElement));
|
|
355
449
|
|
|
356
|
-
const previewDiv = ui.divV([ui.h1('Code preview'), area]);
|
|
450
|
+
const previewDiv = ui.panel([ui.divV([ui.h1('Code preview'), area])]);
|
|
357
451
|
previewDiv.style.flexGrow = '1';
|
|
358
452
|
|
|
359
453
|
propsForm = functionPropsForm();
|
|
@@ -429,10 +523,10 @@ export function _functionEditor(functionCode: string) {
|
|
|
429
523
|
if (propValue) result += `#${functionPropsCode(propField as keyof FuncPropsState)}: ${propValue}\n`;
|
|
430
524
|
});
|
|
431
525
|
functionInputParamsCopy.map((param) => {
|
|
432
|
-
result +=
|
|
526
|
+
result += generateParamLine(param, DIRECTION.INPUT);
|
|
433
527
|
});
|
|
434
528
|
functionOutputParamsCopy.map((param) => {
|
|
435
|
-
result +=
|
|
529
|
+
result += generateParamLine(param, DIRECTION.OUTPUT);
|
|
436
530
|
});
|
|
437
531
|
myCM.setValue(result);
|
|
438
532
|
};
|
|
@@ -0,0 +1,262 @@
|
|
|
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
|
+
export class OutliersSelectionViewer extends DG.JsViewer {
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// override to handle property changes
|
|
11
|
+
onPropertyChanged(prop: any) {
|
|
12
|
+
grok.shell.info(`${prop.name}: ${prop.get(this)}`);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
onTableAttached() {
|
|
16
|
+
if (this.dataFrame) {
|
|
17
|
+
this.initialRender();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
render() {
|
|
22
|
+
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
initialRender() {
|
|
26
|
+
if (!this.dataFrame) {
|
|
27
|
+
this.root.innerHTML = '';
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const inputData = this.dataFrame;
|
|
32
|
+
const IS_OUTLIER_COL_LABEL = 'isOutlier';
|
|
33
|
+
const OUTLIER_RATIONALE_COL_LABEL = 'Rationale';
|
|
34
|
+
const OUTLIER_COUNT_COL_LABEL = 'Count';
|
|
35
|
+
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
|
+
|
|
55
|
+
const clearTable = () => {
|
|
56
|
+
return DG.DataFrame.fromColumns([
|
|
57
|
+
DG.Column.fromStrings(OUTLIER_RATIONALE_COL_LABEL, []),
|
|
58
|
+
DG.Column.fromInt32Array(OUTLIER_COUNT_COL_LABEL, new Int32Array([])),
|
|
59
|
+
DG.Column.fromStrings('Actions', []),
|
|
60
|
+
DG.Column.fromBitSet(IS_GROUP_CONFIRMED_LABEL, DG.BitSet.create(0, () => false)),
|
|
61
|
+
]);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const groupsListGrid = DG.Viewer.grid(clearTable());
|
|
65
|
+
groupsListGrid.root.style.width = '100%';
|
|
66
|
+
groupsListGrid.columns.setVisible([OUTLIER_RATIONALE_COL_LABEL, OUTLIER_COUNT_COL_LABEL, 'Actions']);
|
|
67
|
+
|
|
68
|
+
groupsListGrid.onCellPrepare((gc) => {
|
|
69
|
+
if (!gc.isTableCell) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const confirmBtn = () => ui.div(
|
|
74
|
+
ui.iconFA('check', () => {
|
|
75
|
+
if (!groupsListGrid.dataFrame) return;
|
|
76
|
+
|
|
77
|
+
const newRationale =
|
|
78
|
+
groupsListGrid.dataFrame?.cell(groupsListGrid.dataFrame.rowCount-1, OUTLIER_RATIONALE_COL_LABEL).value;
|
|
79
|
+
|
|
80
|
+
inputData.selection.getSelectedIndexes().forEach((selectedIndex: number) => {
|
|
81
|
+
inputData.set(IS_OUTLIER_COL_LABEL, selectedIndex, true);
|
|
82
|
+
inputData.set(
|
|
83
|
+
OUTLIER_RATIONALE_COL_LABEL,
|
|
84
|
+
selectedIndex,
|
|
85
|
+
newRationale,
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
inputData.selection.setAll(false);
|
|
89
|
+
}, 'Confirm the outliers'), {style: {'text-align': 'center', 'margin': '6px'}},
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const cancelBtn = () => ui.div(
|
|
93
|
+
ui.iconFA('times', () => {
|
|
94
|
+
if (!groupsListGrid.dataFrame) return;
|
|
95
|
+
|
|
96
|
+
groupsListGrid.dataFrame.rows.removeAt(groupsListGrid.dataFrame.rowCount-1);
|
|
97
|
+
inputData.selection.setAll(false);
|
|
98
|
+
}, 'Cancel the outliers'), {style: {'text-align': 'center', 'margin': '6px'}},
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
const deleteBtn = (rationale: string) => ui.div(
|
|
102
|
+
ui.icons.delete(() => {
|
|
103
|
+
for (let i = 0; i < inputData.rowCount; i++) {
|
|
104
|
+
if (inputData.columns.byName(OUTLIER_RATIONALE_COL_LABEL).get(i) === rationale) {
|
|
105
|
+
inputData.columns.byName(OUTLIER_RATIONALE_COL_LABEL).set(i, '');
|
|
106
|
+
inputData.columns.byName(IS_OUTLIER_COL_LABEL).set(i, false);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}, 'Remove the outliers group'), {style: {'text-align': 'center', 'margin': '6px'}},
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
if (gc.gridColumn.name === 'Actions') {
|
|
113
|
+
gc.gridColumn.cellType = 'html';
|
|
114
|
+
gc.style.element =
|
|
115
|
+
ui.divH([
|
|
116
|
+
...!gc.grid.dataFrame?.get(IS_GROUP_CONFIRMED_LABEL, gc.gridRow) ?
|
|
117
|
+
[confirmBtn(), cancelBtn()] :
|
|
118
|
+
[deleteBtn(gc.grid.dataFrame?.get(OUTLIER_RATIONALE_COL_LABEL, gc.gridRow))],
|
|
119
|
+
]);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
groupsListGrid.onCellValueEdited.subscribe((editedCell) => {
|
|
124
|
+
if (!groupsListGrid.dataFrame || editedCell.gridColumn.name !== OUTLIER_RATIONALE_COL_LABEL) return;
|
|
125
|
+
|
|
126
|
+
if (!(groupsListGrid.dataFrame.columns as DG.ColumnList)
|
|
127
|
+
.byName(IS_GROUP_CONFIRMED_LABEL).get(editedCell.gridRow)) return;
|
|
128
|
+
|
|
129
|
+
const uniqueValues= new Set<string>();
|
|
130
|
+
for (let i = 0; i < groupsListGrid.dataFrame?.rowCount; i++) {
|
|
131
|
+
const record = groupsListGrid.dataFrame?.columns.byName(OUTLIER_RATIONALE_COL_LABEL).get(i);
|
|
132
|
+
uniqueValues.add(record);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
for (let i = 0; i < inputData.rowCount; i++) {
|
|
136
|
+
const currentCellValue = inputData.columns.byName(OUTLIER_RATIONALE_COL_LABEL).get(i);
|
|
137
|
+
if (currentCellValue != '' && !uniqueValues.has(currentCellValue)) {
|
|
138
|
+
inputData.columns.byName(OUTLIER_RATIONALE_COL_LABEL).set(i, editedCell.cell.value);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
const updateGroupsTable = () => {
|
|
144
|
+
const uniqueValues: {[key:string]: number} = {};
|
|
145
|
+
for (let i = 0; i < inputData.rowCount; i++) {
|
|
146
|
+
const record = inputData.columns.byName(OUTLIER_RATIONALE_COL_LABEL).get(i);
|
|
147
|
+
const count = uniqueValues[record];
|
|
148
|
+
if (record != '') {
|
|
149
|
+
count ?
|
|
150
|
+
uniqueValues[record]++ :
|
|
151
|
+
uniqueValues[record] = 1;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
groupsListGrid.dataFrame = clearTable();
|
|
155
|
+
groupsListGrid.columns.setVisible([OUTLIER_RATIONALE_COL_LABEL, OUTLIER_COUNT_COL_LABEL, 'Actions']);
|
|
156
|
+
|
|
157
|
+
Object.keys(uniqueValues).map((key: string) => {
|
|
158
|
+
groupsListGrid.dataFrame?.rows.addNew([key, uniqueValues[key], '', true]);
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
inputData.onDataChanged.subscribe(updateGroupsTable);
|
|
163
|
+
inputData.onSelectionChanged.subscribe(() => {
|
|
164
|
+
if (!groupsListGrid.dataFrame || !inputData.selection.trueCount) return;
|
|
165
|
+
|
|
166
|
+
const isConfirmedColumn = (groupsListGrid.dataFrame.columns as DG.ColumnList)
|
|
167
|
+
.byName(IS_GROUP_CONFIRMED_LABEL).toList();
|
|
168
|
+
|
|
169
|
+
if (isConfirmedColumn.some((value) => value === false)) {
|
|
170
|
+
groupsListGrid.dataFrame.set(
|
|
171
|
+
OUTLIER_COUNT_COL_LABEL,
|
|
172
|
+
groupsListGrid.dataFrame.rowCount-1,
|
|
173
|
+
inputData.selection.trueCount,
|
|
174
|
+
);
|
|
175
|
+
} else {
|
|
176
|
+
const newRow = groupsListGrid.dataFrame.rows.addNew(['Manual', inputData.selection.trueCount, '', false]);
|
|
177
|
+
groupsListGrid.dataFrame.currentCell = groupsListGrid.dataFrame.cell(newRow.idx, OUTLIER_RATIONALE_COL_LABEL);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
const resetSelectedBtn = ui.button(
|
|
182
|
+
'RESET SELECTED',
|
|
183
|
+
() => {
|
|
184
|
+
inputData.selection.getSelectedIndexes().forEach((selectedIndex: number) => {
|
|
185
|
+
inputData.set(IS_OUTLIER_COL_LABEL, selectedIndex, false);
|
|
186
|
+
inputData.set(OUTLIER_RATIONALE_COL_LABEL, selectedIndex, '');
|
|
187
|
+
});
|
|
188
|
+
inputData.selection.setAll(false);
|
|
189
|
+
},
|
|
190
|
+
'Remove the selected points from oultiers list',
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
const resetAllBtn = ui.button(
|
|
194
|
+
'RESET ALL',
|
|
195
|
+
() => {
|
|
196
|
+
(inputData.columns as DG.ColumnList).byName(IS_OUTLIER_COL_LABEL).init(
|
|
197
|
+
(index) => initialData.get(IS_OUTLIER_COL_LABEL, index),
|
|
198
|
+
);
|
|
199
|
+
(inputData.columns as DG.ColumnList).byName(OUTLIER_RATIONALE_COL_LABEL).init(
|
|
200
|
+
(index) => initialData.get(OUTLIER_RATIONALE_COL_LABEL, index),
|
|
201
|
+
);
|
|
202
|
+
},
|
|
203
|
+
'Cancel all changes',
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
const autoOutlierGroupBtn = ui.button(
|
|
207
|
+
'AUTO DETECT...',
|
|
208
|
+
() => {
|
|
209
|
+
const intInput = ui.intInput('N', 3);
|
|
210
|
+
const columnInput = ui.columnInput('Column', inputData, null);
|
|
211
|
+
ui.dialog('Detect outliers automatically')
|
|
212
|
+
.add(columnInput.root)
|
|
213
|
+
.add(intInput.root)
|
|
214
|
+
.onOK(()=>{
|
|
215
|
+
const meanValue = (columnInput.value as DG.Column).stats.avg;
|
|
216
|
+
const stddev = (columnInput.value as DG.Column).stats.stdev;
|
|
217
|
+
inputData.selection.init((index)=>
|
|
218
|
+
Math.abs(meanValue - (columnInput.value as DG.Column).get(index)) > stddev*intInput.value,
|
|
219
|
+
);
|
|
220
|
+
inputData.selection.getSelectedIndexes().forEach((selectedIndex: number) => {
|
|
221
|
+
inputData.set(IS_OUTLIER_COL_LABEL, selectedIndex, true);
|
|
222
|
+
inputData.set(OUTLIER_RATIONALE_COL_LABEL, selectedIndex, `${intInput.value}x stddev rule`);
|
|
223
|
+
});
|
|
224
|
+
inputData.selection.setAll(false);
|
|
225
|
+
})
|
|
226
|
+
.show();
|
|
227
|
+
},
|
|
228
|
+
'Detect outliers automatically',
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
inputData.selection.setAll(false);
|
|
232
|
+
|
|
233
|
+
inputData.onSelectionChanged.subscribe(() => {
|
|
234
|
+
if (inputData.selection.trueCount === 0) {
|
|
235
|
+
resetSelectedBtn.classList.add('disabled');
|
|
236
|
+
} else {
|
|
237
|
+
resetSelectedBtn.classList.remove('disabled');
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
updateGroupsTable();
|
|
242
|
+
resetSelectedBtn.classList.add('disabled');
|
|
243
|
+
|
|
244
|
+
const info = ui.info(
|
|
245
|
+
ui.div([
|
|
246
|
+
ui.p('Hold the “SHIFT” key and start to draw a freehand selection on the plot area'),
|
|
247
|
+
], {style: {'white-space': 'pre-wrap'}}),
|
|
248
|
+
);
|
|
249
|
+
info.style.marginBottom = '0px';
|
|
250
|
+
|
|
251
|
+
this.root.replaceWith(
|
|
252
|
+
ui.divV([
|
|
253
|
+
info,
|
|
254
|
+
ui.divV([
|
|
255
|
+
ui.divH([
|
|
256
|
+
resetSelectedBtn, resetAllBtn, autoOutlierGroupBtn,
|
|
257
|
+
], {style: {'text-align': 'center', 'justify-content': 'center'}}),
|
|
258
|
+
groupsListGrid.root,
|
|
259
|
+
], {style: {'height': '75%'}}),
|
|
260
|
+
], {style: {'height': '100%', 'min-width': '230px'}}));
|
|
261
|
+
}
|
|
262
|
+
}
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
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
|
-
import {_package} from '
|
|
4
|
+
import {_package} from '../package';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* @param inputData The data to select the outliers in
|
|
8
|
+
* @returns Two dataframes: 1) with selected outliers and 2) with removed outliers
|
|
9
|
+
* @deprecated Use the OutliersSelectionViewer instead
|
|
10
|
+
*/
|
|
6
11
|
export async function selectOutliersManually(inputData: DG.DataFrame) {
|
|
7
12
|
const IS_OUTLIER_COL_LABEL = 'isOutlier';
|
|
8
13
|
const OUTLIER_RATIONALE_COL_LABEL = 'Rationale';
|
|
9
14
|
const OUTLIER_COUNT_COL_LABEL = 'Count';
|
|
10
15
|
const IS_GROUP_CONFIRMED_LABEL = 'isConfirmed';
|
|
11
|
-
const FLUX = 't/V (hr/L)';
|
|
16
|
+
const FLUX = 't/V (hr/(L/m²))';
|
|
17
|
+
const DEFAULT_TEST_AREA = 3.5;
|
|
12
18
|
|
|
13
19
|
if (!inputData.columns.byName(IS_OUTLIER_COL_LABEL)) {
|
|
14
20
|
inputData.columns
|
|
@@ -21,7 +27,7 @@ export async function selectOutliersManually(inputData: DG.DataFrame) {
|
|
|
21
27
|
}
|
|
22
28
|
|
|
23
29
|
if (!inputData.columns.byName(FLUX)) {
|
|
24
|
-
(inputData.columns as DG.ColumnList).addNew(FLUX, 'double').init((index) => (inputData.cell(index, '
|
|
30
|
+
(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)));
|
|
25
31
|
}
|
|
26
32
|
|
|
27
33
|
const initialData = inputData.clone();
|
package/src/package.ts
CHANGED
|
@@ -3,12 +3,13 @@ import * as grok from 'datagrok-api/grok';
|
|
|
3
3
|
import * as ui from 'datagrok-api/ui';
|
|
4
4
|
import * as DG from 'datagrok-api/dg';
|
|
5
5
|
import {ModelHandler} from './model-handler';
|
|
6
|
-
import {selectOutliersManually} from './outliers-selection';
|
|
6
|
+
import {selectOutliersManually} from './outliers-selection/outliers-selection';
|
|
7
7
|
import {exportFuncCall} from './export-funccall';
|
|
8
8
|
import {_functionParametersGrid} from './function-views/function-parameters-grid';
|
|
9
9
|
import {ModelCatalogView} from './model-catalog-view';
|
|
10
10
|
import wu from 'wu';
|
|
11
11
|
import {_functionEditor} from './function-editor/function-editor';
|
|
12
|
+
import {OutliersSelectionViewer} from './outliers-selection/outliers-selection-viewer';
|
|
12
13
|
|
|
13
14
|
let initCompleted: boolean = false;
|
|
14
15
|
export const _package = new DG.Package();
|
|
@@ -46,6 +47,14 @@ export async function manualOutlierSelectionDialog(inputData: DG.DataFrame) {
|
|
|
46
47
|
});
|
|
47
48
|
}
|
|
48
49
|
|
|
50
|
+
//name: OutliersSelectionViewer
|
|
51
|
+
//description: Creates an outliers selection viewer
|
|
52
|
+
//tags: viewer
|
|
53
|
+
//output: viewer
|
|
54
|
+
export function OutliersSelection() {
|
|
55
|
+
return new OutliersSelectionViewer();
|
|
56
|
+
}
|
|
57
|
+
|
|
49
58
|
//name: export To Excel
|
|
50
59
|
//input: funccall call
|
|
51
60
|
//tags: export
|
|
@@ -62,13 +71,17 @@ export function functionEditor() {
|
|
|
62
71
|
#language: python
|
|
63
72
|
#sample: chem/smiles_coordinates.csv
|
|
64
73
|
#tags: demo, chem, rdkit
|
|
65
|
-
#input: dataframe
|
|
66
|
-
#input:
|
|
67
|
-
#input:
|
|
68
|
-
#input:
|
|
69
|
-
#
|
|
70
|
-
#
|
|
71
|
-
#
|
|
74
|
+
#input: dataframe t1 {columns:numerical} [first input data table]
|
|
75
|
+
#input: dataframe t2 {columns:numerical} [second input data table]
|
|
76
|
+
#input: column x {type:numerical; table:t1} [x axis column name]
|
|
77
|
+
#input: column y {type:numerical} [y axis column name]
|
|
78
|
+
#input: column date {type:datetime; format:mm/dd/yyyy} [date column name]
|
|
79
|
+
#input: column_list numdata {type:numerical; table:t1} [numerical columns names]
|
|
80
|
+
#input: int numcomp = 2 {range:2-7} [number of components]
|
|
81
|
+
#input: bool center = true [number of components]
|
|
82
|
+
#input: string type = high {choices: ["high", "low"]} [type of filter]
|
|
83
|
+
#output: dataframe result {action:join(t1)} [pca components]
|
|
84
|
+
#output: graphics scatter [scatter plot]
|
|
72
85
|
|
|
73
86
|
import numba
|
|
74
87
|
import hdbscan
|
package/webpack.config.js
CHANGED
|
@@ -11,6 +11,10 @@ module.exports = {
|
|
|
11
11
|
module: {
|
|
12
12
|
rules: [
|
|
13
13
|
{test: /\.tsx?$/, loader: 'ts-loader'},
|
|
14
|
+
{
|
|
15
|
+
test: /\.css$/,
|
|
16
|
+
use: ['style-loader', 'css-loader'],
|
|
17
|
+
},
|
|
14
18
|
],
|
|
15
19
|
},
|
|
16
20
|
devtool: 'inline-source-map',
|
|
@@ -23,7 +27,7 @@ module.exports = {
|
|
|
23
27
|
'rxjs/operators': 'rxjs.operators',
|
|
24
28
|
'cash-dom': '$',
|
|
25
29
|
'dayjs': 'dayjs',
|
|
26
|
-
'wu': 'wu'
|
|
30
|
+
'wu': 'wu',
|
|
27
31
|
},
|
|
28
32
|
output: {
|
|
29
33
|
filename: '[name].js',
|