@datagrok/compute 0.6.2 → 0.6.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@datagrok/compute",
3
3
  "friendlyName": "Compute",
4
- "version": "0.6.2",
4
+ "version": "0.6.3",
5
5
  "description": "",
6
6
  "dependencies": {
7
7
  "cash-dom": "latest",
package/scripts/pMax.js CHANGED
@@ -2,22 +2,22 @@
2
2
  //description: pMax Filtration Model
3
3
  //language: javascript
4
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
- //input: double batchVolume = 100 {units: L} [Batch Volume]
8
- //input: double batchTime = 2 {units: hours} [Batch Time]
9
- //input: double targetPressure = 20 {units: psi} [Target Pressure]
10
- //input: double aMinFilter1Guessed = 0.153 {units: m²; caption:A_guessed Filter 1} [A_guessed Filter 1]
11
- //input: double aMinFilter2Guessed = 0.153 {units: m²; caption:A_guessed Filter 2} [A_guessed Filter 2]
12
- //input: double filterArea1 = 23 {units: m²; caption: A_trial Filter 1} [A_trial Filter 1]
13
- //input: double filterArea2 = 23 {units: m²; caption: A_trial Filter 2} [A_trial Filter 2]
14
- //input: double sf = 1.5 {caption: Safety Factor}
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}
5
+ //input: dataframe inputTable {caption: Input table; viewer: Grid(block: 50)} [Should contain columns Time (min), Vol (mL), P1 (psi), P2 (psi)]
6
+ //input: dataframe reportingParameters {caption: Reporting parameters; viewer: Grid(block: 50)}
7
+ //input: double batchVolume = 100 {caption: Batch volume; units: L} [Batch volume]
8
+ //input: double batchTime = 2 {caption: Batch time; units: hours} [Batch time]
9
+ //input: double targetPressure = 20 {caption: Target pressure; units: psi} [Target pressure]
10
+ //input: double aMinFilter1Guessed = 0.153 {units: m²; caption:A_guessed filter 1} [A_guessed filter 1]
11
+ //input: double aMinFilter2Guessed = 0.153 {units: m²; caption:A_guessed filter 2} [A_guessed filter 2]
12
+ //input: double filterArea1 = 23 {units: m²; caption: A_trial filter 1} [A_trial filter 1]
13
+ //input: double filterArea2 = 23 {units: m²; caption: A_trial filter 2} [A_trial filter 2]
14
+ //input: double sf = 1.5 {caption: Safety factor}
15
+ //output: dataframe Filter1 {caption: Primary filter; viewer: Scatter Plot(block: 50, showDataframeFormulaLines: "true"); category: OUTPUT}
16
+ //output: dataframe Guessed1 {caption: Guessed primary filter; viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); category: OUTPUT}
17
+ //output: dataframe t1 {caption: Primary filter results; viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); category: OUTPUT}
18
+ //output: dataframe Filter2 {caption: Secondary filter; viewer: Scatter Plot(block: 50, showDataframeFormulaLines: "true"); category: OUTPUT}
19
+ //output: dataframe Guessed2 {caption: Guessed secondary filter; viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); category: OUTPUT}
20
+ //output: dataframe t2 {caption: Secondary filter results; viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); category: OUTPUT}
21
21
 
22
22
  function gaussianElimination(input, orderOfPolynomialRegression) {
23
23
  const n = input.length - 1, coefficients = [orderOfPolynomialRegression];
@@ -167,38 +167,25 @@ guessedMaxP1 = predictPolynomialRegression(coefficients1, processLoading1) * pro
167
167
  guessedMaxP2 = predictPolynomialRegression(coefficients2, processLoading2) * processFlux2;
168
168
  guessedProcessFlux1 = processFlow1 / aMinFilter1Guessed, guessedProcessFlux2 = processFlow2 / aMinFilter2Guessed;
169
169
 
170
+ const names = ['Amin (m²)', 'Amin w SF (m²)', 'Trial Loading (L/m²)', 'Process Loading (L/m²)', 'Max P (psi)', 'Trial Flux (LMH)', 'Process Flux (LMH)', 'Process Flow (L/hr)'];
171
+ const guessedNames = ['Amin (m²)', 'Process Loading (L/m²)', 'Max P (psi)', 'Process Flux (LMH)'];
172
+
170
173
  t1 = DG.DataFrame.fromColumns([
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])
174
+ DG.Column.fromStrings('Name', names),
175
+ DG.Column.fromFloat32Array('Value', [amin1, aminSF1, trialLoading1, processLoading1, maxP1, trialFlux1, processFlux1, processFlow1])
179
176
  ]);
180
177
 
181
178
  t2 = DG.DataFrame.fromColumns([
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])
179
+ DG.Column.fromStrings('Name', names),
180
+ DG.Column.fromFloat32Array('Value', [amin2, aminSF2, trialLoading2, processLoading2, maxP2, trialFlux2, processFlux2, processFlow2])
190
181
  ]);
