public ActionResult GetCsv(int hotelId)
        {
            HotelSettings     hotel = _db.HotelSettings.Find(hotelId);
            DefoConfiguration conf  = new DefoConfiguration(hotel.Settings);
            var total = conf.ConfigurationRoot.Categories.BookingPeriods.Any() ? conf.ConfigurationRoot.Categories.BookingPeriods.Count() : 1;
            Dictionary <int, string> stayNames    = new Dictionary <int, string>();
            Dictionary <int, string> bookingNames = new Dictionary <int, string>();

            for (int i = 0; i < conf.ConfigurationRoot.Categories.Total; i++)
            {
                int l  = (i / total);
                int b  = i - l * total;
                var bp = conf.ConfigurationRoot.Categories.BookingPeriods?.FirstOrDefault(c => c.Number == b);
                var sp = conf.ConfigurationRoot.Categories.StayPeriods?.FirstOrDefault(c => c.Number == l);
                bookingNames.Add(i, bp?.LowerBound + " - " + bp?.UpperBound);
                stayNames.Add(i, sp?.LowerBound + " - " + sp?.UpperBound);
            }
            var queryResult = _db.Calculations
                              .Include(c => c.Predictions)
                              .Where(c => c.HotelId == hotelId).ToList();

            var calcs = queryResult.GroupBy(c => c.PredictionDate.Date).Select(c => c.OrderBy(s => s.CalculatedOn).LastOrDefault()).ToList();
            var sb    = new StringBuilder();

            sb.AppendLine(string.Join(";", new string[] { "Date", "Room Type", "Meal Type", "Stay period", "Booking period", "People Number", "Price", "Expected Load", "Cancelation", "No Shows" }));
            foreach (var calc in calcs)
            {
                foreach (var pred in calc.Predictions)
                {
                    sb.AppendLine(string.Join(";", new string[] { calc.PredictionDate.ToShortDateString(), pred.RoomType.Name, pred.MealType.Name, stayNames[pred.CategoryType], bookingNames[pred.CategoryType], pred.PeopleNum.ToString(), pred.Price.ToString(), pred.ExpectedLoad.ToString(), pred.Cancelation.ToString(), pred.NoShows.ToString() }));
                }
            }
            return(File(Encoding.Default.GetBytes(sb.ToString()), System.Net.Mime.MediaTypeNames.Application.Octet, "ResultsCsv.csv"));
        }
        public async Task <ActionResult> Create([Bind(Include = "Id,RoomTypeId,MealTypeId,HotelId,RoomName,PeopleNum,Cancelation,Prepayment,City,HotelName,MealName")] Parser_RoomInfo parser_RoomInfo)
        {
            if (ModelState.IsValid)
            {
                db.Parser_RoomInfos.Add(parser_RoomInfo);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index", new { hotelId = parser_RoomInfo.HotelId }));
            }

            ViewBag.HotelId = parser_RoomInfo.HotelId;
            HotelSettings     hotel = db.HotelSettings.Find(parser_RoomInfo.HotelId);
            DefoConfiguration conf  = new DefoConfiguration(hotel.Settings);
            var roomTypes           = db.RoomTypes.Where(c => c.HotelId == parser_RoomInfo.HotelId).ToList();

            ViewBag.RoomTypes = new SelectList(roomTypes, "Id", "Name");

            if (conf?.ConfigurationRoot?.MealTypes?.MealTypeDescriptions != null)
            {
                var mealIds = conf?.ConfigurationRoot?.MealTypes?.MealTypeDescriptions.Select(c => c.Number);
                if (mealIds.Any())
                {
                    var mealTypes = db.MealTypes.Where(c => mealIds.Contains(c.Id)).ToList();
                    ViewBag.MealTypes = new SelectList(mealTypes, "Id", "Name");
                }
            }
            return(View(parser_RoomInfo));
        }
        // GET: Calculations
        public async Task <ActionResult> Index(int id)
        {
            HotelSettings hotel = await _db.HotelSettings.FindAsync(id);

            if (hotel == null)
            {
                return(HttpNotFound("The hotel not found."));
            }

            var calculations = await GetCalculations(0, id);

            DefoConfiguration conf = new DefoConfiguration(hotel.Settings);
            var total = conf.ConfigurationRoot.Categories.BookingPeriods.Any() ? conf.ConfigurationRoot.Categories.BookingPeriods.Count() : 1;
            Dictionary <int, string> stayNames    = new Dictionary <int, string>();
            Dictionary <int, string> bookingNames = new Dictionary <int, string>();

            for (int i = 0; i < conf.ConfigurationRoot.Categories.Total; i++)
            {
                int l  = (i / total);
                int b  = i - l * total;
                var bp = conf.ConfigurationRoot.Categories.BookingPeriods?.FirstOrDefault(c => c.Number == b);
                var sp = conf.ConfigurationRoot.Categories.StayPeriods?.FirstOrDefault(c => c.Number == l);
                bookingNames.Add(i, bp?.LowerBound + "-" + bp?.UpperBound);
                stayNames.Add(i, sp?.LowerBound + "-" + sp?.UpperBound);
            }
            ViewBag.Id           = id;
            ViewBag.Num          = 0;
            ViewBag.StayNames    = stayNames;
            ViewBag.BookingNames = bookingNames;
            return(View(calculations));
        }
        // GET: Parser_RoomInfo/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Parser_RoomInfo parser_RoomInfo = await db.Parser_RoomInfos.FindAsync(id);

            if (parser_RoomInfo == null)
            {
                return(HttpNotFound());
            }
            DefoConfiguration conf = new DefoConfiguration(parser_RoomInfo.Hotel.Settings);
            var roomTypes          = db.RoomTypes.Where(c => c.HotelId == parser_RoomInfo.HotelId).ToList();

            ViewBag.RoomTypes = new SelectList(roomTypes, "Id", "Name");

            if (conf?.ConfigurationRoot?.MealTypes?.MealTypeDescriptions != null)
            {
                var mealIds = conf?.ConfigurationRoot?.MealTypes?.MealTypeDescriptions.Select(c => c.Number);
                if (mealIds.Any())
                {
                    var mealTypes = db.MealTypes.Where(c => mealIds.Contains(c.Id)).ToList();
                    ViewBag.MealTypes = new SelectList(mealTypes, "Id", "Name");
                }
            }
            return(View(parser_RoomInfo));
        }
