Пример #1
0
        public ActionResult AlgorithmTester(int? kindsMaxCount, int? restaurantsMaxCount, int? dishesMaxCount, int? usersMaxCount, int? maxOrdersPerUser)
        {
            if (!kindsMaxCount.HasValue || !restaurantsMaxCount.HasValue || !dishesMaxCount.HasValue || !usersMaxCount.HasValue || !maxOrdersPerUser.HasValue)
            {
                return Redirect("/Debug/AlgorithmTester/?kindsMaxCount=10&restaurantsMaxCount=50&dishesMaxCount=100&usersMaxCount=60&maxOrdersPerUser=4");
            }

            var random = new Random();
            var group = new Group()
            {
                Id = Guid.NewGuid(),
                Name = "Guinea Pigs"
            };
            var users = GenerateRandomUsers(group, random, usersMaxCount.Value);
            var restaurants = GenerateRestaurants(group, random, restaurantsMaxCount.Value);
            var kinds = GenerateKinds(group, random, kindsMaxCount.Value);
            var dishes = GenerateDishes(group, restaurants, kinds, random, dishesMaxCount.Value);
            var randomOrders = GenerateRandomOrders(random, users, dishes, maxOrdersPerUser.Value);
            var stopwatch = new Stopwatch();
            stopwatch.Start();
            var matches = new OrderMatchHandler(randomOrders).ProcessOrders();
            stopwatch.Stop();

            ViewBag.Time = stopwatch.Elapsed;
            ViewBag.Orders = randomOrders.Select(o => new OrderViewModel()
            {
                Dish = o.Dish.Name,
                DishId = o.Dish.Id,
                Kind = o.Dish.Kind.Name,
                KindId = o.Dish.Kind.Id,
                Id = o.Id,
                RestaurantId = o.Dish.Restaurant.Id,
                Restaurant = o.Dish.Restaurant.Name,
                IsHelpNeeded = o.IsHelpNeeded,
                IsOptional = false,
                UserEmail = o.CreatedBy.Email
            }).OrderBy(o => o.UserEmail).ToList();

            ViewBag.Matches = matches.Select(m => new MatchedOrderViewModel()
            {
                Captain = m.Captain.Email,
                RestaurantId = m.RestaurantId,
                Orders = m.MatchedOrders.Select(o => new OrderViewModel()
                {
                    Dish = o.Dish.Name,
                    DishId = o.Dish.Id,
                    Kind = o.Dish.Kind.Name,
                    KindId = o.Dish.Kind.Id,
                    Id = o.Id,
                    RestaurantId = o.Dish.Restaurant.Id,
                    Restaurant = o.Dish.Restaurant.Name,
                    IsHelpNeeded = o.IsHelpNeeded,
                    IsOptional = false,
                    UserEmail = o.CreatedBy.Email
                }).ToList()
            }).OrderBy(m => m.RestaurantId).ToList();

            return View();
        }
Пример #2
0
        private List<ApplicationUser> GenerateRandomUsers(Group group, Random random, int usersMaxCount)
        {
            using (var webClient = new WebClient())
            {
                var result = new List<ApplicationUser>();
                var usersCount = random.Next(2, usersMaxCount + 1);
                var randomuserMeResponse = JsonConvert.DeserializeObject<RandomuserMeViewModels.RandomuserMeResponse>(webClient.DownloadString(String.Format("https://randomuser.me/api/?results={0}", usersCount)));

                return randomuserMeResponse.Results.Select(r => new ApplicationUser()
                {
                    Id = Guid.NewGuid(),
                    UserName = r.User.Email,
                    Email = r.User.Email,
                    Group = group
                }).ToList();
            }
        }
Пример #3
0
 private List<Kind> GenerateKinds(Group group, Random random, int kindsMaxCount)
 {
     var result = new List<Kind>();
     var kindsCount = random.Next(1, kindsMaxCount + 1);
     for (var i = 0; i < kindsCount; i++)
     {
         result.Add(new Kind()
         {
             Id = Guid.NewGuid(),
             Group = group,
             Name = String.Format("Kind #{0}", i)
         });
     }
     return result;
 }
Пример #4
0
 private List<Restaurant> GenerateRestaurants(Group group, Random random, int restaurantsMaxCount)
 {
     var result = new List<Restaurant>();
     var restaurantsCount = random.Next(1, restaurantsMaxCount + 1);
     for (var i = 0; i < restaurantsCount; i++)
     {
         result.Add(new Restaurant()
         {
             Id = Guid.NewGuid(),
             Group = group,
             Name = String.Format("Restaurant #{0}", i)
         });
     }
     return result;
 }
Пример #5
0
 private List<Dish> GenerateDishes(Group group, List<Restaurant> restaurants, List<Kind> kinds, Random random, int dishesMaxCount)
 {
     var result = new List<Dish>();
     var dishesCount = random.Next(1, dishesMaxCount + 1);
     for (var i = 0; i < dishesCount; i++)
     {
         result.Add(new Dish()
         {
             Id = Guid.NewGuid(),
             Group = group,
             Name = String.Format("Dish #{0}", i),
             Kind = kinds[random.Next(0, kinds.Count)],
             Restaurant = restaurants[random.Next(0, restaurants.Count)]
         });
     }
     return result;
 }