191
182
 
192
183
  Guessed1 = DG.DataFrame.fromColumns([
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]),
184
+ DG.Column.fromStrings('Name', guessedNames),
185
+ DG.Column.fromFloat32Array('Value', [guessedAmin1, guessedProcessLoading1, guessedMaxP1, guessedProcessFlux1])
197
186
  ]);
198
187
 
199
188
  Guessed2 = DG.DataFrame.fromColumns([
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]),
189
+ DG.Column.fromStrings('Name', guessedNames),
190
+ DG.Column.fromFloat32Array('Value', [guessedAmin2, guessedProcessLoading2, guessedMaxP2, guessedProcessFlux2])
204
191
  ]);
package/scripts/vMaxJS.js CHANGED
@@ -2,20 +2,59 @@
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
4
  //tags: model, filtration
5
- //input: dataframe inputTable {caption: Input Table; viewer: OutliersSelectionViewer() | Scatter Plot(filter: "!${isOutlier}", showFilteredOutPoints: "true", filteredOutRowsColor: 4293991195, showRegressionLine: "true")}
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]
5
+ //input: dataframe inputTable {caption: Input table; viewer: OutliersSelectionViewer(block: 25) | Scatter Plot(block: 75, filter: "!${isOutlier}", showFilteredOutPoints: "true", filteredOutRowsColor: 4293991195, showRegressionLine: "true")}
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
11
  //help-url: https://github.com/datagrok-ai/public/blob/master/packages/Compute/src/help.md
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}
12
+ //output: dataframe regressionTable {caption: Regression table; viewer: Scatter Plot(block: 75, filter: "!${isOutlier}", showFilteredOutPoints: "true", filteredOutRowsColor: 4293991195, showRegressionLine: "true"); 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: "J (LMH)", block: 50, filter: "!${isOutlier}", showFilteredOutPoints: "true", filteredOutRowsColor: 4293991195) | Scatter Plot(description: "Relative flux decay", y: "J/Jo", block: 50, filter: "!${isOutlier}", showFilteredOutPoints: "true", filteredOutRowsColor: 4293991195); 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];
21
+ // reportingParameters = grok.shell.tables[1];
22
+ // testFilterArea = 3.5;
23
+ // desiredVolumeOfBatch = 25;
24
+ // desiredProcessTime = 0.5;
25
+ // sf = 1.5;
26
+
27
+ const expectedInputColNames = {
28
+ "time": "time (min)",
29
+ "volume": "filtrate volume (mL)",
30
+ "isOutlier": "isOutlier"
31
+ };
32
+
33
+ const expectedReportParamsNames = {
34
+ 1: "Filter family",
35
+ 2: "Filter name",
36
+ 3: "Pore rating (μm)",
37
+ 4: "Effective membr. area (cm^2)",
38
+ 5: "Membr material",
39
+ 6: "Catalog nr",
40
+ 7: "Date",
41
+ 8: "Prior step",
42
+ 9: "Prot conc. (mg/mL)",
43
+ 10: "Density (g/L)",
44
+ 11: "Turbidity (NTU)",
45
+ 12: "Installed device",
46
+ 13: "Project name",
47
+ 14: "Filtration stage",
48
+ 15: "ELN reference",
49
+ 16: "Bioreactor ID",
50
+ 17: "Bioreactor PCV (%)",
51
+ 18: "Bioreactor turbidity (NTU)",
52
+ 19: "Filter feed turbidity (NTU)",
53
+ 20: "Filter feed PCV (%)",
54
+ 21: "Filter feed pH",
55
+ 22: "Filter feed LDH (U/L)",
56
+ 23: "Filter feed conductivity (mS/cm)"
57
+ };
19
58
 