Beispiel #5
0
        public IEnumerable <Reservation> CreateDB(DateTime start, string settings, int hotelId)
        {
            var configuration = new DefoConfiguration(settings);
            var solver        = new CreateDBSolver(start, configuration.ConfigurationRoot);

            solver.Run();
            var bookings = solver.GetBookings();

            return(bookings.Select(c => new Reservation {
                CreatedOn = c.OrderTime, CheckInDate = c.CheckIn, OrderDate = c.OrderTime, DaysCount = c.LengthOfStay, HotelId = hotelId, MealTypeId = c.MealType, RoomPrice = c.PricePerNight, RoomTypeId = c.RoomType, ReservationStatus = MapStatus(c.Status), ReservationType = MapType(c.Type)
            }));
        }
        // GET: Parser_RoomInfo
        public async Task <ActionResult> Index(int hotelId)
        {
            var parser_RoomInfos = db.Parser_RoomInfos.Where(c => c.HotelId == hotelId).Include(p => p.Hotel);

            ViewBag.HotelId = hotelId;
            HotelSettings hotel = await db.HotelSettings.FindAsync(hotelId);

            DefoConfiguration conf = new DefoConfiguration(hotel.Settings);

            ViewBag.Config = conf;
            return(View(await parser_RoomInfos.ToListAsync()));
        }
Beispiel #7
0
        // GET: Configuration
        public async Task <ActionResult> Index(int hotelId)
        {
            ViewBag.HotelId = hotelId;
            HotelSettings hotel = await db.HotelSettings.FindAsync(hotelId);

            var roomTypes          = db.RoomTypes.Where(c => c.HotelId == hotelId).ToList();
            var mealTypes          = db.MealTypes.ToList();
            DefoConfiguration conf = new DefoConfiguration(hotel.Settings);
            var model = ConfigurationViewModel.Map(conf.ConfigurationRoot, roomTypes);

            model.RoomTypes.IsEditable = !hotel.IsSettingsBlocked;
            ViewBag.DbMealTypes        = new SelectList(mealTypes, "Id", "Name");
            ViewBag.DbRoomTypes        = new SelectList(roomTypes, "RoomTypeCode", "Name");
            return(View(model));
        }
