public ImmEvaluation Evaluate(IpMaturityMatrix imm, IEvaluationContext?context = null) { context ??= new Context(); var ruleEvaluations = new List <RuleEvaluation>(); long totalScore = 0; long maximumPossibleScore = 0; foreach (var rule in imm.Rules.Where(r => !r.OptOut)) { var ruleDefinition = this.ruleDefinitionRepository.GetDefinitionFor(rule); if (ruleDefinition != null) { var calculator = this.ruleCalculatorFactory.Create(ruleDefinition.DataType); var ruleEvaluation = new RuleEvaluation(rule, calculator.Percentage(rule, context), calculator.Score(rule, context)); ruleEvaluations.Add(ruleEvaluation); totalScore += ruleEvaluation.Score; maximumPossibleScore += GetMaximumScoreForRule(ruleDefinition, rule); } } return(new ImmEvaluation(ruleEvaluations, totalScore, maximumPossibleScore)); }
private static async Task Main() { var client = new HttpClient(); HttpResponseMessage ruleSetResponse = await client.GetAsync(IpMaturityMatrixRuleset.RuleSetDefinitionsUrl).ConfigureAwait(false); ruleSetResponse.EnsureSuccessStatusCode(); string yamlRuleText = await ruleSetResponse.Content.ReadAsStringAsync().ConfigureAwait(false); var yamlRules = IpMaturityMatrixRuleset.FromYaml(yamlRuleText); var immProjectScore = IpMaturityMatrix.FromYaml(File.ReadAllText("imm-default.yaml")); var evaluationEngine = new EvaluationEngine(new RuleDefinitionRepository(yamlRules)); var col1 = new StringBuilder(); var col2 = new StringBuilder(); ImmEvaluation evalutionResult = evaluationEngine.Evaluate(immProjectScore); foreach (var result in evalutionResult.RuleEvaluations) { Console.WriteLine($"{result.RuleAssertion.Name} {result.Percentage}% Score: {result.Score}"); #pragma warning disable RCS1197 // Optimize StringBuilder.Append/AppendLine call. col1.AppendLine($"<tspan x='30' dy='1.5em'>{WebUtility.HtmlEncode(result.RuleAssertion.Name)}</tspan>"); col2.AppendLine($"<tspan x='310' dy='1.5em'>{result.Percentage}%</tspan>"); #pragma warning restore RCS1197 // Optimize StringBuilder.Append/AppendLine call. File.WriteAllText($"imm-{result.RuleAssertion.Id}.svg", BadgePainter.DrawSVG(WebUtility.HtmlEncode(result.RuleAssertion.Name !), $"{result.Percentage}%", ColorScheme.Red, Style.FlatSquare)); } Console.WriteLine($"{evalutionResult.TotalScore} / {evalutionResult.MaximumPossibleTotalScore}"); File.WriteAllText("imm.svg", BadgePainter.DrawSVG("IMM", $"{evalutionResult.TotalScore} / {evalutionResult.MaximumPossibleTotalScore}", ColorScheme.Red, Style.Flat)); File.WriteAllText("imm-table.svg", string.Format(Resources.Table, col1.ToString(), col2.ToString())); }
/// <inheritdoc /> public async Task <IpMaturityMatrix> GetIpMaturityMatrixAsync( string gitHubOwner, string gitHubProject, string objectName) { string url = $"https://raw.githubusercontent.com/{gitHubOwner}/{gitHubProject}/{objectName}/imm.yaml"; IpMaturityMatrix imm = await cache.GetAsync(url).ConfigureAwait(false); return(imm); }