Ejemplo n.º 1
0
        /// <summary>
        /// Returns the ItemPrices of the items with the given item IDs
        /// </summary>
        /// <param name="itemIds">The items to search for</param>
        /// <returns>Dictionary containing all item prices for the given items</returns>
        public IDictionary <int, ItemPrices> GetItemPrices(ICollection <int> itemIds)
        {
            Dictionary <int, ItemPrices> prices = new Dictionary <int, ItemPrices>();

            try
            {
                var listings = priceService.FindAll(itemIds);
                foreach (var listing in listings)
                {
                    if (listing.Value.ItemId > 0)
                    {
                        var listingPrices = new ItemPrices()
                        {
                            HighestBuyOrder   = listing.Value.BuyOffers.UnitPrice,
                            BuyOrderQuantity  = listing.Value.BuyOffers.Quantity,
                            LowestSellListing = listing.Value.SellOffers.UnitPrice,
                            SellOrderQuantity = listing.Value.SellOffers.Quantity
                        };
                        prices.Add(listing.Key, listingPrices);
                    }
                }
            }
            catch (GW2DotNET.Common.ServiceException ex)
            {
                // Don't crash, just return null
                logger.Warn("Error finding prices: {0}", ex);
            }

            return(prices);
        }
Ejemplo n.º 2
0
        public async Task <ServiceResponse <GetPriceOfItemDto> > GetAllPricesOfItem(int id)
        {
            ServiceResponse <GetPriceOfItemDto> serviceResponse = new ServiceResponse <GetPriceOfItemDto>();
            var itemObj = new GetPriceOfItemDto();

            itemObj.Item = await _context.Items.FirstOrDefaultAsync(x => x.Id == id);

            if (itemObj.Item != null)
            {
                var itemPrices = await _context.ItemPrices.Where(x => x.ItemId == id).Select(y => new { receipt = y.ReceiptId, price = y.Price }).ToListAsync();

                itemObj.Prices = new List <ItemPrices>();
                foreach (var price in itemPrices)
                {
                    var prc = new ItemPrices();
                    prc.Date = await _context.Receipts.Where(x => x.Id == price.receipt).Select(x => x.Date.Date).FirstOrDefaultAsync();

                    prc.Price = price.price;
                    prc.shop  = await _context.Receipts.Where(x => x.Id == price.receipt).Select(x => x.Shop).FirstOrDefaultAsync();

                    itemObj.Prices.Add(prc);
                }
                serviceResponse.Data = itemObj;
            }
            else
            {
                serviceResponse.Success = false;
                serviceResponse.Message = "Could not find the item.";
            }
            return(serviceResponse);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns the ItemPrices of the item with the given item ID
        /// </summary>
        /// <param name="itemId">the item to retrieve the prices for</param>
        /// <returns>The prices for the item</returns>
        public ItemPrices GetItemPrices(int itemId)
        {
            ItemPrices itemPrices = null;

            try
            {
                var prices = priceService.Find(itemId);
                if (prices != null && prices.ItemId > 0)
                {
                    itemPrices = new ItemPrices()
                    {
                        HighestBuyOrder   = prices.BuyOffers.UnitPrice,
                        BuyOrderQuantity  = prices.BuyOffers.Quantity,
                        LowestSellListing = prices.SellOffers.UnitPrice,
                        SellOrderQuantity = prices.SellOffers.Quantity
                    };
                }
            }
            catch (GW2DotNET.Common.ServiceException ex)
            {
                // Don't crash, just return null
                logger.Warn("Error finding prices for itemId {0}: {1}", ex);
            }

            return(itemPrices);
        }
Ejemplo n.º 4
0
        public override global::System.Data.DataSet Clone()
        {
            ItemPrices cln = ((ItemPrices)(base.Clone()));

            cln.InitVars();
            cln.SchemaSerializationMode = this.SchemaSerializationMode;
            return(cln);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Reads the JSON representation of the object.
        /// </summary>
        /// <param name="reader">The <see cref="T:Newtonsoft.Json.JsonReader" /> to read from.</param>
        /// <param name="objectType">Type of the object.</param>
        /// <param name="existingValue">The existing value of object being read.</param>
        /// <param name="serializer">The calling serializer.</param>
        /// <returns>The object value.</returns>
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
                                        JsonSerializer serializer)
        {
            var result = new ItemPrices();

            serializer.Converters.Add(new EmdRowCollectionJsonConverter <ItemPrices.ItemPriceEntry>());
            result.Prices = serializer.Deserialize <EmdRowCollection <ItemPrices.ItemPriceEntry> >(reader);
            return(result);
        }
Ejemplo n.º 6
0
        public double GetPrice(DateTime dateTime)
        {
            if (ItemPrices.Count > 0)
            {
                var maxDate = ItemPrices.Where(i => i.ScheduleDate <= dateTime).Max(i => i.ScheduleDate);

                return(ItemPrices.FirstOrDefault(i => i.ScheduleDate == maxDate)?.Amount ?? 0);
            }

            return(0);
        }
    // Buying a beer from the pub
    void BuyDrink()
    {
        // Character pays the price of beer, owner gets the money, drink stores go down and character hunger increases slightly
        ItemPrices prices = GameObject.Find("Plane").GetComponent <ItemPrices>();

        characterStats.currentMoney -= prices.beerPrice;
        buildingInside.GetComponent <BuildingStats>().ownedBy.GetComponent <CharacterStats>().currentMoney += prices.beerPrice;
        buildingInside.GetComponent <BuildingStats>().drinkStores[0] = BuildingParts.DrinkStores.None;
        characterStats.currentHunger += 10;
        isDoingHobby = false;
    }
Ejemplo n.º 8
0
        public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(global::System.Xml.Schema.XmlSchemaSet xs)
        {
            ItemPrices ds = new ItemPrices();

            global::System.Xml.Schema.XmlSchemaComplexType type     = new global::System.Xml.Schema.XmlSchemaComplexType();
            global::System.Xml.Schema.XmlSchemaSequence    sequence = new global::System.Xml.Schema.XmlSchemaSequence();
            global::System.Xml.Schema.XmlSchemaAny         any      = new global::System.Xml.Schema.XmlSchemaAny();
            any.Namespace = ds.Namespace;
            sequence.Items.Add(any);
            type.Particle = sequence;
            global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable();
            if (xs.Contains(dsSchema.TargetNamespace))
            {
                global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream();
                global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream();
                try {
                    global::System.Xml.Schema.XmlSchema schema = null;
                    dsSchema.Write(s1);
                    for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();)
                    {
                        schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current));
                        s2.SetLength(0);
                        schema.Write(s2);
                        if ((s1.Length == s2.Length))
                        {
                            s1.Position = 0;
                            s2.Position = 0;
                            for (; ((s1.Position != s1.Length) &&
                                    (s1.ReadByte() == s2.ReadByte()));)
                            {
                                ;
                            }
                            if ((s1.Position == s1.Length))
                            {
                                return(type);
                            }
                        }
                    }
                }
                finally {
                    if ((s1 != null))
                    {
                        s1.Close();
                    }
                    if ((s2 != null))
                    {
                        s2.Close();
                    }
                }
            }
            xs.Add(dsSchema);
            return(type);
        }
        public void Should_not_allow_order_line_if_a_price_is_not_defined()
        {
            var item1 = Guid.NewGuid();
            var item2 = Guid.NewGuid();

            var orderDto = new OrderDto().WithOrderLine(item1, 1);

            var prices = new ItemPrices(); // no price defined

            itemRepository.Setup(repository => repository.GetPrices(item1)).Returns(prices);

            var sut   = CreateSut();
            var order = sut.CreateOrder(orderDto);
        }
        public void Should_create_order_with_item_prices()
        {
            var item1 = Guid.NewGuid();
            var item2 = Guid.NewGuid();

            var orderDto = new OrderDto()
                           .WithOrderLine(item1, 1)
                           .WithOrderLine(item2, 2);

            var prices = new ItemPrices()
                         .WithPrice(item1, Money.From(10, Currency.EUR))
                         .WithPrice(item2, Money.From(12, Currency.EUR));

            itemRepository.Setup(repository => repository.GetPrices(item1, item2)).Returns(prices);

            var sut   = CreateSut();
            var order = sut.CreateOrder(orderDto);

            Assert.AreEqual(2, order.OrderLines.Count);
            Assert.IsTrue(order.OrderlineValueIs(item1, Money.From(10, Currency.EUR)));
            Assert.IsTrue(order.OrderlineValueIs(item2, Money.From(24, Currency.EUR)));
        }
