private static void SetTransportingTimeRelatedData(StatisticsData data, List <Baggage> baggage) { var allTransportingLogs = baggage.SelectMany(b => b.Log) .Where(log => log.Description.Contains(LoggingConstants.BagReceivedText)).ToList(); data.LongestTransportingTime = allTransportingLogs.DefaultIfEmpty().Max(log => log.TimeElapsed.TotalSeconds); data.ShortestTransportingTime = allTransportingLogs.DefaultIfEmpty().Min(log => log?.TimeElapsed.TotalSeconds ?? 0); var nodes = ChainLinkFactory.Nodes.OfType <ITransportingNode>().ToList(); var transportationWaits = allTransportingLogs.Select(log => CalculateLogWait(log, nodes)).OrderBy(t => t.Item2).ToList(); data.MinWaitingTimeAtTransporterOrQueue = transportationWaits.FirstOrDefault(); data.MaxWaitingTimeAtTransporterOrQueue = transportationWaits.LastOrDefault(); data.AverageWaitingTimePerTransporterOrQueue = transportationWaits .GroupBy(pair => pair.Item1, pair => pair.Item2) .Select(g => new KeyValuePair <string, double>(g.Key, g.Average(v => v))) .ToDictionary(x => x.Key, x => x.Value); }
private static void SetBsuRelatedStatistics(StatisticsData data, List <Baggage> baggages) { data.TotalBagsThatWentToBsu = baggages.Where(bag => bag.Log.Any(log => log.Description.Contains(typeof(BSU).Name))).ToList(); data.AverageBsuStayTimeInSeconds = data.TotalBagsThatWentToBsu.DefaultIfEmpty().Average(b => GetBsuStayTimeInSeconds(b)); data.MinBsuStayTimeInSeconds = data.TotalBagsThatWentToBsu.DefaultIfEmpty().Min(b => GetBsuStayTimeInSeconds(b)); data.MaxBsuStayTimeInSeconds = data.TotalBagsThatWentToBsu.DefaultIfEmpty().Max(b => GetBsuStayTimeInSeconds(b)); data.AverageBsuStayTimeInMinutes = data.TotalBagsThatWentToBsu.DefaultIfEmpty().Average(b => GetBsuStayTime(b)); data.MinBsuStayTimeInMinutes = (double)data.TotalBagsThatWentToBsu.DefaultIfEmpty().Min(b => GetBsuStayTime(b)); data.MaxBsuStayTimeInMinutes = (double)data.TotalBagsThatWentToBsu.DefaultIfEmpty().Max(b => GetBsuStayTime(b)); data.LongestSystemStayWithoutBsu = baggages.DefaultIfEmpty().Max(bag => (bag.Log.LastOrDefault()?.LogCreated - bag.Log.FirstOrDefault()?.LogCreated)?.TotalSeconds ?? 0 - GetBsuStayTimeInSeconds(bag)); data.ShortestSystemStayWithoutBsu = baggages.DefaultIfEmpty().Min(bag => (bag.Log.LastOrDefault()?.LogCreated - bag.Log.FirstOrDefault()?.LogCreated)?.TotalSeconds ?? 0 - GetBsuStayTimeInSeconds(bag)); }
public static StatisticsData CalculateStatistics(ISimulationSettings simulationSettings) { var baggage = Baggage.AllBaggage; var statisticsData = new StatisticsData(); try { SetDispatchedTimes(statisticsData, baggage); SetCollectedTimes(statisticsData, baggage); SetPscSucceededAndFailed(statisticsData, baggage); SetAscSucceededAndFailed(statisticsData, baggage); SetFlightDelays(statisticsData, baggage); SetTransferredBagsCount(statisticsData, baggage); SetBsuRelatedStatistics(statisticsData, baggage); SetTransportingTimeRelatedData(statisticsData, baggage); } catch (Exception e) { } return(statisticsData); }
private static void SetTransferredBagsCount(StatisticsData data, List <Baggage> baggages) { data.TotalTransferredBags = baggages.Where(bag => bag.Log.Any(log => log.Description.Contains(LoggingConstants.BagRedirectedToAnotherFlight))).ToList(); }
private static void SetAscSucceededAndFailed(StatisticsData data, List <Baggage> baggage) { data.AscFailedBags = baggage.Where(b => b.Log.Any(log => log.Description.Contains(LoggingConstants.AscCheckFailed))).ToList(); data.AscSucceededBags = baggage.Where(b => b.Log.Any(log => log.Description.Contains(LoggingConstants.AscCheckSucceeded))).ToList(); }