@datagrok/compute 0.8.3 → 0.9.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": "0.8.3",
4
+ "version": "0.9.0",
5
5
  "description": "Provides additional analytical and UI blocks for [Datagrok scientific computing](../../help/compute/compute.md)",
6
6
  "repository": {
7
7
  "type": "git",
@@ -9,10 +9,10 @@
9
9
  "directory": "packages/Compute"
10
10
  },
11
11
  "dependencies": {
12
- "@datagrok-libraries/utils": "^0.4.0",
12
+ "@datagrok-libraries/utils": "^0.5.0",
13
13
  "cash-dom": "latest",
14
14
  "codemirror": "^5.64.0",
15
- "datagrok-api": "^1.0.0",
15
+ "datagrok-api": "^1.4.4",
16
16
  "dayjs": "latest",
17
17
  "exceljs": "^4.3.0",
18
18
  "file-saver": "^2.0.5",
@@ -57,5 +57,6 @@
57
57
  ],
58
58
  "canView": [
59
59
  "All users"
60
- ]
60
+ ],
61
+ "category": "Machine Learning"
61
62
  }
package/package.png CHANGED
Binary file
@@ -0,0 +1,53 @@
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
@@ -0,0 +1,39 @@
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])];
@@ -3,9 +3,12 @@ import * as ui from 'datagrok-api/ui';
3
3
  import * as DG from 'datagrok-api/dg';
4
4
  import {ModelHandler} from './model-handler';
5
5
  import {onboardModel} from './onboard-model';
6
+ import {Subscription} from "rxjs";
6
7
 
7
8
  /* eslint-disable */
8
9
 
