public void UpdatePriceHistory(float price)
 {
     PriceHistory.Add(price);
     if (PriceHistory.Count > _priceHistoryLimit)
     {
         PriceHistory.RemoveAt(0);
     }
 }
Пример #2
0
        /// <summary>
        /// Sets new active price for the item, can update the database
        /// </summary>
        public void SetNewCurrentPrice(int price, DateTime purchaseTime, bool updateDatabase = false)
        {
            CurrentPriceInt = price;
            PriceHistory.Add(purchaseTime, price);

            if (updateDatabase)
            {
                DatabaseAccess.Access.UpdateNewCurrentPrice(ID, price, purchaseTime);
            }
        }
Пример #3
0
        public void UpdatePrice(PriceUpdate updateRequest)
        {
            if (updateRequest.Price == CurrentPrice)
            {
                return;
            }

            PriceHistory.Add(updateRequest);

            MonthlyPrices.Add(updateRequest);
            HistoricalPrices.Last().Price = PriceHistory.Where(pu => pu.Date.Year == updateRequest.Date.Year).Average(value => value.Price);
            YearlyPrices.ElementAt(updateRequest.Date.Month - 1).Price = PriceHistory.Where(pu => pu.Date.Year == updateRequest.Date.Year && pu.Date.Month == updateRequest.Date.Month).Average(value => value.Price);

            CurrentPrice = updateRequest.Price;
        }
Пример #4
0
        public override void StartDay(GameDate thisDate)
        {
            PriceHistory.Add(Price);

            if (Buffs.Any(buff => buff is RedBuff))
            {
                //Todo:ChangeToUseAnotherController
            }
            PriceController.StartDay(thisDate);
            TodayAnticipate = PriceController.GetPrice( );
            Price           = new StockPrice(TodayAnticipate.OpenPrice,
                                             TodayAnticipate.OpenPrice,
                                             TodayAnticipate.OpenPrice,
                                             TodayAnticipate.OpenPrice,
                                             0,
                                             0);
        }
Пример #5
0
        /// <summary>
        /// Set a new price to the product
        /// </summary>
        /// <param name="date"></param>
        /// <param name="price"></param>
        public void SetPrice(decimal?price, DateTimeOffset?date = null)
        {
            var p = new Price();

            if (!price.HasValue)
            {
                throw new ArgumentNullException($"{nameof(price)} is null");
            }
            if (!date.HasValue)
            {
                date = DateTimeOffset.Now;
            }

            p.Value = price;
            p.Date  = date;
            PriceHistory.Add(p);
        }
Пример #6
0
    public void Process()
    {
        float priceTargetApproach = CalculatePriceTargetApproach();
        float newPrice            = CurrentPrice() + priceTargetApproach;

        PriceHistory.Add(newPrice);

        if (IsPriceCloseToTarget() || IsPriceToTargetDistanceIncreasing())
        {
            SetNewTrendEffectAndPriceTarget();
        }
        else
        {
            lastPriceToTargetDistance = GetPriceToTargetDistance();
        }

        OnProcess(this);
    }
Пример #7
0
 private void SetInitialPrice()
 {
     PriceHistory.Add(Ceiling - randomGenerator.NextRandomFloat(0f, Ceiling));
 }