Beispiel #8
0
        public IEnumerable <Parser_RoomData> Run(DateTime startDate, int planningHorizon,
                                                 IEnumerable <Parser_RoomInfo> rooms, string settings, string bookingHotelName, out double rating)
        {
            rating = 0.0;
            var configuration = new DefoConfiguration(settings);
            List <Parser_RoomData> results = new List <Parser_RoomData>();

            foreach (var items in rooms.GroupBy(c => new { c.City, c.PeopleNum }).ToList())
            {
                IBookingService service = new BookingService();
                var             result  = service.Run(startDate, startDate.AddDays(planningHorizon - 1), items.Select(c => new SearchRoomInfo {
                    Cancelation = c.Cancelation, City = c.City, HotelName = c.HotelName, MealName = c.MealName, PeopleNum = c.PeopleNum, Prepayment = c.Prepayment, RoomName = c.RoomName, RoomInfoId = c.Id
                }), configuration.ConfigurationRoot.Categories.StayPeriods?.Select(c => (int)(c.UpperBound + (c.LowerBound < 2?1: c.LowerBound)) / 2), bookingHotelName, out rating);
                results.AddRange(result.Select(c => new Parser_RoomData {
                    Parser_RoomInfoId = c.RoomInfoId, Price = c.Price, Rating = c.Rating, Date = c.Date, CreationDate = startDate, AverageOccupancy = c.AverageOccupancy, StayLength = c.StayLength
                }));
            }
            return(results);
        }
        // GET: Parser_RoomInfo/Create
        public ActionResult Create(int hotelId)
        {
            ViewBag.HotelId = hotelId;
            HotelSettings     hotel = db.HotelSettings.Find(hotelId);
            DefoConfiguration conf  = new DefoConfiguration(hotel.Settings);
            var roomTypes           = db.RoomTypes.Where(c => c.HotelId == hotelId).ToList();

            ViewBag.RoomTypes = new SelectList(roomTypes, "Id", "Name");

            if (conf?.ConfigurationRoot?.MealTypes?.MealTypeDescriptions != null)
            {
                var mealIds = conf?.ConfigurationRoot?.MealTypes?.MealTypeDescriptions.Select(c => c.Number);
                if (mealIds.Any())
                {
                    var mealTypes = db.MealTypes.Where(c => mealIds.Contains(c.Id)).ToList();
                    ViewBag.MealTypes = new SelectList(mealTypes, "Id", "Name");
                }
            }
            //ViewBag.MealTypes = conf?.ConfigurationRoot?.MealTypes?.MealTypeDescriptions.ToDictionary(c => c.Number.ToString(), c => c.DisplayName);
            return(View());
        }