Ejemplo n.º 11
0
 private IEnumerable <OrderLine> BuildDomainOrderLines(ItemPrices itemPrices)
 {
     return(OrderLines?.Select(dto =>
                               new OrderLine(dto.ItemId, dto.Quantity, itemPrices.GetPrice(dto.ItemId))) ??
            new List <OrderLine>());
 }
Ejemplo n.º 12
0
        public Order ToDomain(ItemPrices itemPrices)
        {
            var orderLines = BuildDomainOrderLines(itemPrices);

            return(new Order(orderLines));
        }
Ejemplo n.º 13
0
            public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedTableSchema(global::System.Xml.Schema.XmlSchemaSet xs)
            {
                global::System.Xml.Schema.XmlSchemaComplexType type     = new global::System.Xml.Schema.XmlSchemaComplexType();
                global::System.Xml.Schema.XmlSchemaSequence    sequence = new global::System.Xml.Schema.XmlSchemaSequence();
                ItemPrices ds = new ItemPrices();

                global::System.Xml.Schema.XmlSchemaAny any1 = new global::System.Xml.Schema.XmlSchemaAny();
                any1.Namespace       = "http://www.w3.org/2001/XMLSchema";
                any1.MinOccurs       = new decimal(0);
                any1.MaxOccurs       = decimal.MaxValue;
                any1.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax;
                sequence.Items.Add(any1);
                global::System.Xml.Schema.XmlSchemaAny any2 = new global::System.Xml.Schema.XmlSchemaAny();
                any2.Namespace       = "urn:schemas-microsoft-com:xml-diffgram-v1";
                any2.MinOccurs       = new decimal(1);
                any2.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax;
                sequence.Items.Add(any2);
                global::System.Xml.Schema.XmlSchemaAttribute attribute1 = new global::System.Xml.Schema.XmlSchemaAttribute();
                attribute1.Name       = "namespace";
                attribute1.FixedValue = ds.Namespace;
                type.Attributes.Add(attribute1);
                global::System.Xml.Schema.XmlSchemaAttribute attribute2 = new global::System.Xml.Schema.XmlSchemaAttribute();
                attribute2.Name       = "tableTypeName";
                attribute2.FixedValue = "PricesDataTable";
                type.Attributes.Add(attribute2);
                type.Particle = sequence;
                global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable();
                if (xs.Contains(dsSchema.TargetNamespace))
                {
                    global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream();
                    global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream();
                    try {
                        global::System.Xml.Schema.XmlSchema schema = null;
                        dsSchema.Write(s1);
                        for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();)
                        {
                            schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current));
                            s2.SetLength(0);
                            schema.Write(s2);
                            if ((s1.Length == s2.Length))
                            {
                                s1.Position = 0;
                                s2.Position = 0;
                                for (; ((s1.Position != s1.Length) &&
                                        (s1.ReadByte() == s2.ReadByte()));)
                                {
                                    ;
                                }
                                if ((s1.Position == s1.Length))
                                {
                                    return(type);
                                }
                            }
                        }
                    }
                    finally {
                        if ((s1 != null))
                        {
                            s1.Close();
                        }
                        if ((s2 != null))
                        {
                            s2.Close();
                        }
                    }
                }
                xs.Add(dsSchema);
                return(type);
            }