20
59
  function gaussianElimination(input, orderOfPolynomialRegression) {
21
60
  const n = input.length - 1, coefficients = [orderOfPolynomialRegression];
@@ -65,123 +104,105 @@ function polynomialRegressionCoefficients(xCol, yCol, orderOfPolynomialRegressio
65
104
 
66
105
  const orderOfPolynomialRegression = 2;
67
106
  const area = 0.00035;
68
- const isOutlierCol = inputTable.col('isOutlier');
69
- const timeMin = [];
70
- const vol = [];
71
- for (let i = 0; i < isOutlierCol.length; i++) {
72
- if (isOutlierCol.get(i) == false) {
73
- timeMin.push(inputTable.col('time (min)').get(i));
74
- vol.push(inputTable.col('filtrate volume (mL)').get(i));
75
- }
76
- }
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)');
84
- dfWithoutOutliers.columns.addNewFloat('time (hr)').init((i) => timeInMinutes.get(i) / 60);
85
- const timeInHours = dfWithoutOutliers.col('time (hr)');
86
-
87
- dfWithoutOutliers.columns.addNewFloat('V (L/m2)').init((i) => 10 * volumeInMilliliters.get(i) / testFilterArea);
88
- const newVolume = dfWithoutOutliers.col('V (L/m2)');
89
-
90
- dfWithoutOutliers.columns.addNewFloat('t/V (hr/(L/m2))').init((i) => 100 * timeInHours.get(i) / newVolume.get(i));
91
-
92
- dfWithoutOutliers.columns.addNewFloat('Time (s)').init((i) => 60 * timeInMinutes.get(i));
93
- dfWithoutOutliers.columns.addNewFloat('V (L)').init((i) => volumeInMilliliters.get(i) / 1000);
94
- const volumeInLiters = dfWithoutOutliers.col('V (L)');
95
- const timeInSeconds = dfWithoutOutliers.col('Time (s)');
96
- dfWithoutOutliers.columns.addNewFloat('V/A (L/m2)').init((i) => volumeInLiters.get(i) / area);
97
- const va = dfWithoutOutliers.col('V/A (L/m2)');
98
- // const va = inputTable.
99
- const ca = [], cb = [];
107
+ const timeInMinutesCol = inputTable.col(expectedInputColNames['time']);
108
+ const volumeInMillilitersCol = inputTable.col(expectedInputColNames['volume']);
109
+ const isOutlierCol = inputTable.col(expectedInputColNames["isOutlier"]);
110
+
111
+ let df = DG.DataFrame.fromColumns([timeInMinutesCol, volumeInMillilitersCol, isOutlierCol]);
112
+ df.columns.addNewFloat('time (hr)').init((i) => timeInMinutesCol.get(i) / 60);
113
+ const timeInHours = df.col('time (hr)');
114
+ df.columns.addNewFloat('V (L/m2)').init((i) => 10 * volumeInMillilitersCol.get(i) / testFilterArea);
115
+ const newVolume = df.col('V (L/m2)');
116
+ df.columns.addNewFloat('t/V (hr/(L/m2))').init((i) => 100 * timeInHours.get(i) / newVolume.get(i));
117
+ df.columns.addNewFloat('Time (s)').init((i) => 60 * timeInMinutesCol.get(i));
118
+ df.columns.addNewFloat('V (L)').init((i) => volumeInMillilitersCol.get(i) / 1000);
119
+ const volumeInLiters = df.col('V (L)');
120
+ const timeInSeconds = df.col('Time (s)');
121
+ df.columns.addNewFloat('V/A (L/m2)').init((i) => volumeInLiters.get(i) / area);
122
+ const va = df.col('V/A (L/m2)');
123
+
124
+ const slopes = [], intercepts = [];
100
125
  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));
126
+ for (let i = 0; i < inputTable.rowCount - windowLength; i++) {
127
+ const xCol = DG.Column.fromFloat32Array('name', timeInSeconds.toList().slice(i, i + windowLength));
128
+ const yCol = DG.Column.fromFloat32Array('name', va.toList().slice(i, i + windowLength));
104
129
  const coefficients = polynomialRegressionCoefficients(xCol, yCol, orderOfPolynomialRegression);
105
- ca.push(coefficients[orderOfPolynomialRegression]);
106
- cb.push(coefficients[orderOfPolynomialRegression - 1]);
130
+ slopes.push(coefficients[orderOfPolynomialRegression]);
131
+ intercepts.push(coefficients[orderOfPolynomialRegression - 1]);
107
132
  }
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);
133
+
134
+ let newDf = DG.DataFrame.create(inputTable.rowCount - windowLength);
135
+ newDf.columns.addNewFloat('a2').init((i) => (i > 0) ? 3600 * (2 * slopes[i] * timeInSeconds.get(i) + intercepts[i]) : 0);
136
+ newDf.columns.addNewFloat('a1').init((i) => (i > 0) ? 3600 * (2 * slopes[i] * timeInSeconds.get(i) + intercepts[i]) : 0);
137
+ newDf.columns.addNewFloat('J (LMH)').init((i) => (i > 0) ? 3600 * (2 * slopes[i] * timeInSeconds.get(i) + intercepts[i]) : 0);
112
138
  const j = newDf.col('J (LMH)');
113
139
  newDf.columns.addNewFloat('J/Jo').init((i) => (i > 0) ? j.get(i) / (3600 * area) : 0);
