@datagrok/compute 0.4.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@datagrok/compute",
3
3
  "friendlyName": "Compute",
4
- "version": "0.4.0",
4
+ "version": "0.6.2",
5
5
  "description": "",
6
6
  "dependencies": {
7
7
  "cash-dom": "latest",
8
8
  "codemirror": "^5.64.0",
9
- "datagrok-api": ">=0.95.8",
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
@@ -2,8 +2,8 @@
2
2
  //description: pMax Filtration Model
3
3
  //language: javascript
4
4
  //tags: model, filtration
5
- //input: dataframe inputTable [Should contain columns Time (min), Vol (mL), P1 (psi), P2 (psi)]
6
- //input: dataframe inputParametersForReporting
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,13 +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
- //meta.showInputs: true
16
- //output: dataframe Filter1 {viewer: Scatter Plot(x: "TP 1 (L/m2)", y: "Res. 1 (psi/LMH)", showDataframeFormulaLines: "true"); category: OUTPUT}
17
- //output: dataframe t1 {category: OUTPUT}
18
- //output: dataframe Guessed1 {category: OUTPUT}
19
- //output: dataframe Filter2 {viewer: Scatter Plot(x: "TP 2 (L/m2)", y: "Res. 2 (psi/LMH)", showDataframeFormulaLines: "true"); category: OUTPUT}
20
- //output: dataframe t2 {category: OUTPUT}
21
- //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}
22
21
 
23
22
  function gaussianElimination(input, orderOfPolynomialRegression) {
24
23
  const n = input.length - 1, coefficients = [orderOfPolynomialRegression];
@@ -67,13 +66,13 @@ function polynomialRegressionCoefficients(xCol, yCol, orderOfPolynomialRegressio
67
66
  }
68
67
 
69
68
  function predictPolynomialRegression(coefficients, x) {
70
- let result = coefficients[0];
69
+ let y = coefficients[0];
71
70
  for (let i = coefficients.length - 1; i > 0; i--)
72
- result += coefficients[i] * Math.pow(x, i);
73
- return result;
71
+ y += coefficients[i] * Math.pow(x, i);
72
+ return y;
74
73
  }
75
74
 
76
- function equasionString(xColName, yColName, coefficients) {
75
+ function equationString(xColName, yColName, coefficients) {
77
76
  let s = '';
78
77
  for (let [index, coefficient] of coefficients.slice(1).reverse().entries()) {
79
78
  s += String(coefficient);
@@ -120,23 +119,21 @@ Filter1 = DG.DataFrame.fromColumns([df1.col(colNames1['tp1']), df1.col(colNames1
120
119
  Filter2 = DG.DataFrame.fromColumns([df1.col(colNames1['tp2']), df1.col(colNames1['res2'])]);
121
120
  const coefficients1 = polynomialRegressionCoefficients(df1.col(colNames1['tp1']), df1.col(colNames1['res1']), orderOfPolynomialRegression);
122
121
  const coefficients2 = polynomialRegressionCoefficients(df1.col(colNames1['tp2']), df1.col(colNames1['res2']), orderOfPolynomialRegression);
123
- // alert(equasionString(colNames1['tp1'], colNames1['res1'], coefficients1))
124
- // alert(equasionString(colNames1['tp2'], colNames1['res2'], coefficients2))
125
122
 
126
123
  Filter1.meta.addFormulaLine({
127
- title: 'Parabola',
128
- equation: equasionString(colNames1['tp1'], colNames1['res1'], coefficients1),
124
+ title: 'Third-order polynomial regression',
125
+ equation: equationString(colNames1['tp1'], colNames1['res1'], coefficients1),
129
126
  zindex: -30,
130
127
  color: '#ff0000',
131
- width: 2
128
+ width: 3
132
129
  });
133
130
 
134
131
  Filter2.meta.addFormulaLine({
135
- title: 'Parabola',
136
- equation: equasionString(colNames1['tp2'], colNames1['res2'], coefficients2),
132
+ title: 'Third-order polynomial regression',
133
+ equation: equationString(colNames1['tp2'], colNames1['res2'], coefficients2),
137
134
  zindex: -30,
138
135
  color: '#ff0000',
139
- width: 2
136
+ width: 3
140
137
  });
141
138
 
142
139
  const df2 = DG.DataFrame.create(lengthOfSecondTable);
@@ -171,21 +168,37 @@ guessedMaxP2 = predictPolynomialRegression(coefficients2, processLoading2) * pro
171
168
  guessedProcessFlux1 = processFlow1 / aMinFilter1Guessed, guessedProcessFlux2 = processFlow2 / aMinFilter2Guessed;
172
169
 
173
170
  t1 = DG.DataFrame.fromColumns([
174
- DG.Column.fromList('string', 'Parameter', ['amin', 'aminSF', 'trialLoading', 'processLoading', 'maxP', 'trialFlux', 'processFlux', 'processFlow']),
175
- DG.Column.fromList('double', 'Value', [amin1, aminSF1, trialLoading1, processLoading1, maxP1, trialFlux1, processFlux1, processFlow1])
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])
176
179
  ]);
177
180
 
178
181
  t2 = DG.DataFrame.fromColumns([
179
- DG.Column.fromList('string', 'Parameter', ['amin', 'aminSF', 'trialLoading', 'processLoading', 'maxP', 'trialFlux', 'processFlux', 'processFlow']),
180
- DG.Column.fromList('double', 'Value', [amin2, aminSF2, trialLoading2, processLoading2, maxP2, trialFlux2, processFlux2, processFlow2])
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])
181
190
  ]);
182
191
 
183
192
  Guessed1 = DG.DataFrame.fromColumns([
184
- DG.Column.fromList('string', 'Parameter', ['amin', 'processLoading', 'maxP', 'processFlux']),
185
- DG.Column.fromList('double', 'Value', [guessedAmin1 , guessedProcessLoading1, guessedMaxP1, guessedProcessFlux1])
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]),
186
197
  ]);
187
198
 
188
199
  Guessed2 = DG.DataFrame.fromColumns([
189
- DG.Column.fromList('string', 'Parameter', ['amin', 'processLoading', 'maxP', 'processFlux']),
190
- DG.Column.fromList('double', 'Value', [guessedAmin2, guessedProcessLoading2, guessedMaxP2, guessedProcessFlux2])
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]),
191
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 {editor: Compute:manualOutlierSelectionDialog; editor-button: Outliers...}
6
- //input: double testArea = 3.5 {caption: Test Filter Area; units: cm²} [Test Filter area]
7
- //input: double vbatch = 25 {caption: Desired Volume of Batch; units: L} [Desired Volume of Batch]
8
- //input: double tbatch = 0.5 {caption: Desired process time; units: hr} [Desired process time]
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]
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 {viewer: Scatter Plot(x: "time (min)", y: "filtrate volume (mL)", filter: "!${isOutlier}", showFilteredOutPoints: "true", filteredOutRowsColor: 4293991195, showRegressionLine: "true"); category: OUTPUT}
14
- //output: dataframe absoluteFluxDecay {viewer: Scatter Plot(x: "V/A (L/m2)", y: "J (LMH)"); category: OUTPUT}
15
- //output: dataframe normalizedFluxDecay {viewer: Scatter Plot(x: "V/A (L/m2)", y: "J/Jo"); category: OUTPUT}
16
- //output: dataframe experimentalResults {category: OUTPUT}
17
- //output: dataframe experimentalResultsSummary {category: OUTPUT}
18
- //output: dataframe recommendations {category: OUTPUT}
19
- //output: dataframe trialData {category: OUTPUT}
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,125 @@ 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("isOutlier");
72
- let timeMin = [];
73
- let vol = [];
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("time (min)").get(i));
77
- vol.push(inputTable.col("filtrate volume (mL)").get(i));
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 = DG.DataFrame.fromColumns([
81
- DG.Column.fromList('double', "time (min)", timeMin),
82
- DG.Column.fromList('double', "filtrate volume (mL)", vol)
83
- ]);
84
- const timeInMinutes = dfWithoutOutliers.col("time (min)");
85
- const volumeInMilliliters = dfWithoutOutliers.col("filtrate volume (mL)");
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("time (hr)");
85
+ const timeInHours = dfWithoutOutliers.col('time (hr)');
88
86
 