10
+ let propsSub: Subscription;
11
+
9
12
  export class ModelCatalogView extends DG.CustomCardView {
10
13
 
11
14
  constructor() {
@@ -30,16 +33,36 @@ export class ModelCatalogView extends DG.CustomCardView {
30
33
  'Favorites': 'starredBy = @current',
31
34
  'Used by me': 'usedBy = @current'
32
35
  };
36
+
33
37
  this.hierarchy = [
34
38
  'options.department',
35
39
  'options.group',
36
40
  'options.process'
37
41
  ];
42
+
43
+ this.hierarchyProperties = {
44
+ 'options.department': 'Department',
45
+ 'options.group': 'Group',
46
+ 'options.process': 'Process'
47
+ };
48
+
38
49
  this.showTree = true;
39
50
  this.initRibbon();
40
51
  this.initMenu();
52
+ this.currentCall = grok.functions.getCurrentCall();
53
+ if (propsSub == null && window.localStorage.getItem('ModelCatalogShowProperties') == null) { // @ts-ignore
54
+ propsSub = grok.events.onCurrentObjectChanged.subscribe((o) => {
55
+ if (new ModelHandler().isApplicable(o.sender)) {
56
+ grok.shell.windows.showProperties = true;
57
+ window.localStorage.setItem('ModelCatalogShowProperties', 'false');
58
+ propsSub.unsubscribe();
59
+ }
60
+ })
61
+ }
41
62
  }
42
63
 
64
+ currentCall: DG.FuncCall;
65
+
43
66
  initRibbon() {
44
67
  this.setRibbonPanels([[ui.icons.sync(() => this.refresh())]]);
45
68
  }
@@ -2,6 +2,7 @@ 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 wu from "wu";
5
+ import {ModelCatalogView} from "./model-catalog-view";
5
6
 
6
7
  export class ModelHandler extends DG.ObjectHandler {
7
8
  get type() {
@@ -28,8 +29,12 @@ export class ModelHandler extends DG.ObjectHandler {
28
29
  }
29
30
 
30
31
  renderIcon(x: DG.Func, context: any = null): HTMLElement {
31
- if (x instanceof DG.Script)
32
+ if (x.options['icon'] != null && (x.options['icon'].startsWith('http://') || x.options['icon'].startsWith('https://'))) {
33
+ return ui.iconImage('model-icon', x.options['icon']);
34
+ }
35
+ if (x instanceof DG.Script) {
32
36
  return this.getLanguageIcon(x.language);
37
+ }
33
38
  let iconUrl = x.package.getIconUrl();
34
39
  if (x.options['icon'] != null) {
35
40
  let packagePathSegments = iconUrl.split('/');
@@ -60,7 +65,19 @@ export class ModelHandler extends DG.ObjectHandler {
60
65
  }
61
66
 
62
67
  renderDetails(x: DG.Func) {
63
- return ui.divV([ui.markdown(x.description), ui.span([ui.render(x.author), ' created ', ui.render(x.createdOn)])], {style: {lineHeight: '150%'}});
68
+ let educationLink = ui.link('Education materials', x.options['education']);
69
+ ui.setDisplay(educationLink, x.options['education'] != null);
70
+ let video = ui.link('Video', x.options['video']);
71
+ ui.setDisplay(video, x.options['video'] != null);
72
+ let status = ui.markdown(`Status: ${x.options['dev.status']}`);
73
+ ui.setDisplay(status, x.options['dev.status'] != null);
74
+ return ui.divV([
75
+ status,
76
+ ui.markdown(x.description),
77
+ ui.tags(x),
78
+ educationLink,
79
+ video
80
+ ], {style: {lineHeight: '150%'}});
64
81
  }
65
82
 
66
83
  renderTooltip(x: DG.Func) {
@@ -84,16 +101,48 @@ export class ModelHandler extends DG.ObjectHandler {
84
101
  return card;
85
102
  }
86
103
 
104
+ static getModelCatalogView(): ModelCatalogView {
105
+ let modelsView = this.findModelCatalogView();
106
+ if (modelsView == null) {
107
+ let mc: DG.Func = DG.Func.find({package:'Compute', name: 'ModelCatalog'})[0];
108
+ let fc = mc.prepare();
109
+ let view = new ModelCatalogView();
110
+ view.name = 'Models';
111
+ view.parentCall = fc;
112
+ grok.shell.addView(view);
113
+ }
114
+ modelsView = this.findModelCatalogView();
115
+ return modelsView as ModelCatalogView;
116
+ }
117
+
118
+ static findModelCatalogView(): ModelCatalogView | undefined {
119
+ return wu(grok.shell.views).find((v) => v.parentCall?.func.name == 'modelCatalog') as ModelCatalogView;
120
+ }
121
+
87
122
  static openModel(x: DG.Func, parentCall?: DG.FuncCall) {
88
123
  let fc = x.prepare();
89
- if (parentCall != null) {
90
- let modelsView = wu(grok.shell.views).find((v) => v.parentCall?.func.name == 'modelCatalog');
91
- parentCall.aux['view'] = modelsView;
92
- fc.parentCall = parentCall;
93
- }
94
124
  fc.edit();
95
125
  }
96
126
 
127
+ static bindModel(fc: DG.FuncCall) {
128
+ let modelsView = ModelHandler.getModelCatalogView();
129
+ fc.aux['showOnTaskBar'] = false;
130
+ if (modelsView != null) {
131
+ let parentCall = modelsView.parentCall;
132
+ if (parentCall != null) {
133
+ parentCall.aux['view'] = modelsView;
134
+ fc.parentCall = parentCall;
135
+ }
136
+ }
137
+ }
138
+
97
139
  init() {
140
+ setTimeout(() => {
141
+ grok.functions.onBeforeRunAction.subscribe((fc) => {
142
+ if (fc.func.hasTag('model') || fc.func.hasTag('model-editor')) {
143
+ ModelHandler.bindModel(fc);
144
+ }
145
+ });
146
+ });
98
147
  }
99
148
  }
package/src/package.ts CHANGED
@@ -8,9 +8,9 @@ import {ModelCatalogView} from './model-catalog-view';
8
8
  import wu from 'wu';
9
9
  import {OutliersSelectionViewer} from './outliers-selection/outliers-selection-viewer';
10
10
  //import {ModelsWidget} from './models-widget'
11
- import {FunctionView} from "@datagrok-libraries/utils/src/function-view";
12
11
  import {delay} from "@datagrok-libraries/utils/src/test";
13
12
  import {ComputationView} from "@datagrok-libraries/utils/src/computation-view";
13
+ import {FunctionView} from "@datagrok-libraries/utils/src/function-view";
14
14
  import './css/model-card.css';
15
15
 
16
16
  let initCompleted: boolean = false;
@@ -24,13 +24,25 @@ export function OutliersSelection() {
24
24
  return new OutliersSelectionViewer();
25
25
  }
26
26
 
27
- //name: ComputationViewTest
28
- //description: Creates an outliers selection viewer
29
- //tags: viewer
27
+ //name: ComputationView
28
+ //tags: model-editor, editor
29
+ //input: funccall call
30
+ //output: view result
31
+ // export function ComputationViewEditor(call: DG.FuncCall) {
32
+ // let v = new ComputationView(call);
33
+ // v.parentCall = call;
34
+ // v.name = call.func.friendlyName;
35
+ // v.parentView = grok.functions.getCurrentCall().parentCall.aux['view']; // modelCatalog view
36
+ // //todo: parse url, set parameters to call
37
+ // return v;
38
+ // }
39
+
40
+ //name: FunctionView
41
+ //tags: model-editor, editor
30
42
  //input: funccall call
31
43
  //output: view result
32
- export function ComputationViewTest(call: DG.FuncCall) {
33
- // return new ComputationView(call.func);
44
+ export function FunctionViewEditor(call: DG.FuncCall) {
45
+ return new FunctionView(call);
34
46
  }
35
47
 
36
48
 
@@ -48,14 +60,13 @@ export function modelsWidget(): DG.Widget {
48
60
  //output: view result
49
61
  export function functionParametersGrid(f: DG.Func): DG.View {
50
62
  return _functionParametersGrid(f);
51
- document.getElementById('root')?.appendChild(ui.h1('Hello World'));
52
63
  }
53
64
 
54
65
  //name: hof
55
- //tags: sidebar
56
66
  //description: some description
67
+ //sidebar: @compute
57
68
  export function hof() {
58
- grok.shell.info('hof');
69
+ console.log('hof');
59
70
  let f: DG.Func = DG.Func.byName('Sin');
60
71
  let v: DG.View = functionParametersGrid(f);
61
72
  v.parentCall = grok.functions.getCurrentCall();
@@ -65,14 +76,34 @@ export function hof() {
65
76
 
66
77
 
67
78
  //name: hof2
79
+ //tags:
68
80
  //description: some description 2 2 2
81
+ //sidebar: @compute
82
+ //meta.icon: package1.png
69
83
  export function hof2() {
70
- grok.shell.info('hof2');
84
+ console.log('hof2');
85
+
71
86
  let f: DG.Func = DG.Func.byName('Sin');
72
87
  let v: DG.View = functionParametersGrid(f);
73
- v.parentCall = grok.functions.getCurrentCall().parentCall;
74
- v.parentView = v.parentCall?.aux['view'];
75
- v.path = 'hof';
88
+
89
+ v.root.appendChild(ui.narrowForm([
90
+ ui.switchInput('test', true),
91
+ ui.boolInput('test', true)]));
92
+ v.root.appendChild(ui.form([
93
+ ui.switchInput('test', true),
94
+ ui.boolInput('test', true)]));
95
+ v.parentCall = grok.functions.getCurrentCall(); // hof2 call itself
96
+ v.parentView = v.parentCall.parentCall?.aux['view']; // modelCatalog view
97
+ let path = v.parentCall.parentCall?.aux['url']; // uri if called from model catalog
98
+ // grok.shell.info(path);
99
+
100
+
101
+ let path2 = v.parentCall?.aux['url']; // uri if called directly (if app)
102
+ // grok.shell.info(path2);
103
+
104
+ v.basePath = '/' + v.parentCall.func.name;
105
+ v.path = '/';
106
+
76
107
  grok.shell.addView(v);
77
108
  }
78
109
 
@@ -116,7 +147,14 @@ function getCookie(name: string): string | undefined{
116
147
  return matches ? decodeURIComponent(matches[1]) : undefined;
117
148
  }
118
149
 
119
- //tags: init, autostart
150
+
151
+ //tags: autostart
152
+ //meta.autostartImmediate: true
153
+ export function autostart() {
154
+
155
+ }
156
+
157
+ //tags: init
120
158
  export function init() {
121
159
  if (initCompleted)
122
160
  return;
@@ -132,7 +170,7 @@ export function init() {
132
170
  if (!restPane)
133
171
  acc.addPane('REST', () => ui.wait(async () => (await renderRestPanel(ent)).root));
134
172
  });
135
-
173
+ /*
136
174
  let modelsList = ui.waitBox(async () => {
137
175
  let models = await grok.dapi.scripts
138
176
  .filter('#model')
@@ -155,17 +193,6 @@ export function init() {
155
193
  'LIST': list,
156
194
  'TREE': tree
157
195
  }).root;
158
- });
159
-
160
- /* grok.events.onViewAdding.subscribe((v: DG.ViewBase) => {
161
- if (v instanceof ComputationView && (v as ComputationView).func?.hasTag("model")) {
162
- let modelsView = wu(grok.shell.views).find((v) => v.parentCall?.func.name == 'modelCatalog');
163
- if (modelsView != undefined) {
164
- v.parentCall = modelsView!.parentCall;
165
- v.parentView = modelsView!;
166
- v.toolbox = modelsList;
167
- }
168
- }
169
196
  });*/
170
197
 
171
198
  initCompleted = true;
@@ -173,11 +200,26 @@ export function init() {
173
200
 
174
201
  //name: Model Catalog
175
202
  //tags: app
176
- export function modelCatalog() {
177
- let view = new ModelCatalogView();
178
- view.name = 'Models';
179
- grok.shell.addView(view);
180
- }
203
+ //sidebar: @compute
204
+ export function modelCatalog() {
205
+ let modelsView = ModelHandler.findModelCatalogView();
206
+ if (modelsView == null) {
207
+ let view = new ModelCatalogView();
208
+ view.name = 'Models';
209
+ let parser = document.createElement('a');
210
+ parser.href = window.location.href;
211
+ let pathSegments = parser.pathname.split('/');
212
+ grok.shell.addView(view);
213
+ // console.log(parser.href);
214
+ if (pathSegments.length > 3) {
215
+ let c = grok.functions.getCurrentCall();
216
+ grok.dapi.functions.filter(`shortName = "${pathSegments[3]}" and #model`).list().then((lst) => {
217
+ if (lst.length == 1)
218
+ ModelHandler.openModel(lst[0], c);
219
+ });
220
+ }
221
+ } else grok.shell.v = modelsView;
222
+ }
181
223
 
182
224
 
183
225
  //name: computationTest