Ejemplo n.º 14
0
    // Moves a character to the pub and picks actions if their task is to go drinking
    void GoDrinking()
    {
        GameObject findCounter = null;
        GameObject findPub     = null;
        GameObject getAll      = GameObject.Find("Plane").gameObject;

        // Searches all buildings for a pub
        for (int i = 0; i < getAll.transform.childCount; i++)
        {
            if (getAll.transform.GetChild(i).GetComponent <BuildingStats>() != null)
            {
                if (getAll.transform.GetChild(i).GetComponent <BuildingStats>().buildingType == BuildingParts.BuildingType.Pub)
                {
                    findPub = getAll.transform.GetChild(i).gameObject;
                    break;
                }
            }
        }

        // Find the counter inside the pub
        for (int i = 0; i < findPub.transform.childCount; i++)
        {
            if (findPub.transform.GetChild(i).GetComponent <BuildingPartsData>() != null)
            {
                BuildingPartsData obj = findPub.transform.GetChild(i).GetComponent <BuildingPartsData>();
                if (obj.furnitureType == BuildingParts.FurnitureType.ShopCounter)
                {
                    findCounter = obj.gameObject;

                    break;
                }
            }
        }

        // Choses between finding a seat and buying a beer
        if (!isDoingHobby)
        {
            ItemPrices prices = GameObject.Find("Plane").GetComponent <ItemPrices>();
            int        rand   = Random.Range(0, 10);
            // Small chance character will buy a beer if they can afford it, the pub has beer left, and the counter is manned by the owner
            if (rand > 8 && characterStats.currentMoney >= prices.beerPrice && findPub.GetComponent <BuildingStats>().drinkStores[0] != BuildingParts.DrinkStores.None &&
                findCounter.GetComponent <BuildingPartsData>().activated)
            {
                shopCounter = new Vector2(findCounter.transform.position.x + findCounter.GetComponent <ObjectNavOffset>().customerNavOffset.x,
                                          findCounter.transform.position.z + findCounter.GetComponent <ObjectNavOffset>().customerNavOffset.y);
                characterStats.nav.destination = new Vector3(shopCounter.x, 0, shopCounter.y);
            }
            // Large chance character will find a seat in the pub that isn't already occupied
            else
            {
                findChair = 0;
                while (findPub.transform.GetChild(findChair).GetComponent <BuildingPartsData>().furnitureType != BuildingParts.FurnitureType.Chair &&
                       !findPub.transform.GetChild(findChair).GetComponent <BuildingPartsData>().inUse)
                {
                    findChair = Random.Range(0, findPub.transform.childCount);
                }
                characterStats.nav.destination = findPub.transform.GetChild(findChair).transform.position;
            }
            isDoingHobby = true;
        }

        // Look for a new seat if the chair they are heading for was taken
        if (characterStats.nav.destination.x == findPub.transform.GetChild(findChair).transform.position.x&&
            characterStats.nav.destination.z == findPub.transform.GetChild(findChair).transform.position.z&&
            findPub.transform.GetChild(findChair).GetComponent <BuildingPartsData>().inUse&&
            (characterStats.nav.destination.x > transform.position.x + .8f || characterStats.nav.destination.x < transform.position.x - .8f ||
             characterStats.nav.destination.z > transform.position.z + .8f || characterStats.nav.destination.z < transform.position.z - .8f))
        {
            isDoingHobby = false;
        }

        // Buys a beer once the character makes it to the counter
        if (shopCounter != new Vector2(0, 0) && isDoingHobby)
        {
            if (new Vector2(transform.position.x, transform.position.z) == new Vector2(shopCounter.x, shopCounter.y))
            {
                BuyDrink();
                shopCounter = new Vector2(0, 0);
                Debug.Log(gameObject.name + " bought beer");
            }
        }
    }