114
- const jj0 = newDf.col('J/Jo');
140
+ let jj0 = newDf.col('J/Jo');
141
+ jj0 = DG.Column.fromFloat32Array('J/Jo', jj0.toList().map((e) => 100 * e / jj0.max));
115
142
  fluxDecayDf = DG.DataFrame.fromColumns([
116
143
  DG.Column.fromStrings('Run', Array(jj0.length - 1).fill('1')),
117
- DG.Column.fromFloat32Array(va.name, va.toList().slice(1, va.length - windowLength)),
144
+ DG.Column.fromFloat32Array(va.name, va.toList().slice(1, inputTable.rowCount - windowLength)),
118
145
  DG.Column.fromFloat32Array(j.name, j.toList().slice(1, j.length)),
119
146
  DG.Column.fromFloat32Array(jj0.name, jj0.toList().slice(1, jj0.length)),
120
147
  DG.Column.fromList('bool', isOutlierCol.name, isOutlierCol.toList().slice(1, isOutlierCol.length - windowLength))
121
148
  ]);
122
149
 
123
150
  regressionTable = DG.DataFrame.fromColumns([
124
- inputTable.col('time (min)'),
125
- inputTable.col('filtrate volume (mL)'),
126
- dfWithoutOutliers.col('t/V (hr/(L/m2))'),
151
+ timeInMinutesCol,
152
+ volumeInMillilitersCol,
153
+ inputTable.col('t/V (hr/(L/m²))'),
127
154
  isOutlierCol
128
155
  ]);
129
- coefficients = [1.8, 4.32];//[4.32, 1.8];//polynomialRegressionCoefficients(inputTable.col("time (min)"), dfWithoutOutliers.col("t/V (hr/(L/m2))"), 1);
130
- const trialThroughput = va.max;
131
- const flux = 9372.11;
132
- const ff0 = flux / j.get(1);
133
- const meanFlux = j.stats.avg;
134
- const vmax = 0.28;//Math.round(1 / coefficients[1]);
156
+
157
+ const timeMin = [], vol = [], isOutlier = [];
158
+ const isOutlierColList = isOutlierCol.toList();
159
+ for (let i = 0; i < inputTable.rowCount - windowLength; i++) {
160
+ if (isOutlierCol.get(i) == false) {
161
+ timeMin.push(timeInMinutesCol.get(i));
162
+ vol.push(volumeInMillilitersCol.get(i));
163
+ isOutlier.push(true in isOutlierColList.slice(i, i + windowLength));
164
+ }
165
+ }
166
+
167
+ coefficients = polynomialRegressionCoefficients(DG.Column.fromFloat32Array("time (min)", timeMin), DG.Column.fromFloat32Array("t/V (hr/(L/m2))", vol), 1);
168
+ const initialFlowRate = coefficients[0];
169
+ const trialThroughput = Math.round(1000 * va.max) / 1000;
170
+ const flux = initialFlowRate / testFilterArea;
171
+ const initialFlux = Math.round(1000 * j.get(1)) / 1000;
172
+ const ff0 = flux / initialFlux;
173
+ const meanFlux = Math.round(1000 * j.stats.avg) / 1000;
174
+ const vmax = Math.round(1000 * coefficients[1]) / 1000;
175
+ const v90 = Math.round(1000 * (vmax * 0.68)) / 1000;
135
176
  const instantaneousFlux = j.get(j.length - 1);
136
- const initialFlux = j.get(1);
137
- const fluxDecay = (1 - instantaneousFlux / initialFlux) * 100;
138
- const names = reportingParameters.col('Parameter').toList();
139
- const values = reportingParameters.col('Value').toList();
177
+ const fluxDecay = Math.round(1000 * (1 - instantaneousFlux / initialFlux) * 100) / 1000;
178
+ const names = reportingParameters.col('Parameter name').toList();
179
+ const values = reportingParameters.col('Parameter value').toList();
180
+ const q0 = 1 / coefficients[0];
181
+ const amin = Math.round(1000 * (desiredVolumeOfBatch / vmax) + (desiredVolumeOfBatch / desiredProcessTime / q0)) / 1000;
182
+ const installedArea = Math.round(1000 * sf * amin) / 1000;
183
+ const processLoading = Math.round(1000 * volumeInLiters.get(volumeInLiters.length - 1) / installedArea) / 1000;
184
+
140
185
  experimentalResultsSummary = DG.DataFrame.fromColumns([
141
- DG.Column.fromStrings('Run', ['1']),
142
- DG.Column.fromStrings('Filter', [values[names.indexOf('Filter Name')]]),
143
- DG.Column.fromFloat32Array('Trial Throughput (L/m²)', [trialThroughput]),
144
- DG.Column.fromFloat32Array('Flux0 (LMH)', [j.get(1)]),
145
- DG.Column.fromFloat32Array('Mean Flux (LMH)', [meanFlux]),
146
- DG.Column.fromFloat32Array('Vmax (L/m²)', [vmax]),
147
- DG.Column.fromFloat32Array('Flux Decay (%)', [fluxDecay]),
186
+ DG.Column.fromStrings('Name', ['Run', 'Filter', 'Trial Throughput (L/m²)', 'Flux0 (LMH)', 'Mean Flux (LMH)', 'Vmax (L/m²)', 'Flux Decay (%)']),
187
+ DG.Column.fromStrings('Value', ['1', values[names.indexOf(expectedReportParamsNames[1])], String(trialThroughput), String(initialFlux), String(meanFlux), String(vmax), String(fluxDecay)])
148
188
  ]);
