-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #211 from GannettDigital/issue-210
issue-210: replanning updates for actionTree
- Loading branch information
Showing
10 changed files
with
4,146 additions
and
3,334 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,27 @@ | ||
'use strict'; | ||
|
||
const setOperations = require('../util/set-operations.js'); | ||
const crypto = require('crypto'); | ||
|
||
module.exports = function reduceToMinimumSetOfPlans(plans, algorithm, callback) { | ||
let finalPlans = []; | ||
let hashes = new Set(); | ||
|
||
plans.forEach(function(plan, index) { | ||
let planPath; | ||
switch (algorithm) { | ||
case 'actionTree': | ||
planPath = new Set(plan); | ||
break; | ||
default: | ||
planPath = new Set(plan.path); | ||
} | ||
let hasSuperset = false; | ||
if (algorithm.toLowerCase() === 'actiontree') { | ||
plans.forEach(function(plan, index) { | ||
const hash = crypto.createHash('sha256'); | ||
let planString = JSON.stringify(plan); | ||
const planHashDigest = hash.update(planString).digest('base64'); | ||
|
||
let plansWithCurrentPlanRemoved = plans.filter(function(plan, filterIndex) { | ||
return index !== filterIndex; | ||
}); | ||
let hasExistingPlan = hashes.has(planHashDigest); | ||
|
||
for (let myPlan of plansWithCurrentPlanRemoved) { | ||
let myPlanPath; | ||
switch (algorithm) { | ||
case 'actionTree': | ||
myPlanPath = new Set(myPlan); | ||
break; | ||
default: | ||
myPlanPath = new Set(myPlan.path); | ||
} | ||
if (setOperations.isSuperset(myPlanPath, planPath)) { | ||
hasSuperset = true; | ||
break; | ||
if (!hasExistingPlan) { | ||
hashes.add(planHashDigest); | ||
finalPlans.push(plan); | ||
} | ||
} | ||
|
||
if (!hasSuperset) { | ||
finalPlans.push(plan); | ||
} | ||
}); | ||
}); | ||
|
||
callback(null, finalPlans); | ||
callback(null, finalPlans); | ||
} else { | ||
callback(null, plans); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.