@datagrok/compute 1.16.1 → 1.17.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@datagrok/compute",
3
3
  "friendlyName": "Compute",
4
- "version": "1.16.1",
4
+ "version": "1.17.0",
5
5
  "author": {
6
6
  "name": "Aufar Zakiev",
7
7
  "email": "aufar.zakiev@softwarecountry.com"
@@ -13,7 +13,7 @@
13
13
  "directory": "packages/Compute"
14
14
  },
15
15
  "dependencies": {
16
- "@datagrok-libraries/compute-utils": "^1.16.1",
16
+ "@datagrok-libraries/compute-utils": "^1.17.0",
17
17
  "cash-dom": "latest",
18
18
  "datagrok-api": "^1.17.0",
19
19
  "dayjs": "^1.11.10",
@@ -1,4 +1,4 @@
1
- .model-catalog-view .d4-gallery-card.entity-model i {
1
+ .model-catalog-view .d4-gallery-card.entity-model i.grok-icon {
2
2
  height: 64px;
3
3
  width: 64px;
4
4
  position: initial;
@@ -4,7 +4,58 @@ import * as DG from 'datagrok-api/dg';
4
4
  import wu from "wu";
5
5
  import {ModelCatalogView} from "./model-catalog-view";
6
6
 
7
+ function addPopover(popover: HTMLElement) {
8
+ stylePopover(popover);
9
+ document.body.append(popover);
10
+ }
11
+
12
+ function displayPopover(icon: HTMLElement, popover: HTMLElement) {
13
+ alignPopover(icon, popover);
14
+ popover.showPopover();
15
+ }
16
+
17
+ function alignPopover(target: HTMLElement, popover: HTMLElement): void {
18
+ const bounds = target.getBoundingClientRect().toJSON();
19
+ popover.style.inset = 'unset';
20
+ popover.style.top = bounds.y + 'px';
21
+ popover.style.left = (bounds.x + 20) + 'px';
22
+ }
23
+
24
+ function stylePopover(popover: HTMLElement): void {
25
+ popover.popover = 'auto';
26
+ popover.style.cursor = 'default';
27
+ popover.style.padding = '10px';
28
+ popover.style.background = '#fdffe5';
29
+ popover.style.border = '1px solid #E4E6CE';
30
+ popover.style.borderRadius = '2px';
31
+ popover.style.boxShadow = '0 0 5px #E4E6CE';
32
+ popover.style.maxWidth = '500px';
33
+ popover.style.color = 'var(--gray-6)';
34
+ }
35
+
36
+ function requestMembership(groupName: string) {
37
+ return async () => {
38
+ try {
39
+ const groups = await grok.dapi.groups.filter(`friendlyName="${groupName}"`).list();
40
+ if (groups.length === 0) {
41
+ throw new Error(`group with specified name is not found`);
42
+ }
43
+ if (groups.length > 1) {
44
+ throw new Error(`found more than one group with specified name`);
45
+ }
46
+ const group = groups[0];
47
+
48
+ // Workaround till JS API is not ready: https://reddata.atlassian.net/browse/GROK-14160
49
+ fetch(`${window.location.origin}/api/groups/${group.id}/requests/${grok.shell.user.group.id}`, {method: "POST"})
50
+ } catch (e: any) {
51
+ grok.shell.error(e.toString());
52
+ }
53
+ }
54
+ }
55
+
7
56
  export class ModelHandler extends DG.ObjectHandler {
57
+ userGroups = [] as DG.Group[];
58
+
8
59
  get type() {
9
60
  return 'Model';
10
61
  }
@@ -47,9 +98,54 @@ export class ModelHandler extends DG.ObjectHandler {
47
98
  }
48
99
 
49
100
  renderMarkup(x: DG.Func): HTMLElement {
50
- let markup = ui.span([this.renderIcon(x), ui.label(x.friendlyName)]);
51
- markup.ondblclick = (e) => { ModelHandler.openModel(x); }
52
- markup.onclick = (e) => { ModelHandler.openHelp(x); }
101
+ const mandatoryUserGroups = JSON.parse(x.options['mandatoryUserGroups'] ? `${x.options['mandatoryUserGroups']}` : '[]') as {name: string, help?: string}[];
102
+ const hasMissingMandatoryGroups = mandatoryUserGroups.filter((group) => !this.userGroups.map((userGroup) => userGroup.friendlyName).includes(group.name)).length > 0;
103
+ const mandatoryGroupsIcon = ui.iconFA('exclamation-triangle', null);
104
+ mandatoryGroupsIcon.classList.remove('grok-icon');
105
+
106
+ const getBulletIcon = () => {
107
+ const bulletIcon = ui.iconFA('times');
108
+ bulletIcon.style.marginRight = '6px';
109
+ bulletIcon.classList.remove('grok-icon');
110
+ return bulletIcon;
111
+ }
112
+
113
+ const mandatoryGroupsInfo = ui.div(ui.divV([
114
+ ui.label('You should be a member of the following group(s):', {style: {marginLeft: '0px'}}),
115
+ ...mandatoryUserGroups.map((group) => ui.divV([
116
+ ui.span([getBulletIcon(), group.name], {style: {'font-weight': 600}}),
117
+ ...group.help ? [ui.span([group.help], {style: {marginLeft: '16px'}})]: [],
118
+ ui.link(`Request group membership`, requestMembership(group.name), undefined, {style: {marginLeft: '16px'}})
119
+ ])),
120
+ ], {style: {gap: '10px'}})) as HTMLElement;
121
+
122
+ if (hasMissingMandatoryGroups) {
123
+ addPopover(mandatoryGroupsInfo);
124
+
125
+ mandatoryGroupsIcon.addEventListener('click', () => {
126
+ displayPopover(mandatoryGroupsIcon, mandatoryGroupsInfo)
127
+ })
128
+ mandatoryGroupsIcon.addEventListener('mouseover', (e) => {
129
+ e.stopPropagation();
130
+ })
131
+ }
132
+
133
+ const label = ui.span([
134
+ this.renderIcon(x),
135
+ ui.label(x.friendlyName)
136
+ ]);
137
+ const markup = ui.divH([
138
+ label,
139
+ ...hasMissingMandatoryGroups ? [ui.span([mandatoryGroupsIcon])]: [],
140
+ ], {style: {'justify-content': 'space-between', 'width': '100%'}})
141
+
142
+ if (!hasMissingMandatoryGroups) {
143
+ markup.ondblclick = () => { ModelHandler.openModel(x); }
144
+ markup.onclick = () => { ModelHandler.openHelp(x); }
145
+ } else {
146
+ label.classList.add('d4-disabled');
147
+ }
148
+
53
149
  return markup;
54
150
  }
55
151
 
@@ -85,13 +181,12 @@ export class ModelHandler extends DG.ObjectHandler {
85
181
  }
86
182
 
87
183
  renderTooltip(x: DG.Func) {
88
- let h = this.renderMarkup(x);
184
+ let h = ui.span([this.renderIcon(x), ui.label(x.friendlyName)]);
89
185
  h.classList.add('d4-link-label');
90
186
  let card = ui.bind(x, ui.divV([
91
187
  ui.h2(h),
92
188
  ui.divV([ui.divText(x.description, 'ui-description')], {style: {lineHeight: '150%'}})
93
189
  ]));
94
- card.ondblclick = (e) => { ModelHandler.openModel(x); }
95
190
  return card;
96
191
  }
97
192
 
@@ -99,8 +194,6 @@ export class ModelHandler extends DG.ObjectHandler {
99
194
  let h = this.renderMarkup(x);
100
195
  h.classList.add('d4-link-label');
101
196
  let card = ui.bind(x, ui.h2(h));
102
- card.ondblclick = (e) => { ModelHandler.openModel(x); }
103
- card.onclick = (e) => { ModelHandler.openHelp(x); }
104
197
  return card;
105
198
  }
106
199
 
@@ -154,7 +247,10 @@ export class ModelHandler extends DG.ObjectHandler {
154
247
  }
155
248
 
156
249
  init() {
157
- setTimeout(() => {
250
+ setTimeout(async () => {
251
+ // Workaround till JS API is not ready: https://reddata.atlassian.net/browse/GROK-14159
252
+ this.userGroups = (await (await fetch(`${window.location.origin}/api/groups/all_parents`)).json() as DG.Group[]);
253
+
158
254
  grok.functions.onBeforeRunAction.subscribe((fc) => {
159
255
  if (fc.func.hasTag('model') || fc.func.hasTag('model-editor')) {
160
256
  ModelHandler.bindModel(fc);
package/scripts/trig.js DELETED
@@ -1,15 +0,0 @@
1
- //name: trig
2
- //description: Returns sin, cos, and tan
3
- //language: javascript
4
- //input: double x
5
- //output: double sin
6
- //output: double cos
7
- //output: double tan
8
- //meta.domain: math
9
- //meta.runOnOpen: true
10
- //meta.runOnInput: true
11
-
12
-
13
- sin = Math.sin(x);
14
- cos = Math.cos(x);
15
- tan = Math.tan(x);
package/scripts/vmax.js DELETED
@@ -1,179 +0,0 @@
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: filtration, scale-up, model
5
- //meta.status: Upstream
6
- //input: dataframe inputTable {caption: Input table; viewer: OutliersSelectionViewer(block: 25) | Scatter Plot(y: "t/V (hr/(L/m²))", block: 75, filter: "!${isOutlier}", showFilteredOutPoints: "true", filteredOutRowsColor: 4293991195, showRegressionLine: "true", markers: "isOutlier", lassoTool: "true", legendVisibility: "Never", filterByZoom: "false")}
7
- //input: dataframe reportingParameters {caption: Reporting parameters; viewer: Grid()}
8
- //input: double testFilterArea = 3.5 {caption: Test filter area; units: cm²} [Test filter area]
9
- //input: double desiredVolumeOfBatch = 25 {caption: Desired batch volume; units: L} [Desired batch volume]
10
- //input: double desiredProcessTime = 0.5 {caption: Desired process time; units: hr} [Desired process time]
11
- //input: double sf = 1.5 {caption: Safety factor} [Safety factor]
12
- //help-url: https://github.com/datagrok-ai/public/blob/master/packages/Compute/src/help.md
13
- //output: dataframe filtrationKinetics {caption: Filtration kinetics; viewer: Scatter Plot(block: 75, filter: "!${isOutlier}", markers: "isOutlier", showFilteredOutPoints: "true", filteredOutRowsColor: 4293991195, showRegressionLine: "true", legendVisibility: "Never"); category: OUTPUT}
14
- //output: dataframe trialData {caption: Trial data; viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); category: OUTPUT}
15
- //output: dataframe fluxDecayDf {caption: Flux decay experimental results; viewer: Scatter Plot(description: "Absolute flux decay", y: "Flux", block: 50, filter: "!${isOutlier}", markers: "isOutlier", showFilteredOutPoints: "true", filteredOutRowsColor: 4293991195, legendVisibility: "Never") | Scatter Plot(description: "Relative flux decay", y: "Rel Flux", block: 50, filter: "!${isOutlier}", markers: "isOutlier", showFilteredOutPoints: "true", filteredOutRowsColor: 4293991195, legendVisibility: "Never"); category: OUTPUT}
16
- //output: dataframe experimentalResultsSummary {viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); caption: Experimental results summary; category: OUTPUT}
17
- //output: dataframe recommendations {viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); caption: Recommendations; category: OUTPUT}
18
- //output: dataframe sampleCharacteristics {viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); caption: Sample characteristics; category: OUTPUT}
19
- //output: dataframe filter {viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); caption: Filter; category: OUTPUT}
20
- //editor: Compute:ComputationView
21
- //meta.runOnOpen: true
22
- //meta.runOnInput: true
23
-
24
- const COL_NAMES = {
25
- INPUT_TIME_IN_MINUTES: "time (min)",
26
- INPUT_VOLUME_IN_MILLILITERS: "filtrate volume (mL)",
27
- INPUT_IS_OUTLIER: "isOutlier",
28
- TIME_IN_HOURS: "Time [hr]",
29
- TRIAL_THROUGHPUT: "Throughput [L/m²]",
30
- T_V: "Time/volume/area [hr/L/m²]",
31
- FLOW_RATE: "Flow rate",
32
- FLUX: "Flux",
33
- RELATIVE_FLUX: "Rel Flux"
34
- };
35
-
36
- const PARAM_NAMES = {
37
- FILTER_FAMILY: "Filter family",
38
- FILTER_NAME: "Filter name",
39
- PORE_RATING: "Pore rating (μm)",
40
- EFFECTIVE_MEMBR_AREA: "Effective membr. area (cm^2)",
41
- MEMBR_MATERIAL: "Membr material",
42
- CATALOG_NR: "Catalog nr",
43
- DATE: "Date",
44
- PRIOR_STEP: "Prior step",
45
- PROT_CONC: "Prot conc. (mg/mL)",
46
- DENSITY: "Density (g/L)",
47
- TURBIDITY: "Turbidity (NTU)",
48
- INSTALLED_DEVICE: "Installed device",
49
- PROJECT_NAME: "Project name", // PARAMETERS BELOW ARE NOT USED
50
- FILTRATION_STAGE: "Filtration stage",
51
- ELN_REFERENCE: "ELN reference",
52
- BIOREACTOR_ID: "Bioreactor ID",
53
- BIOREACTOR_PCV: "Bioreactor PCV (%)",
54
- BIOREACTOR_TURBIDITY: "Bioreactor turbidity (NTU)",
55
- FILTER_FEED_TURBIDITY: "Filter feed turbidity (NTU)",
56
- FILTER_FEED_PCV: "Filter feed PCV (%)",
57
- FILTER_FEED_PH: "Filter feed pH",
58
- FILTER_FEED_LDH: "Filter feed LDH (U/L)",
59
- FILTER_FEED_CONDUCTIVITY: "Filter feed conductivity (mS/cm)"
60
- };
61
-
62
- function linearRegression(x, y) {
63
- let sum_x = 0, sum_y = 0, sum_xy = 0, sum_xx = 0;
64
- for (let i = 0; i < y.length; i++) {
65
- sum_x += x[i];
66
- sum_y += y[i];
67
- sum_xy += x[i] * y[i];
68
- sum_xx += x[i] * x[i];
69
- }
70
- const slope = (y.length * sum_xy - sum_x * sum_y) / (y.length * sum_xx - sum_x * sum_x);
71
- const intercept = (sum_y - slope * sum_x) / y.length;
72
- return { slope: slope, intercept: intercept };
73
- }
74
-
75
- const timeInMinutes = inputTable.col(COL_NAMES.INPUT_TIME_IN_MINUTES);
76
- const volumeInMilliliters = inputTable.col(COL_NAMES.INPUT_VOLUME_IN_MILLILITERS);
77
- const isOutlier = inputTable.col(COL_NAMES.INPUT_IS_OUTLIER);
78
-
79
- let df = DG.DataFrame.fromColumns([timeInMinutes, volumeInMilliliters, isOutlier]);
80
-
81
- df.columns.addNewFloat(COL_NAMES.TIME_IN_HOURS).init((i) => timeInMinutes.get(i) / 60);
82
- const timeInHours = df.col(COL_NAMES.TIME_IN_HOURS);
83
-
84
- df.columns.addNewFloat(COL_NAMES.TRIAL_THROUGHPUT).init((i) => 10 * volumeInMilliliters.get(i) / testFilterArea);
85
- const trialThroughputCol = df.col(COL_NAMES.TRIAL_THROUGHPUT);
86
-
87
- df.columns.addNewFloat(COL_NAMES.T_V).init((i) => timeInHours.get(i) / trialThroughputCol.get(i));
88
- const tv = df.col(COL_NAMES.T_V);
89
-
90
- df.columns.addNewFloat(COL_NAMES.FLOW_RATE).init((i) => (i > 0) ?
91
- 0.06 * (volumeInMilliliters.get(i) - volumeInMilliliters.get(i - 1)) / (timeInMinutes.get(i) - timeInMinutes.get(i - 1)) : 0
92
- );
93
- const flowRate = df.col(COL_NAMES.FLOW_RATE);
94
-
95
- df.columns.addNewFloat(COL_NAMES.FLUX).init((i) => 10000 * flowRate.get(i) / testFilterArea);
96
- const flux = df.col(COL_NAMES.FLUX);
97
-
98
- df.columns.addNewFloat(COL_NAMES.RELATIVE_FLUX).init((i) => flux.get(i) / flux.get(1));
99
- const relativeFlux = df.col(COL_NAMES.RELATIVE_FLUX);
100
-
101
- fluxDecayDf = DG.DataFrame.fromColumns([
102
- DG.Column.fromFloat32Array(COL_NAMES.TRIAL_THROUGHPUT, df.col(COL_NAMES.TRIAL_THROUGHPUT).toList().slice(1)),
103
- DG.Column.fromFloat32Array(COL_NAMES.FLUX, df.col(COL_NAMES.FLUX).toList().slice(1)),
104
- DG.Column.fromFloat32Array(COL_NAMES.RELATIVE_FLUX, df.col(COL_NAMES.RELATIVE_FLUX).toList().slice(1)),
105
- DG.Column.fromList(DG.COLUMN_TYPE.BOOL, isOutlier.name, isOutlier.toList().slice(1))
106
- ]);
107
-
108
- filtrationKinetics = DG.DataFrame.fromColumns([
109
- timeInHours,
110
- df.col(COL_NAMES.T_V),
111
- volumeInMilliliters,
112
- isOutlier
113
- ]);
114
-
115
- df.col(COL_NAMES.INPUT_IS_OUTLIER).markers.assign('true', DG.MARKER_TYPE.OUTLIER);
116
- filtrationKinetics.col(COL_NAMES.INPUT_IS_OUTLIER).markers.assign('true', DG.MARKER_TYPE.OUTLIER);
117
-
118
- for (let i = df.rowCount - 1; i > -1; i--)
119
- if (isOutlier.get(i))
120
- df.rows.removeAt(i, 1, false);
121
-
122
- const coefficients = linearRegression(df.col(COL_NAMES.TIME_IN_HOURS).toList(), df.col(COL_NAMES.T_V).toList());
123
- const vmax = 1 / coefficients.slope;
124
- const j0 = 1 / coefficients.intercept;
125
- const flux0 = flux.get(1);
126
- const amin = desiredVolumeOfBatch / vmax + desiredVolumeOfBatch / desiredProcessTime / j0;
127
- const installedArea = sf * amin;
128
- const processLoading = desiredVolumeOfBatch / installedArea;
129
- const trialThroughput = df.col(COL_NAMES.TRIAL_THROUGHPUT).get(df.rowCount - 1);
130
- const fluxDecay = (1 - df.col(COL_NAMES.RELATIVE_FLUX).get(df.rowCount - 1)) * 100;
131
- const initialFlowRate = flowRate.get(1);
132
- const meanFlux = flux.stats.avg * df.rowCount / (df.rowCount - 1); // exclude zero from calculation
133
-
134
- const names = reportingParameters.col('Parameter name').toList();
135
- const values = reportingParameters.col('Parameter value').toList();
136
-
137
- experimentalResultsSummary = DG.DataFrame.fromObjects([
138
- { Name: 'Run', Value: '1' },
139
- { Name: 'Filter', Value: values[names.indexOf(PARAM_NAMES.FILTER_FAMILY)] },
140
- { Name: 'Trial Throughput [L/m²]', Value: Math.round(1000 * trialThroughput) / 1000 },
141
- { Name: 'Flux0 [LMH]', Value: Math.round(1000 * flux0) / 1000 },
142
- { Name: 'Mean Flux [LMH]', Value: Math.round(1000 * meanFlux) / 1000 },
143
- { Name: 'Vmax [L/m²]', Value: Math.round(1000 * vmax) / 1000 },
144
- { Name: 'Flux Decay [%]', Value: Math.round(1000 * fluxDecay) / 1000 }
145
- ]);
146
-
147
- recommendations = DG.DataFrame.fromObjects([
148
- { Name: 'Volume [L]', Value: desiredVolumeOfBatch },
149
- { Name: 'Time [h]', Value: desiredProcessTime },
150
- { Name: 'Amin [m²]', Value: Math.round(1000 * amin) / 1000 },
151
- { Name: 'Safety Factor', Value: sf },
152
- { Name: 'Installed Area', Value: Math.round(1000 * installedArea) / 1000 },
153
- { Name: 'Process Loading [L/m²]', Value: Math.round(1000 * processLoading) / 1000 },
154
- { Name: PARAM_NAMES.FILTER_FAMILY, Value: values[names.indexOf(PARAM_NAMES.FILTER_FAMILY)] },
155
- { Name: PARAM_NAMES.INSTALLED_DEVICE, Value: values[names.indexOf(PARAM_NAMES.INSTALLED_DEVICE)] }
156
- ]);
157
-
158
- trialData = DG.DataFrame.fromObjects([
159
- { Name: 'Test Filter Area [cm²]', Value: testFilterArea },
160
- { Name: 'Initial Flow Rate [L/h]', Value: Math.round(1000 * initialFlowRate) / 1000 },
161
- { Name: 'Vmax [L/m²]', Value: Math.round(1000 * vmax) / 1000 }
162
- ]);
163
-
164
- filter = DG.DataFrame.fromObjects([
165
- { Name: PARAM_NAMES.FILTER_FAMILY, Value: values[names.indexOf(PARAM_NAMES.FILTER_FAMILY)] },
166
- { Name: PARAM_NAMES.FILTER_NAME, Value: values[names.indexOf(PARAM_NAMES.FILTER_NAME)] },
167
- { Name: PARAM_NAMES.PORE_RATING, Value: values[names.indexOf(PARAM_NAMES.PORE_RATING)] },
168
- { Name: PARAM_NAMES.EFFECTIVE_MEMBR_AREA, Value: values[names.indexOf(PARAM_NAMES.EFFECTIVE_MEMBR_AREA)] },
169
- { Name: PARAM_NAMES.MEMBR_MATERIAL, Value: values[names.indexOf(PARAM_NAMES.MEMBR_MATERIAL)] },
170
- { Name: PARAM_NAMES.CATALOG_NR, Value: values[names.indexOf(PARAM_NAMES.CATALOG_NR)] }
171
- ]);
172
-
173
- sampleCharacteristics = DG.DataFrame.fromObjects([
174
- { Name: PARAM_NAMES.DATE, Value: values[names.indexOf(PARAM_NAMES.DATE)].slice(0, 10) },
175
- { Name: PARAM_NAMES.PRIOR_STEP, Value: values[names.indexOf(PARAM_NAMES.PRIOR_STEP)] },
176
- { Name: PARAM_NAMES.PROT_CONC, Value: values[names.indexOf(PARAM_NAMES.PROT_CONC)] },
177
- { Name: PARAM_NAMES.DENSITY, Value: values[names.indexOf(PARAM_NAMES.DENSITY)].slice(0, 5) },
178
- { Name: PARAM_NAMES.TURBIDITY, Value: values[names.indexOf(PARAM_NAMES.TURBIDITY)] }
179
- ]);
@@ -1,8 +0,0 @@
1
- //name: wrapper
2
- //language: javascript
3
- //output: view v
4
- //meta.domain: math
5
- //meta.direction: up
6
-
7
- v = grok.shell.newView('Wrapper', [ui.div(['hello world'])]);
8
- // here, launch the app