89
- dfWithoutOutliers.columns.addNewFloat('V (L/m2)').init((i) => 10 * volumeInMilliliters.get(i) / testArea);
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("t/V (hr/(L/m2))").init((i) => 100 * timeInHours.get(i) / newVolume.get(i));
90
+ dfWithoutOutliers.columns.addNewFloat('t/V (hr/(L/m2))').init((i) => 100 * timeInHours.get(i) / newVolume.get(i));
93
91
 
94
- dfWithoutOutliers.columns.addNewFloat("Time (s)").init((i) => 60 * timeInMinutes.get(i));
95
- dfWithoutOutliers.columns.addNewFloat("V (L)").init((i) => volumeInMilliliters.get(i) / 1000);
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
- let ca = [];
101
- let cb = [];
102
- for (let i = 1; i < va.length - 3; i++) {
103
- let xCol = DG.Column.fromList('double', 'name', timeInSeconds.toList().slice(i, i + 3));
104
- let yCol = DG.Column.fromList('double', 'name', va.toList().slice(i, i + 3));
105
- let coefficients = polynomialRegressionCoefficients(xCol, yCol, orderOfPolynomialRegression);
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
  }
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
+ ]);
109
122
 
110
- dfWithoutOutliers.columns.addNewFloat('a2').init((i) => (i > 0) ? 3600 * (2 * ca[i] * timeInSeconds.get(i) + cb[i]) : 0);
111
- dfWithoutOutliers.columns.addNewFloat('a1').init((i) => (i > 0) ? 3600 * (2 * ca[i] * timeInSeconds.get(i) + cb[i]) : 0);
112
- dfWithoutOutliers.columns.addNewFloat('J (LMH)').init((i) => (i > 0) ? 3600 * (2 * ca[i] * timeInSeconds.get(i) + cb[i]) : 0);
113
- const j = dfWithoutOutliers.col('J (LMH)');
114
- dfWithoutOutliers.columns.addNewFloat('J/Jo').init((i) => (i > 0) ? j.get(i) / (3600 * area) : 0);
115
- const jj0 = dfWithoutOutliers.col('J/Jo');
116
- absoluteFluxDecay = DG.DataFrame.fromColumns([va, j]);
117
- normalizedFluxDecay = DG.DataFrame.fromColumns([va, jj0]);
118
-
119
- regressionTable = inputTable;
123
+ regressionTable = DG.DataFrame.fromColumns([
124
+ inputTable.col('time (min)'),
125
+ inputTable.col('filtrate volume (mL)'),
126
+ dfWithoutOutliers.col('t/V (hr/(L/m2))'),
127
+ isOutlierCol
128
+ ]);
120
129
  coefficients = [1.8, 4.32];//[4.32, 1.8];//polynomialRegressionCoefficients(inputTable.col("time (min)"), dfWithoutOutliers.col("t/V (hr/(L/m2))"), 1);