Beispiel #10
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            var planningHorizon = int.Parse(ConfigurationManager.AppSettings["planningHorizon"]);  // 365
            var pastPeriod      = int.Parse(ConfigurationManager.AppSettings["pastPeriod"]);
            var startDate       = DateTime.ParseExact(ConfigurationManager.AppSettings["startDate"], "yyyy.MM.dd",
                                                      CultureInfo.InvariantCulture); // new DateTime(2011, 6, 24);
            var config = new DefoConfiguration();


            _solver = new Solver(startDate, planningHorizon, pastPeriod,
                                 new DummyDataProvider(startDate, ConfigurationManager.AppSettings["orders"], ConfigurationManager.AppSettings["inflation"], config),
                                 new MatLabProblemSolver(),
                                 config,
                                 new FloorForecastRounder(),
                                 new MatLabProblemTransformer());

            _solver.Run();

            //#region ExcelResults
            ////price and load
            //List<List<string[]>> strings = new List<List<string[]>>();
            //var hasValues = true;
            //var item = new List<string[]>();
            //item.Add(null);
            //strings.Add(item);

            //for (int d = 0; d < planningHorizon; ++d)
            //{
            //    item = new List<string[]>();
            //    var text = startDate.AddDays(d).ToShortDateString();
            //    string[] st = new string[2] { text, text };
            //    item.Add(st);
            //    strings.Add(item);
            //}
            //double profit = 0;
            //for (var r = 0; r < _solver.TotalRoomTypes; ++r)
            //    for (var c = 0; c < _solver.TotalCategories; ++c)
            //        for (var m = 0; m < _solver.TotalMealTypes; ++m)
            //        {
            //            hasValues = false;
            //            string text = (r + 1).ToString() + " " + (c + 1).ToString() + " " + (m + 1).ToString();
            //            item = strings.First();
            //            item.Add(new string[2] { text, text });
            //            for (int d = 0; d < planningHorizon; ++d)
            //            {
            //                item = strings.ElementAt(d + 1);
            //                var price = _solver.GetPrice(startDate.AddDays(d), r, c, m);
            //                if (price > 0)
            //                {
            //                    var load = _solver.GetExpectedLoad(startDate.AddDays(d), r, c, m);
            //                    profit += load * (price - _solver.GetOperationalCost(r, m));
            //                    item.Add(new string[2] { price.ToString("F2"), load.ToString() });
            //                    hasValues = true;
            //                }
            //                else
            //                    item.Add(new string[2] { "0", "0" });
            //            }
            //            if (!hasValues)
            //                strings.ForEach(k => k.Remove(k.Last()));
            //        }
            //System.IO.File.WriteAllLines(startDate.ToShortDateString() + ".csv", strings.Select(c => string.Join(";", c.Select(k => k == null ? null : k[0]).ToArray())));
            //System.IO.File.AppendAllLines(startDate.ToShortDateString() + ".csv", strings.Select(c => string.Join(";", c.Select(k => k == null ? null : k[1]).ToArray())));
            //System.IO.File.AppendAllText(startDate.ToShortDateString() + ".csv", "\n");
            //System.IO.File.AppendAllText(startDate.ToShortDateString() + ".csv", "Profit: "+ profit.ToString());
            //#endregion

            #region PrintResults

            PricesGrid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(80)
            });
            PriceCushionsGrid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(80)
            });
            LoadPredictionGrid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(80)
            });
            for (int i = 0; i < _solver.TotalCategories * _solver.TotalRoomTypes * _solver.TotalMealTypes; ++i)
            {
                PricesGrid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(80)
                });
                PriceCushionsGrid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(80)
                });
                LoadPredictionGrid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(80)
                });
            }
            PricesGrid.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(15)
            });
            PriceCushionsGrid.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(15)
            });
            LoadPredictionGrid.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(15)
            });
            for (int i = 0; i < planningHorizon; ++i)
            {
                PricesGrid.RowDefinitions.Add(new RowDefinition {
                    Height = new GridLength(15)
                });
                PriceCushionsGrid.RowDefinitions.Add(new RowDefinition {
                    Height = new GridLength(15)
                });
                LoadPredictionGrid.RowDefinitions.Add(new RowDefinition {
                    Height = new GridLength(15)
                });
            }

            for (int d = 0; d < planningHorizon; ++d)
            {
                TextBlock tx1 = new TextBlock {
                    Text = startDate.AddDays(d).ToShortDateString()
                };
                Grid.SetRow(tx1, d + 1);
                Grid.SetColumn(tx1, 0);
                PricesGrid.Children.Add(tx1);

                TextBlock tx2 = new TextBlock {
                    Text = startDate.AddDays(d).ToShortDateString()
                };
                Grid.SetRow(tx2, d + 1);
                Grid.SetColumn(tx2, 0);
                PriceCushionsGrid.Children.Add(tx2);

                TextBlock tx3 = new TextBlock {
                    Text = startDate.AddDays(d).ToShortDateString()
                };
                Grid.SetRow(tx3, d + 1);
                Grid.SetColumn(tx3, 0);
                LoadPredictionGrid.Children.Add(tx3);
            }

            string[] rooms = new string[config.ConfigurationRoot.RoomTypes.Total];

            foreach (var r in config.ConfigurationRoot.RoomTypes.RoomTypeDescriptions
                     .Where(r => !string.IsNullOrEmpty(r.Description)))
            {
                rooms[r.Number] = r.Description;
            }

            var categories = new string[config.ConfigurationRoot.Categories.Total];

            if (config.ConfigurationRoot.Categories.Descriptions != null)
            {
                foreach (var c in config.ConfigurationRoot.Categories.Descriptions
                         .Where(c => !string.IsNullOrEmpty(c.Description)))
                {
                    categories[c.Number] = c.Description;
                }
            }

            for (var r = 0; r < _solver.TotalRoomTypes; ++r)
            {
                for (var c = 0; c < _solver.TotalCategories; ++c)
                {
                    for (var m = 0; m < _solver.TotalMealTypes; ++m)
                    {
                        string text  = (rooms[r] ?? (r + 1).ToString()) + "-" + (categories[c] ?? (c + 1).ToString()) + "-" + (m + 1).ToString();
                        int    index = 1 + r * _solver.TotalCategories * _solver.TotalMealTypes + c * _solver.TotalMealTypes + m;
                        var    tx1   = new TextBlock {
                            Text = text
                        };
                        Grid.SetRow(tx1, 0);
                        Grid.SetColumn(tx1, index);
                        PricesGrid.Children.Add(tx1);

                        var tx2 = new TextBlock {
                            Text = text
                        };
                        Grid.SetRow(tx2, 0);
                        Grid.SetColumn(tx2, index);
                        PriceCushionsGrid.Children.Add(tx2);

                        var tx3 = new TextBlock {
                            Text = text
                        };
                        Grid.SetRow(tx3, 0);
                        Grid.SetColumn(tx3, index);
                        LoadPredictionGrid.Children.Add(tx3);
                    }
                }
            }

            for (int d = 0; d < planningHorizon; ++d)
            {
                for (int r = 0; r < _solver.TotalRoomTypes; ++r)
                {
                    for (int c = 0; c < _solver.TotalCategories; ++c)
                    {
                        for (int m = 0; m < _solver.TotalMealTypes; ++m)
                        {
                            int       index = 1 + r * _solver.TotalCategories * _solver.TotalMealTypes + c * _solver.TotalMealTypes + m;
                            TextBlock tx1   = new TextBlock {
                                Text = _solver.GetPrice(startDate.AddDays(d), r, c, m).ToString("F2")
                            };
                            Grid.SetRow(tx1, d + 1);
                            Grid.SetColumn(tx1, index);
                            PricesGrid.Children.Add(tx1);

                            TextBlock tx2 = new TextBlock {
                                Text = _solver.GetPriceCushion(startDate.AddDays(d), r, c, m).ToString("F2")
                            };
                            Grid.SetRow(tx2, d + 1);
                            Grid.SetColumn(tx2, index);
                            PriceCushionsGrid.Children.Add(tx2);

                            TextBlock tx3 = new TextBlock {
                                Text = _solver.GetExpectedLoad(startDate.AddDays(d), r, c, m).ToString()
                            };
                            Grid.SetRow(tx3, d + 1);
                            Grid.SetColumn(tx3, index);
                            LoadPredictionGrid.Children.Add(tx3);
                        }
                    }
                }
            }
            ((Button)sender).IsEnabled = false;

            #endregion
        }
