onroute-policy-engine 0.2.1 → 0.4.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.
@@ -45,3 +45,10 @@ jobs:
45
45
  run: npm publish --provenance --access public
46
46
  env:
47
47
  NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
48
+
49
+ - name: Create Release
50
+ run: |
51
+ gh release create "${{ steps.semver.outputs.next }}" \
52
+ --repo="${{ github.repository }}" \
53
+ --title="${{ steps.semver.outputs.next }}" \
54
+ --generate-notes
@@ -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
+ }
@@ -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
  }
@@ -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;
@@ -0,0 +1,8 @@
1
+ export type AxleConfiguration = {
2
+ numberOfAxles: number;
3
+ spread?: number;
4
+ spacingToNext?: number;
5
+ weight: number;
6
+ numberOfTires?: number;
7
+ tireSize?: number;
8
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ export type BridgeCalculationConstants = {
2
+ multiplier: number;
3
+ minWeight: number;
4
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ export type BridgeCalculationResult = {
2
+ startAxleUnit: number;
3
+ endAxleUnit: number;
4
+ maxBridge: number;
5
+ actualWeight: number;
6
+ success: boolean;
7
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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
@@ -7,6 +7,19 @@
7
7
  "./types": "./dist/types/index.js",
8
8
  "./enum": "./dist/enum/index.js"
9
9
  },
10
+ "typesVersions": {
11
+ "*": {
12
+ ".": [
13
+ "dist/index.d.ts"
14
+ ],
15
+ "types": [
16
+ "dist/types/index.d.ts"
17
+ ],
18
+ "enum": [
19
+ "dist/enum/index.d.ts"
20
+ ]
21
+ }
22
+ },
10
23
  "types": "dist/index.d.ts",
11
24
  "private": false,
12
25
  "scripts": {
@@ -73,5 +86,5 @@
73
86
  ],
74
87
  "testEnvironment": "node"
75
88
  },
76
- "version": "v0.2.1"
89
+ "version": "v0.4.0"
77
90
  }