コード例 #1
0
        public ActionResult Index(String faction = "horde", String realm = "bonechewer", Int32 count = 20, Int32 results = 25, Int32 buymin = 250)
        {
            var StartDate = DateTime.Today.Subtract(new TimeSpan(3, 0, 0, 0));

            // EqulityComparer for Item
            var itemComparer = new GenericEqualityComparer<Item>(
                (a, b) => a.ID == b.ID,
                (a) => a.GetHashCode()
            );
            // Get a set of Item:IE<Auction>
            var items = (from a in wac.Auctions
                           where a.MyAuctionHouse.Realm == realm
                              && a.MyAuctionHouse.Faction == faction
                              && a.TimeStamp >= StartDate
                              && a.TimeStamp <= DateTime.Now
                              && a.Buyout > 0
                           select a.MyItem).ToList();

            items = items.Distinct(itemComparer).ToList();

            // result collection
            ConcurrentBag<AuctionSummary> bag = new ConcurrentBag<AuctionSummary>();
            Parallel.ForEach(items, new ParallelOptions { MaxDegreeOfParallelism = 8 }, (itemAuctions) =>
                {
                    AuctionSummary ret = new AuctionSummary();
                    AuctionAPIController api = new AuctionAPIController();

                    var result = api.SingleZStats(realm, faction, itemAuctions.ID, StartDate, DateTime.Now, .15, 250);

                    // If there is no variance, there is no volatility
                    if (result.StdDev != 0.0 && result.AvgSeen >= count)
                    {
                        ret.ItemID = itemAuctions.ID;
                        ret.ItemName = itemAuctions.Name;
                        ret.Mean = Math.Round(result.Mean, 4);
                        ret.MinBuyout = result.CurrMin;
                        ret.StdDev = Math.Round(result.StdDev, 4);
                        ret.ZValue = Math.Round(result.ZValue, 4);

                        bag.Add(ret);
                    }
                }
            );

            var vmIndex = new HomeIndexVM() { Faction = faction, Realm = realm };
            vmIndex.Items = bag.OrderBy(a => a.ZValue).Take(results).ToList();

            ViewData["faction"] = faction;
            ViewData["realm"] = realm;

            return View(vmIndex);
        }
コード例 #2
0
        //
        // GET: /Auction/
        public ActionResult Item(Int32 id, String faction = "horde", String realm = "bonechewer", Int32 numPriceCat = 10)
        {
            AuctionAPIController api = new AuctionAPIController();
            String offFaction = faction == "horde" ? "alliance" : "horde";

            AuctionItemVM vm = new AuctionItemVM();

            var item = wac.Items.Find(id);
            if (item == null)
                return new HttpNotFoundResult("No Items found!");

            vm.ItemName = item.Name;
            vm.Faction = faction;
            vm.Realm = realm;

            // we get the most recent time so that we can get a cross-section of
            // the most recent scan
            DateTime startDate = wac.Auctions.Select(a => a.TimeStamp).Max();
            var factionItems = (from auc in wac.Auctions
                               where auc.MyAuctionHouse.Realm == realm
                                    && auc.MyAuctionHouse.Faction == faction
                                    && auc.ItemID == id
                                    && auc.TimeStamp == startDate
                               select auc).ToList();
            var offFactionItems = (from auc in wac.Auctions
                                   where auc.MyAuctionHouse.Realm == realm
                                        && auc.MyAuctionHouse.Faction == offFaction
                                        && auc.ItemID == id
                                        && auc.TimeStamp == startDate
                                   select auc).ToList();

            IEnumerable<long> allBuyoutPrices = factionItems.Union(offFactionItems).Select(a => a.Buyout / a.Quanity).Distinct();
            Int32 uniquePrices = allBuyoutPrices.Count();
            // Note Cats refers to categories
            Int32 numberOfCats = uniquePrices < numPriceCat ? uniquePrices : numPriceCat;
            Int64[] catPriceBreakdown = new Int64[numberOfCats];

            // Used to calculate our category ranges
            var bottom = allBuyoutPrices.Min();
            var top = allBuyoutPrices.Max();
            var diff = (top - bottom) / numberOfCats;

            // Actual category range calculation
            for (int i = 0; i < catPriceBreakdown.Length; ++i)
            {
                    catPriceBreakdown[i] = bottom + (diff * i);
            }

            // Category structure
            vm.Data.Primary = new KeyValuePair<long, int>[numberOfCats];
            vm.Data.Off = new KeyValuePair<long, int>[numberOfCats];
            // here we get the number of items in certain price ranges to get a
            // histogram of a pricing cross-section
            for (int i = 0; i < vm.Data.Primary.Length; ++i )
            {
                if(i != vm.Data.Primary.Length -1)
                {
                    vm.Data.Primary[i] = new KeyValuePair<long, int>(
                        // the bottom price for the histogram category
                        bottom + (i * diff),
                        (from a in factionItems
                         where (a.Buyout / a.Quanity) >= bottom + (i * diff)
                            && (a.Buyout / a.Quanity) < bottom + ((i + 1) * diff)
                         select (int?)a.Quanity).Sum() ?? 0
                    );

                    vm.Data.Off[i] = new KeyValuePair<long, int>(
                        // the bottom price for the histogram category
                        bottom + (i * diff),
                        (from a in offFactionItems
                         where (a.Buyout / a.Quanity) >= bottom + (i * diff)
                            && (a.Buyout / a.Quanity) < bottom + ((i + 1) * diff)
                         select (int?)a.Quanity).Sum() ?? 0
                    );

                }
                else
                {
                    vm.Data.Primary[i] = new KeyValuePair<long,int>(
                        // the bottom price for category
                        bottom + (i * diff),
                        // number of items in range
                        factionItems.Where(a => a.Buyout >= bottom + (i * diff)).Sum(a => (int?)a.Quanity) ?? 0
                    );

                    vm.Data.Off[i] = new KeyValuePair<long, int>(
                        // the bottom price for category
                        bottom + (i * diff),
                        // number of items in range
                        offFactionItems.Where(a => a.Buyout >= bottom + (i * diff)).Sum(a => (int?)a.Quanity) ?? 0
                    );
                }
            }

            DateTime historicalStart = DateTime.Today.Subtract(new TimeSpan(30,0,0,0,0));
            vm.HistoryData = api.HistoricalData(realm, faction, id, historicalStart, DateTime.UtcNow);

            ViewData["faction"] = faction;
            ViewData["realm"] = realm;

            return View(vm);
        }