@datagrok/compute 0.7.3 → 0.9.1

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,18 +1,18 @@
1
1
  {
2
2
  "name": "@datagrok/compute",
3
3
  "friendlyName": "Compute",
4
- "version": "0.7.3",
5
- "description": "",
4
+ "version": "0.9.1",
5
+ "description": "Provides additional analytical and UI blocks for [Datagrok scientific computing](../../help/compute/compute.md)",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/datagrok-ai/public.git",
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": "^0.151.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
@@ -1,8 +1,9 @@
1
1
  #name: Fab Arm Exchange
2
2
  #language: python
3
- #tags: model, simulation
4
- #meta.modality: Antibody
5
- #meta.domain: Manufacturing
3
+ #tags: antibody-eng
4
+ #meta.department: BTDS
5
+ #meta.status: Upstream
6
+ #meta.group: Bioengineering process
6
7
  #input: double meaConcentration = 60 {category:FAE Reaction Parameters; units:mM; caption:2-MEA Concentration} [2-MEA Concentration]
7
8
  #input: double phOfFaeReaction = 7.5 {category:FAE Reaction Parameters; caption:pH of FAE Reaction} [pH of FAE Reaction]
8
9
  #input: double faeReactionTime = 3 {category:FAE Reaction Parameters; units:hr; caption:FAE Reaction Time} [FAE Reaction Time]
@@ -1,7 +1,6 @@
1
1
  //name: Heat Exchange
2
2
  //language: javascript
3
- //tags: model, simulation
4
- //meta.modality: Small molecule
3
+ //tags: simulation
5
4
  //input: int len = 1000
6
5
  //input: double k = 1.2
7
6
  //output: dataframe simulation {viewer: Line Chart(multiAxis: "true")}
@@ -9,6 +8,7 @@
9
8
  //output: double finalSaturation
10
9
  //output: double finalConcentration
11
10
  //meta.domain: Manufacturing
11
+ //meta.modality: Small molecule
12
12
 
13
13
  function sigmoid(z) {
14
14
  return 1 / (1 + Math.exp(-z));
@@ -1,7 +1,6 @@
1
1
  #name: IntervalsFromECG
2
2
  #description: Identify the beats in an ECG signal and compute the IBIs
3
3
  #language: python
4
- #tags: model
5
4
  #input: double samplingFrequency = 2048
6
5
  #input: int bpmMax = 120 [Maximal expected heart rate (in beats per minute): (1 < bpm_max <= 400)]
7
6
  #input: double delta = 0 [Threshold for the peak detection. By default it is computed from the signal (adaptive thresholding)]
@@ -1,5 +1,5 @@
1
1
  //name: Logistic Map
2
- //tags: model, simulation
2
+ //tags: simulation
3
3
  //description: Archetypal example of how complex, chaotic behaviour can arise from very simple non-linear dynamical equations.
4
4
  //language: javascript
5
5
  //input: int iterations = 1000 [Number of iterations per point]
@@ -1,5 +1,5 @@
1
1
  //name: Lorenz Attractor
2
- //tags: model, simulation
2
+ //tags: simulation
3
3
  //meta.domain: Nonlinear dynamics
4
4
  //description: Set of chaotic solutions of the system for weather prediction. It illustrates the phenomenon known as the Butterfly effect or (more technically) sensitive dependence on initial conditions
5
5
  //language: javascript
@@ -1,5 +1,5 @@
1
1
  //name: Lotka-Volterra
2
- //tags: model, simulation
2
+ //tags: simulation
3
3
  //meta.domain: Nonlinear dynamics
4
4
  //description: Model describes the dynamics of biological systems in which two species interact, one as a predator and the other as prey.
5
5
  //language: javascript
@@ -14,6 +14,7 @@
14
14
  //input: double timeStop = 18
15
15
  //output: dataframe df {viewer: Line Chart(x: "Time", multiAxis: "true", title: "Lotka-Volterra Model")}
16
16
 
17
+
17
18
  function sumArrays(...arrays) {
18
19
  return Array.from({ length: 2 })
19
20
  .map((_, i) => arrays
@@ -1,7 +1,6 @@
1
1
  #name: Vmax
2
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
3
  #language: r
4
- #tags: model
5
4
  #input: dataframe test_data {editor: Compute:manualOutlierSelectionDialog; editor-button: Outliers...}
6
5
  #input: double test_area = 3.5 {caption: Filter Area; units: cm²} [Filter area]
7
6
  #input: double vbatch = 25 {caption: VBatch; units: L} [Desired batch size to process]
@@ -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])];
package/scripts/pkpd.R CHANGED
@@ -12,7 +12,6 @@
12
12
  #input: double effect = 8 {category: PD parameters} [EC50]
13
13
  #output: graphics PKPD
14
14
  #output: double Cmax {units: nM}
15
- #tags: model
16
15
  #meta.domain: PKPD
17
16
 
18
17
  require("ggplot2")
package/scripts/popPK.R CHANGED
@@ -10,7 +10,6 @@
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
- #tags: model
14
13
  #meta.domain: PKPD
15
14
 
16
15
  require("ggplot2")
package/scripts/trig.js CHANGED
@@ -1,7 +1,6 @@
1
1
  //name: trig
2
2
  //description: Returns sin, cos, and tan
3
3
  //language: javascript
4
- //tags: model
5
4
  //input: double x
6
5
  //output: double sin
7
6
  //output: double cos
package/scripts/vmax.js CHANGED
@@ -1,7 +1,9 @@
1
1
  //name: Vmax
2
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
3
  //language: javascript
4
- //tags: model, filtration
4
+ //tags: filtration, scale-up
5
+ //meta.department: BTDS
6
+ //meta.status: Upstream
5
7
  //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")}
6
8
  //input: dataframe reportingParameters {caption: Reporting parameters; viewer: Grid()}
7
9
  //input: double testFilterArea = 3.5 {caption: Test filter area; units: cm²} [Test filter area]
@@ -16,7 +18,7 @@
16
18
  //output: dataframe recommendations {viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); caption: Recommendations; category: OUTPUT}
17
19
  //output: dataframe sampleCharacteristics {viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); caption: Sample characteristics; category: OUTPUT}
18
20
  //output: dataframe filter {viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); caption: Filter; category: OUTPUT}
19
-
21
+ //editor: Compute:ComputationView
20
22
  // inputTable = grok.shell.tables[0]; reportingParameters = grok.shell.tables[1];
21
23
  // testFilterArea = 3.5; desiredVolumeOfBatch = 25; desiredProcessTime = 0.5; sf = 1.5;
22
24
 
@@ -1,8 +1,8 @@
1
1
  //name: wrapper
2
2
  //language: javascript
3
3
  //output: view v
4
- //tags: model
5
4
  //meta.domain: math
5
+ //meta.direction: up
6
6
 
7
7
  v = grok.shell.newView('Wrapper', [ui.div(['hello world'])]);
8
8
  // here, launch the app
@@ -0,0 +1,94 @@
1
+ .model-catalog-view .d4-gallery-card.entity-model i {
2
+ height: 64px;
3
+ width: 64px;
4
+ position: initial;
5
+ flex-shrink: 0;
6
+ }
7
+
8
+ .model-catalog-view .d4-gallery-card.entity-model .d4-link-label i.grok-icon + label {
9
+ margin-left: 6px;
10
+ align-items: center;
11
+ display: inline-flex;
12
+ white-space: normal;
13
+ }
14
+
15
+ .model-catalog-view .d4-gallery-card.entity-model {
16
+ padding: 0 8px;
17
+ align-items: center;
18
+ display: flex;
19
+ margin: 0;
20
+ height: 94px;
21
+ }
22
+
23
+ .model-catalog-view .grok-gallery-grid[mode="Brief"] .grok-gallery-grid {
24
+ flex-direction: row!important;
25
+ }
26
+
27
+ .model-catalog-view .grok-gallery-grid[mode="Brief"] .d4-link-label i.grok-icon {
28
+ width: 32px;
29
+ height: 32px;
30
+ position: initial;
31
+ }
32
+
33
+ .model-catalog-view .grok-gallery-grid[mode="Brief"] .d4-link-label label {
34
+ margin-left: 8px;
35
+ }
36
+
37
+ .model-catalog-view .grok-gallery-grid[mode="Brief"] .grok-gallery-grid .d4-link-label {
38
+ min-width: 250px;
39
+ margin-bottom: 9px;
40
+ color: var(--grey-6);
41
+ padding: 10px;
42
+ width: initial;
43
+ }
44
+
45
+ .model-catalog-view .d4-tree-view-root > .d4-tree-view-group-host > .d4-tree-view-group > .d4-tree-view-node {
46
+ font-size: 20px;
47
+ padding: 4px 0;
48
+ color: var(--grey-6);
49
+ }
50
+
51
+ .model-catalog-view .d4-tree-view-root > .d4-tree-view-group-host > .d4-tree-view-group > .d4-tree-view-group-host > .d4-tree-view-group > .d4-tree-view-node {
52
+ font-size: 16px;
53
+ padding: 4px 0;
54
+ color: var(--grey-6);
55
+ }
56
+
57
+ .model-catalog-view .d4-tree-view-root > .d4-tree-view-group-host > .d4-tree-view-group > .d4-tree-view-group-host > .d4-tree-view-group > .d4-tree-view-group-host > .d4-tree-view-group .d4-tree-view-node {
58
+ font-size: 14px;
59
+ padding: 4px 0;
60
+ color: var(--grey-6);
61
+ }
62
+
63
+ .model-catalog-video {
64
+ width: 80%;
65
+ height: 0;
66
+ padding-bottom: 50%;
67
+ margin: 10px 10px 0 0;
68
+ border: 1px solid var(--grey-2);
69
+ position: relative;
70
+ background-size: cover;
71
+ background-repeat: no-repeat;
72
+ }
73
+
74
+ .model-catalog-video i {
75
+ position: absolute;
76
+ right: 0;
77
+ left: 0;
78
+ bottom: 0;
79
+ top: 0;
80
+ display: flex;
81
+ align-items: center;
82
+ justify-content: center;
83
+ font-weight: 600;
84
+ color: var(--grey-2);
85
+ font-size: 42px;
86
+ }
87
+
88
+ .model-catalog-video i:hover {
89
+ color: var(--grey-1);
90
+ }
91
+
92
+ .model-catalog-description {
93
+ padding: 10px 0 0 0;
94
+ }
@@ -3,43 +3,72 @@ 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() {
12
15
  super({dataSource: grok.dapi.functions, permanentFilter: '#model'});
13
16
 
17
+ this.root.classList.add('model-catalog-view');
14
18
  this.meta = new ModelHandler();
15
19
  this.name = 'Models';
16
20
  this.permanentFilter = '#model';
21
+ this.renderMode = DG.RENDER_MODE.BRIEF;
17
22
 
18
23
  this.objectType = 'Func';
19
24
  this.categoryFilters = {
20
- 'options.direction': 'Direction',
21
- 'tag': 'Tags',
22
- 'createdOn': 'Created',
23
- 'author.id': 'Author'
25
+ 'options.department': 'Department',
26
+ 'options.HL_process': 'HL_process',
27
+ 'options.process': 'Process',
28
+ 'tag': 'Tags'
29
+ };
30
+
31
+ this.filters = {
32
+ 'All': '',
33
+ 'Favorites': 'starredBy = @current',
34
+ 'Used by me': 'usedBy = @current'
24
35
  };
36
+
25
37
  this.hierarchy = [
26
- 'options.direction',
27
- 'options.domain'
38
+ 'options.department',
39
+ 'options.HL_process',
40
+ 'options.process'
28
41
  ];
42
+
43
+ this.hierarchyProperties = {
44
+ 'options.department': 'Department',
45
+ 'options.HL_process': 'HL_process',
46
+ 'options.process': 'Process'
47
+ };
48
+
29
49
  this.showTree = true;
30
50
  this.initRibbon();
31
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
+ }
32
62
  }
