Accomodate updated RPS targets in V2 ruleset.

This commit is contained in:
Patrick Fic
2023-02-15 12:05:43 -08:00
parent 1f0bcf5611
commit 2380a282ba
23 changed files with 506 additions and 134 deletions

View File

@@ -1,11 +1,39 @@
export default function GetJobTarget(group, v_age, targets) {
const targetsForGroup = targets.filter((t) => t.group === group);
if (!targetsForGroup) return 0;
const targetPc = targetsForGroup.filter(
import { store } from "../redux/store";
import { WhichRulesetToApply } from "./constants";
export default function GetJobTarget({ group, v_age, targets, close_date }) {
// //Old Validation
// const targetsForGroup = targets.filter((t) => t.group === group);
// console.log(
// "🚀 ~ file: GetJobTarget.js:7 ~ GetJobTarget ~ targetsForGroup",
// targetsForGroup
// );
// if (!targetsForGroup) {
// console.log("Result:", 0);
// }
// const targetPc = targetsForGroup.filter(
// (t) => t.ageGte <= v_age && (t.ageLt ? t.ageLt > v_age : true)
// );
// if (targetPc.length === 0) console.log("Result:", 1);
// else if (targetPc.length === 1) console.log("Result: ", targetPc[0].target);
// else {
// console.log("Result:", 1);
// }
//V2 Check
const newTargets = store.getState().user.targets;
const rulesToApply = WhichRulesetToApply(close_date);
const newTargetsForGroup = newTargets.filter(
(t) => t.name === rulesToApply && t.group === group
);
if (!newTargetsForGroup) return 0;
const newTargetPc = newTargetsForGroup.filter(
(t) => t.ageGte <= v_age && (t.ageLt ? t.ageLt > v_age : true)
);
if (targetPc.length === 0) return 1;
else if (targetPc.length === 1) return targetPc[0].target;
if (newTargetPc.length === 0) return 1;
else if (newTargetPc.length === 1) return newTargetPc[0].target;
else {
return 1;
}

View File

@@ -19,24 +19,29 @@ export function ChangeOfRuleSet({
const prevRuleSet = RuleSets.find(
(r) =>
prevDateMoment.isSameOrAfter(r.range[0]) &&
prevDateMoment.isSameOrBefore(r.range[1])
prevDateMoment.isBefore(r.range[1])
);
const newRuleSet = RuleSets.find(
(r) =>
newDateMoment.isSameOrAfter(r.range[0]) &&
newDateMoment.isSameOrBefore(r.range[1])
newDateMoment.isBefore(r.range[1])
);
return prevRuleSet?.title !== newRuleSet?.title;
}
export function WhichRulesetToApply({ DateMoment = moment() }) {
export function WhichRulesetToApply(close_date) {
const DateMoment = close_date ? moment(close_date) : moment();
console.log(
"🚀 ~ file: constants.js:36 ~ WhichRulesetToApply ~ DateMoment",
DateMoment
);
const newRuleSet = RuleSets.find(
(r) =>
DateMoment.isSameOrAfter(r.range[0]) &&
DateMoment.isSameOrBefore(r.range[1])
DateMoment.isSameOrAfter(r.range[0]) && DateMoment.isBefore(r.range[1])
);
console.log("Using ruleset:", newRuleSet);
return newRuleSet?.title;
}