|
1 | 1 | import { UNIT_TYPES } from "../enums";
|
2 | 2 |
|
3 |
| -export const ConvergenceMixin = (superclass) => |
4 |
| - class extends superclass { |
5 |
| - addConvergence({ |
6 |
| - parameter, |
7 |
| - parameterInitial, |
8 |
| - result, |
9 |
| - resultInitial, |
10 |
| - condition, |
11 |
| - operator, |
12 |
| - tolerance, |
13 |
| - maxOccurrences, |
14 |
| - }) { |
15 |
| - // RF: added TODO comments for future improvements |
| 3 | +export const ConvergenceMixin = (superclass) => class extends superclass { |
| 4 | + addConvergence({ |
| 5 | + parameter, |
| 6 | + parameterInitial, |
| 7 | + result, |
| 8 | + resultInitial, |
| 9 | + condition, |
| 10 | + operator, |
| 11 | + tolerance, |
| 12 | + maxOccurrences, |
| 13 | + }) { |
| 14 | + // RF: added TODO comments for future improvements |
16 | 15 |
|
17 |
| - const { units } = this; |
18 |
| - // Find unit to converge: should contain passed result in its results list |
19 |
| - // TODO: make user to select unit for convergence explicitly |
20 |
| - const unitForConvergence = units.find((x) => |
21 |
| - x.resultNames.find((name) => name === result), |
22 |
| - ); |
| 16 | + const { units } = this; |
| 17 | + // Find unit to converge: should contain passed result in its results list |
| 18 | + // TODO: make user to select unit for convergence explicitly |
| 19 | + const unitForConvergence = units.find((x) => x.resultNames.find((name) => name === result)); |
23 | 20 |
|
24 |
| - if (!unitForConvergence) { |
25 |
| - // eslint-disable-next-line no-undef |
26 |
| - sAlert.error( |
| 21 | + if (!unitForConvergence) { |
| 22 | + // eslint-disable-next-line no-undef |
| 23 | + sAlert.error( |
27 | 24 | `Subworkflow does not contain unit with '${result}' as extracted property.`,
|
28 |
| - ); |
29 |
| - throw new Error("There is no result to converge"); |
30 |
| - } |
| 25 | + ); |
| 26 | + throw new Error("There is no result to converge"); |
| 27 | + } |
31 | 28 |
|
32 |
| - // Replace kgrid to be ready for convergence |
33 |
| - // TODO: kgrid should be abstracted and selected by user |
34 |
| - unitForConvergence.updateContext({ |
35 |
| - kgrid: { |
36 |
| - dimensions: [`{{${parameter}}}`, `{{${parameter}}}`, `{{${parameter}}}`], |
37 |
| - shifts: [0, 0, 0], |
38 |
| - }, |
39 |
| - isKgridEdited: true, |
40 |
| - isUsingJinjaVariables: true, |
41 |
| - }); |
| 29 | + // Replace kgrid to be ready for convergence |
| 30 | + // TODO: kgrid should be abstracted and selected by user |
| 31 | + unitForConvergence.updateContext({ |
| 32 | + kgrid: { |
| 33 | + dimensions: [`{{${parameter}}}`, `{{${parameter}}}`, `{{${parameter}}}`], |
| 34 | + shifts: [0, 0, 0], |
| 35 | + }, |
| 36 | + isKgridEdited: true, |
| 37 | + isUsingJinjaVariables: true, |
| 38 | + }); |
42 | 39 |
|
43 |
| - const prevResult = "prev_result"; |
| 40 | + const prevResult = "prev_result"; |
44 | 41 |
|
45 |
| - // Assignment with result's initial value |
46 |
| - const prevResultInit = this._UnitFactory.create({ |
47 |
| - type: UNIT_TYPES.assignment, |
48 |
| - head: true, |
49 |
| - operand: prevResult, |
50 |
| - value: resultInitial, |
51 |
| - }); |
| 42 | + // Assignment with result's initial value |
| 43 | + const prevResultInit = this._UnitFactory.create({ |
| 44 | + type: UNIT_TYPES.assignment, |
| 45 | + head: true, |
| 46 | + operand: prevResult, |
| 47 | + value: resultInitial, |
| 48 | + }); |
52 | 49 |
|
53 |
| - // Assignment with initial value of convergence parameter |
54 |
| - const paramInit = this._UnitFactory.create({ |
55 |
| - type: UNIT_TYPES.assignment, |
56 |
| - operand: parameter, |
57 |
| - value: parameterInitial, |
58 |
| - }); |
| 50 | + // Assignment with initial value of convergence parameter |
| 51 | + const paramInit = this._UnitFactory.create({ |
| 52 | + type: UNIT_TYPES.assignment, |
| 53 | + operand: parameter, |
| 54 | + value: parameterInitial, |
| 55 | + }); |
59 | 56 |
|
60 |
| - // Assignment for storing iteration result: extracts 'result' from convergence unit scope |
61 |
| - const storePrevResult = this._UnitFactory.create({ |
62 |
| - type: UNIT_TYPES.assignment, |
63 |
| - input: [ |
64 |
| - { |
65 |
| - scope: unitForConvergence.flowchartId, |
66 |
| - name: result, |
67 |
| - }, |
68 |
| - ], |
69 |
| - operand: prevResult, |
70 |
| - value: result, |
71 |
| - }); |
| 57 | + // Assignment for storing iteration result: extracts 'result' from convergence unit scope |
| 58 | + const storePrevResult = this._UnitFactory.create({ |
| 59 | + type: UNIT_TYPES.assignment, |
| 60 | + input: [ |
| 61 | + { |
| 62 | + scope: unitForConvergence.flowchartId, |
| 63 | + name: result, |
| 64 | + }, |
| 65 | + ], |
| 66 | + operand: prevResult, |
| 67 | + value: result, |
| 68 | + }); |
72 | 69 |
|
73 |
| - // Assignment for convergence param increase |
74 |
| - const nextStep = this._UnitFactory.create({ |
75 |
| - type: UNIT_TYPES.assignment, |
76 |
| - input: [], |
77 |
| - operand: parameter, |
78 |
| - value: `${parameter} + 1`, |
79 |
| - next: unitForConvergence.flowchartId, |
80 |
| - }); |
| 70 | + // Assignment for convergence param increase |
| 71 | + const nextStep = this._UnitFactory.create({ |
| 72 | + type: UNIT_TYPES.assignment, |
| 73 | + input: [], |
| 74 | + operand: parameter, |
| 75 | + value: `${parameter} + 1`, |
| 76 | + next: unitForConvergence.flowchartId, |
| 77 | + }); |
81 | 78 |
|
82 |
| - // Final step of convergence |
83 |
| - const exit = this._UnitFactory.create({ |
84 |
| - type: UNIT_TYPES.assignment, |
85 |
| - name: "exit", |
86 |
| - input: [], |
87 |
| - operand: parameter, |
88 |
| - value: `${parameter} + 0`, |
89 |
| - }); |
| 79 | + // Final step of convergence |
| 80 | + const exit = this._UnitFactory.create({ |
| 81 | + type: UNIT_TYPES.assignment, |
| 82 | + name: "exit", |
| 83 | + input: [], |
| 84 | + operand: parameter, |
| 85 | + value: `${parameter} + 0`, |
| 86 | + }); |
90 | 87 |
|
91 |
| - // Final step of convergence |
92 |
| - const storeResult = this._UnitFactory.create({ |
93 |
| - type: UNIT_TYPES.assignment, |
94 |
| - input: [ |
95 |
| - { |
96 |
| - scope: unitForConvergence.flowchartId, |
97 |
| - name: result, |
98 |
| - }, |
99 |
| - ], |
100 |
| - operand: result, |
101 |
| - value: result, |
102 |
| - }); |
| 88 | + // Final step of convergence |
| 89 | + const storeResult = this._UnitFactory.create({ |
| 90 | + type: UNIT_TYPES.assignment, |
| 91 | + input: [ |
| 92 | + { |
| 93 | + scope: unitForConvergence.flowchartId, |
| 94 | + name: result, |
| 95 | + }, |
| 96 | + ], |
| 97 | + operand: result, |
| 98 | + value: result, |
| 99 | + }); |
103 | 100 |
|
104 |
| - // Convergence condition unit |
105 |
| - const conditionUnit = this._UnitFactory.create({ |
106 |
| - type: UNIT_TYPES.condition, |
107 |
| - statement: `${condition} ${operator} ${tolerance}`, |
108 |
| - then: exit.flowchartId, |
109 |
| - else: storePrevResult.flowchartId, |
110 |
| - maxOccurrences, |
111 |
| - next: storePrevResult.flowchartId, |
112 |
| - }); |
| 101 | + // Convergence condition unit |
| 102 | + const conditionUnit = this._UnitFactory.create({ |
| 103 | + type: UNIT_TYPES.condition, |
| 104 | + statement: `${condition} ${operator} ${tolerance}`, |
| 105 | + then: exit.flowchartId, |
| 106 | + else: storePrevResult.flowchartId, |
| 107 | + maxOccurrences, |
| 108 | + next: storePrevResult.flowchartId, |
| 109 | + }); |
113 | 110 |
|
114 |
| - this.addUnit(prevResultInit, true); |
115 |
| - this.addUnit(paramInit, true); |
116 |
| - this.addUnit(storeResult); |
117 |
| - this.addUnit(conditionUnit); |
118 |
| - this.addUnit(storePrevResult); |
119 |
| - this.addUnit(nextStep); |
120 |
| - this.addUnit(exit); |
| 111 | + this.addUnit(prevResultInit, true); |
| 112 | + this.addUnit(paramInit, true); |
| 113 | + this.addUnit(storeResult); |
| 114 | + this.addUnit(conditionUnit); |
| 115 | + this.addUnit(storePrevResult); |
| 116 | + this.addUnit(nextStep); |
| 117 | + this.addUnit(exit); |
121 | 118 |
|
122 |
| - // `addUnit` adjusts the `next` field, hence the below. |
123 |
| - nextStep.next = unitForConvergence.flowchartId; |
124 |
| - } |
125 |
| - }; |
| 119 | + // `addUnit` adjusts the `next` field, hence the below. |
| 120 | + nextStep.next = unitForConvergence.flowchartId; |
| 121 | + } |
| 122 | +}; |
0 commit comments