149
- const q0 = Math.round(1 / coefficients[0]);
150
- const amin = (desiredVolumeOfBatch / vmax) + (desiredVolumeOfBatch / desiredProcessTime / q0);
151
- const installedArea = sf * amin;
152
- const processLoading = volumeInLiters.get(volumeInLiters.length - 1) / installedArea;
189
+
153
190
  recommendations = DG.DataFrame.fromColumns([
154
- DG.Column.fromFloat32Array('Volume (L)', [desiredVolumeOfBatch]),
155
- DG.Column.fromFloat32Array('Time (h)', [desiredProcessTime]),
156
- DG.Column.fromFloat32Array('Amin (m²)', [amin]),
157
- DG.Column.fromFloat32Array('Safety Factor', [sf]),
158
- DG.Column.fromFloat32Array('Installed Area', [installedArea]),
159
- DG.Column.fromFloat32Array('Process Loading (L/m²)', [processLoading]),
160
- DG.Column.fromStrings('Filter', [values[names.indexOf('Filter Name')]]),
161
- DG.Column.fromStrings('Installed Device', [values[names.indexOf('Installed Device')]]),
191
+ DG.Column.fromStrings('Name', ['Volume (L)', 'Time (h)', 'Amin (m²)', 'Safety Factor', 'Installed Area', 'Process Loading (L/m²)', expectedReportParamsNames[1], expectedReportParamsNames[12]]),
192
+ DG.Column.fromStrings('Value', [String(desiredVolumeOfBatch), String(desiredProcessTime), String(amin), String(sf), String(installedArea), String(processLoading), values[names.indexOf(expectedReportParamsNames[1])], values[names.indexOf(expectedReportParamsNames[12])]])
162
193
  ]);
163
194
 
164
- const v90 = vmax * 0.68;
165
- const initialFlowRate = coefficients[0];
166
195
  trialData = DG.DataFrame.fromColumns([
167
- DG.Column.fromFloat32Array('Test Filter Area (m²)', [testFilterArea]),
168
- DG.Column.fromFloat32Array('Initial Flow Rate (L/h)', [initialFlowRate]),
169
- DG.Column.fromFloat32Array('Vmax (m²)', [vmax]),
170
- DG.Column.fromFloat32Array('V90 (m²)', [v90]),
196
+ DG.Column.fromStrings('Name', ['Test Filter Area (m²)', 'Initial Flow Rate (L/h)', 'Vmax (m²)', 'V90 (m²)']),
197
+ DG.Column.fromStrings('Value', [String(Math.round(1000 * testFilterArea) / 1000), String(Math.round(1000 * initialFlowRate) / 1000), String(vmax), String(v90)])
171
198
  ]);
172
199
 
173
200
  filter = DG.DataFrame.fromColumns([
174
- DG.Column.fromStrings('Filter Family', [values[names.indexOf('Filter Family')]]),
175
- DG.Column.fromStrings('Filter Name', [values[names.indexOf('Filter Name')]]),
176
- DG.Column.fromStrings('Pore Rating (μm)', [values[names.indexOf('Pore rating (μm)')]]),
177
- DG.Column.fromStrings('Effective Membr. Area (cm^2)', [values[names.indexOf('Effective Membr. Area (cm^2)')]]),
178
- DG.Column.fromStrings('Membr material', [values[names.indexOf('Membr material')]]),
179
- DG.Column.fromStrings('Catalog Nr', [values[names.indexOf('Catalog Nr')]]),
201
+ DG.Column.fromStrings('Name', [expectedReportParamsNames[1], expectedReportParamsNames[2], expectedReportParamsNames[3], expectedReportParamsNames[4], expectedReportParamsNames[5], expectedReportParamsNames[6]]),
202
+ DG.Column.fromStrings('Value', [values[names.indexOf(expectedReportParamsNames[1])], values[names.indexOf(expectedReportParamsNames[2])], values[names.indexOf(expectedReportParamsNames[3])], values[names.indexOf(expectedReportParamsNames[4])], values[names.indexOf(expectedReportParamsNames[5])], values[names.indexOf(expectedReportParamsNames[6])]])
180
203
  ]);