121
130
  const trialThroughput = va.max;
122
131
  const flux = 9372.11;
123
132
  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
133
  const meanFlux = j.stats.avg;
130
134
  const vmax = 0.28;//Math.round(1 / coefficients[1]);
131
135
  const instantaneousFlux = j.get(j.length - 1);
132
136
  const initialFlux = j.get(1);
133
137
  const fluxDecay = (1 - instantaneousFlux / initialFlux) * 100;
138
+ const names = reportingParameters.col('Parameter').toList();
139
+ const values = reportingParameters.col('Value').toList();
134
140
  experimentalResultsSummary = DG.DataFrame.fromColumns([
135
- DG.Column.fromList('string', 'Parameter', ['Trial Throughput', 'Flux', 'Flux/Flux0', 'Mean Flux', 'Vmax', 'Flux Decay']),
136
- DG.Column.fromList('double', 'Value', [trialThroughput, flux, ff0, meanFlux, vmax, fluxDecay]),
137
- DG.Column.fromList('string', 'Unit', ["L/m²", "LMH", "LMH", "LMH", "L/m²", '%'])
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]),
138
148
  ]);
139
149
  const q0 = Math.round(1 / coefficients[0]);
140
- const amin = (vbatch / vmax) + (vbatch / tbatch / q0);
150
+ const amin = (desiredVolumeOfBatch / vmax) + (desiredVolumeOfBatch / desiredProcessTime / q0);
141
151
  const installedArea = sf * amin;
