public RuleDefinition GetDefinitionFor(RuleAssertion ruleAssertion) { RuleDefinition?result = this.ruleSet.Rules.FirstOrDefault(x => x.Id == ruleAssertion.Id); if (result == null) { throw new ArgumentException("No definition found for rule id " + ruleAssertion.Id); } return(result); }
private static long GetMaximumScoreForRule(RuleDefinition definition, RuleAssertion assertion) { var optedOut = assertion.Measures.Where(m => m.OptOut).Select(m => m.Description).ToHashSet(); var applicableMeasures = definition.Measures.Where(m => !optedOut.Contains(m.Description)).ToList(); return(definition.DataType switch { DataType.Continuous => applicableMeasures.Sum(x => x.Score), _ => applicableMeasures.Max(m => m.Score), });
public CalculationContext( IEvaluationContext evaluationContext, RuleDefinition definition, RuleAssertion assertion, List <MeasureDefinition> applicableMeasureDefinitions, List <MeasureAssertion> applicableMeasureAssertions) { EvaluationContext = evaluationContext; Assertion = assertion; Definition = definition; ApplicableMeasureDefinitions = applicableMeasureDefinitions; ApplicableMeasureAssertions = applicableMeasureAssertions; }
private CalculationContext MakeContext(RuleAssertion ruleAssertion, IEvaluationContext context) { // TODO: Validate any opt outs? Reject attempts to opt out of a non-optional rule. // That would need to be done as part of https://github.com/endjin/Endjin.Ip.Maturity.Matrix/issues/9 List <string> optedOutMeasures = ruleAssertion.Measures.Where(m => m.OptOut).Select(m => m.Description).ToList(); var ruleDefinition = this.ruleDefinitions.GetDefinitionFor(ruleAssertion); return(new CalculationContext( context, ruleDefinition, ruleAssertion, ruleDefinition.Measures .Where(md => !md.CanOptOut || !optedOutMeasures.Contains(md.Description)) .ToList(), ruleAssertion.Measures .Where(m => !m.OptOut) .ToList())); }
public RuleEvaluation(RuleAssertion ruleAssertion, decimal percentage, long score) { RuleAssertion = ruleAssertion; Percentage = percentage; Score = score; }
public decimal Percentage(RuleAssertion ruleAssertion, IEvaluationContext context) { return(0m); }
public long Score(RuleAssertion ruleAssertion, IEvaluationContext context) { return(0); }
/// <inheritdoc/> public long Score(RuleAssertion ruleAssertion, IEvaluationContext context) { return(this.ScoreFromApplicableMeasures(this.MakeContext(ruleAssertion, context))); }
/// <inheritdoc/> public decimal Percentage(RuleAssertion ruleAssertion, IEvaluationContext context) { var higestScore = this.MaximumFromApplicableMeasures(this.MakeContext(ruleAssertion, context)); return(Math.Round(Convert.ToDecimal(this.Score(ruleAssertion, context) / Convert.ToDecimal(higestScore)) * 100)); }