Пример #8
0
        public GameViewModel(Game game) : this()
        {
            GameID           = game.GameID;
            GameName         = game.GameName;
            URL              = game.URL;
            CoverImageURL    = game.CoverImageURL;
            StoryLine        = game.StoreLine;
            Summary          = game.Summary;
            FirstReleaseDate = game.FirstReleaseDate;
            Published        = game.Published.HasValue ? game.Published.Value : false;

            foreach (var gameGenre in game.GameGenres)
            {
                Genres.Add(
                    new GenreViewModel(gameGenre.Genre)
                    );
            }

            foreach (var gameTheme in game.GameThemes)
            {
                Themes.Add(
                    new ThemeViewModel(gameTheme.Theme)
                    );
            }

            foreach (var gameMode in game.GameModes)
            {
                Modes.Add(
                    new ModeViewModel(gameMode.Mode)
                    );
            }

            foreach (var gamePerspective in game.GamePerspectives)
            {
                Perspectives.Add(
                    new PerspectiveViewModel(gamePerspective.Perspective)
                    );
            }

            foreach (var gameScreenshots in game.GameScreenshots)
            {
                Screenshots.Add(
                    new ScreenshotViewModel(gameScreenshots.Screenshot)
                    );
            }

            foreach (var gamePlatform in game.GamePlatforms)
            {
                Platforms.Add(
                    new PlatformViewModel(
                        gamePlatform.Platform,
                        gamePlatform.ReleaseDate.Value)
                    );

                foreach (var history in gamePlatform.VendorGameHistories)
                {
                    PriceHistory.Add(
                        new PriceHistoryViewModel(history)
                        );
                }
            }


            if (PriceHistory.Count() > 0)
            {
                TodaysPrices  = PriceHistory?.Where(ph => ph.CreatedDate >= DateTime.Today).ToList();
                Cheapest      = TodaysPrices?.GroupBy(ph => ph.Price)?.OrderBy(ph => double.Parse(ph.Key))?.FirstOrDefault()?.Select(ph => ph).ToList();
                CheapestPrice = Cheapest?.FirstOrDefault().Price;
            }

            foreach (var settings in game.GamePlatforms.Select(gp => gp.VendorGameSettings))
            {
                foreach (var setting in settings)
                {
                    Settings.Add(new VendorGameSettingViewModel(setting));
                }
            }
        }
        private static void ProcessVehicleListOnPage(HtmlNodeCollection vehicleListItems, string DealerName, ref List <VEHICLE> PreviouslyFoundVehicles, string Market)
        {
            if (vehicleListItems == null)
            {
                return;
            }

            char[] killcomma = { ',' };
            foreach (HtmlNode vehicle in vehicleListItems)
            {
                HtmlNode VehicleNode      = vehicle.SelectSingleNode("div[@data-vin]");
                string   VehicleVIN       = VehicleNode.Attributes["data-vin"].Value.ToString();
                string   VehicleBodyStyle = VehicleNode.Attributes["data-bodyStyle"].Value.ToString();
                string   VehicleMake      = VehicleNode.Attributes["data-make"].Value.ToString();
                string   VehicleYear      = VehicleNode.Attributes["data-year"].Value.ToString();
                string   VehicleModel     = VehicleNode.Attributes["data-model"].Value.ToString();
                string   VehicleTrim      = VehicleNode.Attributes["data-trim"].Value.ToString();
                string   VehicleExtColor  = VehicleNode.Attributes["data-exteriorcolor"].Value.ToString();

                VEHICLE ExistingVehicle = VehicleDBManager.GetVehicleByVIN(VehicleVIN);
                List <VehiclePriceHistory> PriceHistory = null;
                bool Existing = false;

                // Check this vehicle against the list of previously found vehicles.
                // If it is found, remove it from the list, which ultimately removes it
                // from the "sold vehicle" list.
                if (ExistingVehicle != null && PreviouslyFoundVehicles != null)
                {
                    Existing     = true;
                    PriceHistory = RetrieveHistory(ExistingVehicle.VEHICLE_HISTORY);
                    var FoundThisOne = (from v in PreviouslyFoundVehicles
                                        where v.VIN == VehicleVIN
                                        select v).SingleOrDefault <VEHICLE>();
                    if (!ReferenceEquals(null, FoundThisOne))
                    {
                        PreviouslyFoundVehicles.Remove((VEHICLE)FoundThisOne);
                    }
                }
                else
                {
                    PriceHistory = new List <VehiclePriceHistory>();
                }

                HtmlNodeCollection VehicleNodeChildren = vehicle.ChildNodes;

                HtmlNode LinkNode    = VehicleNodeChildren[1].SelectSingleNode("div/div[@class='media']/a[@href]");
                string   VehicleLink = BaseURI + LinkNode.Attributes["href"].Value.ToString();

                HtmlNode           DescriptionNode  = VehicleNodeChildren[1].SelectSingleNode("div/div[@class='description']");
                HtmlNodeCollection DescriptionLists = VehicleNodeChildren[1].SelectNodes("div/div[@class='description']/dl");

                string VehicleEngine    = string.Empty;
                string VehicleTrans     = string.Empty;
                string IntColor         = string.Empty;
                string Mileage          = string.Empty;
                string StockNumber      = string.Empty;
                string ModelCode        = string.Empty;
                string VehicleDriveType = string.Empty;

                foreach (HtmlNode DList in DescriptionLists)
                {
                    string ItemType = string.Empty;
                    foreach (HtmlNode Item in DList.ChildNodes)
                    {
                        string Data = string.Empty;

                        if (Item.Name == "dt")
                        {
                            ItemType = Item.InnerText;
                            continue;
                        }
                        else if (Item.Name == "dd")
                        {
                            Data = Item.InnerText.Trim(killcomma);
                        }
                        else
                        {
                            continue;
                        }

                        switch (ItemType)
                        {
                        case "Engine:":
                            VehicleEngine = Data;
                            break;

                        case "Transmission:":
                            if (VehicleTrans.Length <= Data.Length)
                            {
                                VehicleTrans = Data;
                            }
                            break;

                        case "Exterior Color:":
                            if (Data != VehicleBodyStyle)
                            {
                                VehicleExtColor = Data;
                            }
                            break;

                        case "Interior Color:":
                            IntColor = Data;
                            break;

                        case "Stock #:":
                            StockNumber = Data;
                            break;

                        case "Mileage:":
                            Mileage = Data.Trim();
                            Mileage = Mileage.Replace(",", "");
                            Mileage = Mileage.Replace("miles", "");
                            if (Mileage.Length == 0 || Mileage == null || Mileage == " ")
                            {
                                Mileage = "0";
                            }
                            break;

                        case "Model Code:":
                            ModelCode = Data;
                            break;

                        case "Drive Line:":
                            VehicleDriveType = Data;
                            break;
                        }

                        ItemType = string.Empty;
                    }
                }

                // Stuff we might have to go to vehicle detail pages to retrieve: Mileage, Drive type, price

                // Mileage not on search page? (Snethkamp)
                if (Mileage == string.Empty || Mileage == "UNKNOWN" || Mileage == "0")
                {
                    Mileage = GetVehicleDetail(VehicleLink, "ddc-span6", "Mileage", "UNKNOWN");
                    Mileage = Mileage.Trim();
                    Mileage = Mileage.Replace(",", "");
                    Mileage = Mileage.Replace("miles", "");
                    Mileage = Mileage.Replace(@"\n", "");
                }

                // Vehicle Drive Type not on search page?
                if (VehicleDriveType == string.Empty || VehicleDriveType == "UNKNOWN")
                {
                    VehicleDriveType = GetVehicleDetail(VehicleLink, "item powertrain", "Drive type", "UNKNOWN");
                }
                if (VehicleDriveType == string.Empty || VehicleDriveType == "UNKNOWN")
                {
                    VehicleDriveType = GetVehicleDetail(VehicleLink, "powertrain", "Drive type", "UNKNOWN");
                }

                // Wheel Size
                string WheelSizeInches = GetVehicleDetail(VehicleLink, "item suspension-handling", "Wheel size", "UNKNOWN");
                if (WheelSizeInches == "UNKNOWN")
                {
                    WheelSizeInches = GetVehicleDetail(VehicleLink, "suspension-handling", "Wheel size", "UNKNOWN");
                }
                if (WheelSizeInches == "UNKNOWN")
                {
                    WheelSizeInches = GetVehicleDetail(VehicleLink, "standard-features", "Wheel Diameter", "UNKNOWN");
                }

                // Vehicle Price
                string   Price     = string.Empty;
                HtmlNode PriceNode = VehicleNodeChildren[1].SelectSingleNode("div/div[@class='pricing-area has-buttons']");
                HtmlNode ValueNode = PriceNode.SelectSingleNode("ul/li/span/span[@class='value']");
                if (ValueNode != null)
                {
                    Price = PriceNode.SelectSingleNode("ul/li/span/span[@class='value']").InnerText;
                    Price = Price.Replace("$", "");
                    Price = Price.Replace(",", "");
                    if (Price.Contains("/mo") || Price.Contains("month"))
                    {
                        Price = "0.00";
                    }
                }
                VehiclePriceHistory vph = new VehiclePriceHistory();
                vph.VIN           = VehicleVIN;
                vph.Date_Recorded = DateTime.Now.ToLocalTime();
                vph.Price         = Price;
                PriceHistory.Add(vph);

                // Carfax
                string   CarfaxURL  = string.Empty;
                HtmlNode CarfaxNode = DescriptionNode.SelectSingleNode("div[@class='calloutDetails']/ul/li[@class='carfax']");
                if (CarfaxNode != null)
                {
                    CarfaxURL = CarfaxNode.SelectSingleNode("a").Attributes["href"].Value.ToString();
                }

                // Images
                // List<int> ImageIds = GetandStoreVehicleImages(VehicleLink);

                //var strImageIdListcsv = string.Join(", ", ImageIds);
                // Console.WriteLine(strImageIdListcsv);

                if (ExistingVehicle != null)
                {
                    ExistingVehicle.VEHICLE_HISTORY   = SaveHistory(PriceHistory);
                    ExistingVehicle.BODY_STYLE        = VehicleBodyStyle;
                    ExistingVehicle.CARFAX_URL        = CarfaxURL;
                    ExistingVehicle.COLOR_EXTERIOR    = VehicleExtColor;
                    ExistingVehicle.COLOR_INTERIOR    = IntColor;
                    ExistingVehicle.CURRENT_PRICE     = Price;
                    ExistingVehicle.DATE_LAST_SEEN    = DateTime.Now;
                    ExistingVehicle.DEALERSHIP_NAME   = DealerName;
                    ExistingVehicle.DEALER_DETAIL_URL = VehicleDetailURL;
                    ExistingVehicle.DRIVE_TRAIN       = VehicleDriveType;
                    ExistingVehicle.ENGINE            = VehicleEngine;
                    ExistingVehicle.MAKE   = VehicleMake;
                    ExistingVehicle.MARKET = Market;
                    //ExistingVehicle.IMAGEIDCSV = strImageIdListcsv;
                    ExistingVehicle.MILEAGE         = Mileage;
                    ExistingVehicle.MODEL           = VehicleModel;
                    ExistingVehicle.MODEL_CODE      = ModelCode;
                    ExistingVehicle.STOCK_NUMBER    = StockNumber;
                    ExistingVehicle.TRANSMISSION    = VehicleTrans;
                    ExistingVehicle.TRIM            = VehicleTrim;
                    ExistingVehicle.VEHICLE_HISTORY = SaveHistory(PriceHistory);
                    ExistingVehicle.VIN             = VehicleVIN;
                    ExistingVehicle.WHEEL_SIZE      = WheelSizeInches;
                    ExistingVehicle.YEAR            = VehicleYear;
                    VehicleDBManager.UpdateVehicleRecord(ExistingVehicle);
                }
                else
                {
                    VEHICLE foundvehicle = new VEHICLE();
                    foundvehicle.BODY_STYLE        = VehicleBodyStyle;
                    foundvehicle.CARFAX_URL        = CarfaxURL;
                    foundvehicle.COLOR_EXTERIOR    = VehicleExtColor;
                    foundvehicle.COLOR_INTERIOR    = IntColor;
                    foundvehicle.CURRENT_PRICE     = Price;
                    foundvehicle.DATE_LAST_SEEN    = DateTime.Now;
                    foundvehicle.DEALERSHIP_NAME   = DealerName;
                    foundvehicle.DEALER_DETAIL_URL = VehicleDetailURL;
                    foundvehicle.DRIVE_TRAIN       = VehicleDriveType;
                    foundvehicle.ENGINE            = VehicleEngine;
                    foundvehicle.MAKE   = VehicleMake;
                    foundvehicle.MARKET = Market;
                    //foundvehicle.IMAGEIDCSV = strImageIdListcsv;
                    foundvehicle.MILEAGE         = Mileage;
                    foundvehicle.MODEL           = VehicleModel;
                    foundvehicle.MODEL_CODE      = ModelCode;
                    foundvehicle.STOCK_NUMBER    = StockNumber;
                    foundvehicle.TRANSMISSION    = VehicleTrans;
                    foundvehicle.TRIM            = VehicleTrim;
                    foundvehicle.VEHICLE_HISTORY = SaveHistory(PriceHistory);
                    foundvehicle.VIN             = VehicleVIN;
                    foundvehicle.WHEEL_SIZE      = WheelSizeInches;
                    foundvehicle.YEAR            = VehicleYear;
                    VehicleDBManager.InsertVehicle(foundvehicle);
                }

                Console.WriteLine($@"
        VIN : {VehicleVIN}  Found Previously? {Existing}
            {VehicleYear} {VehicleMake} {VehicleModel} {VehicleTrim} ({VehicleBodyStyle})
            Drivetrain: Engine: {VehicleEngine} | Transmission: {VehicleTrans} 
                        Drive type: {VehicleDriveType} | Wheel size: {WheelSizeInches}
            Color:      Exterior: {VehicleExtColor} | Interior: {IntColor} 
            Mileage:    {Mileage}
            Price:      {Price}
                        Stock #: {StockNumber} | Model Code: {ModelCode}  
            Direct URL: {VehicleLink}
            Carfax URL: {CarfaxURL}");

                VehicleVIN               = StockNumber = VehicleYear = VehicleMake = VehicleModel = ModelCode =
                    VehicleTrim          = VehicleEngine = VehicleTrans = VehicleDriveType = WheelSizeInches =
                        VehicleBodyStyle = VehicleExtColor = Mileage = IntColor = Price = CarfaxURL = VehicleLink = string.Empty;
            }
        }