Ejemplo n.º 1
0
        public override Task Execute(MessageData data)
        {
            ItemSearchQuery details = ItemPricesCommand.GetQuery(data);

            // temporary map none (0) to any
            if (details.Reforge == Reforge.None)
            {
                details.Reforge = Reforge.Any;
            }


            if (Program.LightClient && details.Start < DateTime.Now - TimeSpan.FromDays(7))
            {
                return(ClientProxy.Instance.Proxy(data));
            }

            var thread = ItemPrices.Instance.GetPriceFor(details);
            var res    = thread.Result;

            var maxAge = A_MINUTE;

            if (IsDayRange(details))
            {
                maxAge = A_DAY;
            }
            Console.WriteLine("made response");

            return(data.SendBack(data.Create("itemResponse", res, maxAge)));
        }
Ejemplo n.º 2
0
        internal async Task <Resonse> GetPriceFor(ItemSearchQuery details)
        {
            var itemId  = ItemDetails.Instance.GetItemIdForName(details.name, false);
            var itemTag = details.name;

            if (details.Reforge != ItemReferences.Reforge.Any ||
                (details.Enchantments != null && details.Enchantments.Count != 0)
                //|| details.Rarity != Tier.UNKNOWN
                || details.Tier != Tier.UNKNOWN ||
                details.Filter != null)
            {
                return(await QueryDB(details));
            }


            if (details.Start > DateTime.Now - TimeSpan.FromHours(1.1))
            {
                return(await RespondIntraHour(itemId, itemTag));
            }


            if (details.Start > DateTime.Now - TimeSpan.FromDays(1.01))
            {
                return(await RespondHourly(itemId, itemTag));
            }

            using (var context = new HypixelContext())
            {
                Console.WriteLine("query prices db ");
                var response = await context.Prices
                               .Where(p => p.ItemId == itemId && p.Date > details.Start && p.Date <= details.End).ToListAsync();

                return(FromList(response, itemTag));
            }
        }
Ejemplo n.º 3
0
        public override System.Threading.Tasks.Task Execute(MessageData data)
        {
            ItemSearchQuery details = GetQuery(data);



            Console.WriteLine($"Start: {details.Start} End: {details.End}");

            int hourAmount = DetermineHourAmount(details);

            var fromDB = ItemPrices.Instance.GetPriceFor(details);

            fromDB.Wait();

            var result = new List <Result>();

            result.AddRange(fromDB.Result.Prices.Select(p => new Result()
            {
                Count = p.Volume,
                Price = (int)p.Avg,
                End   = p.Date
            }));

            var response = GroupResponseByHour(result, hourAmount);

            var maxAge = 100;

            if (details.Start < DateTime.Now - TimeSpan.FromDays(2))
            {
                maxAge = A_DAY;
            }

            return(data.SendBack(data.Create("itemResponse", response, maxAge)));
        }
Ejemplo n.º 4
0
        private async Task <Resonse> QueryDB(ItemSearchQuery details)
        {
            using (var context = new HypixelContext())
            {
                var itemId = ItemDetails.Instance.GetItemIdForName(details.name);
                IQueryable <SaveAuction>   select   = CreateSelect(details, context, itemId);
                IEnumerable <AveragePrice> response = await AvgFromAuctions(itemId, select, details.Start > DateTime.Now - TimeSpan.FromDays(1.1));

                return(FromList(response.ToList(), details.name));
            }
        }
Ejemplo n.º 5
0
        private static int DetermineHourAmount(ItemSearchQuery details)
        {
            var hourAmount = 1;

            if (details.End - details.Start > TimeSpan.FromDays(6))
            {
                hourAmount = 4;
            }
            if (details.End - details.Start > TimeSpan.FromDays(10))
            {
                hourAmount = 12;
            }
            return(hourAmount);
        }
        public override Task Execute(MessageData data)
        {
            ItemSearchQuery details = ItemPricesCommand.GetQuery(data);

            if (Program.LightClient && details.Start < DateTime.Now - TimeSpan.FromDays(7))
            {
                return(ClientProxy.Instance.Proxy(data));
            }
            // temporary map none (0) to any
            if (details.Reforge == Reforge.None)
            {
                details.Reforge = Reforge.Any;
            }

            var res = ItemPrices.Instance.GetRecentAuctions(details);

            return(data.SendBack(data.Create("auctionResponse", res, A_MINUTE * 2)));
        }
Ejemplo n.º 7
0
        private IQueryable <SaveAuction> CreateSelect(ItemSearchQuery details, HypixelContext context, int itemId, int limit = 0, IQueryable <SaveAuction> select = null)
        {
            var min = DateTime.Now - TimeSpan.FromDays(35);

            if (details.Filter != null && details.Start < min)
            {
                throw new CoflnetException("filter_to_large", $"You are only allowed to filter for the last month, please set 'start' to a value greater than {min.AddHours(1).ToUnix()}");
            }
            if (select == null)
            {
                select = AuctionSelect(details.Start, details.End, context, itemId);
            }

            if (details.Filter != null && details.Filter.Count > 0)
            {
                details.Filter["ItemId"] = itemId.ToString();
                return(FilterEngine.AddFilters(select, details.Filter));
            }

            if (details.Enchantments != null && details.Enchantments.Any())
            {
                select = AddEnchantmentWhere(details.Enchantments, select, context, itemId, limit);
            }

            if (details.Reforge != ItemReferences.Reforge.Any)
            {
                select = select.Where(auction => auction.Reforge == details.Reforge);
            }


            if (details.Tier != Tier.UNKNOWN)
            {
                select = select.Where(a => a.Tier == details.Tier);
            }

            /*
             * if(details.Data != null && details.Data.Count > 0)
             * {
             *  var kv = details.Data.First();
             *  select = select.Where(a=>(a.NbtData.Data as Dictionary<string,object>)[kv.Key].ToString() == kv.Value);
             * }*/

            return(select);
        }
Ejemplo n.º 8
0
        public IEnumerable <AuctionPreview> GetRecentAuctions(ItemSearchQuery query, int amount = 12)
        {
            using (var context = new HypixelContext())
            {
                var itemId = ItemDetails.Instance.GetItemIdForName(query.name);

                var result = CreateSelect(query, context, itemId, amount)
                             .OrderByDescending(a => a.End).Take(amount).Select(a => new
                {
                    a.End,
                    Price = a.HighestBidAmount,
                    a.AuctioneerId,
                    a.Uuid
                }).ToList();
                return(result.Select(async a => new AuctionPreview()
                {
                    End = a.End,
                    Price = a.Price,
                    Seller = a.AuctioneerId,
                    Uuid = a.Uuid,
                    PlayerName = await PlayerSearch.Instance.GetNameWithCacheAsync(a.AuctioneerId)
                }).Select(a => a.Result).ToList());
            }
        }
Ejemplo n.º 9
0
 private static bool IsDayRange(ItemSearchQuery details)
 {
     return(details.Start < DateTime.Now - TimeSpan.FromDays(2));
 }