33
63
 
64
+ currentCall: DG.FuncCall;
65
+
34
66
  initRibbon() {
35
- this.setRibbonPanels([[ui.icons.add(() => onboardModel())]]);
67
+ this.setRibbonPanels([[ui.icons.sync(() => this.refresh())]]);
36
68
  }
37
69
 
38
70
  initMenu() {
39
71
  this.ribbonMenu
40
- .group('Models')
41
- .item('Add New...', () => onboardModel())
42
- .endGroup()
43
72
  .group('Help')
44
73
  .item('Compute Engine', () => window.open('https://github.com/datagrok-ai/public/tree/master/packages/Compute', '_blank'))
45
74
  .item('Developing Models', () => window.open('https://datagrok.ai/help/compute/scripting', '_blank'))
@@ -1,9 +1,8 @@
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 wu from "wu";
4
5
  import {ModelCatalogView} from "./model-catalog-view";
5
- import {TYPE} from "datagrok-api/dg";
6
- import {FunctionView} from '@datagrok-libraries/utils/src/function-view';
7
6
 
8
7
  export class ModelHandler extends DG.ObjectHandler {
9
8
  get type() {
@@ -11,14 +10,11 @@ export class ModelHandler extends DG.ObjectHandler {
11
10
  }
12
11
 
13
12
  async getById(id: string): Promise<DG.Func> {
14
- console.log('id:', id);
15
13
  return await grok.dapi.functions.find(id);
16
14
  }
17
15
 
18
16
  async refresh(x: DG.Script): Promise<DG.Func> {
19
- let script = await this.getById(x.id);
20
- console.log('script:', script);
21
- return script;
17
+ return await this.getById(x.id);
22
18
  }
23
19
 
24
20
  getLanguageIcon(language: string) {
@@ -32,58 +28,154 @@ export class ModelHandler extends DG.ObjectHandler {
32
28
  return x instanceof DG.Func && x.hasTag('model');
33
29
  }
34
30
 
31
+ getVideoBackgroundUrl(x: DG.Func): string {
32
+ let url = x.options['video-preview'];
33
+ if (url == null)
34
+ return '';
35
+ if (url.startsWith('http://') || url.startsWith('https://'))
36
+ return url;
37
+ if (x instanceof DG.Script) {
38
+ if (x.options['icon'] != null) {
39
+ let iconPath = x.options['icon'].substring(0, x.options['icon'].lastIndexOf('/'));
40
+ return `${iconPath}/${url}`;
41
+ }
42
+ return '';
43
+ }
44
+ let iconPath = x.package.getIconUrl();
45
+ iconPath = iconPath.substring(0, iconPath.lastIndexOf('/'));
46
+ return `${iconPath}/${url}`;
47
+ }
48
+
35
49
  renderIcon(x: DG.Func, context: any = null): HTMLElement {
36
- return x instanceof DG.Script ? this.getLanguageIcon(x.language) : ui.iconImage(x.package.name, x.package.getIconUrl());
50
+ if (x.options['icon'] != null && (x.options['icon'].startsWith('http://') || x.options['icon'].startsWith('https://'))) {
51
+ return ui.iconImage('model-icon', x.options['icon']);
52
+ }
53
+ if (x instanceof DG.Script) {
54
+ return this.getLanguageIcon(x.language);
55
+ }
56
+ let iconUrl = x.package.getIconUrl();
57
+ if (x.options['icon'] != null) {
58
+ let packagePathSegments = iconUrl.split('/');
59
+ packagePathSegments.pop();
60
+ packagePathSegments.push(x.options['icon']);
61
+ iconUrl = packagePathSegments.join('/')
62
+ }
63
+ return ui.iconImage(x.package.name, iconUrl);
37
64
  }
38
65
 
39
66
  renderMarkup(x: DG.Func): HTMLElement {
40
- return ui.span([this.renderIcon(x), ui.label(x.friendlyName)]);
67
+ let markup = ui.span([this.renderIcon(x), ui.label(x.friendlyName)]);
68
+ let c = grok.functions.getCurrentCall();
69
+ markup.ondblclick = (e) => {
70
+ ModelHandler.openModel(x, c); }
71
+ return markup;
41
72
  }
42
73
 
43
74
  renderProperties(x: DG.Func) {
44
75
  const a = ui.accordion('ComputeModel');
45
76
  a.context = x;
46
- a.addTitle(ui.span([this.renderIcon(x), ui.label(x.friendlyName), ui.contextActions(x), ui.star(x.id)]));
47
- a.addPane('Details', () => {
48
- return this.renderDetails(x);
49
- });
50
- a.addCountPane('Usage', () => {
51
- return ui.span(['Usage statistics']);
52
- }, () => 99);
77
+ let titleDiv = ui.div([
78
+ ui.span([this.renderIcon(x), ui.label(x.friendlyName), ui.contextActions(x), ui.star(x.id)])]);
79
+ a.addTitle(titleDiv);
80
+
81
+ if (x.description != null)
82
+ titleDiv.appendChild(ui.div([ui.markdown(x.description)], 'model-catalog-description'));
83
+ titleDiv.appendChild(ui.tags(x));
84
+ if ( x.options['dev.status'] != null)
85
+ titleDiv.appendChild(ui.tableFromMap({Status: x.options['dev.status']}));
86
+
87
+ if (x.options['video'] != null || x.options['education'] != null) {
88
+ let educationLink = ui.link('Education materials', x.options['education']);
89
+ ui.setDisplay(educationLink, x.options['education'] != null);
90
+ let video = ui.div(ui.icons.play(() => {window.open(x.options['video'], '_blank')}), 'model-catalog-video');
91
+ ui.setDisplay(video, x.options['video'] != null);
92
+ video.style.backgroundImage = `url('${this.getVideoBackgroundUrl(x)}')`;
93
+
94
+ a.addPane('Documentation', () => {
95
+ return ui.divV([
96
+ educationLink,
97
+ video], {style: {lineHeight: '150%'}});
98
+ }, true);
99
+ }
53
100
  a.end();
54
101
  return a.root;
55
102
  }
56
103
 
57
104
  renderDetails(x: DG.Func) {
58
- return ui.divV([ui.render(x.author), ui.render(x.createdOn)], {style: {lineHeight: '150%'}});
105
+ let status = ui.markdown(`**Status:** ${x.options['dev.status']}`);
106
+ ui.setDisplay(status, x.options['dev.status'] != null);
107
+ return ui.divV([
108
+ ui.markdown(`**Description: ** ${x.description}`),
109
+ status,
110
+ ui.markdown('**Tags:**'),
111
+ ui.tags(x),
112
+ ui.markdown('**Documentation:**'),
113
+ ], {style: {lineHeight: '150%'}});
59
114
  }
60
115
 
61
116
  renderTooltip(x: DG.Func) {
62
- return ui.divText(`${x.friendlyName}`);
63
- }
64
-
65
- renderCard(x: DG.Func, context?: any): HTMLElement {
66
117
  let h = this.renderMarkup(x);
67
118
  h.classList.add('d4-link-label');
68
119
  let card = ui.bind(x, ui.divV([
69
120
  ui.h2(h),
70
- ui.divText(x.description, 'ui-description'),
71
- this.renderDetails(x),
121
+ ui.divV([ui.divText(x.description, 'ui-description')], {style: {lineHeight: '150%'}})
72
122
  ]));
73
123
  let c = grok.functions.getCurrentCall();
74
- card.ondblclick = (e) => {
75
- ModelHandler.openModel(x, c);
76
- }
124
+ card.ondblclick = (e) => { ModelHandler.openModel(x, c); }
77
125
  return card;
78
126
  }
79
127
 
128
+ renderCard(x: DG.Func, context?: any): HTMLElement {
129
+ let h = this.renderMarkup(x);
130
+ h.classList.add('d4-link-label');
131
+ let card = ui.bind(x, ui.h2(h));
132
+ let c = grok.functions.getCurrentCall();
133
+ card.ondblclick = (e) => { ModelHandler.openModel(x, c); }
134
+ return card;
135
+ }
136
+
137
+ static getModelCatalogView(): ModelCatalogView {
138
+ let modelsView = this.findModelCatalogView();
139
+ if (modelsView == null) {
140
+ let mc: DG.Func = DG.Func.find({package:'Compute', name: 'ModelCatalog'})[0];
141
+ let fc = mc.prepare();
142
+ let view = new ModelCatalogView();
143
+ view.name = 'Models';
144
+ view.parentCall = fc;
145
+ grok.shell.addView(view);
146
+ }
147
+ modelsView = this.findModelCatalogView();
148
+ return modelsView as ModelCatalogView;
149
+ }
150
+
151
+ static findModelCatalogView(): ModelCatalogView | undefined {
152
+ return wu(grok.shell.views).find((v) => v.parentCall?.func.name == 'modelCatalog') as ModelCatalogView;
153
+ }
154
+
80
155
  static openModel(x: DG.Func, parentCall?: DG.FuncCall) {
81
156
  let fc = x.prepare();
82
- if (parentCall != null)
83
- fc.parentCall = parentCall;
84
157
  fc.edit();
85
158
  }
86
159
 
160
+ static bindModel(fc: DG.FuncCall) {
161
+ let modelsView = ModelHandler.getModelCatalogView();
162
+ fc.aux['showOnTaskBar'] = false;
163
+ if (modelsView != null) {
164
+ let parentCall = modelsView.parentCall;
165
+ if (parentCall != null) {
166
+ parentCall.aux['view'] = modelsView;
167
+ fc.parentCall = parentCall;
168
+ }
169
+ }
170
+ }
171
+
87
172
  init() {
173
+ setTimeout(() => {
174
+ grok.functions.onBeforeRunAction.subscribe((fc) => {
175
+ if (fc.func.hasTag('model') || fc.func.hasTag('model-editor')) {
176
+ ModelHandler.bindModel(fc);
177
+ }
178
+ });
179
+ });
88
180
  }
89
181
  }