142
152
  const processLoading = volumeInLiters.get(volumeInLiters.length - 1) / installedArea;
143
153
  recommendations = DG.DataFrame.fromColumns([
144
- DG.Column.fromList('string', 'Parameter', ['Volume', 'Time', 'Amin', 'Safety Factor', 'Installed Area', 'Process Loading']),
145
- DG.Column.fromList('double', 'Value', [vbatch, tbatch, amin, sf, installedArea, processLoading]),
146
- DG.Column.fromList('string', 'Unit', ["L", "h", "m²", "", '', 'L/m²'])
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')]]),
147
162
  ]);
148
163
 
149
164
  const v90 = vmax * 0.68;
150
- const initialFlowArea = coefficients[0];
165
+ const initialFlowRate = coefficients[0];
151
166
  trialData = DG.DataFrame.fromColumns([
152
- DG.Column.fromList('string', 'Parameter', ['Test Filter Area', 'Initial Flow Area', 'Vmax', 'V90']),
153
- DG.Column.fromList('double', 'Value', [testArea, initialFlowArea, vmax, v90]),
154
- DG.Column.fromList('string', 'Unit', ["m²", "L/h", "m²", "m²"])
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]),
155
171
  ]);
156
172
 
157
173
  filter = DG.DataFrame.fromColumns([
158
- DG.Column.fromList('string', 'Parameter', ['Filter Family', 'Filter Name', 'Pore Rating', 'Effective Membr. Area', 'Membr material', 'Catalog']),
159
- DG.Column.fromList('string', 'Value', ['', '', '', '', '', ''])
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')]]),
160
180
  ]);
161
-
162
181
  sampleCharacteristics = DG.DataFrame.fromColumns([
163
- DG.Column.fromList('string', 'Parameter', ['Date', 'Prior step', 'Prot conc', 'Density', 'Turbidity']),
164
- DG.Column.fromList('string', 'Value', ['', '', '', '', ''])
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)')]]),
165
187
  ]);
