@datagrok/compute 0.9.1 → 1.0.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.
Files changed (36) hide show
  1. package/README.md +1 -1
  2. package/dist/package.js +2 -10148
  3. package/dist/package.js.map +1 -0
  4. package/files/default_data.csv +2425 -0
  5. package/help/{outliers_selection → outliers-selection}/main.md +8 -7
  6. package/icons/flux.png +0 -0
  7. package/package.json +24 -21
  8. package/scripts/default-complex.js +30 -0
  9. package/scripts/default-file-script.js +13 -0
  10. package/scripts/default.js +35 -0
  11. package/src/import-script-generator/store.ts +12 -0
  12. package/src/import-script-generator/view.ts +185 -0
  13. package/src/model-catalog-view.ts +2 -3
  14. package/src/model-handler.ts +1 -0
  15. package/src/models-widget.ts +0 -1
  16. package/src/outliers-selection/outliers-selection-viewer.ts +17 -15
  17. package/src/package.ts +26 -21
  18. package/tsconfig.json +5 -5
  19. package/webpack.config.js +4 -2
  20. package/files/model-templates.json +0 -27
  21. package/scripts/default-complex.m +0 -53
  22. package/scripts/default.m +0 -39
  23. package/src/function-views/compute-view.ts +0 -162
  24. package/src/help.md +0 -3
  25. package/src/onboard-model.ts +0 -76
  26. package/src/view-samples/computation-test-view.ts +0 -8
  27. /package/help/{outliers_selection/auto_detection_demo.gif → outliers-selection/auto-detection-demo.gif} +0 -0
  28. /package/help/{outliers_selection/manual_selection_demo.gif → outliers-selection/manual-selection-demo.gif} +0 -0
  29. /package/scripts/{Fab Arm Exchange.py → fab-arm-exchange.py} +0 -0
  30. /package/scripts/{Heat Exchange.js → heat-exchange.js} +0 -0
  31. /package/scripts/{IntervalsFromECG.py → intervals-from-ecg.py} +0 -0
  32. /package/scripts/{Logistic Map.js → logistic-map.js} +0 -0
  33. /package/scripts/{Lorenz Attractor.js → lorenz-attractor.js} +0 -0
  34. /package/scripts/{Maximal Volume.R → maximal-volume.R} +0 -0
  35. /package/scripts/{popPK.R → pop-pk.R} +0 -0
  36. /package/src/{function-views/function-parameters-grid.ts → function-parameters-grid.ts} +0 -0
