Ejemplo n.º 1
0
 public ItemIndexElement(string uUId, DateTime end, long price, ItemReferences.Reforge reforge, List <Enchantment> enchantments, long count, short bidCount)
 {
     UUId         = uUId;
     End          = end;
     Price        = price;
     Reforge      = reforge;
     Enchantments = enchantments;
     Count        = count;
     BidCount     = bidCount;
 }
Ejemplo n.º 2
0
        private static IQueryable <SaveAuction> GetSelect(
            SaveAuction auction,
            HypixelContext context,
            string clearedName,
            int itemId,
            DateTime youngest,
            int matchingCount,
            Enchantment ulti,
            List <Enchantment.EnchantmentType> highLvlEnchantList,
            DateTime oldest,
            ItemReferences.Reforge reforge,
            int limit = 60)
        {
            var select = context.Auctions
                         .Where(a => a.ItemId == itemId)
                         .Where(a => a.HighestBidAmount > 0)
                         .Where(a => a.Tier == auction.Tier);

            byte ultiLevel = 127;

            Enchantment.EnchantmentType ultiType = Enchantment.EnchantmentType.unknown;
            if (ulti != null)
            {
                ultiLevel = ulti.Level;
                ultiType  = ulti.Type;
            }

            if (relevantReforges.Contains(reforge))
            {
                select = select.Where(a => a.Reforge == reforge);
            }


            if (auction.ItemName != clearedName && clearedName != null)
            {
                select = select.Where(a => EF.Functions.Like(a.ItemName, "%" + clearedName));
            }
            else if (auction.Tag.StartsWith("PET"))
            {
                select = AddPetLvlSelect(auction, select);
            }
            else
            {
                select = select.Where(a => a.ItemName == clearedName);
            }

            if (auction.Tag == "MIDAS_STAFF" || auction.Tag == "MIDAS_SWORD")
            {
                try
                {
                    var val   = (long)auction.NbtData.Data["winning_bid"];
                    var keyId = NBT.GetLookupKey(auction.Tag);
                    select  = select.Where(a => a.NBTLookup.Where(n => n.KeyId == keyId && n.Value > val - 2_000_000 && n.Value < val + 2_000_000).Any());
                    oldest -= TimeSpan.FromDays(10);
                } catch
                {}
            }

            select = AddEnchantmentSubselect(auction, matchingCount, highLvlEnchantList, select, ultiLevel, ultiType);
            if (limit == 0)
            {
                return(select);
            }

            return(select
                   .Where(a => a.End > oldest && a.End < youngest)
                   //.OrderByDescending(a=>a.Id)
                   //.Include(a => a.NbtData)
                   .Take(limit));
        }
Ejemplo n.º 3
0
        private IEnumerable <Result> QueryDBFor(string itemName, DateTime start, DateTime end, ItemReferences.Reforge reforge, List <Enchantment> enchantments)
        {
            using (var context = new HypixelContext())
            {
                var tag        = ItemDetails.Instance.GetIdForName(itemName);
                var itemId     = ItemDetails.Instance.GetItemIdForName(itemName);
                var mainSelect = context.Auctions
                                 .Where(auction => /*auction.ItemName == itemName || */ auction.ItemId == itemId);


                var selectWithTime = mainSelect.Where(auction => auction.End > start && auction.End < end);

                // override select if there is no cache anyways
                if (end == default(DateTime))
                {
                    selectWithTime = mainSelect.Where(auction => auction.End > start && auction.End < end);
                }


                var moreThanOneBidQuery = selectWithTime
                                          .Where(auction => auction.HighestBidAmount > 1);



                if (enchantments != null && enchantments.Any())
                {
                    moreThanOneBidQuery = AddEnchantmentWhere(enchantments, moreThanOneBidQuery);
                }

                if (reforge != Reforge.None)
                {
                    moreThanOneBidQuery = moreThanOneBidQuery.Where(auction => auction.Reforge == reforge);
                }


                return(moreThanOneBidQuery

                       .GroupBy(item => new { item.End.Year, item.End.Month, item.End.Day, item.End.Hour })
                       .Select(item =>
                               new
                {
                    End = new DateTime(item.Key.Year, item.Key.Month, item.Key.Day, item.Key.Hour, 0, 0),
                    Price = (int)item.Average(a => ((int)a.HighestBidAmount) / a.Count), ///(a.Count == 0 ? 1 : a.Count)),
                    Count = item.Sum(a => a.Count)
                                                                                         //Bids =  (long) item.Sum(a=> a.Bids.Count)
                }).ToList().Select(i => new Result()
                {
                    Count = i.Count, End = i.End, Price = i.Price
                }));

                // cache result
            }
        }