コード例 #1
0
        protected override void LoadBins(SignalAggregationMetricOptions options, Models.Signal signal)
        {
            var signalEventCountAggregationRepository = SignalEventCountAggregationRepositoryFactory
                                                        .Create();
            var signalEventCounts =
                signalEventCountAggregationRepository.GetSignalEventCountAggregationBySignalIdAndDateRange(
                    signal.SignalID, BinsContainers.Min(b => b.Start), BinsContainers.Max(b => b.End));

            if (signalEventCounts != null)
            {
                var concurrentBinContainers = new ConcurrentBag <BinsContainer>();
                //foreach (var binsContainer in binsContainers)
                Parallel.ForEach(BinsContainers, binsContainer =>
                {
                    var tempBinsContainer =
                        new BinsContainer(binsContainer.Start, binsContainer.End);
                    var concurrentBins = new ConcurrentBag <Bin>();
                    //foreach (var bin in binsContainer.Bins)
                    Parallel.ForEach(binsContainer.Bins, bin =>
                    {
                        if (signalEventCounts.Any(s => s.BinStartTime >= bin.Start && s.BinStartTime < bin.End))
                        {
                            var signalEventCountSum = 0;

                            switch (options.SelectedAggregatedDataType.DataName)
                            {
                            case "EventCount":
                                signalEventCountSum = signalEventCounts.Where(s =>
                                                                              s.BinStartTime >= bin.Start && s.BinStartTime < bin.End)
                                                      .Sum(s => s.EventCount);
                                break;
                            }
                            Bin newBin = new Bin
                            {
                                Start   = bin.Start,
                                End     = bin.End,
                                Sum     = signalEventCountSum,
                                Average = signalEventCountSum
                            };
                            concurrentBins.Add(newBin);
                        }
                        else
                        {
                            concurrentBins.Add(new Bin
                            {
                                Start   = bin.Start,
                                End     = bin.End,
                                Sum     = 0,
                                Average = 0
                            });
                        }
                    });
                    tempBinsContainer.Bins = concurrentBins.OrderBy(c => c.Start).ToList();
                    concurrentBinContainers.Add(tempBinsContainer);
                });
                BinsContainers = concurrentBinContainers.OrderBy(b => b.Start).ToList();
            }
        }
コード例 #2
0
        protected override void LoadBins(SignalAggregationMetricOptions options, Models.Signal signal)
        {
            var priorityAggregationRepository =
                PriorityAggregationDatasRepositoryFactory.Create();
            var priorityAggregations =
                priorityAggregationRepository.GetPriorityBySignalIdAndDateRange(
                    signal.SignalID, BinsContainers.Min(b => b.Start), BinsContainers.Max(b => b.End));

            if (priorityAggregations != null)
            {
                var concurrentBinContainers = new ConcurrentBag <BinsContainer>();
                //foreach (var binsContainer in binsContainers)
                Parallel.ForEach(BinsContainers, binsContainer =>
                {
                    var tempBinsContainer =
                        new BinsContainer(binsContainer.Start, binsContainer.End);
                    var concurrentBins = new ConcurrentBag <Bin>();
                    //foreach (var bin in binsContainer.Bins)
                    Parallel.ForEach(binsContainer.Bins, bin =>
                    {
                        if (priorityAggregations.Any(s => s.BinStartTime >= bin.Start && s.BinStartTime < bin.End))
                        {
                            var preemptionSum = 0;

                            switch (options.SelectedAggregatedDataType.DataName)
                            {
                            case "TotalCycles":
                                preemptionSum = priorityAggregations.Where(s =>
                                                                           s.BinStartTime >= bin.Start && s.BinStartTime < bin.End)
                                                .Sum(s => s.TotalCycles);
                                break;

                            case "PriorityNumber":
                                preemptionSum = priorityAggregations.Where(s =>
                                                                           s.BinStartTime >= bin.Start && s.BinStartTime < bin.End)
                                                .Sum(s => s.PriorityNumber);
                                break;

                            case "PriorityRequests":
                                preemptionSum = priorityAggregations.Where(s =>
                                                                           s.BinStartTime >= bin.Start && s.BinStartTime < bin.End)
                                                .Sum(s => s.PriorityRequests);
                                break;

                            case "PriorityServiceEarlyGreen":
                                preemptionSum = priorityAggregations.Where(s =>
                                                                           s.BinStartTime >= bin.Start && s.BinStartTime < bin.End)
                                                .Sum(s => s.PriorityServiceEarlyGreen);
                                break;

                            case "PriorityServiceExtendedGreen":
                                preemptionSum = priorityAggregations.Where(s =>
                                                                           s.BinStartTime >= bin.Start && s.BinStartTime < bin.End)
                                                .Sum(s => s.PriorityServiceEarlyGreen);
                                break;

                            default:
                                throw new Exception("Invalid Aggregate Data Type");
                            }

                            Bin newBin = new Bin
                            {
                                Start   = bin.Start,
                                End     = bin.End,
                                Sum     = preemptionSum,
                                Average = preemptionSum
                            };
                            concurrentBins.Add(newBin);
                        }
                        else
                        {
                            concurrentBins.Add(new Bin
                            {
                                Start   = bin.Start,
                                End     = bin.End,
                                Sum     = 0,
                                Average = 0
                            });
                        }
                    });
                    tempBinsContainer.Bins = concurrentBins.OrderBy(c => c.Start).ToList();
                    concurrentBinContainers.Add(tempBinsContainer);
                });
                BinsContainers = concurrentBinContainers.OrderBy(b => b.Start).ToList();
            }
        }