onroute-policy-engine 0.6.0 → 0.7.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.
|
@@ -63,6 +63,6 @@ jobs:
|
|
|
63
63
|
if: always()
|
|
64
64
|
runs-on: ubuntu-22.04
|
|
65
65
|
steps:
|
|
66
|
-
- if: contains(needs.*.result, 'failure')
|
|
66
|
+
- if: contains(needs.*.result, 'failure')||contains(needs.*.result, 'canceled')
|
|
67
67
|
run: echo "At least one job has failed." && exit 1
|
|
68
68
|
- run: echo "Success!"
|
|
@@ -115,4 +115,60 @@ function addRuntimeFacts(engine, policy) {
|
|
|
115
115
|
}
|
|
116
116
|
return cost;
|
|
117
117
|
});
|
|
118
|
+
/**
|
|
119
|
+
* Add runtime fact to look up the permit cost from a matrix of
|
|
120
|
+
* value ranges configured in policy json. This is most commonly
|
|
121
|
+
* used for a permit cost that is based on the vehicle weight.
|
|
122
|
+
*/
|
|
123
|
+
engine.addFact(enum_1.CostFacts.RangeMatrixCostLookup.toString(), async function (params, almanac) {
|
|
124
|
+
var _a, _b;
|
|
125
|
+
// Get the parameter from the permit application whose
|
|
126
|
+
// value will be used to select the correct range matrix key
|
|
127
|
+
const rangeLookupKey = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, params.rangeLookupKey);
|
|
128
|
+
// Initialize cost to zero, if we are unable to find
|
|
129
|
+
// a matching value or matrix for whatever reason, the
|
|
130
|
+
// cost will default to zero (no matrix applicable)
|
|
131
|
+
let cost = 0;
|
|
132
|
+
// Get the ID of the matrix to look up
|
|
133
|
+
const matrixRef = (_a = params.matrixMap) === null || _a === void 0 ? void 0 : _a.find((r) => r.key === rangeLookupKey);
|
|
134
|
+
if (matrixRef) {
|
|
135
|
+
// If a matrix ID was returned, retrieve the matrix from the
|
|
136
|
+
// policy configuration that we need to use for cost lookup
|
|
137
|
+
// (for example, the 'annualFeeIndustrial' matrix)
|
|
138
|
+
const matrix = (_b = policy.policyDefinition.rangeMatrices) === null || _b === void 0 ? void 0 : _b.find((m) => m.id === matrixRef.value);
|
|
139
|
+
if (matrix) {
|
|
140
|
+
// if the matrix exists in policy configuration
|
|
141
|
+
// Retrieve the numeric value for the matrix lookup
|
|
142
|
+
// (for example, may be loaded GVW)
|
|
143
|
+
const matrixFactValue = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, params.matrixFactValue);
|
|
144
|
+
// Look up the correct entry in the matrix, where the lookup
|
|
145
|
+
// value falls within the min/max range
|
|
146
|
+
const matrixMatch = matrix.matrix.find((m) => {
|
|
147
|
+
let min = m.min;
|
|
148
|
+
if (typeof min !== 'number') {
|
|
149
|
+
min = Number.MIN_SAFE_INTEGER;
|
|
150
|
+
}
|
|
151
|
+
let max = m.max;
|
|
152
|
+
if (typeof max !== 'number') {
|
|
153
|
+
max = Number.MAX_SAFE_INTEGER;
|
|
154
|
+
}
|
|
155
|
+
return matrixFactValue >= min && matrixFactValue <= max;
|
|
156
|
+
});
|
|
157
|
+
if (matrixMatch) {
|
|
158
|
+
// If we got a hit from the matrix
|
|
159
|
+
cost = matrixMatch.value;
|
|
160
|
+
// If the cost rule includes a divisor, apply it here. A divisor
|
|
161
|
+
// may be used if, for example, the value from the lookup matrix
|
|
162
|
+
// is an annual fee but the permit is just a month or quarter.
|
|
163
|
+
if (typeof params.divisor === 'number' && params.divisor > 0) {
|
|
164
|
+
cost = Math.round(cost / params.divisor);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
console.log(`No range matrix with id ${matrixRef} found in the policy configuration`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return cost;
|
|
173
|
+
});
|
|
118
174
|
}
|
package/package.json
CHANGED