Пример #1
0
        static void Calculation(CustomerList customers, TellerList tellers)
        {
            // Your code goes here .....
            // Re-write this method to be more efficient instead of a assigning all customers to the same teller

            //Create a list of al the customer orderby type and the by te longest time
            IList <Customer> customersSorted = new List <Customer>();

            customersSorted = customers.Customer.OrderBy(x => x.type).ThenByDescending(o => o.duration).ToList();

            foreach (Customer customer in customersSorted)
            {
                IList <Appointment> tellersDuration = new List <Appointment>();

                //Create a list of the appointment time of a customer for all tellers
                foreach (Teller teller in tellers.Teller)
                {
                    var appointment = new Appointment(customer, teller);
                    tellersDuration.Add(appointment);
                }


                var sortedTellers = tellersDuration.OrderBy(o => o.duration).ToList();

                //if no appointmet exist yet, add the customer to the quickest teller
                if (appointmentList.Count == 0)
                {
                    appointmentList.Add(sortedTellers[0]);
                }

                else
                {
                    for (int i = 0; i < sortedTellers.Count(); i++)
                    {
                        bool containsItem = appointmentList.Any(o => o.teller.id == sortedTellers[i].teller.id);

                        //if the quickest teller doesn't existe yet, we add that appointment
                        if (!containsItem && appointmentList.Count() < sortedTellers.Count())
                        {
                            appointmentList.Add(sortedTellers[i]);
                            break;
                        }
                        //once i add one customer to all teller we can start adding more custemer to the same tellers
                        else if (containsItem && appointmentList.Count() >= sortedTellers.Count())
                        {
                            var tellerAppointments =
                                from appointments in appointmentList
                                group appointments by appointments.teller into tellerGroup
                                select new
                            {
                                teller        = tellerGroup.Key,
                                totalDuration = tellerGroup.Sum(x => x.duration),
                            };

                            double totalTime                = 0;
                            int    tellerIndexAdd           = 0;
                            var    tellerAppointmentsSorted = tellerAppointments.OrderBy(x => x.totalDuration).ToList();

                            //iterate through the teller order by the total duration of their appointments
                            for (int j = 0; j < tellerAppointmentsSorted.Count(); j++)
                            {
                                var tellerTotalDurationId = tellerAppointmentsSorted[j].teller.id;
                                int tellerIndex           = sortedTellers.FindIndex(a => a.teller.id == tellerTotalDurationId);

                                //if it is the first time in this loop we update the
                                //total time to the total time plus the duration of the new apppoitment
                                //and get that teller index to add the appointment
                                if (totalTime == 0)
                                {
                                    totalTime      = tellerAppointmentsSorted[j].totalDuration + sortedTellers[tellerIndex].duration;
                                    tellerIndexAdd = tellerIndex;
                                }
                                //if the total time plus the new appointment time of the previous teller is  higher than the next teller
                                //then we update the total time for the fastest one and get that telle index to add the new appointment
                                else if (totalTime > tellerAppointmentsSorted[j].totalDuration + sortedTellers[tellerIndex].duration)
                                {
                                    totalTime      = tellerAppointmentsSorted[j].totalDuration + sortedTellers[tellerIndex].duration;
                                    tellerIndexAdd = tellerIndex;
                                }
                            }

                            appointmentList.Add(sortedTellers[tellerIndexAdd]);
                            break;
                        }
                    }
                }
            }
        }