Beispiel #11
0
 private int GetMealTypeIndex(int?Id, DefoConfiguration config)
 {
     return(Id.HasValue ? config.ConfigurationRoot.MealTypes.MealTypeDescriptions.FindIndex(k => k.Number == Id.Value) : 0);
 }
Beispiel #12
0
        public IEnumerable <Calculation> Run(DateTime startDate, int planningHorizon, int pastPeriod,
                                             IEnumerable <Reservation> reservations, IEnumerable <Inflation> inflations, IEnumerable <Event> events, IEnumerable <Parser_RoomData> parserRoomData,
                                             string settings, double rating)
        {
            //new DummyDataProvider(startDate, ConfigurationManager.AppSettings["orders"], ConfigurationManager.AppSettings["inflation"], settings)

            var configuration = new DefoConfiguration(settings);
            Dictionary <int, int> roomTypesIndexes = new Dictionary <int, int>();

            foreach (var r in configuration.ConfigurationRoot.RoomTypes.RoomTypeDescriptions)
            {
                roomTypesIndexes.Add(r.Number, configuration.ConfigurationRoot.RoomTypes.RoomTypeDescriptions.FindIndex(c => c.Number == r.Number));
            }
            Dictionary <int, int> mealTypesIndexes = new Dictionary <int, int>();

            if (configuration.ConfigurationRoot.MealTypes?.MealTypeDescriptions != null && configuration.ConfigurationRoot.MealTypes.MealTypeDescriptions.Any())
            {
                foreach (var m in configuration.ConfigurationRoot.MealTypes.MealTypeDescriptions)
                {
                    mealTypesIndexes.Add(m.Number, configuration.ConfigurationRoot.MealTypes.MealTypeDescriptions.FindIndex(c => c.Number == m.Number));
                }
            }
            var solver = new Solver(startDate, planningHorizon, pastPeriod,
                                    new DummyDataProvider(
                                        startDate,
                                        inflations.Select(i => new InflationCoef {
                Date = i.Date, Coef = i.Coef
            }).ToList(),
                                        reservations.Where(c => mealTypesIndexes.Keys.Contains(c.MealTypeId) && roomTypesIndexes.Keys.Contains(c.RoomTypeId)).
                                        Select(r => new InternalOrder
            {
                BookingTime  = r.OrderDate,
                CheckIn      = r.CheckInDate,
                PeopleNum    = r.PeopleNum,
                LengthOfStay = r.DaysCount,
                RoomPrice    = r.RoomPrice,
                MealPrice    = r.MealPrice,
                RoomType     = roomTypesIndexes[r.RoomTypeId],
                Status       = MapStatus(r.ReservationStatus),
                MealType     = mealTypesIndexes[r.MealTypeId],
                Type         = MapType(r.ReservationType)
            }).ToList(),
                                        configuration,
                                        events.Select(c => new InternalEvent {
                Name = c.Name, Coef = c.Coef, PriceCoef = c.PriceCoef, Start = c.Start, End = c.End
            }),
                                        parserRoomData?.Select(c => new InternalParserRoomData {
                AverageOccupancy = c.AverageOccupancy, Date = c.Date, HotelName = c.Parser_RoomInfo.HotelName, MealType = mealTypesIndexes[c.Parser_RoomInfo.MealTypeId], RoomType = roomTypesIndexes[c.Parser_RoomInfo.RoomTypeId], Price = c.Price, StayLength = c.StayLength
            })),
                                    new MatLabProblemSolver(),
                                    configuration,
                                    new FloorForecastRounder(),
                                    new MatLabProblemTransformer(), rating);

            solver.Run();

            List <Calculation> result = new List <Calculation>();

            for (int d = 0; d < planningHorizon; ++d)
            {
                var predictionDate = startDate.AddDays(d);

                List <Prediction> predictions = new List <Prediction>();
                for (int r = 0; r < solver.TotalRoomTypes; ++r)
                {
                    var rt    = configuration.ConfigurationRoot.RoomTypes.RoomTypeDescriptions[r];
                    var pnMin = rt.PeopleNum;
                    var pnMax = rt.PeopleNum;
                    if (configuration.ConfigurationRoot.RoomTypes.RoomTypeCoefs.Any())
                    {
                        var pn = configuration.ConfigurationRoot.RoomTypes.RoomTypeCoefs.Select(c => c.PeopleNum);
                        pnMin = Math.Min(pn.Min(), rt.PeopleNum);
                        pnMax = Math.Max(pn.Max(), rt.PeopleNum);
                    }
                    for (int c = 0; c < solver.TotalCategories; ++c)
                    {
                        for (int n = pnMin; n <= pnMax; n++)
                        {
                            for (int m = 0; m < solver.TotalMealTypes; ++m)
                            {
                                int mealTypeId = (int)MealTypeEnum.OB;
                                if (configuration.ConfigurationRoot.MealTypes?.MealTypeDescriptions != null && configuration.ConfigurationRoot.MealTypes.MealTypeDescriptions.Any())
                                {
                                    mealTypeId = configuration.ConfigurationRoot.MealTypes.MealTypeDescriptions[m].Number;
                                }
                                predictions.Add(new Prediction
                                {
                                    MealTypeId   = mealTypeId,
                                    CategoryType = c,
                                    RoomTypeId   = rt.Number,
                                    PeopleNum    = n,
                                    Price        = solver.GetPrice(predictionDate, r, c, m, n),
                                    Cancelation  = solver.GetCancelation(predictionDate, r, c, m),
                                    NoShows      = solver.GetNoShows(predictionDate, r, c, m),
                                    ExpectedLoad = solver.GetExpectedLoad(predictionDate, r, c, m)
                                });
                            }
                        }
                    }
                }
                result.Add(new Calculation
                {
                    PredictionDate = predictionDate,
                    Predictions    = predictions
                });
            }
            return(result);
        }
