@datagrok/compute 0.1.0 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -100
- package/files/model-templates.json +27 -0
- package/package.json +9 -6
- package/scripts/Fab Arm Exchange.py +3 -1
- package/scripts/Heat Exchange.js +3 -1
- package/scripts/IntervalsFromECG.py +24 -0
- package/scripts/{Logistic map.js → Logistic Map.js } +3 -2
- package/scripts/{Lorenz attractor.js → Lorenz Attractor.js } +3 -2
- package/scripts/{Lotka-Volterra Model.js → Lotka-Volterra.js} +3 -2
- package/scripts/Maximal Volume.R +36 -20
- package/scripts/pMax.js +163 -0
- package/scripts/pkpd.R +1 -0
- package/scripts/popPK.R +10 -6
- package/scripts/trig.js +1 -0
- package/scripts/vMaxJS.js +115 -0
- package/src/export-funccall.ts +46 -1
- package/src/help.md +3 -0
- package/src/model-catalog-view.ts +9 -12
- package/src/model-handler.ts +22 -7
- package/src/onboard-model.ts +54 -4
- package/src/outliers-selection.ts +77 -40
- package/src/package.ts +112 -14
- package/webpack.config.js +1 -0
- package/scripts/AT-COE.py +0 -8
- package/scripts/Chemometric.py +0 -16
- package/scripts/Heat Transfer Cooling.py +0 -8
- package/scripts/High-titer field.py +0 -8
- package/scripts/pMax.py +0 -8
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
//name: Vmax
|
|
2
|
+
//description: Predict the minimum filter size required for the separation of effluent from bioreactors, given the constraints of batch size and total batch time based on a training dataset of time vs filtrate volume for a given filter type, filter area and pressure
|
|
3
|
+
//language: javascript
|
|
4
|
+
//tags: model
|
|
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]
|
|
9
|
+
//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
|
+
//help-url: https://datagrok.ai/help/access/parameterized-queries
|
|
13
|
+
//output: dataframe regressionTable {viewer: Scatter Plot(x: "time (min)", y: "filtrate volume (mL)", filter: "!${isOutlier}", showFilteredOutPoints: "true", color: "isOutlier", showRegressionLine: "true"); category: OUTPUT}
|
|
14
|
+
//output: dataframe absoluteFluxDecay {viewer: Scatter Plot(x: "V/A (L/m2)", y: "J (LMH)", showRegressionLine: "true"); category: OUTPUT}
|
|
15
|
+
//output: dataframe normalizedFluxDecay {viewer: Scatter Plot(x: "V/A (L/m2)", y: "J/Jo", showRegressionLine: "true"); category: OUTPUT}
|
|
16
|
+
//output: double volume {caption: Volume, L; category: OUTPUT}
|
|
17
|
+
|
|
18
|
+
volume = vbatch;
|
|
19
|
+
function gaussianElimination(input, orderOfPolynomialRegression) {
|
|
20
|
+
const n = input.length - 1, coefficients = [orderOfPolynomialRegression];
|
|
21
|
+
for (let i = 0; i < n; i++) {
|
|
22
|
+
let maxrow = i;
|
|
23
|
+
for (let j = i + 1; j < n; j++)
|
|
24
|
+
if (Math.abs(input[i][j]) > Math.abs(input[i][maxrow]))
|
|
25
|
+
maxrow = j;
|
|
26
|
+
for (let k = i; k < n + 1; k++) {
|
|
27
|
+
const tmp = input[k][i];
|
|
28
|
+
input[k][i] = input[k][maxrow];
|
|
29
|
+
input[k][maxrow] = tmp;
|
|
30
|
+
}
|
|
31
|
+
for (let j = i + 1; j < n; j++)
|
|
32
|
+
for (let k = n; k >= i; k--)
|
|
33
|
+
input[k][j] -= (input[k][i] * input[i][j]) / input[i][i];
|
|
34
|
+
}
|
|
35
|
+
for (let j = n - 1; j >= 0; j--) {
|
|
36
|
+
let total = 0;
|
|
37
|
+
for (let k = j + 1; k < n; k++)
|
|
38
|
+
total += input[k][j] * coefficients[k];
|
|
39
|
+
coefficients[j] = (input[n][j] - total) / input[j][j];
|
|
40
|
+
}
|
|
41
|
+
return coefficients;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function polynomialRegressionCoefficients(xCol, yCol, orderOfPolynomialRegression) {
|
|
45
|
+
const lhs = [], rhs = [], len = xCol.length, k = orderOfPolynomialRegression + 1;
|
|
46
|
+
let a = 0, b = 0;
|
|
47
|
+
for (let i = 0; i < k; i++) {
|
|
48
|
+
for (let l = 0; l < len; l++)
|
|
49
|
+
a += (xCol.get(l) ** i) * yCol.get(l);
|
|
50
|
+
lhs.push(a);
|
|
51
|
+
a = 0;
|
|
52
|
+
const c = [];
|
|
53
|
+
for (let j = 0; j < k; j++) {
|
|
54
|
+
for (let l = 0; l < len; l++)
|
|
55
|
+
b += xCol.get(l) ** (i + j);
|
|
56
|
+
c.push(b);
|
|
57
|
+
b = 0;
|
|
58
|
+
}
|
|
59
|
+
rhs.push(c);
|
|
60
|
+
}
|
|
61
|
+
rhs.push(lhs);
|
|
62
|
+
return gaussianElimination(rhs, k);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const area = 0.00035;
|
|
66
|
+
const isOutlierCol = inputTable.col("isOutlier");
|
|
67
|
+
let timeMin = [];
|
|
68
|
+
let vol = [];
|
|
69
|
+
for (let i = 0; i < isOutlierCol.length; i++) {
|
|
70
|
+
if (isOutlierCol.get(i) == false) {
|
|
71
|
+
timeMin.push(inputTable.col("time (min)").get(i));
|
|
72
|
+
vol.push(inputTable.col("filtrate volume (mL)").get(i));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
dfWithoutOutliers = DG.DataFrame.fromColumns([
|
|
76
|
+
DG.Column.fromList('double', "time (min)", timeMin),
|
|
77
|
+
DG.Column.fromList('double', "filtrate volume (mL)", vol)
|
|
78
|
+
]);
|
|
79
|
+
const timeInMinutes = dfWithoutOutliers.col("time (min)");
|
|
80
|
+
const volumeInMilliliters = dfWithoutOutliers.col("filtrate volume (mL)");
|
|
81
|
+
dfWithoutOutliers.columns.addNewFloat('time (hr)').init((i) => timeInMinutes.get(i) / 60);
|
|
82
|
+
const timeInHours = dfWithoutOutliers.col("time (hr)");
|
|
83
|
+
|
|
84
|
+
dfWithoutOutliers.columns.addNewFloat('V (L/m2)').init((i) => 10 * volumeInMilliliters.get(i) / testArea);
|
|
85
|
+
const newVolume = dfWithoutOutliers.col('V (L/m2)');
|
|
86
|
+
|
|
87
|
+
dfWithoutOutliers.columns.addNewFloat("t/V (hr/(L/m2))").init((i) => timeInHours.get(i) / newVolume.get(i));
|
|
88
|
+
|
|
89
|
+
dfWithoutOutliers.columns.addNewFloat("Time (s)").init((i) => 60 * timeInMinutes.get(i));
|
|
90
|
+
dfWithoutOutliers.columns.addNewFloat("V (L)").init((i) => volumeInMilliliters.get(i) / 1000);
|
|
91
|
+
const volumeInLiters = dfWithoutOutliers.col('V (L)');
|
|
92
|
+
const timeInSeconds = dfWithoutOutliers.col('Time (s)');
|
|
93
|
+
dfWithoutOutliers.columns.addNewFloat('V/A (L/m2)').init((i) => volumeInLiters.get(i) / area);
|
|
94
|
+
const va = dfWithoutOutliers.col('V/A (L/m2)');
|
|
95
|
+
let ca = [];
|
|
96
|
+
let cb = [];
|
|
97
|
+
for (let i = 1; i < va.length - 3; i++) {
|
|
98
|
+
let xCol = DG.Column.fromList('double', 'name', timeInSeconds.toList().slice(i, i + 3));
|
|
99
|
+
let yCol = DG.Column.fromList('double', 'name', va.toList().slice(i, i + 3));
|
|
100
|
+
let coefficients = polynomialRegressionCoefficients(xCol, yCol, orderOfPolynomialRegression);
|
|
101
|
+
ca.push(coefficients[orderOfPolynomialRegression]);
|
|
102
|
+
cb.push(coefficients[orderOfPolynomialRegression - 1]);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
dfWithoutOutliers.columns.addNewFloat('a2').init((i) => (i > 0) ? 3600 * (2 * ca[i] * timeInSeconds.get(i) + cb[i]) : 0);
|
|
106
|
+
dfWithoutOutliers.columns.addNewFloat('a1').init((i) => (i > 0) ? 3600 * (2 * ca[i] * timeInSeconds.get(i) + cb[i]) : 0);
|
|
107
|
+
dfWithoutOutliers.columns.addNewFloat('J (LMH)').init((i) => (i > 0) ? 3600 * (2 * ca[i] * timeInSeconds.get(i) + cb[i]) : 0);
|
|
108
|
+
const j = dfWithoutOutliers.col('J (LMH)');
|
|
109
|
+
dfWithoutOutliers.columns.addNewFloat('J/Jo').init((i) => (i > 0) ? j.get(i) / (3600 * area) : 0);
|
|
110
|
+
const jj0 = dfWithoutOutliers.col('J/Jo');
|
|
111
|
+
absoluteFluxDecay = DG.DataFrame.fromColumns([va, j]);
|
|
112
|
+
normalizedFluxDecay = DG.DataFrame.fromColumns([va, jj0]);
|
|
113
|
+
|
|
114
|
+
regressionTable = inputTable;
|
|
115
|
+
// coefficients = polynomialRegressionCoefficients(inputTable.col("time (hr)"), dfWithoutOutliers.col("t/V (hr/(L/m2))"), 1);
|
package/src/export-funccall.ts
CHANGED
|
@@ -4,7 +4,7 @@ import * as DG from 'datagrok-api/dg';
|
|
|
4
4
|
import ExcelJS from 'exceljs';
|
|
5
5
|
import {saveAs} from 'file-saver';
|
|
6
6
|
|
|
7
|
-
export function exportFuncCall(call: DG.FuncCall) {
|
|
7
|
+
export async function exportFuncCall(call: DG.FuncCall) {
|
|
8
8
|
//todo: check status
|
|
9
9
|
// if (call.status != FuncCall.STATUS_COMPLETED) ...
|
|
10
10
|
|
|
@@ -45,6 +45,51 @@ export function exportFuncCall(call: DG.FuncCall) {
|
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
+
// UWAGA: very fragile solution
|
|
49
|
+
const resultView = document.getElementsByClassName('d4-tab-host ui-box')[0];
|
|
50
|
+
const tabs = resultView.getElementsByClassName('d4-tab-header-stripe')[0].children;
|
|
51
|
+
const selectedByUser = resultView.getElementsByClassName('d4-tab-header selected')[0];
|
|
52
|
+
for (let i=0; i< tabs.length; i++) {
|
|
53
|
+
(tabs[i] as HTMLElement).click();
|
|
54
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
55
|
+
|
|
56
|
+
const titleDivs = document.getElementsByClassName('grok-func-results-header');
|
|
57
|
+
if (!titleDivs.length) continue;
|
|
58
|
+
|
|
59
|
+
for (let i = 0; i < titleDivs.length; i++) {
|
|
60
|
+
const titleDiv = titleDivs[i];
|
|
61
|
+
|
|
62
|
+
const title = titleDiv.firstChild?.textContent;
|
|
63
|
+
if (!title) continue;
|
|
64
|
+
|
|
65
|
+
const plot = titleDiv.nextSibling;
|
|
66
|
+
if (!plot) continue;
|
|
67
|
+
|
|
68
|
+
const canvas = await DG.HtmlUtils.renderToCanvas(plot as HTMLElement);
|
|
69
|
+
const dataUrl = canvas.toDataURL('image/png');
|
|
70
|
+
const testImageId = exportWorkbook.addImage({
|
|
71
|
+
base64: dataUrl,
|
|
72
|
+
extension: 'png',
|
|
73
|
+
});
|
|
74
|
+
const worksheet = exportWorkbook.getWorksheet(`Output - ${title}`);
|
|
75
|
+
|
|
76
|
+
if (worksheet) {
|
|
77
|
+
const columnForImage = ((call.outputs[title] as DG.DataFrame).columns as DG.ColumnList).length + 1;
|
|
78
|
+
worksheet.addImage(testImageId, {
|
|
79
|
+
tl: {col: columnForImage, row: 0},
|
|
80
|
+
ext: {width: canvas.width, height: canvas.height},
|
|
81
|
+
});
|
|
82
|
+
} else {
|
|
83
|
+
const newWorksheet = exportWorkbook.addWorksheet(`Output - Plot - ${title}`);
|
|
84
|
+
newWorksheet.addImage(testImageId, {
|
|
85
|
+
tl: {col: 0, row: 0},
|
|
86
|
+
ext: {width: canvas.width, height: canvas.height},
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
(selectedByUser as HTMLElement).click();
|
|
92
|
+
|
|
48
93
|
const outputScalarsSheet = exportWorkbook.addWorksheet('Output scalars');
|
|
49
94
|
scalarOutputs.forEach((scalarOutput) => {
|
|
50
95
|
outputScalarsSheet.addRow([scalarOutput.name, call.outputs[scalarOutput.name]]);
|
package/src/help.md
ADDED
|
@@ -16,7 +16,13 @@ export class ModelCatalogView extends DG.CardView {
|
|
|
16
16
|
this.name = 'Models';
|
|
17
17
|
this.permanentFilter = '#model';
|
|
18
18
|
|
|
19
|
-
this.
|
|
19
|
+
this.objectType = 'Script';
|
|
20
|
+
this.categoryFilters = {
|
|
21
|
+
'language': 'Language',
|
|
22
|
+
'tag': 'Tags',
|
|
23
|
+
'createdOn': 'Created',
|
|
24
|
+
'author.id': 'Author'
|
|
25
|
+
};
|
|
20
26
|
this.initRibbon();
|
|
21
27
|
this.initMenu();
|
|
22
28
|
}
|
|
@@ -32,22 +38,13 @@ export class ModelCatalogView extends DG.CardView {
|
|
|
32
38
|
.endGroup()
|
|
33
39
|
.group('Help')
|
|
34
40
|
.item('Compute Engine', () => window.open('https://github.com/datagrok-ai/public/tree/master/packages/Compute', '_blank'))
|
|
35
|
-
.item('Developing Models', () => window.open('https://datagrok.ai/help/
|
|
41
|
+
.item('Developing Models', () => window.open('https://datagrok.ai/help/compute/scripting', '_blank'))
|
|
36
42
|
.endGroup();
|
|
37
43
|
}
|
|
38
44
|
|
|
39
|
-
initToolbox() {
|
|
40
|
-
grok.dapi.scripts
|
|
41
|
-
.filter('#model')
|
|
42
|
-
.list()
|
|
43
|
-
.then((models) => {
|
|
44
|
-
this.toolbox = ui.divV(models.map((model) => ui.render(model, {onClick: (_) => this.setCurrentModel(model)})));
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
45
|
setCurrentModel(model: DG.Script) {
|
|
49
46
|
let modelView = DG.View.forObject(model)!;
|
|
50
|
-
let host: HTMLDivElement = this.root.querySelector('.grok-gallery-grid')
|
|
47
|
+
let host: HTMLDivElement = this.root.querySelector('.grok-gallery-grid')! as HTMLDivElement;
|
|
51
48
|
ui.empty(host);
|
|
52
49
|
host.appendChild(modelView.root);
|
|
53
50
|
}
|
package/src/model-handler.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
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 {ModelCatalogView} from "./model-catalog-view";
|
|
4
5
|
|
|
5
6
|
export class ModelHandler extends DG.ObjectHandler {
|
|
6
7
|
get type() {
|
|
@@ -18,21 +19,28 @@ export class ModelHandler extends DG.ObjectHandler {
|
|
|
18
19
|
return script;
|
|
19
20
|
}
|
|
20
21
|
|
|
22
|
+
getLanguageIcon(language: string) {
|
|
23
|
+
if (language == 'grok')
|
|
24
|
+
return ui.iconSvg('project');
|
|
25
|
+
return ui.iconImage('script', `/images/entities/${language}.png`);
|
|
26
|
+
}
|
|
27
|
+
|
|
21
28
|
// Checks whether this is the handler for [x]
|
|
22
29
|
isApplicable(x: any) {
|
|
23
30
|
return x instanceof DG.Script && x.hasTag('model');
|
|
24
31
|
}
|
|
25
32
|
|
|
26
33
|
renderIcon(x: DG.Script, context: any = null): HTMLElement {
|
|
27
|
-
return
|
|
34
|
+
return this.getLanguageIcon(x.language);
|
|
28
35
|
}
|
|
29
36
|
|
|
30
37
|
renderMarkup(x: DG.Script): HTMLElement {
|
|
31
|
-
return ui.span([this.renderIcon(x), ui.label(x.
|
|
38
|
+
return ui.span([this.renderIcon(x), ui.label(x.friendlyName, {style: {marginLeft: '4px'}})], {style: {display: 'inline-flex'}});
|
|
32
39
|
}
|
|
33
40
|
|
|
34
41
|
renderProperties(x: DG.Script) {
|
|
35
42
|
const a = ui.accordion();
|
|
43
|
+
a.context = x;
|
|
36
44
|
a.addTitle(ui.span([this.renderIcon(x), ui.label(x.friendlyName), ui.contextActions(x), ui.star(x.id)]));
|
|
37
45
|
a.addPane('Details', () => {
|
|
38
46
|
return this.renderDetails(x);
|
|
@@ -40,28 +48,35 @@ export class ModelHandler extends DG.ObjectHandler {
|
|
|
40
48
|
a.addCountPane('Usage', () => {
|
|
41
49
|
return ui.span(['Usage statistics']);
|
|
42
50
|
}, () => 99);
|
|
51
|
+
a.end();
|
|
43
52
|
return a.root;
|
|
44
53
|
}
|
|
45
54
|
|
|
46
55
|
renderDetails(x: DG.Script) {
|
|
47
|
-
return ui.
|
|
56
|
+
return ui.divV([ui.render(x.author), ui.render(x.createdOn)], {style: {lineHeight: '150%'}});
|
|
48
57
|
}
|
|
49
58
|
|
|
50
59
|
renderTooltip(x: DG.Script) {
|
|
51
|
-
return ui.divText(`${x.
|
|
60
|
+
return ui.divText(`${x.friendlyName}`);
|
|
52
61
|
}
|
|
53
62
|
|
|
54
63
|
renderCard(x: DG.Script, context?: any): HTMLElement {
|
|
55
64
|
let card = ui.bind(x, ui.divV([
|
|
56
|
-
ui.h2(x
|
|
65
|
+
ui.h2(this.renderMarkup(x)),
|
|
66
|
+
ui.divText(x.description, 'ui-description'),
|
|
57
67
|
this.renderDetails(x),
|
|
58
|
-
], 'd4-gallery-item'));
|
|
68
|
+
], 'd4-gallery-item'), {contextMenu: false});
|
|
59
69
|
card.ondblclick = (e) => {
|
|
60
|
-
|
|
70
|
+
ModelHandler.openModel(x);
|
|
61
71
|
}
|
|
62
72
|
return card;
|
|
63
73
|
}
|
|
64
74
|
|
|
75
|
+
static openModel(x: DG.Script, parentView?: DG.ViewBase) {
|
|
76
|
+
let view = DG.FunctionView.createFromFunc(x);
|
|
77
|
+
grok.shell.addView(view);
|
|
78
|
+
}
|
|
79
|
+
|
|
65
80
|
init() {
|
|
66
81
|
this.registerParamFunc('Open', async (t: DG.Script) => {
|
|
67
82
|
|
package/src/onboard-model.ts
CHANGED
|
@@ -2,17 +2,39 @@ 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 {_package} from './package';
|
|
5
|
+
import {Property, PropertyOptions} from "datagrok-api/dg";
|
|
5
6
|
|
|
6
7
|
/* eslint-disable */
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
interface IModelTemplate {
|
|
10
|
+
name: string;
|
|
11
|
+
props: PropertyOptions[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function onboardModel(): Promise<void> {
|
|
15
|
+
|
|
16
|
+
let modelPropertiesHost = ui.divV([]);
|
|
9
17
|
let name = ui.stringInput('Name', '');
|
|
10
|
-
let type = ui.choiceInput('Type',
|
|
18
|
+
let type = ui.choiceInput('Type', templates[0].name, templates.map((t) => t.name));
|
|
19
|
+
let modelProperties: any = {};
|
|
20
|
+
|
|
21
|
+
function updateProps() {
|
|
22
|
+
let template: IModelTemplate = templates.filter((t) => t.name == type.value)[0];
|
|
23
|
+
ui.empty(modelPropertiesHost);
|
|
24
|
+
modelPropertiesHost.appendChild(ui.input.form(modelProperties, template.props.map((p) => Property.fromOptions(p))));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
updateProps();
|
|
28
|
+
type.onChanged(updateProps);
|
|
11
29
|
|
|
12
30
|
new DG.Wizard({ title: 'Onboard a model' })
|
|
13
31
|
.page({
|
|
14
32
|
caption: 'Details',
|
|
15
|
-
root: ui.
|
|
33
|
+
root: ui.divV([
|
|
34
|
+
name,
|
|
35
|
+
type,
|
|
36
|
+
modelPropertiesHost
|
|
37
|
+
]),
|
|
16
38
|
validate: () => name.value !== '' ? null : 'Please provide a name'
|
|
17
39
|
})
|
|
18
40
|
.page({
|
|
@@ -23,4 +45,32 @@ export function onboardModel() {
|
|
|
23
45
|
root: ui.divText('Finish') })
|
|
24
46
|
.onOK(() => {})
|
|
25
47
|
.show({width: 500, height: 300});
|
|
26
|
-
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
let templates: IModelTemplate[] = [
|
|
51
|
+
{
|
|
52
|
+
"name": "Bioreactor simulation",
|
|
53
|
+
"props": [
|
|
54
|
+
{
|
|
55
|
+
"name": "reactorType",
|
|
56
|
+
"type": "string",
|
|
57
|
+
"choices": ["Experimental", "Production"]
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"name": "department",
|
|
61
|
+
"type": "string",
|
|
62
|
+
"choices": ["", "Production"]
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"name": "Biosensors",
|
|
68
|
+
"props": [
|
|
69
|
+
{
|
|
70
|
+
"name": "sensor",
|
|
71
|
+
"type": "string",
|
|
72
|
+
"choices": ["Accelerometer", "GSR", "EEG", "ECG", "Eye Tracker"]
|
|
73
|
+
}
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
];
|
|
@@ -7,6 +7,8 @@ export async function selectOutliersManually(inputData: DG.DataFrame) {
|
|
|
7
7
|
const IS_OUTLIER_COL_LABEL = 'isOutlier';
|
|
8
8
|
const OUTLIER_RATIONALE_COL_LABEL = 'Rationale';
|
|
9
9
|
const OUTLIER_COUNT_COL_LABEL = 'Count';
|
|
10
|
+
const IS_GROUP_CONFIRMED_LABEL = 'isConfirmed';
|
|
11
|
+
const FLUX = 't/V (hr/L)';
|
|
10
12
|
|
|
11
13
|
if (!inputData.columns.byName(IS_OUTLIER_COL_LABEL)) {
|
|
12
14
|
inputData.columns
|
|
@@ -18,6 +20,10 @@ export async function selectOutliersManually(inputData: DG.DataFrame) {
|
|
|
18
20
|
.add(DG.Column.fromStrings(OUTLIER_RATIONALE_COL_LABEL, Array.from({length: inputData.rowCount}, () => '')));
|
|
19
21
|
}
|
|
20
22
|
|
|
23
|
+
if (!inputData.columns.byName(FLUX)) {
|
|
24
|
+
(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));
|
|
25
|
+
}
|
|
26
|
+
|
|
21
27
|
const initialData = inputData.clone();
|
|
22
28
|
|
|
23
29
|
const scatterPlot = DG.Viewer.scatterPlot(inputData, {
|
|
@@ -33,15 +39,49 @@ export async function selectOutliersManually(inputData: DG.DataFrame) {
|
|
|
33
39
|
return DG.DataFrame.fromColumns([
|
|
34
40
|
DG.Column.fromStrings(OUTLIER_RATIONALE_COL_LABEL, []),
|
|
35
41
|
DG.Column.fromInt32Array(OUTLIER_COUNT_COL_LABEL, new Int32Array([])),
|
|
36
|
-
DG.Column.fromStrings('', []),
|
|
42
|
+
DG.Column.fromStrings('Actions', []),
|
|
43
|
+
DG.Column.fromBitSet(IS_GROUP_CONFIRMED_LABEL, DG.BitSet.create(0, () => false)),
|
|
37
44
|
]);
|
|
38
45
|
};
|
|
39
46
|
|
|
40
47
|
const groupsListGrid = DG.Viewer.grid(clearTable());
|
|
41
48
|
groupsListGrid.root.style.width = '100%';
|
|
49
|
+
groupsListGrid.columns.setVisible([OUTLIER_RATIONALE_COL_LABEL, OUTLIER_COUNT_COL_LABEL, 'Actions']);
|
|
42
50
|
|
|
43
51
|
groupsListGrid.onCellPrepare((gc) => {
|
|
44
|
-
|
|
52
|
+
if (!gc.isTableCell) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const confirmBtn = () => ui.div(
|
|
57
|
+
ui.iconFA('check', () => {
|
|
58
|
+
if (!groupsListGrid.dataFrame) return;
|
|
59
|
+
|
|
60
|
+
const newRationale =
|
|
61
|
+
groupsListGrid.dataFrame?.cell(groupsListGrid.dataFrame.rowCount-1, OUTLIER_RATIONALE_COL_LABEL).value;
|
|
62
|
+
|
|
63
|
+
inputData.selection.getSelectedIndexes().forEach((selectedIndex: number) => {
|
|
64
|
+
inputData.set(IS_OUTLIER_COL_LABEL, selectedIndex, true);
|
|
65
|
+
inputData.set(
|
|
66
|
+
OUTLIER_RATIONALE_COL_LABEL,
|
|
67
|
+
selectedIndex,
|
|
68
|
+
newRationale,
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
inputData.selection.setAll(false);
|
|
72
|
+
}, 'Confirm the outliers'), {style: {'text-align': 'center', 'margin': '6px'}},
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const cancelBtn = () => ui.div(
|
|
76
|
+
ui.iconFA('times', () => {
|
|
77
|
+
if (!groupsListGrid.dataFrame) return;
|
|
78
|
+
|
|
79
|
+
groupsListGrid.dataFrame.rows.removeAt(groupsListGrid.dataFrame.rowCount-1);
|
|
80
|
+
inputData.selection.setAll(false);
|
|
81
|
+
}, 'Cancel the outliers'), {style: {'text-align': 'center', 'margin': '6px'}},
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const deleteBtn = (rationale: string) => ui.div(
|
|
45
85
|
ui.icons.delete(() => {
|
|
46
86
|
for (let i = 0; i < inputData.rowCount; i++) {
|
|
47
87
|
if (inputData.columns.byName(OUTLIER_RATIONALE_COL_LABEL).get(i) === rationale) {
|
|
@@ -52,18 +92,22 @@ export async function selectOutliersManually(inputData: DG.DataFrame) {
|
|
|
52
92
|
}, 'Remove the outliers group'), {style: {'text-align': 'center', 'margin': '6px'}},
|
|
53
93
|
);
|
|
54
94
|
|
|
55
|
-
if (
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (gc.gridColumn.name === '') {
|
|
95
|
+
if (gc.gridColumn.name === 'Actions') {
|
|
60
96
|
gc.gridColumn.cellType = 'html';
|
|
61
|
-
gc.style.element =
|
|
97
|
+
gc.style.element =
|
|
98
|
+
ui.divH([
|
|
99
|
+
...!gc.grid.dataFrame?.get(IS_GROUP_CONFIRMED_LABEL, gc.gridRow) ?
|
|
100
|
+
[confirmBtn(), cancelBtn()] :
|
|
101
|
+
[deleteBtn(gc.grid.dataFrame?.get(OUTLIER_RATIONALE_COL_LABEL, gc.gridRow))],
|
|
102
|
+
]);
|
|
62
103
|
}
|
|
63
104
|
});
|
|
64
105
|
|
|
65
106
|
groupsListGrid.onCellValueEdited.subscribe((editedCell) => {
|
|
66
|
-
if (!groupsListGrid.dataFrame) return;
|
|
107
|
+
if (!groupsListGrid.dataFrame || editedCell.gridColumn.name !== OUTLIER_RATIONALE_COL_LABEL) return;
|
|
108
|
+
|
|
109
|
+
if (!(groupsListGrid.dataFrame.columns as DG.ColumnList)
|
|
110
|
+
.byName(IS_GROUP_CONFIRMED_LABEL).get(editedCell.gridRow)) return;
|
|
67
111
|
|
|
68
112
|
const uniqueValues= new Set<string>();
|
|
69
113
|
for (let i = 0; i < groupsListGrid.dataFrame?.rowCount; i++) {
|
|
@@ -91,12 +135,31 @@ export async function selectOutliersManually(inputData: DG.DataFrame) {
|
|
|
91
135
|
}
|
|
92
136
|
}
|
|
93
137
|
groupsListGrid.dataFrame = clearTable();
|
|
138
|
+
groupsListGrid.columns.setVisible([OUTLIER_RATIONALE_COL_LABEL, OUTLIER_COUNT_COL_LABEL, 'Actions']);
|
|
139
|
+
|
|
94
140
|
Object.keys(uniqueValues).map((key: string) => {
|
|
95
|
-
groupsListGrid.dataFrame?.rows.addNew([key, uniqueValues[key], '']);
|
|
141
|
+
groupsListGrid.dataFrame?.rows.addNew([key, uniqueValues[key], '', true]);
|
|
96
142
|
});
|
|
97
143
|
};
|
|
98
144
|
|
|
99
145
|
inputData.onDataChanged.subscribe(updateGroupsTable);
|
|
146
|
+
inputData.onSelectionChanged.subscribe(() => {
|
|
147
|
+
if (!groupsListGrid.dataFrame || !inputData.selection.trueCount) return;
|
|
148
|
+
|
|
149
|
+
const isConfirmedColumn = (groupsListGrid.dataFrame.columns as DG.ColumnList)
|
|
150
|
+
.byName(IS_GROUP_CONFIRMED_LABEL).toList();
|
|
151
|
+
|
|
152
|
+
if (isConfirmedColumn.some((value) => value === false)) {
|
|
153
|
+
groupsListGrid.dataFrame.set(
|
|
154
|
+
OUTLIER_COUNT_COL_LABEL,
|
|
155
|
+
groupsListGrid.dataFrame.rowCount-1,
|
|
156
|
+
inputData.selection.trueCount,
|
|
157
|
+
);
|
|
158
|
+
} else {
|
|
159
|
+
const newRow = groupsListGrid.dataFrame.rows.addNew(['Manual', inputData.selection.trueCount, '', false]);
|
|
160
|
+
groupsListGrid.dataFrame.currentCell = groupsListGrid.dataFrame.cell(newRow.idx, OUTLIER_RATIONALE_COL_LABEL);
|
|
161
|
+
}
|
|
162
|
+
});
|
|
100
163
|
|
|
101
164
|
let shouldCancel = true;
|
|
102
165
|
|
|
@@ -111,31 +174,8 @@ export async function selectOutliersManually(inputData: DG.DataFrame) {
|
|
|
111
174
|
}
|
|
112
175
|
};
|
|
113
176
|
|
|
114
|
-
const addOutlierGroupBtn = ui.button(
|
|
115
|
-
'MARK',
|
|
116
|
-
() => {
|
|
117
|
-
if (!groupsListGrid.dataFrame) return;
|
|
118
|
-
|
|
119
|
-
inputData.selection.getSelectedIndexes().forEach((selectedIndex: number) => {
|
|
120
|
-
inputData.set(IS_OUTLIER_COL_LABEL, selectedIndex, true);
|
|
121
|
-
inputData.set(OUTLIER_RATIONALE_COL_LABEL, selectedIndex, 'Manual');
|
|
122
|
-
});
|
|
123
|
-
inputData.selection.setAll(false);
|
|
124
|
-
|
|
125
|
-
let rowNumber = 0;
|
|
126
|
-
for (let i=0; i< (groupsListGrid.dataFrame.rowCount); i++) {
|
|
127
|
-
if ((groupsListGrid.dataFrame?.columns as DG.ColumnList).byName(OUTLIER_RATIONALE_COL_LABEL).get(i) === 'Manual') {
|
|
128
|
-
rowNumber = i;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
groupsListGrid.dataFrame.currentCell = groupsListGrid.dataFrame.cell(rowNumber, OUTLIER_RATIONALE_COL_LABEL);
|
|
133
|
-
},
|
|
134
|
-
'Mark the selected points as outliers',
|
|
135
|
-
);
|
|
136
|
-
|
|
137
177
|
const removeOutlierGroupBtn = ui.button(
|
|
138
|
-
'
|
|
178
|
+
'RESET SELECTED',
|
|
139
179
|
() => {
|
|
140
180
|
inputData.selection.getSelectedIndexes().forEach((selectedIndex: number) => {
|
|
141
181
|
inputData.set(IS_OUTLIER_COL_LABEL, selectedIndex, false);
|
|
@@ -147,11 +187,11 @@ export async function selectOutliersManually(inputData: DG.DataFrame) {
|
|
|
147
187
|
);
|
|
148
188
|
|
|
149
189
|
const autoOutlierGroupBtn = ui.button(
|
|
150
|
-
'
|
|
190
|
+
'AUTO DETECT...',
|
|
151
191
|
() => {
|
|
152
192
|
const intInput = ui.intInput('N', 3);
|
|
153
193
|
const columnInput = ui.columnInput('Column', inputData, null);
|
|
154
|
-
ui.dialog('
|
|
194
|
+
ui.dialog('Detect outliers automatically')
|
|
155
195
|
.add(columnInput.root)
|
|
156
196
|
.add(intInput.root)
|
|
157
197
|
.onOK(()=>{
|
|
@@ -175,16 +215,13 @@ export async function selectOutliersManually(inputData: DG.DataFrame) {
|
|
|
175
215
|
|
|
176
216
|
inputData.onSelectionChanged.subscribe(() => {
|
|
177
217
|
if (inputData.selection.trueCount === 0) {
|
|
178
|
-
addOutlierGroupBtn.classList.add('disabled');
|
|
179
218
|
removeOutlierGroupBtn.classList.add('disabled');
|
|
180
219
|
} else {
|
|
181
|
-
addOutlierGroupBtn.classList.remove('disabled');
|
|
182
220
|
removeOutlierGroupBtn.classList.remove('disabled');
|
|
183
221
|
}
|
|
184
222
|
});
|
|
185
223
|
|
|
186
224
|
updateGroupsTable();
|
|
187
|
-
addOutlierGroupBtn.classList.add('disabled');
|
|
188
225
|
removeOutlierGroupBtn.classList.add('disabled');
|
|
189
226
|
|
|
190
227
|
const result = new Promise<{augmentedInput: DG.DataFrame, editedInput: DG.DataFrame}>((resolve, reject) => {
|
|
@@ -202,7 +239,7 @@ export async function selectOutliersManually(inputData: DG.DataFrame) {
|
|
|
202
239
|
ui.block25([
|
|
203
240
|
ui.divV([
|
|
204
241
|
ui.divH([
|
|
205
|
-
|
|
242
|
+
removeOutlierGroupBtn, autoOutlierGroupBtn,
|
|
206
243
|
], {style: {'text-align': 'center'}}),
|
|
207
244
|
groupsListGrid.root,
|
|
208
245
|
], {style: {height: '75%'}}),
|