204
+
181
205
  sampleCharacteristics = DG.DataFrame.fromColumns([
182
- DG.Column.fromStrings('Date', [values[names.indexOf('date ')]]),
183
- DG.Column.fromStrings('Prior Step', [values[names.indexOf('Prior Step')]]),
184
- DG.Column.fromStrings('Prot conc. (mg/mL)', [values[names.indexOf('Prot conc. (mg/mL)')]]),
185
- DG.Column.fromStrings('Density (g/L)', [values[names.indexOf('Density (g/L)')]]),
186
- DG.Column.fromStrings('Turbidity (NTU)', [values[names.indexOf('Turbidity (NTU)')]]),
206
+ DG.Column.fromStrings('Name', [expectedReportParamsNames[7], expectedReportParamsNames[8], expectedReportParamsNames[9], expectedReportParamsNames[10], expectedReportParamsNames[11]]),
207
+ DG.Column.fromStrings('Value', [values[names.indexOf(expectedReportParamsNames[7])].slice(0, 10), values[names.indexOf(expectedReportParamsNames[8])], values[names.indexOf(expectedReportParamsNames[9])], values[names.indexOf(expectedReportParamsNames[10])], values[names.indexOf(expectedReportParamsNames[11])]])
187
208
  ]);
@@ -4,6 +4,17 @@ import * as DG from 'datagrok-api/dg';
4
4
  import ExcelJS from 'exceljs';
5
5
  import {saveAs} from 'file-saver';
6
6
 
