Example #1
0
        public void Test_average_difference()
        {
            var estimates = new List <double>
            {
                100, 50, 300, 200, 130
            };
            var highestBids = new List <double>
            {
                160, 100, 600, 400, 230
            };

            var difference = OfferUtility.GetAverageDifference(highestBids, estimates);

            Assert.Equal(142, difference);
        }
        public async Task <IActionResult> AllAuctions(DateTime?date = null)
        {
            var stapleVM       = new StapleViewModel();
            var highestBidList = new List <double>();
            var estimateList   = new List <double>();

            var auctionItems = await _auctionFacade.GetAllAuctionsAsync();

            if (date.HasValue)
            {
                auctionItems = auctionItems.Where(a => a.StartDate.Month == date.Value.Month).ToArray();
            }

            if (auctionItems.Length == 0)
            {
                stapleVM.WinningBidAvg = 0;
                stapleVM.EstimateAvg   = 0;
                stapleVM.Difference    = 0;

                return(PartialView("_AuctionList", stapleVM));
            }

            foreach (var auction in auctionItems)
            {
                auction.OfferList.AddRange(await _auctionFacade.GetAllOffersAsync((int)auction.Id));
                if (auction.OfferList.Count > 0)
                {
                    estimateList.Add((double)auction.Estimate);
                    highestBidList.Add(OfferUtility.GetHighestBid(auction.OfferList));
                }
            }

            stapleVM.WinningBidAvg = highestBidList.Average();
            stapleVM.EstimateAvg   = estimateList.Average();
            stapleVM.Difference    = OfferUtility.GetAverageDifference(highestBidList, estimateList);

            return(PartialView("_AuctionList", stapleVM));
        }