@datagrok/compute 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +6 -1
- package/package.json +1 -1
- package/scripts/pMax.js +34 -6
- package/src/export-funccall.ts +75 -12
- package/src/outliers-selection/outliers-selection-viewer.ts +259 -0
- package/src/{outliers-selection.ts → outliers-selection/outliers-selection.ts} +6 -1
- package/src/package.ts +10 -1
package/.eslintrc.json
CHANGED
|
@@ -21,7 +21,12 @@
|
|
|
21
21
|
{ "ignoreStrings": true }
|
|
22
22
|
],
|
|
23
23
|
"require-jsdoc": "off",
|
|
24
|
-
"spaced-comment": "off"
|
|
24
|
+
"spaced-comment": "off",
|
|
25
|
+
"valid-jsdoc": [
|
|
26
|
+
"error",
|
|
27
|
+
{ "requireParamType": false,
|
|
28
|
+
"requireReturnType": false }
|
|
29
|
+
]
|
|
25
30
|
},
|
|
26
31
|
"parser": "@typescript-eslint/parser",
|
|
27
32
|
"plugins": [
|
package/package.json
CHANGED
package/scripts/pMax.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
//name:
|
|
1
|
+
//name: Pmax
|
|
2
2
|
//description: pMax Filtration Model
|
|
3
3
|
//language: javascript
|
|
4
|
-
//tags: model
|
|
4
|
+
//tags: model, filtration
|
|
5
5
|
//input: dataframe inputTable [Should contain columns Time (min), Vol (mL), P1 (psi), P2 (psi)]
|
|
6
|
-
//input: dataframe
|
|
6
|
+
//input: dataframe inputParametersForReporting
|
|
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,12 +12,11 @@
|
|
|
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
|
-
//input: int orderOfPolynomialRegression = 3 {caption: Order Of Polynomial Regression} [Order Of Polynomial Regression]
|
|
16
15
|
//meta.showInputs: true
|
|
17
|
-
//output: dataframe Filter1 {viewer: Scatter Plot(x: "TP 1 (L/m2)", y: "Res. 1 (psi/LMH)",
|
|
16
|
+
//output: dataframe Filter1 {viewer: Scatter Plot(x: "TP 1 (L/m2)", y: "Res. 1 (psi/LMH)", showDataframeFormulaLines: "true"); category: OUTPUT}
|
|
18
17
|
//output: dataframe t1 {category: OUTPUT}
|
|
19
18
|
//output: dataframe Guessed1 {category: OUTPUT}
|
|
20
|
-
//output: dataframe Filter2 {viewer: Scatter Plot(x: "TP 2 (L/m2)", y: "Res. 2 (psi/LMH)",
|
|
19
|
+
//output: dataframe Filter2 {viewer: Scatter Plot(x: "TP 2 (L/m2)", y: "Res. 2 (psi/LMH)", showDataframeFormulaLines: "true"); category: OUTPUT}
|
|
21
20
|
//output: dataframe t2 {category: OUTPUT}
|
|
22
21
|
//output: dataframe Guessed2 {category: OUTPUT}
|
|
23
22
|
|
|
@@ -74,6 +73,18 @@ function predictPolynomialRegression(coefficients, x) {
|
|
|
74
73
|
return result;
|
|
75
74
|
}
|
|
76
75
|
|
|
76
|
+
function equasionString(xColName, yColName, coefficients) {
|
|
77
|
+
let s = '';
|
|
78
|
+
for (let [index, coefficient] of coefficients.slice(1).reverse().entries()) {
|
|
79
|
+
s += String(coefficient);
|
|
80
|
+
for (let i = 0; i < coefficients.length - index - 1; i++)
|
|
81
|
+
s += " * ${" + String(xColName) + "}";
|
|
82
|
+
s += " + ";
|
|
83
|
+
}
|
|
84
|
+
return "${" + yColName + "} = " + s + String(coefficients[0]);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const orderOfPolynomialRegression = 3;
|
|
77
88
|
const lengthOfSecondTable = 2985;
|
|
78
89
|
const colNames1 = {
|
|
79
90
|
'time': 'Time (min)',
|
|
@@ -109,7 +120,24 @@ Filter1 = DG.DataFrame.fromColumns([df1.col(colNames1['tp1']), df1.col(colNames1
|
|
|
109
120
|
Filter2 = DG.DataFrame.fromColumns([df1.col(colNames1['tp2']), df1.col(colNames1['res2'])]);
|
|
110
121
|
const coefficients1 = polynomialRegressionCoefficients(df1.col(colNames1['tp1']), df1.col(colNames1['res1']), orderOfPolynomialRegression);
|
|
111
122
|
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
|
+
|
|
126
|
+
Filter1.meta.addFormulaLine({
|
|
127
|
+
title: 'Parabola',
|
|
128
|
+
equation: equasionString(colNames1['tp1'], colNames1['res1'], coefficients1),
|
|
129
|
+
zindex: -30,
|
|
130
|
+
color: '#ff0000',
|
|
131
|
+
width: 2
|
|
132
|
+
});
|
|
112
133
|
|
|
134
|
+
Filter2.meta.addFormulaLine({
|
|
135
|
+
title: 'Parabola',
|
|
136
|
+
equation: equasionString(colNames1['tp2'], colNames1['res2'], coefficients2),
|
|
137
|
+
zindex: -30,
|
|
138
|
+
color: '#ff0000',
|
|
139
|
+
width: 2
|
|
140
|
+
});
|
|
113
141
|
|
|
114
142
|
const df2 = DG.DataFrame.create(lengthOfSecondTable);
|
|
115
143
|
df2.columns.addNewFloat(colNames2['area']).init((i) => (i > 0) ? batchVolume / i : 0);
|
package/src/export-funccall.ts
CHANGED
|
@@ -46,21 +46,85 @@ export async function exportFuncCall(call: DG.FuncCall) {
|
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
// UWAGA: very fragile solution
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
const funcView = document.getElementsByClassName('grok-view grok-view-func ui-box')[0];
|
|
50
|
+
const resultView = funcView.getElementsByClassName('d4-tab-host ui-box')[0];
|
|
51
|
+
if (resultView) {
|
|
52
|
+
const tabs = resultView.getElementsByClassName('d4-tab-header-stripe')[0].children;
|
|
53
|
+
const selectedByUser = resultView.getElementsByClassName('d4-tab-header selected')[0];
|
|
54
|
+
for (let i=0; i< tabs.length; i++) {
|
|
55
|
+
(tabs[i] as HTMLElement).click();
|
|
56
|
+
await new Promise((r) => setTimeout(r, 150));
|
|
57
|
+
|
|
58
|
+
const titleDivs = document.getElementsByClassName('grok-func-results-header');
|
|
59
|
+
if (!titleDivs.length) continue;
|
|
60
|
+
|
|
61
|
+
for (let i = 0; i < titleDivs.length; i++) {
|
|
62
|
+
const titleDiv = titleDivs[i];
|
|
63
|
+
|
|
64
|
+
const title = titleDiv.firstChild?.textContent;
|
|
65
|
+
if (title === null || title === undefined) continue;
|
|
66
|
+
|
|
67
|
+
let imageId;
|
|
68
|
+
let width = 0;
|
|
69
|
+
let height = 0;
|
|
70
|
+
|
|
71
|
+
const imageDiv = titleDiv.parentElement?.getElementsByClassName('grok-scripting-image-container')[0];
|
|
72
|
+
if (imageDiv) {
|
|
73
|
+
const regex = /background-image: url\(.*\)/;
|
|
74
|
+
const urlAttr = imageDiv.outerHTML.match(regex)?.[0];
|
|
75
|
+
if (!urlAttr) continue;
|
|
76
|
+
const url = urlAttr.substring(23, urlAttr?.length - 2);
|
|
77
|
+
const pic = (await (await fetch(url)).arrayBuffer());
|
|
78
|
+
imageId = exportWorkbook.addImage({
|
|
79
|
+
buffer: pic,
|
|
80
|
+
extension: 'png',
|
|
81
|
+
});
|
|
82
|
+
width = imageDiv.clientWidth;
|
|
83
|
+
height = imageDiv.clientHeight;
|
|
84
|
+
} else {
|
|
85
|
+
const plot = titleDiv.nextSibling;
|
|
86
|
+
// if plot does not exist or it is only grid, skip it
|
|
87
|
+
if (!plot || (plot.firstChild as HTMLElement).getAttribute('name') === 'viewer-Grid') continue;
|
|
88
|
+
|
|
89
|
+
if (plot) {
|
|
90
|
+
const canvas = await DG.HtmlUtils.renderToCanvas(plot as HTMLElement);
|
|
91
|
+
const dataUrl = canvas.toDataURL('image/png');
|
|
92
|
+
|
|
93
|
+
imageId = exportWorkbook.addImage({
|
|
94
|
+
base64: dataUrl,
|
|
95
|
+
extension: 'png',
|
|
96
|
+
});
|
|
97
|
+
width = canvas.width;
|
|
98
|
+
height = canvas.height;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
55
101
|
|
|
56
|
-
|
|
57
|
-
if (!titleDivs.length) continue;
|
|
102
|
+
if (imageId === null || imageId === undefined) continue;
|
|
58
103
|
|
|
59
|
-
|
|
104
|
+
const worksheet = exportWorkbook.getWorksheet(`Output - ${title}`);
|
|
105
|
+
if (worksheet) {
|
|
106
|
+
const columnForImage = ((call.outputs[title] as DG.DataFrame).columns as DG.ColumnList).length + 1;
|
|
107
|
+
worksheet.addImage(imageId, {
|
|
108
|
+
tl: {col: columnForImage, row: 0},
|
|
109
|
+
ext: {width, height},
|
|
110
|
+
});
|
|
111
|
+
} else {
|
|
112
|
+
const newWorksheet = exportWorkbook.addWorksheet(`Output - Plot - ${title}`);
|
|
113
|
+
newWorksheet.addImage(imageId, {
|
|
114
|
+
tl: {col: 0, row: 0},
|
|
115
|
+
ext: {width, height},
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
(selectedByUser as HTMLElement).click();
|
|
121
|
+
} else {
|
|
122
|
+
const resultView = document.getElementsByClassName('ui-panel grok-func-results')[0];
|
|
123
|
+
const titleDivs = resultView.getElementsByClassName('grok-func-results-header');
|
|
124
|
+
for (let i=0; i< titleDivs.length; i++) {
|
|
60
125
|
const titleDiv = titleDivs[i];
|
|
61
|
-
|
|
62
126
|
const title = titleDiv.firstChild?.textContent;
|
|
63
|
-
if (
|
|
127
|
+
if (title === null || title === undefined) continue;
|
|
64
128
|
|
|
65
129
|
let imageId;
|
|
66
130
|
let width = 0;
|
|
@@ -115,7 +179,6 @@ export async function exportFuncCall(call: DG.FuncCall) {
|
|
|
115
179
|
}
|
|
116
180
|
}
|
|
117
181
|
}
|
|
118
|
-
(selectedByUser as HTMLElement).click();
|
|
119
182
|
|
|
120
183
|
const outputScalarsSheet = exportWorkbook.addWorksheet('Output scalars');
|
|
121
184
|
scalarOutputs.forEach((scalarOutput) => {
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import * as grok from 'datagrok-api/grok';
|
|
2
|
+
import * as ui from 'datagrok-api/ui';
|
|
3
|
+
import * as DG from 'datagrok-api/dg';
|
|
4
|
+
|
|
5
|
+
export class OutliersSelectionViewer extends DG.JsViewer {
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// override to handle property changes
|
|
11
|
+
onPropertyChanged(prop: any) {
|
|
12
|
+
grok.shell.info(`${prop.name}: ${prop.get(this)}`);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
onTableAttached() {
|
|
16
|
+
if (this.dataFrame) {
|
|
17
|
+
this.initialRender();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
render() {
|
|
22
|
+
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
initialRender() {
|
|
26
|
+
if (!this.dataFrame) {
|
|
27
|
+
this.root.innerHTML = '';
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const inputData = this.dataFrame;
|
|
32
|
+
const IS_OUTLIER_COL_LABEL = 'isOutlier';
|
|
33
|
+
const OUTLIER_RATIONALE_COL_LABEL = 'Rationale';
|
|
34
|
+
const OUTLIER_COUNT_COL_LABEL = 'Count';
|
|
35
|
+
const IS_GROUP_CONFIRMED_LABEL = 'isConfirmed';
|
|
36
|
+
const FLUX = 't/V (hr/L)';
|
|
37
|
+
|
|
38
|
+
if (!inputData.columns.byName(IS_OUTLIER_COL_LABEL)) {
|
|
39
|
+
inputData.columns
|
|
40
|
+
.add(DG.Column.fromBitSet(IS_OUTLIER_COL_LABEL, DG.BitSet.create(inputData.rowCount, () => false)));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (!inputData.columns.byName(OUTLIER_RATIONALE_COL_LABEL)) {
|
|
44
|
+
inputData.columns
|
|
45
|
+
.add(DG.Column.fromStrings(OUTLIER_RATIONALE_COL_LABEL, Array.from({length: inputData.rowCount}, () => '')));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
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
|
+
}
|
|
51
|
+
|
|
52
|
+
const initialData = inputData.clone();
|
|
53
|
+
|
|
54
|
+
const clearTable = () => {
|
|
55
|
+
return DG.DataFrame.fromColumns([
|
|
56
|
+
DG.Column.fromStrings(OUTLIER_RATIONALE_COL_LABEL, []),
|
|
57
|
+
DG.Column.fromInt32Array(OUTLIER_COUNT_COL_LABEL, new Int32Array([])),
|
|
58
|
+
DG.Column.fromStrings('Actions', []),
|
|
59
|
+
DG.Column.fromBitSet(IS_GROUP_CONFIRMED_LABEL, DG.BitSet.create(0, () => false)),
|
|
60
|
+
]);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const groupsListGrid = DG.Viewer.grid(clearTable());
|
|
64
|
+
groupsListGrid.root.style.width = '100%';
|
|
65
|
+
groupsListGrid.columns.setVisible([OUTLIER_RATIONALE_COL_LABEL, OUTLIER_COUNT_COL_LABEL, 'Actions']);
|
|
66
|
+
|
|
67
|
+
groupsListGrid.onCellPrepare((gc) => {
|
|
68
|
+
if (!gc.isTableCell) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const confirmBtn = () => ui.div(
|
|
73
|
+
ui.iconFA('check', () => {
|
|
74
|
+
if (!groupsListGrid.dataFrame) return;
|
|
75
|
+
|
|
76
|
+
const newRationale =
|
|
77
|
+
groupsListGrid.dataFrame?.cell(groupsListGrid.dataFrame.rowCount-1, OUTLIER_RATIONALE_COL_LABEL).value;
|
|
78
|
+
|
|
79
|
+
inputData.selection.getSelectedIndexes().forEach((selectedIndex: number) => {
|
|
80
|
+
inputData.set(IS_OUTLIER_COL_LABEL, selectedIndex, true);
|
|
81
|
+
inputData.set(
|
|
82
|
+
OUTLIER_RATIONALE_COL_LABEL,
|
|
83
|
+
selectedIndex,
|
|
84
|
+
newRationale,
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
inputData.selection.setAll(false);
|
|
88
|
+
}, 'Confirm the outliers'), {style: {'text-align': 'center', 'margin': '6px'}},
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
const cancelBtn = () => ui.div(
|
|
92
|
+
ui.iconFA('times', () => {
|
|
93
|
+
if (!groupsListGrid.dataFrame) return;
|
|
94
|
+
|
|
95
|
+
groupsListGrid.dataFrame.rows.removeAt(groupsListGrid.dataFrame.rowCount-1);
|
|
96
|
+
inputData.selection.setAll(false);
|
|
97
|
+
}, 'Cancel the outliers'), {style: {'text-align': 'center', 'margin': '6px'}},
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const deleteBtn = (rationale: string) => ui.div(
|
|
101
|
+
ui.icons.delete(() => {
|
|
102
|
+
for (let i = 0; i < inputData.rowCount; i++) {
|
|
103
|
+
if (inputData.columns.byName(OUTLIER_RATIONALE_COL_LABEL).get(i) === rationale) {
|
|
104
|
+
inputData.columns.byName(OUTLIER_RATIONALE_COL_LABEL).set(i, '');
|
|
105
|
+
inputData.columns.byName(IS_OUTLIER_COL_LABEL).set(i, false);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}, 'Remove the outliers group'), {style: {'text-align': 'center', 'margin': '6px'}},
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
if (gc.gridColumn.name === 'Actions') {
|
|
112
|
+
gc.gridColumn.cellType = 'html';
|
|
113
|
+
gc.style.element =
|
|
114
|
+
ui.divH([
|
|
115
|
+
...!gc.grid.dataFrame?.get(IS_GROUP_CONFIRMED_LABEL, gc.gridRow) ?
|
|
116
|
+
[confirmBtn(), cancelBtn()] :
|
|
117
|
+
[deleteBtn(gc.grid.dataFrame?.get(OUTLIER_RATIONALE_COL_LABEL, gc.gridRow))],
|
|
118
|
+
]);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
groupsListGrid.onCellValueEdited.subscribe((editedCell) => {
|
|
123
|
+
if (!groupsListGrid.dataFrame || editedCell.gridColumn.name !== OUTLIER_RATIONALE_COL_LABEL) return;
|
|
124
|
+
|
|
125
|
+
if (!(groupsListGrid.dataFrame.columns as DG.ColumnList)
|
|
126
|
+
.byName(IS_GROUP_CONFIRMED_LABEL).get(editedCell.gridRow)) return;
|
|
127
|
+
|
|
128
|
+
const uniqueValues= new Set<string>();
|
|
129
|
+
for (let i = 0; i < groupsListGrid.dataFrame?.rowCount; i++) {
|
|
130
|
+
const record = groupsListGrid.dataFrame?.columns.byName(OUTLIER_RATIONALE_COL_LABEL).get(i);
|
|
131
|
+
uniqueValues.add(record);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
for (let i = 0; i < inputData.rowCount; i++) {
|
|
135
|
+
const currentCellValue = inputData.columns.byName(OUTLIER_RATIONALE_COL_LABEL).get(i);
|
|
136
|
+
if (currentCellValue != '' && !uniqueValues.has(currentCellValue)) {
|
|
137
|
+
inputData.columns.byName(OUTLIER_RATIONALE_COL_LABEL).set(i, editedCell.cell.value);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const updateGroupsTable = () => {
|
|
143
|
+
const uniqueValues: {[key:string]: number} = {};
|
|
144
|
+
for (let i = 0; i < inputData.rowCount; i++) {
|
|
145
|
+
const record = inputData.columns.byName(OUTLIER_RATIONALE_COL_LABEL).get(i);
|
|
146
|
+
const count = uniqueValues[record];
|
|
147
|
+
if (record != '') {
|
|
148
|
+
count ?
|
|
149
|
+
uniqueValues[record]++ :
|
|
150
|
+
uniqueValues[record] = 1;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
groupsListGrid.dataFrame = clearTable();
|
|
154
|
+
groupsListGrid.columns.setVisible([OUTLIER_RATIONALE_COL_LABEL, OUTLIER_COUNT_COL_LABEL, 'Actions']);
|
|
155
|
+
|
|
156
|
+
Object.keys(uniqueValues).map((key: string) => {
|
|
157
|
+
groupsListGrid.dataFrame?.rows.addNew([key, uniqueValues[key], '', true]);
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
inputData.onDataChanged.subscribe(updateGroupsTable);
|
|
162
|
+
inputData.onSelectionChanged.subscribe(() => {
|
|
163
|
+
if (!groupsListGrid.dataFrame || !inputData.selection.trueCount) return;
|
|
164
|
+
|
|
165
|
+
const isConfirmedColumn = (groupsListGrid.dataFrame.columns as DG.ColumnList)
|
|
166
|
+
.byName(IS_GROUP_CONFIRMED_LABEL).toList();
|
|
167
|
+
|
|
168
|
+
if (isConfirmedColumn.some((value) => value === false)) {
|
|
169
|
+
groupsListGrid.dataFrame.set(
|
|
170
|
+
OUTLIER_COUNT_COL_LABEL,
|
|
171
|
+
groupsListGrid.dataFrame.rowCount-1,
|
|
172
|
+
inputData.selection.trueCount,
|
|
173
|
+
);
|
|
174
|
+
} else {
|
|
175
|
+
const newRow = groupsListGrid.dataFrame.rows.addNew(['Manual', inputData.selection.trueCount, '', false]);
|
|
176
|
+
groupsListGrid.dataFrame.currentCell = groupsListGrid.dataFrame.cell(newRow.idx, OUTLIER_RATIONALE_COL_LABEL);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
const resetSelectedBtn = ui.button(
|
|
181
|
+
'RESET SELECTED',
|
|
182
|
+
() => {
|
|
183
|
+
inputData.selection.getSelectedIndexes().forEach((selectedIndex: number) => {
|
|
184
|
+
inputData.set(IS_OUTLIER_COL_LABEL, selectedIndex, false);
|
|
185
|
+
inputData.set(OUTLIER_RATIONALE_COL_LABEL, selectedIndex, '');
|
|
186
|
+
});
|
|
187
|
+
inputData.selection.setAll(false);
|
|
188
|
+
},
|
|
189
|
+
'Remove the selected points from oultiers list',
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
const resetAllBtn = ui.button(
|
|
193
|
+
'RESET ALL',
|
|
194
|
+
() => {
|
|
195
|
+
(inputData.columns as DG.ColumnList).byName(IS_OUTLIER_COL_LABEL).init(
|
|
196
|
+
(index) => initialData.get(IS_OUTLIER_COL_LABEL, index),
|
|
197
|
+
);
|
|
198
|
+
(inputData.columns as DG.ColumnList).byName(OUTLIER_RATIONALE_COL_LABEL).init(
|
|
199
|
+
(index) => initialData.get(OUTLIER_RATIONALE_COL_LABEL, index),
|
|
200
|
+
);
|
|
201
|
+
},
|
|
202
|
+
'Cancel all changes',
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
const autoOutlierGroupBtn = ui.button(
|
|
206
|
+
'AUTO DETECT...',
|
|
207
|
+
() => {
|
|
208
|
+
const intInput = ui.intInput('N', 3);
|
|
209
|
+
const columnInput = ui.columnInput('Column', inputData, null);
|
|
210
|
+
ui.dialog('Detect outliers automatically')
|
|
211
|
+
.add(columnInput.root)
|
|
212
|
+
.add(intInput.root)
|
|
213
|
+
.onOK(()=>{
|
|
214
|
+
const meanValue = (columnInput.value as DG.Column).stats.avg;
|
|
215
|
+
const stddev = (columnInput.value as DG.Column).stats.stdev;
|
|
216
|
+
inputData.selection.init((index)=>
|
|
217
|
+
Math.abs(meanValue - (columnInput.value as DG.Column).get(index)) > stddev*intInput.value,
|
|
218
|
+
);
|
|
219
|
+
inputData.selection.getSelectedIndexes().forEach((selectedIndex: number) => {
|
|
220
|
+
inputData.set(IS_OUTLIER_COL_LABEL, selectedIndex, true);
|
|
221
|
+
inputData.set(OUTLIER_RATIONALE_COL_LABEL, selectedIndex, `${intInput.value}x stddev rule`);
|
|
222
|
+
});
|
|
223
|
+
inputData.selection.setAll(false);
|
|
224
|
+
})
|
|
225
|
+
.show();
|
|
226
|
+
},
|
|
227
|
+
'Detect outliers automatically',
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
inputData.selection.setAll(false);
|
|
231
|
+
|
|
232
|
+
inputData.onSelectionChanged.subscribe(() => {
|
|
233
|
+
if (inputData.selection.trueCount === 0) {
|
|
234
|
+
resetSelectedBtn.classList.add('disabled');
|
|
235
|
+
} else {
|
|
236
|
+
resetSelectedBtn.classList.remove('disabled');
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
updateGroupsTable();
|
|
241
|
+
resetSelectedBtn.classList.add('disabled');
|
|
242
|
+
|
|
243
|
+
this.root.replaceWith(ui.panel([
|
|
244
|
+
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
|
+
),
|
|
250
|
+
ui.divV([
|
|
251
|
+
ui.divH([
|
|
252
|
+
resetSelectedBtn, resetAllBtn, autoOutlierGroupBtn,
|
|
253
|
+
], {style: {'text-align': 'center'}}),
|
|
254
|
+
groupsListGrid.root,
|
|
255
|
+
], {style: {'height': '75%'}}),
|
|
256
|
+
], {style: {'height': '100%', 'min-width': '230px'}}),
|
|
257
|
+
], {style: {'height': '100%'}}));
|
|
258
|
+
}
|
|
259
|
+
}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import * as grok from 'datagrok-api/grok';
|
|
2
2
|
import * as ui from 'datagrok-api/ui';
|
|
3
3
|
import * as DG from 'datagrok-api/dg';
|
|
4
|
-
import {_package} from '
|
|
4
|
+
import {_package} from '../package';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* @param inputData The data to select the outliers in
|
|
8
|
+
* @returns Two dataframes: 1) with selected outliers and 2) with removed outliers
|
|
9
|
+
* @deprecated Use the OutliersSelectionViewer instead
|
|
10
|
+
*/
|
|
6
11
|
export async function selectOutliersManually(inputData: DG.DataFrame) {
|
|
7
12
|
const IS_OUTLIER_COL_LABEL = 'isOutlier';
|
|
8
13
|
const OUTLIER_RATIONALE_COL_LABEL = 'Rationale';
|
package/src/package.ts
CHANGED
|
@@ -3,12 +3,13 @@ import * as grok from 'datagrok-api/grok';
|
|
|
3
3
|
import * as ui from 'datagrok-api/ui';
|
|
4
4
|
import * as DG from 'datagrok-api/dg';
|
|
5
5
|
import {ModelHandler} from './model-handler';
|
|
6
|
-
import {selectOutliersManually} from './outliers-selection';
|
|
6
|
+
import {selectOutliersManually} from './outliers-selection/outliers-selection';
|
|
7
7
|
import {exportFuncCall} from './export-funccall';
|
|
8
8
|
import {_functionParametersGrid} from './function-views/function-parameters-grid';
|
|
9
9
|
import {ModelCatalogView} from './model-catalog-view';
|
|
10
10
|
import wu from 'wu';
|
|
11
11
|
import {_functionEditor} from './function-editor/function-editor';
|
|
12
|
+
import {OutliersSelectionViewer} from './outliers-selection/outliers-selection-viewer';
|
|
12
13
|
|
|
13
14
|
let initCompleted: boolean = false;
|
|
14
15
|
export const _package = new DG.Package();
|
|
@@ -46,6 +47,14 @@ export async function manualOutlierSelectionDialog(inputData: DG.DataFrame) {
|
|
|
46
47
|
});
|
|
47
48
|
}
|
|
48
49
|
|
|
50
|
+
//name: OutliersSelectionViewer
|
|
51
|
+
//description: Creates an outliers selection viewer
|
|
52
|
+
//tags: viewer
|
|
53
|
+
//output: viewer
|
|
54
|
+
export function OutliersSelection() {
|
|
55
|
+
return new OutliersSelectionViewer();
|
|
56
|
+
}
|
|
57
|
+
|
|
49
58
|
//name: export To Excel
|
|
50
59
|
//input: funccall call
|
|
51
60
|
//tags: export
|