/// <summary> /// /// </summary> /// <param name="snapshot"></param> /// <param name="onlyFailedChecks"></param> /// <returns></returns> public static Int32? GetNbRuleWithViolations(Snapshot snapshot, Constants.RulesViolation rulesViolationType, Constants.BusinessCriteria businessCriteriaId, bool onlyFailedChecks) { var query = GetQueryRuleViolations(snapshot, rulesViolationType, businessCriteriaId, onlyFailedChecks); return (query != null) ? query.Select(_ => _.Reference.HRef).Distinct().Count() : (Int32?)null; }
/// <summary> /// /// </summary> /// <param name="snapshot"></param> /// <param name="rulesViolationType"></param> /// <param name="businessCriteriaId"></param> /// <returns></returns> public static List<RuleViolationResultDTO> GetAllRuleViolations(Snapshot snapshot, Constants.RulesViolation rulesViolationType, Constants.BusinessCriteria businessCriteriaId, bool onlyFailedChecks) { var query = GetQueryRuleViolations(snapshot, rulesViolationType, businessCriteriaId, onlyFailedChecks); if (query != null) return query.Select(_ => new RuleViolationResultDTO { Rule = new RuleDetailsDTO { Name = _.Reference.Name, Key = _.Reference.Key }, TotalChecks = _.DetailResult.ViolationRatio.TotalChecks, TotalFailed = _.DetailResult.ViolationRatio.FailedChecks, Grade = _.DetailResult.Grade }) .OrderByDescending(_ => _.TotalFailed) .ToList(); else return null; }
/// <summary> /// /// </summary> /// <param name="snapshot"></param> /// <param name="rulesViolationType"></param> /// <param name="businessCriteriaId"></param> /// <param name="onlyFailedChecks"></param> /// <returns></returns> private static IQueryable<ApplicationResult> GetQueryRuleViolations(Snapshot snapshot, Constants.RulesViolation rulesViolationType, Constants.BusinessCriteria businessCriteriaId, bool onlyFailedChecks) { if (snapshot == null || snapshot.BusinessCriteriaResults == null) return null; var query = snapshot.BusinessCriteriaResults.AsQueryable(); if (businessCriteriaId != 0) { query = query.Where(_ => _.Reference.Key == businessCriteriaId.GetHashCode()); } switch (rulesViolationType) { case Constants.RulesViolation.CriticalRulesViolation: query = query.SelectMany(_ => _.CriticalRulesViolation); break; case Constants.RulesViolation.NonCriticalRulesViolation: query = query.SelectMany(_ => _.NonCriticalRulesViolation); break; default: query = query.SelectMany(_ => _.CriticalRulesViolation.Union(_.NonCriticalRulesViolation)); break; } query = (from bc in query where bc.DetailResult != null && bc.DetailResult.ViolationRatio != null && (!onlyFailedChecks || bc.DetailResult.ViolationRatio.FailedChecks > 0) select bc); return query; }
/// <summary> /// /// </summary> /// <param name="CurrentSnapshot"></param> /// <param name="PreviousSnapshot"></param> /// <param name="application"></param> /// <param name="indicatorId"></param> /// <returns></returns> public static Double? SumDeltaIndicator(Snapshot CurrentSnapshot, Snapshot PreviousSnapshot, Application application, Constants.SizingInformations measureId) { double? result = null; if(application != null && CurrentSnapshot != null && CurrentSnapshot.SizingMeasuresResults != null) { result = GetSizingMeasure(CurrentSnapshot, measureId); if (PreviousSnapshot != null && PreviousSnapshot.Annotation.Date.DateSnapShot.HasValue && PreviousSnapshot.SizingMeasuresResults != null ) { DateTime dtPrevoiusSnapshot = PreviousSnapshot.Annotation.Date.DateSnapShot.Value; DateTime dtCurrentSnapshot = CurrentSnapshot.Annotation.Date.DateSnapShot.Value; var quryPreviusIndicators = from s in application.Snapshots where s.Annotation.Date.DateSnapShot > dtPrevoiusSnapshot && s.Annotation.Date.DateSnapShot < dtCurrentSnapshot from i in s.SizingMeasuresResults where i.Reference.Key == measureId.GetHashCode() select i; result += quryPreviusIndicators.Sum(s => s.DetailResult.Value); } } return result; }
/// <summary> /// /// </summary> /// <param name="snapshot"></param> /// <param name="ruleExplorer"></param> /// <param name="businessCriteriasIds"></param> /// <param name="count"></param> /// <returns></returns> public static List<TechnicalCriteriaResultDTO> GetTechnicalCriteriaViolations(Snapshot snapshot, Constants.BusinessCriteria businessCriteriaId, Int32 count) { RuleViolationResultDTO ruleViolationResult = new RuleViolationResultDTO(); if (snapshot.QIBusinessCriterias != null && snapshot.TechnicalCriteriaResults!=null) { IEnumerable<Int32> technicalCriteriaId = snapshot.QIBusinessCriterias.Where(_ => (Int32)businessCriteriaId == _.Key) .SelectMany(_ => _.Contributors).Select( _ => _.Key); return snapshot.TechnicalCriteriaResults.Where(_ => technicalCriteriaId.Contains(_.Reference.Key) && _.Reference !=null && _.DetailResult != null && _.RulesViolation != null) .Select(_ => new TechnicalCriteriaResultDTO { Name = _.Reference.Name, Grade = _.DetailResult.Grade, TotalChecks = _.RulesViolation.Sum(r => (r.DetailResult != null && r.DetailResult.ViolationRatio!=null) ? r.DetailResult.ViolationRatio.TotalChecks : 0), TotalFailed = _.RulesViolation.Sum(r => (r.DetailResult != null && r.DetailResult.ViolationRatio!=null) ? r.DetailResult.ViolationRatio.FailedChecks : 0) }) .OrderByDescending(_ => _.TotalFailed) .Take(count) .ToList(); } return null; }
/// <summary> /// /// </summary> /// <param name="snapshot"></param> /// <returns></returns> public static Double? GetSizingMeasure(Snapshot snapshot, Constants.SizingInformations measureId) { if (null != snapshot && snapshot.SizingMeasuresResults != null) { var measure = snapshot.SizingMeasuresResults.Where(_ => _.Reference.Key == measureId.GetHashCode()) .FirstOrDefault(); if (null != measure && measure.DetailResult != null) return MathUtility.GetRound(measure.DetailResult.Value); } return null; }
/// <summary> /// /// </summary> /// <param name="snapshot"></param> /// <param name="nbResult"></param> /// <returns></returns> public static List<ModuleResultDTO> GetModulesMeasure(Snapshot snapshot, int nbResult, Constants.SizingInformations measureId) { if(snapshot !=null && snapshot.SizingMeasuresResults != null) { return snapshot.SizingMeasuresResults .Where(_ => _.Reference.Key == measureId.GetHashCode()) .SelectMany(_ => _.ModulesResult) .Where(m => m.DetailResult != null) .Select( _ => new ModuleResultDTO { Name = _.Module.Name, Value= _.DetailResult.Value}) .OrderByDescending(_ => _.Value) .Take(nbResult) .ToList(); } return null; }
/// <summary> /// /// </summary> /// <param name="snapshot"></param> /// <param name="moduleHRef"></param> /// <param name="bcId"></param> /// <returns></returns> public static Double GetModuleMeasureGrade(Snapshot snapshot, Int32 moduleId, Constants.SizingInformations measureId) { return snapshot.SizingMeasuresResults .Where(_ => _.Reference.Key == (Int32)measureId && _.ModulesResult != null) .SelectMany(_ => _.ModulesResult) .Where(_ => _.Module.Id == moduleId && _.DetailResult != null) .Select(_ => MathUtility.GetRound(_.DetailResult.Grade).Value) .FirstOrDefault(); }
/// <summary> /// Get TQI for snapshot /// </summary> /// <param name="snapshot"></param> /// <returns></returns> public static Double? GetSnapshotBusinessCriteriaGrade(Snapshot snapshot, Constants.BusinessCriteria bcId, bool Round) { double? res = null; if (null != snapshot && null != snapshot.BusinessCriteriaResults) { var resultBC = snapshot.BusinessCriteriaResults.SingleOrDefault(_ => _.Reference.Key == bcId.GetHashCode()); if (resultBC != null) { res = Round ? MathUtility.GetRound(resultBC.DetailResult.Grade) : resultBC.DetailResult.Grade; } } return res; }
/// <summary> /// /// </summary> /// <param name="snapshot"></param> /// <param name="moduleHRef"></param> /// <param name="bcId"></param> /// <returns></returns> public static Double? GetBusinessCriteriaModuleGrade(Snapshot snapshot, Int32 moduleId, Constants.BusinessCriteria bcId, bool Round) { double? res = null; if (null != snapshot && null != snapshot.BusinessCriteriaResults) { double? result = null; result = snapshot.BusinessCriteriaResults .Where(_ => _.Reference.Key == (Int32)bcId && _.ModulesResult != null) .SelectMany(_ => _.ModulesResult) .Where(_ => _.Module.Id == moduleId && _.DetailResult != null) .Select(_ => _.DetailResult.Grade) .FirstOrDefault(); if (result != null) { res = Round ? MathUtility.GetRound(result) : result; } } return res; }