@@ -1,53 +0,0 @@
1
- #name: Default complex script
2
- #description: Shows that default view works (or not)
3
- #language: octave
4
- #tags: bioreactor
5
- #input: dataframe test { viewer: Line chart(x: "Time (hours)", y: "Temperature (°C)", showSplitSelector: false) }
6
- #input: double UA = 424.2832 {caption: UA; units: ft² * BTU / hr °F}
7
- #input: double CoolingWaterFlow = 12 {caption: Coolant flowrate; units: L/min}
8
- #input: double Tcoolingin = -2 {caption: Coolant temp.; units: °C}
9
- #input: double VCD = 5 {caption: Target VCD; units: cells/mL}
10
- #input: double VL = 210.5 {caption: Final Volume; units: L}
11
- #input: double IC = 31.1 {caption: Culture temp.; units: °C}
12
- #output: dataframe tempOnTime { viewer: Line chart(x: "Time (hours)", y: "Temperature (°C)", showSplitSelector: false); category: Cooling rate }
13
- #output: double IC2 {caption: Culture temp.; units: °C; category: Cooling rate}
14
- #output: dataframe tempOnTime2 { viewer: Line chart(x: "Time (hours)", y: "Temperature (°C)", showSplitSelector: false) | Grid(block: 50); category: Cooling rate 2 }
15
- #output: dataframe tempOnTime3 { viewer: Line chart(block: 50, x: "Time (hours)", y: "Temperature (°C)", showSplitSelector: false) | Line chart(block: 50, x: "Time (hours)", y: "Temperature (°C)", showSplitSelector: false); category: Cooling rate 3 }
16
- #output: dataframe tempOnTime4 { viewer: Line chart(block: 50, x: "Time (hours)", y: "Temperature (°C)", showSplitSelector: false); category: Cooling rate 3 }
17
- #output: dataframe tempOnTime5 { viewer: Line chart(block: 50, x: "Time (hours)", y: "Temperature (°C)", showSplitSelector: false) | Line chart(block: 50, x: "Time (hours)", y: "Temperature (°C)", showSplitSelector: false); category: Cooling rate 3 }
18
- #output: double IC3 {caption: Culture temp.; units: °C; category: Cooling rate 3}
19
- #editor: Compute:FunctionViewEditor
20
-
21
- pkg load symbolic
22
-
23
- ## Conversion
24
- CalperBTU = 252;
25
- CalperhourperWatt = 3600/4.183076;
26
- Cp = 1;
27
- CoolingFactor = 56.5;
28
-
29
- ## Explicit Equation
30
- ##specificenthalpyreaction = 3.7136 * exp(0.0652*Tsub);
31
- ##Qrxn = VCD * 10^6 * VL * specificenthalpyofreaction/10^9;
32
- ##LMTD = (Tcoolingin-(Tsub + (Tcoolingin-Tsub)/(exp(UA*(CoolingFactor/100)*1.8*CalperBTU/(CoolingWaterFlow*Cp*60*1000)))))/log((Tsub-(Tsub + (Tcoolingin-Tsub)/(exp(UA*(CoolingFactor/100)*1.8*CalperBTU/(CoolingWaterFlow*Cp*60*1000)))))/(Tsub-Tcoolingin));
33
- ##Tcoolingout = Tsub + (Tcoolingin-Tsub)/(exp(UA*(CoolingFactor/100)*1.8*CalperBTU/(CoolingWaterFlow*Cp*60*1000)));
34
- ## Differential equation
35
- syms Tsub;
36
-
37
- F1 = @(t, Tsub) -UA * (CoolingFactor / 100) * ((Tcoolingin - (Tsub + (Tcoolingin - Tsub) / (exp(UA * (CoolingFactor / 100) * 1.8 * CalperBTU / (CoolingWaterFlow * Cp * 60 * 1000))))) / log((Tsub - (Tsub + (Tcoolingin - Tsub) / (exp(UA * (CoolingFactor / 100) * 1.8 * CalperBTU / (CoolingWaterFlow * Cp * 60 * 1000))))) / (Tsub - Tcoolingin))) * 1.8 * CalperBTU / (VL * Cp * 1000) + (VCD * 10^6 * VL * 3.7136 * exp(0.0652 * Tsub) / 10^9) * CalperhourperWatt / (VL * Cp * 1000);
38
-
39
- ## Change the time here
40
- t = 3;
41
- dt = 3/20;
42
-
43
- ## Solving the differential equations
44
- [tt, Sol] = ode45(F1, 0:dt:t, IC);
45
- labels = {"Time (hours)", "Temperature (°C)"};
46
- tempOnTime = [labels; num2cell([tt, Sol])];
47
- tempOnTime2 = tempOnTime;
48
- tempOnTime3 = tempOnTime;
49
- tempOnTime4 = tempOnTime;
50
- tempOnTime5 = tempOnTime;
51
-
52
- IC2 = IC
53
- IC3 = IC
package/scripts/default.m DELETED
@@ -1,39 +0,0 @@
1
- #name: Default simple script
2
- #description: Shows that default view works (or not)
3
- #language: octave
4
- #tags: bioreactor
5
- #input: double UA = 424.2832 {caption: UA; units: ft² * BTU / hr °F}
6
- #input: double CoolingWaterFlow = 12 {caption: Coolant flowrate; units: L/min}
7
- #input: double Tcoolingin = -2 {caption: Coolant temp.; units: °C}
8
- #input: double VCD = 5 {caption: Target VCD; units: cells/mL}
9
- #input: double VL = 210.5 {caption: Final Volume; units: L}
10
- #input: double IC = 31.1 {caption: Culture temp.; units: °C}
11
- #output: dataframe tempOnTime { viewer: Line chart(x: "Time (hours)", y: "Temperature (°C)", showSplitSelector: false); category: Cooling rate }
12
- #editor: Compute:FunctionViewEditor
13
-
14
- pkg load symbolic
15
-
16
- ## Conversion
17
- CalperBTU = 252;
18
- CalperhourperWatt = 3600/4.183076;
19
- Cp = 1;
20
- CoolingFactor = 56.5;
21
-
22
- ## Explicit Equation
23
- ##specificenthalpyreaction = 3.7136 * exp(0.0652*Tsub);
24
- ##Qrxn = VCD * 10^6 * VL * specificenthalpyofreaction/10^9;
25
- ##LMTD = (Tcoolingin-(Tsub + (Tcoolingin-Tsub)/(exp(UA*(CoolingFactor/100)*1.8*CalperBTU/(CoolingWaterFlow*Cp*60*1000)))))/log((Tsub-(Tsub + (Tcoolingin-Tsub)/(exp(UA*(CoolingFactor/100)*1.8*CalperBTU/(CoolingWaterFlow*Cp*60*1000)))))/(Tsub-Tcoolingin));
26
- ##Tcoolingout = Tsub + (Tcoolingin-Tsub)/(exp(UA*(CoolingFactor/100)*1.8*CalperBTU/(CoolingWaterFlow*Cp*60*1000)));
27
- ## Differential equation
28
- syms Tsub;
29
-
30
- F1 = @(t, Tsub) -UA * (CoolingFactor / 100) * ((Tcoolingin - (Tsub + (Tcoolingin - Tsub) / (exp(UA * (CoolingFactor / 100) * 1.8 * CalperBTU / (CoolingWaterFlow * Cp * 60 * 1000))))) / log((Tsub - (Tsub + (Tcoolingin - Tsub) / (exp(UA * (CoolingFactor / 100) * 1.8 * CalperBTU / (CoolingWaterFlow * Cp * 60 * 1000))))) / (Tsub - Tcoolingin))) * 1.8 * CalperBTU / (VL * Cp * 1000) + (VCD * 10^6 * VL * 3.7136 * exp(0.0652 * Tsub) / 10^9) * CalperhourperWatt / (VL * Cp * 1000);
31
-
32
- ## Change the time here
33
- t = 3;
34
- dt = 3/20;
35
-
36
- ## Solving the differential equations
37
- [tt, Sol] = ode45(F1, 0:dt:t, IC);
38
- labels = {"Time (hours)", "Temperature (°C)"};
39
- tempOnTime = [labels; num2cell([tt, Sol])];
@@ -1,162 +0,0 @@
1
- import * as grok from 'datagrok-api/grok';
2
- import * as rxjs from 'rxjs';
3
- import * as ui from 'datagrok-api/ui';
4
- import * as DG from 'datagrok-api/dg';
5
- import {DataFrame, FuncCall, FuncCallParam, Grid, TYPE} from 'datagrok-api/dg';
6
-
7
- /**
8
- * Base class for handling Compute models (see https://github.com/datagrok-ai/public/blob/master/help/compute/compute.md).
9
- * In most cases, the computation is a simple {@link Func}
10
- * Extend it in cases where a behavior or UI not supported by the {@link FunctionView} is needed.
11
- *
12
- * It provides the following functionality out-of-the-box, where each section could be customized:
13
- * - a structured way to represent input and output parameters: {@link parameters}
14
- * - generic way to generate UI for inputs, outputs, and interactivity (running the model, etc)
15
- * - persisting historical results to the db (via {@link parameters})
16
- * - export (to Excel and PDF): {@link export}
17
- * - easy loading of historical runs
18
- * - routing
19
- * - entering the real, measured (as opposed to predicted) values manually
20
- * - notifications for changing inputs, completion of computations, etc: {@link onInputChanged}
21
- * */
22
- export class ComputeView extends DG.ViewBase {
23
-
24
- func: DG.Func;
25
- call: DG.FuncCall; // what is being currently edited
26
- lastCall?: DG.FuncCall;
27
- _inputFields: Map<string, DG.InputBase> = new Map<string, DG.InputBase>();
28
- _inputBlock?: HTMLDivElement;
29
- _outputBlock?: HTMLDivElement;
30
-
31
- onViewInitialized: rxjs.Subject<void> = new rxjs.Subject();
32
- onInputChanged: rxjs.Subject<void> = new rxjs.Subject();
33
- onComputationStarted: rxjs.Subject<FuncCall> = new rxjs.Subject();
34
- onComputationCompleted: rxjs.Subject<FuncCall> = new rxjs.Subject();
35
- onComputationSucceeded: rxjs.Subject<FuncCall> = new rxjs.Subject();
36
- onComputationError: rxjs.Subject<FuncCall> = new rxjs.Subject();
37
-
38
- constructor(func: DG.Func) {
39
- super();
40
-
41
- this.func = func;
42
- this.name = func.friendlyName;
43
- this.call = func.prepare();
44
-
45
- this.initTopMenu();
46
- this.initRibbonPanels();
47
-
48
- this.init().then((_) => {
49
- this.root.appendChild(this.build());
50
- return this.onViewInitialized.next();
51
- });
52
- }
53
-
54
- /** All inputs that are bound to fields */
55
- get inputFields(): Map<string, DG.InputBase> { return this._inputFields; }
56
-
57
- /** Saves the computation results to the historical results, returns its id. See also {@link loadRun}. */
58
- async saveRun(call: FuncCall): Promise<string> { return 'xxx'; }
59
-
60
- /** Loads the specified historical results. See also {@link saveRun}. */
61
- async loadRun(runId: string): Promise<void> { }
62
-
63
- /** The actual computation function. */
64
- async compute(call: FuncCall): Promise<void> { await call.call(); }
65
-
66
- /** Maps inputs to parameters, computes, and maps output parameters to the UI. */
67
- async run(): Promise<void> {
68
- this.lastCall = this.call.clone();
69
- this.inputFieldsToParameters(this.lastCall);
70
-
71
- try {
72
- await this.compute(this.lastCall);
73
- }
74
- catch (e) {
75
- this.onComputationError.next(this.lastCall);
76
- }
77
-
78
- this.outputParametersToView(this.lastCall);
79
- }
80
-
81
- /** Override to provide custom initialization. {@link onViewInitialized} gets fired after that. */
82
- async init(): Promise<void> {}
83
-
84
- /** Override to customize top menu*/
85
- initTopMenu() {
86
- this.ribbonMenu = DG.Menu.create()
87
- .group(this.func.friendlyName)
88
- .item('Run', () => this.run());
89
- }
90
-
91
- /** Override to customize ribbon panels */
92
- initRibbonPanels() {
93
- this.setRibbonPanels([[
94
- ui.icons.play(() => this.run(), 'RUN'),
95
- ui.comboPopup(
96
- ui.icons.save(null, 'Export'),
97
- this.supportedExportFormats,
98
- async (format) => DG.Utils.download('output.csv', await this.export(format)),
99
- ),
100
- ]]);
101
- }
102
-
103
- /** Builds the complete view. Override it if completely custom implementation is needed,
104
- * otherwise consider overriding {@link buildInputBlock} and/or {@link buildOutputBlock} */
105
- build(): HTMLElement { return ui.splitH([this.buildInputBlock(), this.buildOutputBlock()]); }
106
-
107
- /** Override to build completely custom input block (the one with inputs, usually on the left).
108
- * If only specific field, consider overriding {@link buildCustomInputs}. */
109
- buildInputBlock(): HTMLElement {
110
- for (const p of this.func.inputs)
111
- this._inputFields.set(p.name, DG.InputBase.forProperty(p, this.call.dart));
112
-
113
- return this._inputBlock = ui.inputs(this._inputFields.values())
114
- }
115
-
116
- /** Custom inputs for the specified fields. Inputs for these fields will not be created by {@link buildInputBlock}. */
117
- buildCustomInputs(): Map<String, DG.InputBase> { return new Map(); }
118
-
119
- /** Override to create output block. */
120
- buildOutputBlock(): HTMLElement { return this._outputBlock = ui.div(); }
121
-
122
- /** Override to create a custom input control. */
123
- buildRibbonPanel(): HTMLElement { return ui.divH([
124
- ui.button('RUN', () => {}),
125
- ui.comboPopup('Export', this.supportedExportFormats, (format) => this.export(format))]);
126
- }
127
-
128
- /** Creates function parameters based on the data entered by the user. */
129
- inputFieldsToParameters(call: FuncCall): void { }
130
-
131
- /** Visualizes computation results. Requires _outputBlock. */
132
- outputParametersToView(call: FuncCall | null): void {
133
- ui.empty(this._outputBlock!);
134
-
135
- if (call == null)
136
- return;
137
-
138
- for (let p of this.func.outputs)
139
- this._outputBlock?.appendChild(this.renderOutputParameter(call, call?.outputParams[p.name]));
140
- }
141
-
142
- renderOutputParameter(call: FuncCall, param: FuncCallParam): HTMLElement {
143
- if (param.property.propertyType == TYPE.DATA_FRAME)
144
- return Grid.grid(call.outputParams[param.name]).root;
145
- else
146
- return ui.divText(`Unknown type: ${param.property.propertyType}`);
147
- }
148
-
149
- /** Override to provide custom computation error handling. */
150
- processComputationError(call: FuncCall) { grok.shell.error(call.errorMessage!); }
151
-
152
- /** Override to provide supported export formats.
153
- * These formats are available under the "Export" popup on the ribbon panel. */
154
- get supportedExportFormats(): string[] { return ['Excel', 'PDF', 'CSV']; }
155
-
156
- /** Override to provide custom export. */
157
- async export(format: string): Promise<Blob> {
158
- if (format == 'CSV')
159
- return new Blob([(this.lastCall?.getOutputParamValue() as DataFrame).toCsv()]);
160
- throw `Format "${format}" is not supported.`;
161
- }
162
- }
package/src/help.md DELETED
@@ -1,3 +0,0 @@
1
- # Vmax
2
-
3
- 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.
@@ -1,76 +0,0 @@
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
- import {_package} from './package';
5
- import {Property, PropertyOptions} from "datagrok-api/dg";
6
-
7
- /* eslint-disable */
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([]);
17
- let name = ui.stringInput('Name', '');
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);
29
-
30
- new DG.Wizard({ title: 'Onboard a model' })
31
- .page({
32
- caption: 'Details',
33
- root: ui.divV([
34
- name,
35
- type,
36
- modelPropertiesHost
37
- ]),
38
- validate: () => name.value !== '' ? null : 'Please provide a name'
39
- })
40
- .page({
41
- caption: 'Model Source',
42
- root: ui.divText('Second page') })
43
- .page({
44
- caption: 'Finalize',
45
- root: ui.divText('Finish') })
46
- .onOK(() => {})
47
- .show({width: 500, height: 300});
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
- ];
@@ -1,8 +0,0 @@
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
- import {ComputationView} from "@datagrok-libraries/utils/src/computation-view";
5
-
6
- export class ComputationTestView extends ComputationView {
7
-
8
- }
File without changes
File without changes
File without changes
File without changes