public void IncidentMetricAggregateSuccess() { var incidents = new List <IncidentEntity>(); incidents.Add(new IncidentEntity() { TTD = 1, TTE = 2, TTF = 3 }); incidents.Add(new IncidentEntity() { TTD = 7, TTE = 8, TTF = 9 }); var agg = new IncidentMetricAggregate(incidents); var result = agg.Metrics(); Assert.Equal(4, result.mttd); Assert.Equal(5, result.mtte); Assert.Equal(6, result.mttf); Assert.Equal(15, result.mttm); }
public async Task <OperationProductDashboardRp> GetProductDashboard(int productId, DateTime start, DateTime end) { var product = await this._dbContext.FullLoadProduct(productId); var squadsData = await this._dbContext.SquadFeatures .Include(c => c.Squad) .Where(c => c.Feature.ProductId == productId).ToListAsync(); var incidentsData = await this._dbContext.IncidentMaps .Include(c => c.Incident) .Where(c => c.Feature.ProductId == productId).ToListAsync(); var sourceItems = await this._dbContext.GetSourceItemsByProduct(productId, start, end); var result = new OperationProductDashboardRp(); foreach (var source in product.Sources) { source.SourceItems = sourceItems.Where(c => c.SourceId == source.Id).ToList(); var measure = source.Measure(); result.Sources.Add(new SourceGetListRp() { Id = source.Id.Value, Measure = measure, Avatar = source.Avatar, CreatedBy = source.CreatedBy, CreatedOn = source.CreatedOn.Value, AvailabilityDefinition = source.AvailabilityDefinition, LatencyDefinition = source.LatencyDefinition, ExperienceDefinition = source.ExperienceDefinition, Name = source.Name }); } foreach (var feature in product.Features) { foreach (var indicator in feature.Indicators) { indicator.Source = product.Sources.Single(c => c.Id == indicator.SourceId); } foreach (var squadMap in squadsData.Where(c => c.FeatureId == feature.Id).ToList()) { squadMap.Feature = feature; feature.Squads.Add(squadMap); } var tmp = this._mapper.Map <FeatureGetListRp>(feature); var measure = feature.Measure(); tmp.LoadMeasure(measure); result.Features.Add(tmp); var featureIncidents = incidentsData.Where(c => c.FeatureId == feature.Id) .Select(c => c.Incident).ToList(); var incidentAggregate = new IncidentMetricAggregate(featureIncidents); var aggIncident = incidentAggregate.Metrics(); result.IncidentInformation[feature.Id.Value] = new { count = featureIncidents.Count, mttd = aggIncident.mttd, mtte = aggIncident.mtte, mttf = aggIncident.mttf, mttm = aggIncident.mttm }; result.FeatureMaps[feature.Id.Value] = feature.Indicators.OrderBy(c => c.Id).Select(c => c.SourceId).ToList(); result.SquadMaps[feature.Id.Value] = squadsData.Where(c => c.FeatureId == feature.Id) .Select(c => c.SquadId) .Distinct().ToList(); } foreach (var squad in squadsData.Select(c => c.Squad).Distinct(new SquadCompare())) { var tmp = this._mapper.Map <SquadGetListRp>(squad); result.Squads.Add(tmp); } int sloFails = 0; foreach (var journey in product.Journeys) { foreach (var map in journey.FeatureMap) { map.Feature = product.Features.Single(c => c.Id == map.FeatureId); } var measure = journey.Measure(); if (measure.Availability < journey.AvailabilitySlo) { sloFails += 1; } var tmp = this._mapper.Map <JourneyGetListRp>(journey); result.Journeys.Add(tmp); result.JourneyMaps[journey.Id.Value] = journey.FeatureMap.OrderBy(c => c.Id).Select(c => c.FeatureId).ToList(); } result.Journeys = result.Journeys.OrderBy(c => c.Availability).ToList(); result.SLOFail = sloFails; result.SLOProportion = QualityUtils.CalculateFailProportion(product.Journeys.Count, sloFails); //TODO: change //result.SourceStats = new StatsValue(result.Sources.Select(c => c.Measure)); result.FeaturesStats = new StatsValue(result.Features.Select(c => c.Availability)); result.FeaturesCoverage = QualityUtils.CalculateProportion(product.Features.Count, squadsData.Select(c => c.FeatureId).Distinct().Count()); result.JourneysStats = new StatsValue(result.Journeys.Select(c => c.Availability)); return(result); }