@@ -84,7 +84,7 @@ export async function exportFuncCall(call: DG.FuncCall) {
84
84
  } else {
85
85
  const plot = titleDiv.nextSibling;
86
86
  // if plot does not exist or it is only grid, skip it
87
- if (!plot || (plot.firstChild as HTMLElement).getAttribute('name') === 'viewer-Grid') continue;
87
+ if (!plot || (plot.firstChild?.firstChild?.firstChild as HTMLElement).getAttribute('name') === 'viewer-Grid') continue;
88
88
 
89
89
  if (plot) {
90
90
  const canvas = await DG.HtmlUtils.renderToCanvas(plot as HTMLElement);
@@ -146,7 +146,7 @@ export async function exportFuncCall(call: DG.FuncCall) {
146
146
  } else {
147
147
  const plot = titleDiv.nextSibling;
148
148
  // if plot does not exist or it is only grid, skip it
149
- 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;
150
150
 
151
151
  if (plot) {
152
152
  const canvas = await DG.HtmlUtils.renderToCanvas(plot as HTMLElement);
@@ -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(), onItemClick);
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('Connections', ()=> {
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 += `#input: ${param.propertyType} ${param.name}\n`;
526
+ result += generateParamLine(param, DIRECTION.INPUT);
433
527
  });
434
528
  functionOutputParamsCopy.map((param) => {
435
- result += `#output: ${param.propertyType} ${param.name}\n`;
529
+ result += generateParamLine(param, DIRECTION.OUTPUT);
436
530
  });
437
531
  myCM.setValue(result);
438
532
  };
@@ -33,7 +33,8 @@ export class OutliersSelectionViewer extends DG.JsViewer {
33
33
  const OUTLIER_RATIONALE_COL_LABEL = 'Rationale';
34
34
  const OUTLIER_COUNT_COL_LABEL = 'Count';
35
35
  const IS_GROUP_CONFIRMED_LABEL = 'isConfirmed';
36
- const FLUX = 't/V (hr/L)';
36
+ const FLUX = 't/V (hr/(L/m²))';
37
+ const DEFAULT_TEST_AREA = 3.5;
37
38
 
38
39
  if (!inputData.columns.byName(IS_OUTLIER_COL_LABEL)) {
39
40
  inputData.columns
@@ -46,7 +47,7 @@ export class OutliersSelectionViewer extends DG.JsViewer {
46
47
  }
47
48
 
48
49
  if (!inputData.columns.byName(FLUX)) {
49
- (inputData.columns as DG.ColumnList).addNew(FLUX, 'double').init((index) => (inputData.cell(index, 'filtrate volume (mL)').value/1000.0) / (inputData.cell(index, 'time (min)').value/60.0));
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)));
50
51
  }
51
52
 
52
53
  const initialData = inputData.clone();
@@ -240,20 +241,22 @@ export class OutliersSelectionViewer extends DG.JsViewer {
240
241
  updateGroupsTable();
241
242
  resetSelectedBtn.classList.add('disabled');
242
243
 
243
- this.root.replaceWith(ui.panel([
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(
244
252
  ui.divV([
245
- ui.info(
246
- ui.div([
247
- ui.p('Hold the “SHIFT” key and start to draw a freehand selection on the plot area'),
248
- ], {style: {'white-space': 'pre-wrap'}}),
249
- ),
253
+ info,
250
254
  ui.divV([
251
255
  ui.divH([
252
256
  resetSelectedBtn, resetAllBtn, autoOutlierGroupBtn,
253
- ], {style: {'text-align': 'center'}}),
257
+ ], {style: {'text-align': 'center', 'justify-content': 'center'}}),
254
258
  groupsListGrid.root,
255
259
  ], {style: {'height': '75%'}}),
256
- ], {style: {'height': '100%', 'min-width': '230px'}}),
257
- ], {style: {'height': '100%'}}));
260
+ ], {style: {'height': '100%', 'min-width': '230px'}}));
258
261
  }
259
262
  }
@@ -13,7 +13,8 @@ export async function selectOutliersManually(inputData: DG.DataFrame) {
13
13
  const OUTLIER_RATIONALE_COL_LABEL = 'Rationale';
14
14
  const OUTLIER_COUNT_COL_LABEL = 'Count';
15
15
  const IS_GROUP_CONFIRMED_LABEL = 'isConfirmed';
16
- const FLUX = 't/V (hr/L)';
16
+ const FLUX = 't/V (hr/(L/m²))';
17
+ const DEFAULT_TEST_AREA = 3.5;
17
18
 
18
19
  if (!inputData.columns.byName(IS_OUTLIER_COL_LABEL)) {
19
20
  inputData.columns
@@ -26,7 +27,7 @@ export async function selectOutliersManually(inputData: DG.DataFrame) {
26
27
  }
27
28
 
28
29
  if (!inputData.columns.byName(FLUX)) {
29
- (inputData.columns as DG.ColumnList).addNew(FLUX, 'double').init((index) => (inputData.cell(index, 'filtrate volume (mL)').value/1000.0) / (inputData.cell(index, 'time (min)').value/60.0));
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)));
30
31
  }
31
32
 
32
33
  const initialData = inputData.clone();
package/src/package.ts CHANGED
@@ -71,13 +71,17 @@ export function functionEditor() {
71
71
  #language: python
72
72
  #sample: chem/smiles_coordinates.csv
73
73
  #tags: demo, chem, rdkit
74
- #input: dataframe data [Input data table]
75
- #input: column smiles {type:categorical, semType: Molecule} [Molecules, in SMILES format]
76
- #input: int components = 2 [Number of components]
77
- #input: int minClusterSize = 3 [Minimum cluster size]
78
- #output: graphics spanningTree
79
- #output: graphics linkageTree
80
- #output: graphics chemSpace
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]
81
85
 
82
86
  import numba
83
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',