Beispiel #13
0
        public void RunGroupCalculation(DateTime start, DateTime end, IEnumerable <Reservation> reservations, IEnumerable <Reservation> groupReservations, IEnumerable <Calculation> predictions,
                                        string settings)
        {
            var configuration = new DefoConfiguration(settings);
            Dictionary <int, int> roomTypesIndexes = new Dictionary <int, int>();

            foreach (var r in configuration.ConfigurationRoot.RoomTypes.RoomTypeDescriptions)
            {
                roomTypesIndexes.Add(r.Number, configuration.ConfigurationRoot.RoomTypes.RoomTypeDescriptions.FindIndex(c => c.Number == r.Number));
            }
            Dictionary <int, int> mealTypesIndexes = new Dictionary <int, int>();

            if (configuration.ConfigurationRoot.MealTypes?.MealTypeDescriptions != null && configuration.ConfigurationRoot.MealTypes.MealTypeDescriptions.Any())
            {
                foreach (var m in configuration.ConfigurationRoot.MealTypes.MealTypeDescriptions)
                {
                    mealTypesIndexes.Add(m.Number, configuration.ConfigurationRoot.MealTypes.MealTypeDescriptions.FindIndex(c => c.Number == m.Number));
                }
            }
            groupSolver = new GroupSolver(DateTime.Today, configuration.ConfigurationRoot, start, end,
                                          new GroupDataProvider(reservations.Where(c => mealTypesIndexes.Keys.Contains(c.MealTypeId) && roomTypesIndexes.Keys.Contains(c.RoomTypeId)).
                                                                Select(r => new InternalOrder
            {
                BookingTime  = r.OrderDate,
                CheckIn      = r.CheckInDate,
                LengthOfStay = r.DaysCount,
                RoomPrice    = r.RoomPrice,
                MealPrice    = r.MealPrice,
                RoomType     = roomTypesIndexes[r.RoomTypeId],
                Status       = MapStatus(r.ReservationStatus),
                MealType     = mealTypesIndexes[r.MealTypeId],
                Type         = MapType(r.ReservationType)
            }).ToList(),
                                                                groupReservations.Where(c => mealTypesIndexes.Keys.Contains(c.MealTypeId) && roomTypesIndexes.Keys.Contains(c.RoomTypeId)).
                                                                Select(r => new InternalOrder
            {
                BookingTime  = r.OrderDate,
                CheckIn      = r.CheckInDate,
                LengthOfStay = r.DaysCount,
                RoomPrice    = r.RoomPrice,
                MealPrice    = r.MealPrice,
                RoomType     = roomTypesIndexes[r.RoomTypeId],
                Status       = MapStatus(r.ReservationStatus),
                MealType     = mealTypesIndexes[r.MealTypeId],
                Type         = MapType(r.ReservationType)
            }).ToList(), predictions.Select(c => c == null? null : new InternalCalculation
            {
                PredictionDate = c.PredictionDate,
                Predictions    = c.Predictions.Where(t => mealTypesIndexes.Keys.Contains(t.MealTypeId)).
                                 Select(s => new InternalPrediction
                {
                    Cancelation  = s.Cancelation,
                    CategoryType = s.CategoryType,
                    ExpectedLoad = s.ExpectedLoad,
                    MealType     = mealTypesIndexes.Keys.Contains(s.MealTypeId)? mealTypesIndexes[s.MealTypeId] : 0,
                    NoShows      = s.NoShows,
                    Price        = s.Price,
                    RoomType     = roomTypesIndexes[s.RoomTypeId]
                })
            }), configuration
                                                                ));


            groupSolver.Run();
        }