Пример #2
0
        static void Calculation(CustomerList customers, TellerList tellers)
        {
            List <Teller> specialtyOne   = new List <Teller>();
            List <Teller> specialtyZero  = new List <Teller>();
            List <Teller> specialtyTwo   = new List <Teller>();
            List <Teller> specialtyThree = new List <Teller>();

            foreach (Teller teller in tellers.Teller)
            {
                if (teller.specialtyType == "0")
                {
                    specialtyZero.Add(teller);
                }
                if (teller.specialtyType == "1")
                {
                    specialtyOne.Add(teller);
                }
                if (teller.specialtyType == "2")
                {
                    specialtyTwo.Add(teller);
                }
                if (teller.specialtyType == "3")
                {
                    specialtyThree.Add(teller);
                }
            }

            /*Console.WriteLine(string.Join("\t", specialtyZero));
             * Console.WriteLine(string.Join("\t", specialtyOne));
             * Console.WriteLine(string.Join("\t", specialtyTwo));
             * Console.WriteLine(string.Join("\t", specialtyThree));*/
            // Your code goes here .....
            // Re-write this method to be more efficient instead of a random assignment
            int i = 0;
            int j = 0;
            int k = 0;
            int l = 0;

            foreach (Customer customer in customers.Customer)
            {
                if (customer.type == "4")
                {
                    var appointmentZero = new Appointment(customer, specialtyZero[i]);
                    appointmentList.Add(appointmentZero);
                    i++;
                    if (i >= specialtyZero.Count)
                    {
                        i = 0;
                    }
                }
                if (customer.type == "1")
                {
                    var appointmentOne = new Appointment(customer, specialtyOne[j]);
                    appointmentList.Add(appointmentOne);
                    j++;
                    if (j >= specialtyOne.Count)
                    {
                        j = 0;
                    }
                }
                if (customer.type == "2")
                {
                    var appointmentTwo = new Appointment(customer, specialtyTwo[k]);
                    appointmentList.Add(appointmentTwo);
                    k++;
                    if (k >= specialtyTwo.Count)
                    {
                        k = 0;
                    }
                }
                if (customer.type == "3")
                {
                    var appointmentThree = new Appointment(customer, specialtyThree[l]);
                    appointmentList.Add(appointmentThree);
                    l++;
                    if (l >= specialtyThree.Count)
                    {
                        l = 0;
                    }
                }
            }
        }
Пример #3
0
        static void Calculation(CustomerList customers, TellerList tellers)
        {
            List <Teller> tellerSpecZero  = new List <Teller>();
            List <Teller> tellerSpecOne   = new List <Teller>();
            List <Teller> tellerSpecTwo   = new List <Teller>();
            List <Teller> tellerSpecThree = new List <Teller>();

            foreach (Teller teller in tellers.Teller)
            {
                if (teller.specialtyType == "0")
                {
                    tellerSpecZero.Add(teller);
                }
                if (teller.specialtyType == "1")
                {
                    tellerSpecOne.Add(teller);
                }
                if (teller.specialtyType == "2")
                {
                    tellerSpecTwo.Add(teller);
                }
                if (teller.specialtyType == "3")
                {
                    tellerSpecThree.Add(teller);
                }
            }

            int i = 0, j = 0, k = 0, l = 0;

            foreach (Customer customer in customers.Customer)
            {
                if (customer.type == "1")
                {
                    var appointmentOne = new Appointment(customer, tellerSpecOne[j]);
                    appointmentList.Add(appointmentOne);
                    j++;
                    if (j >= tellerSpecOne.Count)
                    {
                        j = 0;
                    }
                }
                if (customer.type == "2")
                {
                    var appointmentTwo = new Appointment(customer, tellerSpecTwo[k]);
                    appointmentList.Add(appointmentTwo);
                    k++;
                    if (k >= tellerSpecTwo.Count)
                    {
                        k = 0;
                    }
                }
                if (customer.type == "3")
                {
                    var appointmentThree = new Appointment(customer, tellerSpecThree[l]);
                    appointmentList.Add(appointmentThree);
                    l++;
                    if (l >= tellerSpecThree.Count)
                    {
                        l = 0;
                    }
                }
                if (customer.type == "4")
                {
                    var appointmentZero = new Appointment(customer, tellerSpecZero[i]);
                    appointmentList.Add(appointmentZero);
                    i++;
                    if (i >= tellerSpecZero.Count)
                    {
                        i = 0;
                    }
                }
            }
        }