Skip to content

Commit

Permalink
feat: Initial load of OS permittable data (#1572)
Browse files Browse the repository at this point in the history
Co-authored-by: Derek Roberts <[email protected]>
  • Loading branch information
john-fletcher-aot and DerekRoberts authored Sep 5, 2024
1 parent 0f08c8d commit ab872b9
Show file tree
Hide file tree
Showing 40 changed files with 11,370 additions and 2,256 deletions.
9 changes: 5 additions & 4 deletions policy-engine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ A JSON-based rules engine to validate onRouteBC permit applications against comm
import Policy from 'orbc-policy-engine';

// Instantiate a new Policy object
// policyConfiguration is a JSON object of type PolicyDefinition
// policyDefinition is a JSON object of type PolicyDefinition
const policy: Policy = new Policy(policyDefinition);

// Get list of all available permit types (ID and name)
Expand All @@ -31,19 +31,20 @@ const commodities: Map<string, string> = policy.getCommodities(permitTypeId);
// Get list of all vehicle types valid to be added to a configuration,
// by permit type and commodity. Requires supplying the vehicles already
// added to the configuration, or empty array if starting from scratch
const allowableVehicles: Map<string, string> = policy.getAllowableVehicles(
const allowableVehicles: Map<string, string> = policy.getNextPermittableVehicles(
permitTypeId,
commodityId,
currentConfiguration);

// Validate a permit application against policy
// permitApplication is a JSON object of type PermitApplication
// A PermitApplication is just the standard permitData object wrapped
// A PermitApplication is the standard permitData object wrapped
// in an object with a permitType key. For example:
// {
// permitType: 'TROS',
// permitData: { ... }
// }
const results: ValidationResults = policy.validate(permitApplication);
// Note this is an async call due to the reliance on json-rules-engine
const results: ValidationResults = await policy.validate(permitApplication);
```

49 changes: 40 additions & 9 deletions policy-engine/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion policy-engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"devDependencies": {
"@types/jest": "^29.5.12",
"@typescript-eslint/eslint-plugin": "^7.5.0",
"csv": "^6.3.10",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"jest": "^29.7.0",
Expand All @@ -38,7 +39,6 @@
},
"dependencies": {
"dayjs": "^1.11.10",
"flattie": "^1.1.1",
"json-rules-engine": "^6.5.0"
},
"jest": {
Expand Down
75 changes: 75 additions & 0 deletions policy-engine/src/_examples/_debug-helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { Policy } from 'onroute-policy-engine';
import { completePolicyConfig } from '../_test/policy-config/complete-in-progress.sample';

function start() {
const policy: Policy = new Policy(completePolicyConfig);
console.log(JSON.stringify(policy.policyDefinition));
/*
console.log('***ALL COMMODITIES***');
const allCommodities = policy.getCommodities();
console.log(
JSON.stringify(Array.from(allCommodities.entries()), null, ' '),
);
console.log('***COMMODITIES FOR STOS***');
const stosCommodities = policy.getCommodities('STOS');
console.log(
JSON.stringify(Array.from(stosCommodities.entries()), null, ' '),
);
console.log('***POWER UNITS PERMITTABLE FOR STOS AND EMPTY COMMODITY***');
const puTypesEmpty = policy.getPermittablePowerUnitTypes('STOS', 'EMPTYXX');
console.log(JSON.stringify(Array.from(puTypesEmpty.entries()), null, ' '));
console.log(
'***POWER UNITS PERMITTABLE FOR STOS AND BRIDGE BEAMS COMMODITY***',
);
const puTypesBridgeBeams = policy.getPermittablePowerUnitTypes(
'STOS',
'BRGBEAM',
);
console.log(
JSON.stringify(Array.from(puTypesBridgeBeams.entries()), null, ' '),
);
console.log(
'***PERMITTABLE NEXT VEHICLES WITH EMPTY CONFIGURATION, STOS AND EMPTY***',
);
const vehicleTypes1 = policy.getNextPermittableVehicles(
'STOS',
'EMPTYXX',
[],
);
console.log(JSON.stringify(Array.from(vehicleTypes1.entries()), null, ' '));
console.log(
'***PERMITTABLE NEXT VEHICLES WITH TRUCK TRACTOR AND JEEP, STOS AND EMPTY***',
);
const vehicleTypes2 = policy.getNextPermittableVehicles('STOS', 'EMPTYXX', [
'TRKTRAC',
'JEEPSRG',
]);
console.log(JSON.stringify(Array.from(vehicleTypes2.entries()), null, ' '));
console.log(
'***MAX SIZE FOR TRUCK TRACTOR, JEEP, HIBOEXP, STOS AND EMPTYXX***',
);
const sizeDimension = policy.getSizeDimension('STOS', 'EMPTYXX', ['TRKTRAC', 'JEEPSRG', 'HIBOEXP']);
console.log(JSON.stringify(sizeDimension, null, ' '));
console.log(
'***MAX SIZE FOR TRUCK TRACTOR, JEEP, HIBOEXP, STOS AND EMPTYXX IN PEACE***',
);
const sizeDimensionPeace = policy.getSizeDimension('STOS', 'EMPTYXX', ['TRKTRAC', 'JEEPSRG', 'HIBOEXP'], ['PCE']);
console.log(JSON.stringify(sizeDimensionPeace, null, ' '));
console.log(
'***MAX SIZE FOR TRUCK TRACTOR, JEEP, HIBOEXP, STOS AND EMPTYXX IN PEACE,BC DEFAULT***',
);
const sizeDimensionPeaceBC = policy.getSizeDimension('STOS', 'EMPTYXX', ['TRKTRAC', 'JEEPSRG', 'HIBOEXP'], ['PCE','BCD']);
console.log(JSON.stringify(sizeDimensionPeaceBC, null, ' '));
*/
}

start();
48 changes: 45 additions & 3 deletions policy-engine/src/_examples/get-policy-details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import { completePolicyConfig } from '../_test/policy-config/complete-in-progres
function start() {
const policy: Policy = new Policy(completePolicyConfig);

console.log('***ALL PERMIT TYPES***');
const allPermitTypes = policy.getPermitTypes();
console.log(
JSON.stringify(Array.from(allPermitTypes.entries()), null, ' '),
);

console.log('***ALL COMMODITIES***');
const allCommodities = policy.getCommodities();
console.log(
Expand Down Expand Up @@ -53,20 +59,56 @@ function start() {
console.log(
'***MAX SIZE FOR TRUCK TRACTOR, JEEP, HIBOEXP, STOS AND EMPTYXX***',
);
const sizeDimension = policy.getSizeDimension('STOS', 'EMPTYXX', ['TRKTRAC', 'JEEPSRG', 'HIBOEXP']);
const sizeDimension = policy.getSizeDimension('STOS', 'EMPTYXX', [
'TRKTRAC',
'JEEPSRG',
'HIBOEXP',
]);
console.log(JSON.stringify(sizeDimension, null, ' '));

console.log(
'***MAX SIZE FOR TRUCK TRACTOR, JEEP, HIBOEXP, STOS AND EMPTYXX IN PEACE***',
);
const sizeDimensionPeace = policy.getSizeDimension('STOS', 'EMPTYXX', ['TRKTRAC', 'JEEPSRG', 'HIBOEXP'], ['PCE']);
const sizeDimensionPeace = policy.getSizeDimension(
'STOS',
'EMPTYXX',
['TRKTRAC', 'JEEPSRG', 'HIBOEXP'],
['PCE'],
);
console.log(JSON.stringify(sizeDimensionPeace, null, ' '));

console.log(
'***MAX SIZE FOR TRUCK TRACTOR, JEEP, HIBOEXP, STOS AND EMPTYXX IN PEACE,BC DEFAULT***',
);
const sizeDimensionPeaceBC = policy.getSizeDimension('STOS', 'EMPTYXX', ['TRKTRAC', 'JEEPSRG', 'HIBOEXP'], ['PCE','BCD']);
const sizeDimensionPeaceBC = policy.getSizeDimension(
'STOS',
'EMPTYXX',
['TRKTRAC', 'JEEPSRG', 'HIBOEXP'],
['PCE', 'BCD'],
);
console.log(JSON.stringify(sizeDimensionPeaceBC, null, ' '));

console.log(
'***MAX SIZE FOR TRUCK TRACTOR, JEEP, STWHELR, STOS AND EMPTYXX IN BC DEFAULT***',
);
const sizeDimensionBC = policy.getSizeDimension(
'STOS',
'EMPTYXX',
['TRKTRAC', 'JEEPSRG', 'STWHELR'],
['BCD'],
);
console.log(JSON.stringify(sizeDimensionBC, null, ' '));

console.log(
'***MAX SIZE FOR TRUCK TRACTOR, JEEP, STWHELR, STOS AND EMPTYXX IN PEACE***',
);
const sizeDimensionStwhelrPce = policy.getSizeDimension(
'STOS',
'EMPTYXX',
['TRKTRAC', 'JEEPSRG', 'STWHELR'],
['PCE'],
);
console.log(JSON.stringify(sizeDimensionStwhelrPce, null, ' '));
}

start();
Loading

0 comments on commit ab872b9

Please sign in to comment.