Last active
August 24, 2017 17:15
-
-
Save aconfee/de953ebffd37a1a0d5174de33fa535a4 to your computer and use it in GitHub Desktop.
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
private matchTargetPriceBucket(ruleSet: Models.IPricingTargetRuleSet, dayValue: number): number { | |
if (ruleSet === null || ruleSet.Rules.length === 0) { | |
console.error("No price buckets were provided."); | |
return null; | |
} | |
if (!dayValue || dayValue < 0) { | |
console.error("Invalid day value. Won't match any price target bucket."); | |
return null; | |
} | |
var priceBucket = ruleSet.Rules | |
.sort((a, b) => { return b.MatchValue - a.MatchValue; }) | |
.filter(x => { return dayValue >= x.MatchValue; })[0]; | |
return +((priceBucket.TargetMax + priceBucket.TargetMin) / 2).toFixed(2); | |
} |
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
private matchTargetPriceBucket(ruleSet: Models.IPricingTargetRuleSet, value: number) : number { | |
var priceBucket = ruleSet.Rules[0]; | |
var matchFound = false; | |
//MDS match value for NA is -1 | |
if (ruleSet.Type === Models.PricingTargetType.Exact_Days_Supply && value === null) | |
value = -1; | |
ruleSet.Rules.some((rule) => { | |
if (value <= rule.MatchValue) { | |
matchFound = true; | |
return true; | |
} | |
priceBucket = rule; | |
return false; | |
}); | |
// If no match was found, verify we're in the last bucket | |
if (!matchFound && value >= priceBucket.MatchValue) | |
matchFound = true; | |
return matchFound ? +((priceBucket.TargetMax + priceBucket.TargetMin) / 2).toFixed(2) : null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment