@datagrok/compute 0.9.2 → 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.
@@ -1,28 +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 AA = 424.2832 {caption: AA; units: ft² * BTU / hr °F}
7
- #input: double FWC = 12 {caption: Bblabla flowrate; units: L/min}
8
- #input: double Dummy scalar = -2 {caption: Dummy scalar.; units: °C}
9
- #input: double VCD = 5 {caption: VCD; units: cells/mL}
10
- #input: double VL = 210.5 {caption: Final Volume; units: L}
11
- #input: double IC = 31.1 {caption: 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
- tempOnTime = test;
22
- tempOnTime2 = tempOnTime;
23
- tempOnTime3 = tempOnTime;
24
- tempOnTime4 = tempOnTime;
25
- tempOnTime5 = tempOnTime;
26
-
27
- IC2 = IC
28
- IC3 = IC
package/scripts/default.m DELETED
@@ -1,18 +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 AA = 424.2832 {caption: AA; units: ft² * BTU / hr °F}
6
- #input: double FWC = 12 {caption:FWC; 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: 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
- tt = zeros(10, 1)
15
- Sol = ones(10, 1)
16
-
17
- labels = {"Time (hours)", "Temperature (°C)"};
18
- 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
- }