Ejemplo n.º 15
0
 public void CreateItemPrices()
 {
     _itemPrices = new ItemPrices();
 }
Ejemplo n.º 16
0
        public async System.Threading.Tasks.Task NewAuction(SaveAuction auction, HypixelContext context)
        {
            if (!Program.Migrated)
            {
                if (auction.UId % 20 == 0) // don't spam the log
                {
                    Console.WriteLine("not yet migrated skiping flip");
                }
                return;
            }
            if (diabled && auction.UId % 5 != 0)
            {
                return; // don't run on full cap on my dev machine :D
            }
            var price = (auction.HighestBidAmount == 0 ? auction.StartingBid : (auction.HighestBidAmount * 1.1)) / auction.Count;

            // if(auction.Enchantments.Count == 0 && auction.Reforge == ItemReferences.Reforge.None)
            //    Console.WriteLine("easy item");

            var(relevantAuctions, oldest) = await GetRelevantAuctions(auction, context);

            long medianPrice = 0;

            if (relevantAuctions.Count < 2)
            {
                Console.WriteLine($"Could not find enough relevant auctions for {auction.ItemName} {auction.Uuid} ({auction.Enchantments.Count} {relevantAuctions.Count})");
                var itemId = ItemDetails.Instance.GetItemIdForName(auction.Tag, false);
                medianPrice = (long)(await ItemPrices.GetLookupForToday(itemId)).Prices.Average(p => p.Avg * 0.8 + p.Min * 0.2);
            }
            else
            {
                medianPrice = relevantAuctions
                              .OrderByDescending(a => a.HighestBidAmount)
                              .Select(a => a.HighestBidAmount / a.Count)
                              .Skip(relevantAuctions.Count / 2)
                              .FirstOrDefault();
            }



            var recomendedBuyUnder = medianPrice * 0.8;

            if (price > recomendedBuyUnder) // at least 20% profit
            {
                return;                     // not a good flip
            }

            relevantAuctionIds[auction.UId] = relevantAuctions.Select(a => a.UId == 0 ? AuctionService.Instance.GetId(a.Uuid) : a.UId).ToList();
            if (relevantAuctionIds.Count > 10000)
            {
                relevantAuctionIds.Clear();
            }
            var query = new ActiveItemSearchQuery()
            {
                Order  = SortOrder.LOWEST_PRICE,
                Limit  = 1,
                Filter = new Dictionary <string, string>()
                {
                    { "Bin", "true" }
                },
                name = auction.Tag
            };
            var lowestBin = Server.ExecuteCommandWithCache <ActiveItemSearchQuery, List <ItemPrices.AuctionPreview> >("activeAuctions", query);

            var flip = new FlipInstance()
            {
                MedianPrice   = (int)medianPrice,
                Name          = auction.ItemName,
                Uuid          = auction.Uuid,
                LastKnownCost = (int)price,
                Volume        = (float)(relevantAuctions.Count / (DateTime.Now - oldest).TotalDays),
                Tag           = auction.Tag,
                Bin           = auction.Bin,
                UId           = auction.UId,
                SellerName    = await PlayerSearch.Instance.GetNameWithCacheAsync(auction.AuctioneerId),
                LowestBin     = (await lowestBin).FirstOrDefault()?.Price
            };

            FlippFound(flip);
            if (auction.Uuid[0] == 'a') // reduce saves
            {
                await CacheService.Instance.SaveInRedis(FoundFlippsKey, Flipps);
            }
        }