@datagrok/compute 0.1.1 → 0.2.6
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 -234
- 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 +7 -2
- package/src/package.ts +112 -14
- package/webpack.config.js +1 -0
- package/help/ui-auto-generation.png +0 -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
package/scripts/popPK.R
CHANGED
|
@@ -4,18 +4,18 @@
|
|
|
4
4
|
#input: double doseInterval = 12 {category: Dosing options}
|
|
5
5
|
#input: string compartments {category: PK model; choices: ['2 compartment PK', '1 compartment PK']}
|
|
6
6
|
#input: double clearance = 2 {category: PK parameters}
|
|
7
|
-
#input: double omegaClearance {category: Random effects} [omega clearance]
|
|
7
|
+
#input: double omegaClearance = 0.3 {category: Random effects} [omega clearance]
|
|
8
8
|
#input: double rateConstant = 0.3 {category: PK parameters} [rate constant]
|
|
9
9
|
#input: double centralV = 4 {category: PK parameters} [central compartment volume]
|
|
10
10
|
#input: double perV = 30 {category: PK parameters} [peripheral compartment volume]
|
|
11
11
|
#input: double interRate = 1 {category: PK parameters} [intercompartmental rate]
|
|
12
12
|
#output: graphics popPK
|
|
13
|
-
#output: double omega
|
|
14
13
|
#tags: model
|
|
14
|
+
#meta.domain: PKPD
|
|
15
15
|
|
|
16
16
|
require("ggplot2")
|
|
17
17
|
require("RxODE")
|
|
18
|
-
require("
|
|
18
|
+
require("dplyr")
|
|
19
19
|
rxCreateCache()
|
|
20
20
|
|
|
21
21
|
params <-
|
|
@@ -56,14 +56,14 @@ for(i in seq(1, 20)){
|
|
|
56
56
|
a <- params
|
|
57
57
|
a["CL"] <- params["CL"] + rlnorm(1, 0, omegaClearance)
|
|
58
58
|
|
|
59
|
-
Sims <- data.frame(
|
|
59
|
+
Sims <- data.frame(mod$run(a, ev, inits)) %>% mutate(ID = i)
|
|
60
60
|
SimsAll <- SimsAll %>% bind_rows(Sims)
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
|
|
64
64
|
DataSet <- SimsAll %>% select(time, centr, ID)
|
|
65
65
|
|
|
66
|
-
DataSet <-
|
|
66
|
+
DataSet <- DataSet %>%
|
|
67
67
|
group_by(time) %>%
|
|
68
68
|
summarise(mean = mean(centr),
|
|
69
69
|
q95 = quantile(centr, probs = 0.95),
|
|
@@ -75,6 +75,10 @@ ggplot() +
|
|
|
75
75
|
geom_line(data = DataSet, aes(x = time, y = mean), col = "#483D8B", size =1) + theme_bw()+
|
|
76
76
|
geom_ribbon(data = DataSet, aes(x = time, ymin = q05, ymax = q95), col = "#ADFF2F", fill = "#ADFF2F", alpha = 0.5) +
|
|
77
77
|
scale_y_continuous(name = "Drug concentration, uM")+
|
|
78
|
-
scale_x_continuous(name = "Time, hours", breaks = seq(0,
|
|
78
|
+
scale_x_continuous(name = "Time, hours", breaks = seq(0, 4, 24), limits = c(0, 24))+
|
|
79
|
+
theme(axis.text.x = element_text(size = 24, angle = 0,vjust =.5, family="serif"),
|
|
80
|
+
axis.text.y = element_text(size = 24, family = "serif"),
|
|
81
|
+
axis.title.x = element_text(vjust = 1, size = 24, family = "serif"),
|
|
82
|
+
axis.title.y = element_text(vjust = 1, size = 24, family = "serif"))
|
|
79
83
|
|
|
80
84
|
omega <- omegaClearance
|
package/scripts/trig.js
CHANGED
|
@@ -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
|
+
];
|
|
@@ -8,6 +8,7 @@ export async function selectOutliersManually(inputData: DG.DataFrame) {
|
|
|
8
8
|
const OUTLIER_RATIONALE_COL_LABEL = 'Rationale';
|
|
9
9
|
const OUTLIER_COUNT_COL_LABEL = 'Count';
|
|
10
10
|
const IS_GROUP_CONFIRMED_LABEL = 'isConfirmed';
|
|
11
|
+
const FLUX = 't/V (hr/L)';
|
|
11
12
|
|
|
12
13
|
if (!inputData.columns.byName(IS_OUTLIER_COL_LABEL)) {
|
|
13
14
|
inputData.columns
|
|
@@ -19,6 +20,10 @@ export async function selectOutliersManually(inputData: DG.DataFrame) {
|
|
|
19
20
|
.add(DG.Column.fromStrings(OUTLIER_RATIONALE_COL_LABEL, Array.from({length: inputData.rowCount}, () => '')));
|
|
20
21
|
}
|
|
21
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
|
+
|
|
22
27
|
const initialData = inputData.clone();
|
|
23
28
|
|
|
24
29
|
const scatterPlot = DG.Viewer.scatterPlot(inputData, {
|
|
@@ -239,7 +244,7 @@ export async function selectOutliersManually(inputData: DG.DataFrame) {
|
|
|
239
244
|
groupsListGrid.root,
|
|
240
245
|
], {style: {height: '75%'}}),
|
|
241
246
|
]),
|
|
242
|
-
], {style: {height: '100%'}}),
|
|
247
|
+
], {style: {'height': '100%', 'min-height': '600px'}}),
|
|
243
248
|
)
|
|
244
249
|
.onOK(() => {
|
|
245
250
|
shouldCancel = false;
|
|
@@ -263,7 +268,7 @@ export async function selectOutliersManually(inputData: DG.DataFrame) {
|
|
|
263
268
|
cancelAllChanges();
|
|
264
269
|
resolve({augmentedInput: inputData, editedInput});
|
|
265
270
|
}, 100));
|
|
266
|
-
selectionDialog.show({width: 1000
|
|
271
|
+
selectionDialog.show({width: 1000});
|
|
267
272
|
});
|
|
268
273
|
|
|
269
274
|
return result;
|
package/src/package.ts
CHANGED
|
@@ -7,7 +7,9 @@ import {selectOutliersManually} from './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
|
+
import wu from 'wu';
|
|
10
11
|
|
|
12
|
+
let initCompleted: boolean = false;
|
|
11
13
|
export const _package = new DG.Package();
|
|
12
14
|
|
|
13
15
|
//name: test
|
|
@@ -15,18 +17,6 @@ export function test() {
|
|
|
15
17
|
grok.shell.info(_package.webRoot);
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
//tags: init, autostart
|
|
19
|
-
export function init() {
|
|
20
|
-
console.log('init');
|
|
21
|
-
DG.ObjectHandler.register(new ModelHandler());
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
//name: Model Catalog
|
|
25
|
-
//tags: app
|
|
26
|
-
export function modelCatalog() {
|
|
27
|
-
grok.shell.addView(new ModelCatalogView());
|
|
28
|
-
}
|
|
29
|
-
|
|
30
20
|
//name: manualOutlierDetectionDialog
|
|
31
21
|
//input: dataframe inputData
|
|
32
22
|
//output: dataframe augmentedInput
|
|
@@ -35,7 +25,7 @@ export async function manualOutlierSelectionDialog(inputData: DG.DataFrame) {
|
|
|
35
25
|
const call = grok.functions.getCurrentCall();
|
|
36
26
|
|
|
37
27
|
const IS_OUTLIER_COL_LABEL = 'isOutlier';
|
|
38
|
-
const OUTLIER_REASON_COL_LABEL = '
|
|
28
|
+
const OUTLIER_REASON_COL_LABEL = 'Rationale';
|
|
39
29
|
|
|
40
30
|
if (call.options['interactive']) {
|
|
41
31
|
const {augmentedInput, editedInput} = await selectOutliersManually(inputData);
|
|
@@ -77,4 +67,112 @@ export function hof() {
|
|
|
77
67
|
let f: DG.Func = DG.Func.byName('Sin');
|
|
78
68
|
let v: DG.View = functionParametersGrid(f);
|
|
79
69
|
grok.shell.addView(v);
|
|
80
|
-
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
//name: renderRestPanel
|
|
73
|
+
//input: func func
|
|
74
|
+
//output: widget panel
|
|
75
|
+
export async function renderRestPanel(func: DG.Func): Promise<DG.Widget> {
|
|
76
|
+
let params: object = {};
|
|
77
|
+
func.inputs.forEach((i) => (<any>params)[i.name] = null);
|
|
78
|
+
let curl = `
|
|
79
|
+
curl --location --request POST '${(<any>grok.settings).apiUrl}/v1/func/${func.nqName}/run' \\
|
|
80
|
+
--header 'Authorization: ${getCookie('auth')}' \\
|
|
81
|
+
--header 'Content-Type: application/json' \\
|
|
82
|
+
--data-raw '${JSON.stringify(params)}'`
|
|
83
|
+
let js = `
|
|
84
|
+
var myHeaders = new Headers();
|
|
85
|
+
myHeaders.append("Authorization", "${getCookie('auth')}");
|
|
86
|
+
myHeaders.append("Content-Type", "application/json");
|
|
87
|
+
|
|
88
|
+
var raw = JSON.stringify(${JSON.stringify(params)});
|
|
89
|
+
|
|
90
|
+
var requestOptions = {
|
|
91
|
+
method: 'POST',
|
|
92
|
+
headers: myHeaders,
|
|
93
|
+
body: raw,
|
|
94
|
+
redirect: 'follow'
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
fetch("${(<any>grok.settings).apiUrl}/v1/func/${func.nqName}/run", requestOptions)
|
|
98
|
+
.then(response => response.text())
|
|
99
|
+
.then(result => console.log(result))
|
|
100
|
+
.catch(error => console.log('error', error));`
|
|
101
|
+
let tabs = ui.tabControl({'CURL': ui.div([ui.divText(curl)]), 'JS': ui.div([ui.divText(js)])})
|
|
102
|
+
return DG.Widget.fromRoot(tabs.root);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function getCookie(name: string): string | undefined{
|
|
106
|
+
let matches = document.cookie.match(new RegExp(
|
|
107
|
+
"(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
|
|
108
|
+
));
|
|
109
|
+
return matches ? decodeURIComponent(matches[1]) : undefined;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
//tags: init, autostart
|
|
113
|
+
export function init() {
|
|
114
|
+
if (initCompleted)
|
|
115
|
+
return;
|
|
116
|
+
DG.ObjectHandler.register(new ModelHandler());
|
|
117
|
+
|
|
118
|
+
grok.events.onAccordionConstructed.subscribe((acc: DG.Accordion) => {
|
|
119
|
+
const ent = acc.context;
|
|
120
|
+
if (ent == null)
|
|
121
|
+
return;
|
|
122
|
+
if (ent.type != 'script')
|
|
123
|
+
return;
|
|
124
|
+
let restPane = acc.getPane('REST');
|
|
125
|
+
if (!restPane)
|
|
126
|
+
acc.addPane('REST', () => ui.wait(async () => (await renderRestPanel(ent)).root));
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
let modelsList = ui.waitBox(async () => {
|
|
130
|
+
let models = await grok.dapi.scripts
|
|
131
|
+
.filter('#model')
|
|
132
|
+
.list();
|
|
133
|
+
let list = ui.divV(models.map((model) => ui.render(model, {onClick: (_) => ModelHandler.openModel(model)})), {style: {lineHeight: '165%'}});
|
|
134
|
+
|
|
135
|
+
let props = ['domain', 'modality'];
|
|
136
|
+
let mtree: { model: DG.Func}[] = models.map((m) => { return {model: m}});
|
|
137
|
+
mtree.forEach((m: {model: DG.Func}) => {
|
|
138
|
+
props.forEach((k) => {
|
|
139
|
+
(<any>m)[k] = m.model.options[k];
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
let tree = DG.TreeViewNode.fromItemCategories(mtree,
|
|
144
|
+
props,
|
|
145
|
+
{ itemToElement: (x) => ui.render(x.model, {onClick: (_) => ModelHandler.openModel(x.model)}), itemToValue: (x) => x.model, removeEmpty: true }).root
|
|
146
|
+
|
|
147
|
+
return ui.tabControl({
|
|
148
|
+
'LIST': list,
|
|
149
|
+
'TREE': tree
|
|
150
|
+
}).root;
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
grok.events.onViewAdding.subscribe((v: DG.View) => {
|
|
154
|
+
if (v instanceof DG.FunctionView && v.func?.hasTag("model")) {
|
|
155
|
+
let modelsView = wu(grok.shell.views).find((v) => v.parentCall?.func.name == 'modelCatalog');
|
|
156
|
+
if (modelsView != undefined) {
|
|
157
|
+
v.parentCall = modelsView!.parentCall;
|
|
158
|
+
v.parentView = modelsView!;
|
|
159
|
+
v.toolbox = modelsList;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
initCompleted = true;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
//name: Model Catalog
|
|
168
|
+
//tags: app
|
|
169
|
+
export function modelCatalog() {
|
|
170
|
+
/* let view = new DG.MultiView({
|
|
171
|
+
viewFactories: {
|
|
172
|
+
'Models': {factory: () => new ModelCatalogView(), allowClose: false}
|
|
173
|
+
}
|
|
174
|
+
});*/
|
|
175
|
+
let view = new ModelCatalogView();
|
|
176
|
+
view.name = 'Models';
|
|
177
|
+
grok.shell.addView(view);
|
|
178
|
+
}
|
package/webpack.config.js
CHANGED
|
Binary file
|
package/scripts/AT-COE.py
DELETED
package/scripts/Chemometric.py
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
#name: Chemometric
|
|
2
|
-
#language: python
|
|
3
|
-
#input: double a
|
|
4
|
-
#input: double b
|
|
5
|
-
#output: dataframe c1
|
|
6
|
-
#output: dataframe c2
|
|
7
|
-
#output: int d
|
|
8
|
-
#output: double e
|
|
9
|
-
#tags: model
|
|
10
|
-
|
|
11
|
-
d = a + b
|
|
12
|
-
e = a / b
|
|
13
|
-
d1 = {'col1': [1, 2], 'col2': [3, 4]}
|
|
14
|
-
d2 = {'col1': [1, 5], 'col2': [3, 6]}
|
|
15
|
-
c1 = pd.DataFrame(data = d1)
|
|
16
|
-
c2 = pd.DataFrame(data = d2)
|