7
+
8
+ const getSheetName = (name: string, direction: DIRECTION) => {
9
+ const idealName = `${direction} - ${name}`;
10
+ return (idealName.length > 31) ? name.substring(0, 32) : idealName;
11
+ };
12
+
13
+ enum DIRECTION {
14
+ INPUT = 'Input',
15
+ OUTPUT = 'Output'
16
+ }
17
+
7
18
  export async function exportFuncCall(call: DG.FuncCall) {
8
19
  //todo: check status
9
20
  // if (call.status != FuncCall.STATUS_COMPLETED) ...
@@ -22,8 +33,12 @@ export async function exportFuncCall(call: DG.FuncCall) {
22
33
  const dfOutputs = call.func.outputs.filter((output) => isDataFrame(output.propertyType));
23
34
  const scalarOutputs = call.func.outputs.filter((output) => isScalarType(output.propertyType));
24
35
 
36
+ const realNames: Record<string, string> = {};
37
+
25
38
  dfInputs.forEach((dfInput) => {
26
- const currentDfSheet = exportWorkbook.addWorksheet(`Input - ${dfInput.name}`);
39
+ const visibleTitle = dfInput.options.caption || dfInput.name;
40
+ const currentDfSheet = exportWorkbook.addWorksheet(getSheetName(visibleTitle, DIRECTION.INPUT));
41
+ realNames[visibleTitle] = dfInput.name;
27
42
  const currentDf = (call.inputs[dfInput.name] as DG.DataFrame);
28
43
  currentDfSheet.addRow((currentDf.columns as DG.ColumnList).names());
29
44
  for (let i = 0; i < currentDf.rowCount; i++) {
@@ -31,13 +46,17 @@ export async function exportFuncCall(call: DG.FuncCall) {
31
46
  }
32
47
  });
33
48
 
34
- const inputScalarsSheet = exportWorkbook.addWorksheet('Input scalars');
35
- scalarInputs.forEach((scalarInput) => {
36
- inputScalarsSheet.addRow([scalarInput.name, call.inputs[scalarInput.name]]);
37
- });
49
+ if (scalarInputs.length) {
50
+ const inputScalarsSheet = exportWorkbook.addWorksheet('Input scalars');
51
+ scalarInputs.forEach((scalarInput) => {
52
+ inputScalarsSheet.addRow([scalarInput.name, call.inputs[scalarInput.name]]);
53
+ });
54
+ }
38
55
 
39
56
  dfOutputs.forEach((dfOutput) => {
40
- const currentDfSheet = exportWorkbook.addWorksheet(`Output - ${dfOutput.name}`);
57
+ const visibleTitle = dfOutput.options.caption || dfOutput.name;
58
+ const currentDfSheet = exportWorkbook.addWorksheet(getSheetName(visibleTitle, DIRECTION.OUTPUT));
59
+ realNames[visibleTitle] = dfOutput.name;
41
60
  const currentDf = (call.outputs[dfOutput.name] as DG.DataFrame);
42
61
  currentDfSheet.addRow((currentDf.columns as DG.ColumnList).names());
43
62
  for (let i = 0; i < currentDf.rowCount; i++) {
@@ -57,12 +76,18 @@ export async function exportFuncCall(call: DG.FuncCall) {
57
76
 
58
77
  const titleDivs = document.getElementsByClassName('grok-func-results-header');
59
78
  if (!titleDivs.length) continue;
79
+ let skipNext = false;
60
80
 
61
81
  for (let i = 0; i < titleDivs.length; i++) {
82
+ if (skipNext) {
83
+ skipNext = false;
84
+ continue;
85
+ }
62
86
  const titleDiv = titleDivs[i];
87
+ if (titleDiv.parentElement?.style.display === 'none') continue;
63
88
 
64
- const title = titleDiv.firstChild?.textContent;
65
- if (title === null || title === undefined) continue;
89
+ const visibleTitle = titleDiv.firstChild?.textContent;
90
+ if (visibleTitle === null || visibleTitle === undefined) continue;
66
91
 
67
92
  let imageId;
68
93
  let width = 0;
@@ -82,9 +107,22 @@ export async function exportFuncCall(call: DG.FuncCall) {
82
107
  width = imageDiv.clientWidth;
83
108
  height = imageDiv.clientHeight;
84
109
  } 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;
110
+ let plot: ChildNode | null | undefined = titleDiv.nextSibling;
111
+
112
+ if (plot && !titleDiv.getElementsByClassName('svg-table').length && (plot as HTMLElement).getAttribute('name') === 'viewer-Grid') continue;
113
+
114
+ if (plot && titleDiv.getElementsByClassName('svg-table').length) {
115
+ if ((plot as HTMLElement).getAttribute('name') === 'viewer-OutliersSelectionViewer') {
116
+ plot = titleDiv.parentElement?.nextSibling?.firstChild?.nextSibling;
117
+ skipNext = true;
118
+ }
119
+ if ((plot as HTMLElement).getAttribute('name') === 'viewer-Grid') {
120
+ (titleDiv.getElementsByClassName('svg-table')[0] as HTMLElement).click();
121
+ await new Promise((r) => setTimeout(r, 150));
122
+ plot = titleDiv.nextSibling;
123
+ }
124
+ }
125
+ console.log(plot);
88
126
 
89
127
  if (plot) {
90
128
  const canvas = await DG.HtmlUtils.renderToCanvas(plot as HTMLElement);
@@ -101,15 +139,22 @@ export async function exportFuncCall(call: DG.FuncCall) {
101
139
 
102
140
  if (imageId === null || imageId === undefined) continue;
103
141
 
104
- const worksheet = exportWorkbook.getWorksheet(`Output - ${title}`);
142
+ const worksheet = exportWorkbook.getWorksheet(getSheetName(visibleTitle, DIRECTION.INPUT)) ||
143
+ exportWorkbook.getWorksheet(getSheetName(visibleTitle, DIRECTION.OUTPUT));
105
144
  if (worksheet) {
106
- const columnForImage = ((call.outputs[title] as DG.DataFrame).columns as DG.ColumnList).length + 1;
145
+ console.log(visibleTitle);
146
+ console.log(realNames[visibleTitle]);
147
+ const columnForImage = (((call
148
+ .inputs[realNames[visibleTitle]] || call
149
+ .outputs[realNames[visibleTitle]]) as DG.DataFrame)
150
+ .columns as DG.ColumnList)
151
+ .length + 1;
107
152
  worksheet.addImage(imageId, {
108
153
  tl: {col: columnForImage, row: 0},
109
154
  ext: {width, height},
110
155
  });
111
156
  } else {
112
- const newWorksheet = exportWorkbook.addWorksheet(`Output - Plot - ${title}`);
157
+ const newWorksheet = exportWorkbook.addWorksheet(`Output - Plot - ${visibleTitle}`);
113
158
  newWorksheet.addImage(imageId, {
114
159
  tl: {col: 0, row: 0},
115
160
  ext: {width, height},
@@ -121,10 +166,17 @@ export async function exportFuncCall(call: DG.FuncCall) {
121
166
  } else {
122
167
  const resultView = document.getElementsByClassName('ui-panel grok-func-results')[0];
123
168
  const titleDivs = resultView.getElementsByClassName('grok-func-results-header');
169
+ let skipNext = false;
170
+
124
171
  for (let i=0; i< titleDivs.length; i++) {
172
+ if (skipNext) {
173
+ skipNext = false;
174
+ continue;
175
+ }
176
+
125
177
  const titleDiv = titleDivs[i];
126
- const title = titleDiv.firstChild?.textContent;
127
- if (title === null || title === undefined) continue;
178
+ const visibleTitle = titleDiv.firstChild?.textContent;
179
+ if (visibleTitle === null || visibleTitle === undefined) continue;
128
180
 
129
181
  let imageId;
130
182
  let width = 0;
@@ -144,9 +196,20 @@ export async function exportFuncCall(call: DG.FuncCall) {
144
196
  width = imageDiv.clientWidth;
145
197
  height = imageDiv.clientHeight;
146
198
  } else {
147
- const plot = titleDiv.nextSibling;
148
- // if plot does not exist or it is only grid, skip it
149
- if (!plot || (plot.firstChild?.firstChild?.firstChild as HTMLElement).getAttribute('name') === 'viewer-Grid') continue;
199
+ let plot: ChildNode | null | undefined = titleDiv.nextSibling;
200
+
201
+ console.log(plot);
202
+
203
+ if (plot &&
204
+ ((plot as HTMLElement).getAttribute('name') === 'viewer-Grid' ||
205
+ (plot as HTMLElement).getAttribute('name') === 'viewer-OutliersSelectionViewer')) {
206
+ if (titleDiv.getElementsByClassName('svg-table').length) {
207
+ plot = titleDiv.parentElement?.nextSibling?.firstChild?.nextSibling;
208
+ skipNext = true;
209
+ } else {
210
+ continue;
211
+ }
212
+ }
150
213
 
151
214
  if (plot) {
152
215
  const canvas = await DG.HtmlUtils.renderToCanvas(plot as HTMLElement);
@@ -163,15 +226,18 @@ export async function exportFuncCall(call: DG.FuncCall) {
163
226
 
164
227
  if (imageId === null || imageId === undefined) continue;
165
228
 
166
- const worksheet = exportWorkbook.getWorksheet(`Output - ${title}`);
229
+ const worksheet = exportWorkbook.getWorksheet(getSheetName(visibleTitle, DIRECTION.OUTPUT));
167
230
  if (worksheet) {
168
- const columnForImage = ((call.outputs[title] as DG.DataFrame).columns as DG.ColumnList).length + 1;
231
+ const columnForImage = ((call
232
+ .outputs[realNames[visibleTitle]] as DG.DataFrame)
233
+ .columns as DG.ColumnList)
234
+ .length + 1;
169
235
  worksheet.addImage(imageId, {
170
236
  tl: {col: columnForImage, row: 0},
171
237
  ext: {width, height},
172
238
  });
173
239
  } else {
174
- const newWorksheet = exportWorkbook.addWorksheet(`Output - Plot - ${title}`);
240
+ const newWorksheet = exportWorkbook.addWorksheet(`Output - Plot - ${visibleTitle}`);
175
241
  newWorksheet.addImage(imageId, {
176
242
  tl: {col: 0, row: 0},
177
243
  ext: {width, height},
@@ -180,10 +246,12 @@ export async function exportFuncCall(call: DG.FuncCall) {
180
246
  }
181
247
  }
182
248
 
183
- const outputScalarsSheet = exportWorkbook.addWorksheet('Output scalars');
184
- scalarOutputs.forEach((scalarOutput) => {
185
- outputScalarsSheet.addRow([scalarOutput.name, call.outputs[scalarOutput.name]]);
186
- });
249
+ if (scalarOutputs.length) {
250
+ const outputScalarsSheet = exportWorkbook.addWorksheet('Output scalars');
251
+ scalarOutputs.forEach((scalarOutput) => {
252
+ outputScalarsSheet.addRow([scalarOutput.name, call.outputs[scalarOutput.name]]);
253
+ });
254
+ }
187
255
 
188
256
  exportWorkbook.xlsx.writeBuffer().then((data) => {
189
257
  const blob = new Blob([data], {type: BLOB_TYPE});
@@ -63,6 +63,7 @@ export class OutliersSelectionViewer extends DG.JsViewer {
63
63
 
64
64
  const groupsListGrid = DG.Viewer.grid(clearTable());
65
65
  groupsListGrid.root.style.width = '100%';
66
+ groupsListGrid.root.style.minWidth = '230px';
66
67
  groupsListGrid.columns.setVisible([OUTLIER_RATIONALE_COL_LABEL, OUTLIER_COUNT_COL_LABEL, 'Actions']);
67
68
 
68
69
  groupsListGrid.onCellPrepare((gc) => {
@@ -178,85 +179,22 @@ export class OutliersSelectionViewer extends DG.JsViewer {
178
179
  }
179
180
  });
180
181
 
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
182
  inputData.selection.setAll(false);
232
183
 
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
184
  updateGroupsTable();
242
- resetSelectedBtn.classList.add('disabled');
243
185
 
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';
186
+ // const info = ui.info(
187
+ // ui.div([
188
+ // ui.p('Hold the “SHIFT” key and start to draw a freehand selection on the plot area'),
189
+ // ], {style: {'white-space': 'pre-wrap'}}),
190
+ // );
191
+ // info.style.marginBottom = '0px';
250
192
 
251
193
  this.root.replaceWith(
252
194
  ui.divV([
253
- info,
254
195
  ui.divV([
255
- ui.divH([
256
- resetSelectedBtn, resetAllBtn, autoOutlierGroupBtn,
257
- ], {style: {'text-align': 'center', 'justify-content': 'center'}}),
258
196
  groupsListGrid.root,
259
197
  ], {style: {'height': '75%'}}),
260
- ], {style: {'height': '100%', 'min-width': '230px'}}));
198
+ ], {style: {'height': '100%'}}));
261
199
  }
262
200
  }