onroute-policy-engine 0.2.1 → 0.3.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/dist/helper/bridge-calculation.helper.d.ts +13 -0
- package/dist/helper/bridge-calculation.helper.js +92 -0
- package/dist/policy-engine.d.ts +9 -1
- package/dist/policy-engine.js +19 -0
- package/dist/types/axle-configuration.d.ts +8 -0
- package/dist/types/axle-configuration.js +2 -0
- package/dist/types/bridge-calculation-constants.d.ts +4 -0
- package/dist/types/bridge-calculation-constants.js +2 -0
- package/dist/types/bridge-calculation-result.d.ts +7 -0
- package/dist/types/bridge-calculation-result.js +2 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/policy-definition.d.ts +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BridgeCalculationResult, AxleConfiguration } from 'onroute-policy-engine/types';
|
|
2
|
+
import { Policy } from '../policy-engine';
|
|
3
|
+
/**
|
|
4
|
+
* Runs the bridge formula against the supplied vehicle axle configuration.
|
|
5
|
+
* Evaluates the weight against all possible axle group combinations and returns
|
|
6
|
+
* the result of each group comparison, with an indicator of whether or not the
|
|
7
|
+
* axle group failed the bridge calculation.
|
|
8
|
+
* @param axleConfig Vehicle dimensions and weights per axle
|
|
9
|
+
* @param policy Policy Enging object initialized with policy config
|
|
10
|
+
* @returns Array of BridgeCalculationResult objects, one for each
|
|
11
|
+
* axle group in the vehicle configuration
|
|
12
|
+
*/
|
|
13
|
+
export declare function runBridgeFormula(axleConfig: Array<AxleConfiguration>, policy: Policy): Array<BridgeCalculationResult>;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runBridgeFormula = runBridgeFormula;
|
|
4
|
+
/**
|
|
5
|
+
* Runs the bridge formula against the supplied vehicle axle configuration.
|
|
6
|
+
* Evaluates the weight against all possible axle group combinations and returns
|
|
7
|
+
* the result of each group comparison, with an indicator of whether or not the
|
|
8
|
+
* axle group failed the bridge calculation.
|
|
9
|
+
* @param axleConfig Vehicle dimensions and weights per axle
|
|
10
|
+
* @param policy Policy Enging object initialized with policy config
|
|
11
|
+
* @returns Array of BridgeCalculationResult objects, one for each
|
|
12
|
+
* axle group in the vehicle configuration
|
|
13
|
+
*/
|
|
14
|
+
function runBridgeFormula(axleConfig, policy) {
|
|
15
|
+
const BRIDGE_MULTIPLIER = policy.policyDefinition.bridgeCalculationConstants.multiplier;
|
|
16
|
+
const BRIDGE_MIN_WEIGHT = policy.policyDefinition.bridgeCalculationConstants.minWeight;
|
|
17
|
+
const results = [];
|
|
18
|
+
let index = 0;
|
|
19
|
+
if (!axleConfig || axleConfig.length < 2) {
|
|
20
|
+
throw new Error('Invalid axle configuration, bridge formula requires a minimum of two axle units');
|
|
21
|
+
}
|
|
22
|
+
// Loop through each axle unit in the configuration, and
|
|
23
|
+
// calculate the bridge formula for each other axle unit. The
|
|
24
|
+
// number of axle groups calculated will be the Nth triangular
|
|
25
|
+
// number, where N = (number of axle units) - 1.
|
|
26
|
+
axleConfig.forEach((axle) => {
|
|
27
|
+
var _a;
|
|
28
|
+
// Do not process once we reach the last axle unit
|
|
29
|
+
// in the configuration, as they have all been calculated
|
|
30
|
+
// by then.
|
|
31
|
+
if (index < axleConfig.length - 1) {
|
|
32
|
+
// Initialize the variables for our start axle
|
|
33
|
+
const firstAxle = index + 1;
|
|
34
|
+
let nextAxle = firstAxle + 1;
|
|
35
|
+
if (!axle.numberOfAxles || axle.numberOfAxles < 0) {
|
|
36
|
+
throw new Error(`Invalid or missing number of axles for axle unit number ${firstAxle}`);
|
|
37
|
+
}
|
|
38
|
+
if (!axle.weight || axle.weight < 0) {
|
|
39
|
+
throw new Error(`Invalid or missing weight for axle unit number ${firstAxle}`);
|
|
40
|
+
}
|
|
41
|
+
let totalWeight = axle.weight;
|
|
42
|
+
// Spread may be zero or undefined if the axle unit
|
|
43
|
+
// is a single axle. Spacing to next will be zero or
|
|
44
|
+
// undefined for the final axle unit in the configuration.
|
|
45
|
+
if (axle.numberOfAxles > 1 && (!axle.spread || axle.spread < 0)) {
|
|
46
|
+
throw new Error(`Invalid or missing axle spread for axle unit number ${firstAxle}`);
|
|
47
|
+
}
|
|
48
|
+
if (axle.numberOfAxles == 1 && axle.spread && axle.spread < 0) {
|
|
49
|
+
throw new Error(`Invalid axle spread for single axle unit, cannot be a negative number`);
|
|
50
|
+
}
|
|
51
|
+
if (!axle.spacingToNext || axle.spacingToNext < 0) {
|
|
52
|
+
throw new Error(`Invalid or missing axle spacing between axle units ${firstAxle} and ${firstAxle + 1}`);
|
|
53
|
+
}
|
|
54
|
+
let wheelbase = ((_a = axle.spread) !== null && _a !== void 0 ? _a : 0) + axle.spacingToNext;
|
|
55
|
+
// Now loop through all of the next axles, building up a group
|
|
56
|
+
// for each.
|
|
57
|
+
axleConfig.slice(firstAxle).forEach((axleN) => {
|
|
58
|
+
var _a, _b;
|
|
59
|
+
if (!axleN.weight || axleN.weight < 0) {
|
|
60
|
+
throw new Error(`Invalid or missing weight for axle unit number ${nextAxle}`);
|
|
61
|
+
}
|
|
62
|
+
totalWeight += axleN.weight;
|
|
63
|
+
if (axleN.numberOfAxles > 1 && (!axleN.spread || axleN.spread < 0)) {
|
|
64
|
+
throw new Error(`Invalid or missing axle spread for axle unit number ${nextAxle}`);
|
|
65
|
+
}
|
|
66
|
+
wheelbase += (_a = axleN.spread) !== null && _a !== void 0 ? _a : 0;
|
|
67
|
+
// The magic is in the next line
|
|
68
|
+
const maxBridge = BRIDGE_MULTIPLIER * wheelbase + BRIDGE_MIN_WEIGHT;
|
|
69
|
+
// Push the axle group result to the results array, including
|
|
70
|
+
// a convenience success indicator.
|
|
71
|
+
results.push({
|
|
72
|
+
startAxleUnit: firstAxle,
|
|
73
|
+
endAxleUnit: nextAxle,
|
|
74
|
+
maxBridge: maxBridge,
|
|
75
|
+
actualWeight: totalWeight,
|
|
76
|
+
success: totalWeight <= maxBridge,
|
|
77
|
+
});
|
|
78
|
+
// Add the wheelbase only if this end axle unit is not the
|
|
79
|
+
// final one in the configuration
|
|
80
|
+
if (nextAxle < axleConfig.length) {
|
|
81
|
+
if (!axleN.spacingToNext || axleN.spacingToNext < 0) {
|
|
82
|
+
throw new Error(`Invalid or missing axle spacing between axle units ${nextAxle} and ${nextAxle + 1}`);
|
|
83
|
+
}
|
|
84
|
+
wheelbase += (_b = axleN.spacingToNext) !== null && _b !== void 0 ? _b : 0;
|
|
85
|
+
}
|
|
86
|
+
nextAxle++;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
index++;
|
|
90
|
+
});
|
|
91
|
+
return results;
|
|
92
|
+
}
|
package/dist/policy-engine.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PolicyDefinition, PermitType, Commodity, SizeDimension } from 'onroute-policy-engine/types';
|
|
1
|
+
import { PolicyDefinition, PermitType, Commodity, SizeDimension, AxleConfiguration, BridgeCalculationResult } from 'onroute-policy-engine/types';
|
|
2
2
|
import { Engine } from 'json-rules-engine';
|
|
3
3
|
import { ValidationResults } from './validation-results';
|
|
4
4
|
/** Class representing commercial vehicle policy. */
|
|
@@ -136,4 +136,12 @@ export declare class Policy {
|
|
|
136
136
|
* @returns Commodity definition for the supplied ID.
|
|
137
137
|
*/
|
|
138
138
|
getCommodityDefinition(type?: string): Commodity | null;
|
|
139
|
+
/**
|
|
140
|
+
* Convenience method of policy that delegates the bridge calculation
|
|
141
|
+
* to the helper method.
|
|
142
|
+
* @param axleConfig Vehicle dimensions and weights per axle
|
|
143
|
+
* @returns Array of BridgeCalculationResult objects, one for each
|
|
144
|
+
* axle group in the vehicle configuration
|
|
145
|
+
*/
|
|
146
|
+
calculateBridge(axleConfig: Array<AxleConfiguration>): Array<BridgeCalculationResult>;
|
|
139
147
|
}
|
package/dist/policy-engine.js
CHANGED
|
@@ -7,6 +7,7 @@ const validation_results_1 = require("./validation-results");
|
|
|
7
7
|
const validation_result_1 = require("./validation-result");
|
|
8
8
|
const facts_helper_1 = require("./helper/facts.helper");
|
|
9
9
|
const enum_1 = require("onroute-policy-engine/enum");
|
|
10
|
+
const bridge_calculation_helper_1 = require("./helper/bridge-calculation.helper");
|
|
10
11
|
/** Class representing commercial vehicle policy. */
|
|
11
12
|
class Policy {
|
|
12
13
|
/**
|
|
@@ -614,5 +615,23 @@ class Policy {
|
|
|
614
615
|
return null;
|
|
615
616
|
}
|
|
616
617
|
}
|
|
618
|
+
/**
|
|
619
|
+
* Convenience method of policy that delegates the bridge calculation
|
|
620
|
+
* to the helper method.
|
|
621
|
+
* @param axleConfig Vehicle dimensions and weights per axle
|
|
622
|
+
* @returns Array of BridgeCalculationResult objects, one for each
|
|
623
|
+
* axle group in the vehicle configuration
|
|
624
|
+
*/
|
|
625
|
+
calculateBridge(axleConfig) {
|
|
626
|
+
let bridgeResults;
|
|
627
|
+
try {
|
|
628
|
+
bridgeResults = (0, bridge_calculation_helper_1.runBridgeFormula)(axleConfig, this);
|
|
629
|
+
}
|
|
630
|
+
catch (e) {
|
|
631
|
+
console.log(`Error calculating bridge formula: ${e.message}`);
|
|
632
|
+
throw e;
|
|
633
|
+
}
|
|
634
|
+
return bridgeResults;
|
|
635
|
+
}
|
|
617
636
|
}
|
|
618
637
|
exports.Policy = Policy;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export { AxleConfiguration } from './axle-configuration';
|
|
2
|
+
export { BridgeCalculationConstants } from './bridge-calculation-constants';
|
|
3
|
+
export { BridgeCalculationResult } from './bridge-calculation-result';
|
|
1
4
|
export { Commodity, CommoditySize, CommodityWeight } from './commodity';
|
|
2
5
|
export { CostRule } from './cost-rule';
|
|
3
6
|
export { DimensionModifier } from './dimension-modifier';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GeographicRegion, PermitType, DefaultWeightDimensions, VehicleTypes, Commodity, SizeDimension, VehicleCategories, RangeMatrix } from 'onroute-policy-engine/types';
|
|
1
|
+
import { GeographicRegion, PermitType, DefaultWeightDimensions, VehicleTypes, Commodity, SizeDimension, VehicleCategories, RangeMatrix, BridgeCalculationConstants } from 'onroute-policy-engine/types';
|
|
2
2
|
import { RuleProperties } from 'json-rules-engine';
|
|
3
3
|
export type PolicyDefinition = {
|
|
4
4
|
version: string;
|
|
@@ -11,4 +11,5 @@ export type PolicyDefinition = {
|
|
|
11
11
|
vehicleTypes: VehicleTypes;
|
|
12
12
|
commodities: Array<Commodity>;
|
|
13
13
|
rangeMatrices?: Array<RangeMatrix>;
|
|
14
|
+
bridgeCalculationConstants: BridgeCalculationConstants;
|
|
14
15
|
};
|
package/package.json
CHANGED