Пример #1
0
 public Track()
 {
     this.start = 9;
     this.end = 17;
     this.morningSession = new MorningSession();
     this.afternoonSession = new AfternoonSession();
     this.lunch = new Talk("lunch", 1);
     this.lunch.Start = 12.0;
     this.networkEvent = new Talk("Networking Event", 0);
 }
 private bool ScheduleInEvening(Talk talk, Day day)
 {
     foreach (var track in day.Tracks)
     {
         var duration = talk.Duration.Value * (int)(talk.Duration.Unit);
         if (TalkCanBeScheduledInEvening(duration, track))
         {
             track.EveningSession.Talks.Add(talk);
             track.EveningSession.TimeRemaining = track.EveningSession
                                                       .TimeRemaining.Subtract(new TimeSpan(0, duration, 0));
             return true;
         }
     }
     return false;
 }
        public static void Main(string[] args)
        {
            try
            {
                string[] lines = File.ReadAllLines(@"InputData\schedule.txt");
                int len = lines.Length;
                Talk[] talks = new Talk[len];

                Talk talk = new Talk();
                talk.Getduration(talks,lines);
                talk.sortDisplay(talks);
            }
            catch(Exception e)
            {
                Console.WriteLine("Something went wrong.Please check");
                Console.WriteLine(e.Message);
            }
            Console.ReadKey();
        }
 public void Getduration(Talk[] talks, String[] lines)
 {
     for (int i = 0; i < talks.Length; i++)
     {
         talks[i] = new Talk();
         talks[i].Name = lines[i]; ;
         talks[i].IsSchedule = false;
         string[] items = lines[i].Trim().Split(' ');
         int len2 = items.Length - 1;
         string last = items[len2].ToLower();
         if (last == "lightning")
         {
             talks[i].Duration = 5;
         }
         else
         {
             talks[i].Duration = int.Parse(last.Replace("min", ""));
         }
     }
 }
Пример #5
0
 public bool IsValid(Talk talk)
 {
     return talk.End <= 17;
 }
        public void sortDisplay(Talk[] talks)
        {
            List<Talk> track1am = new List<Talk>();
            List<Talk> track1pm = new List<Talk>();
            List<Talk> track2am = new List<Talk>();
            List<Talk> track2pm = new List<Talk>();

            int CheckedAllSession = 0;

            talks = talks.OrderByDescending(t => t.Duration).ToArray();

            int schedule1am = 0, schedule1pm = 0, schedule2am = 0, schedule2pm = 0;
            int next = 0;

            for (int i = 0; i < talks.Length; i++)
            {
                int duration = talks[i].Duration;

                if (next == 0 && (schedule1am + duration) <= 180)
                {
                    track1am.Add(talks[i]);
                    talks[i].IsSchedule = true;
                    schedule1am += duration;
                    next++;
                    CheckedAllSession = 0;
                }
                else if (next == 1 && (schedule2am + duration) <= 180)
                {
                    track2am.Add(talks[i]);
                    talks[i].IsSchedule = true;
                    schedule2am += duration;
                    next++;
                    CheckedAllSession = 0;
                }
                else if (next == 2 && (schedule1pm + duration) <= 240)
                {
                    track1pm.Add(talks[i]);
                    talks[i].IsSchedule = true;
                    schedule1pm += duration;
                    next++;
                    CheckedAllSession = 0;
                }
                else if (next == 3 && (schedule2pm + duration) <= 240)
                {
                    track2pm.Add(talks[i]);
                    talks[i].IsSchedule = true;
                    schedule2pm += duration;
                    next = 0;
                    CheckedAllSession = 0;
                }
                else
                {
                    i--;
                    next++;
                    if (next == 4) next = 0;
                    CheckedAllSession++;
                    if (CheckedAllSession == 4)
                    {
                        i++;
                        CheckedAllSession = 0;
                    }
                }
            }

            int mins = Math.Max(schedule1pm, schedule2pm);
            if (mins < 180)
                mins = 180; // can't be before 4.00 pm
            if (mins > 180)
                mins = 240;
            DateTime nwe = DateTime.Today.AddHours(13).AddMinutes(mins);

            // print results
            Console.Clear();
            Console.WriteLine("Track1:");
            DateTime dt = DateTime.Today.AddHours(9);

            foreach (Talk t in track1am)
            {
                Console.WriteLine("{0} {1}", dt.ToString("hh:mmtt"), t.Name);
                dt = dt.AddMinutes(t.Duration);
            }

            Console.WriteLine("12:00PM Lunch");
            dt = DateTime.Today.AddHours(13);

            foreach (Talk t in track1pm)
            {
                Console.WriteLine("{0} {1}", dt.ToString("hh:mmtt"), t.Name);
                dt = dt.AddMinutes(t.Duration);
            }

            Console.WriteLine("{0} Networking Event", nwe.ToString("hh:mmtt"));

            Console.WriteLine("\nTrack2:");
            dt = DateTime.Today.AddHours(9);

            foreach (Talk t in track2am)
            {
                Console.WriteLine("{0} {1}", dt.ToString("hh:mmtt"), t.Name);
                dt = dt.AddMinutes(t.Duration);
            }

            Console.WriteLine("12:00PM Lunch");
            dt = DateTime.Today.AddHours(13);

            foreach (Talk t in track2pm)
            {
                Console.WriteLine("{0} {1}", dt.ToString("hh:mmtt"), t.Name);
                dt = dt.AddMinutes(t.Duration);
            }

            Console.WriteLine("{0} Networking Event", nwe.ToString("hh:mmtt"));

            Console.WriteLine(" ");
            Console.WriteLine("Un scheduled Event");

            foreach (Talk t in talks)
            {
                if (t.IsSchedule == false)
                {
                    Console.WriteLine(t.Name);
                }
            }

            Console.ReadKey();
        }
 public void ThrowExceptionIfTitleContainsNumbers()
 {
     _testTalk = new Talk("Topic1", _duration);
 }
 public void ThrowExceptionForInvalidDuration()
 {
     _duration = new TalkDuration(TimeUnit.Min, -10);
     _testTalk = new Talk("Topic", _duration);
 }
 public void Initialize()
 {
     _duration = new TalkDuration(TimeUnit.Min, 60);
     _testTalk = new Talk("Topic", _duration);
 }
        public void ReturnOneIfOneTalkRegistered()
        {
            Talk testTalk = new Talk("test Topic", _duration);

            _testConference.TalksLoader = new SingleTalkLoader(testTalk);
            _testConference.RegisterTalks();

            Assert.AreEqual(_testConference.TotalTalks, 1);
        }
        public void ReturnNullIfTalkIsNotRegistered()
        {
            Talk testTalk1 = new Talk("TopicOne", _duration);
            _testConference.TalksLoader = new SingleTalkLoader(testTalk1);
            _testConference.RegisterTalks();

            var registeredTalk = _testConference.GetTalkByName("TopicTwo");

            Assert.AreEqual(_testConference.TotalTalks, 1);
            Assert.AreEqual(null, registeredTalk);
        }
        public void RegisterTheTalkProperly()
        {
            Talk testTalk = new Talk("test Topic", _duration);

            _testConference.TalksLoader=new SingleTalkLoader(testTalk);
            _testConference.RegisterTalks();
            Talk registerTestTalk = _testConference.GetTalkByName("test Topic");

            Assert.AreEqual(testTalk.Topic, registerTestTalk.Topic);
            Assert.AreEqual(_testConference.TotalTalks, 1);
            Assert.AreEqual(testTalk.Duration, registerTestTalk.Duration);
        }
        public void RegisterMultipleTalksProperly()
        {
            var testTalk1 = new Talk("TopicOne", _duration);
            var testTalk2 = new Talk("TopicTwo", _duration);
            var testTalk3 = new Talk("TopicThree", _duration);

            _testConference.TalksLoader = new SingleTalkLoader(testTalk1);
            _testConference.RegisterTalks();
            _testConference.TalksLoader = new SingleTalkLoader(testTalk2);
            _testConference.RegisterTalks();
            _testConference.TalksLoader = new SingleTalkLoader(testTalk3);
            _testConference.RegisterTalks();

            var registeredTalk = _testConference.GetTalkByName("TopicOne");

            Assert.AreEqual(_testConference.TotalTalks, 3);
            Assert.AreEqual(testTalk1.Topic, registeredTalk.Topic);
        }
 public SingleTalkLoader(Talk talk)
 {
     _talk = talk;
 }
Пример #15
0
        static void Main(string[] args)
        {
            TalkController       talkController       = new TalkController();
            SchedulingController schedulingController = new SchedulingController();
            int numberSelected = 0;

            Console.WriteLine("Welcome to CONFERENCE TRACK MANAGEMENT");
            Console.WriteLine("");
            while (numberSelected != 9)
            {
                Console.WriteLine("");
                Console.WriteLine("------------------------------------------------------------------------------");
                Console.WriteLine("Select an option:");
                Console.WriteLine("1 - Create default talks");
                Console.WriteLine("2 - Scheduling talks");
                Console.WriteLine("3 - Add talk");
                Console.WriteLine("4 - List all Talks");
                Console.WriteLine("9 - Exit");
                Console.WriteLine("------------------------------------------------------------------------------");
                string optionSelected = Console.ReadLine();
                if (int.TryParse(optionSelected, out numberSelected))
                {
                    switch (numberSelected)
                    {
                    case 1:
                        Console.Clear();
                        talkController.CreateDefaultTalks();
                        Console.WriteLine("Default talk were created successfully.");
                        break;

                    case 2:
                        try
                        {
                            Console.Clear();
                            Console.WriteLine("Which date start the conference? (YYYY/MM/DD)");
                            string   firstDayConferenceString = Console.ReadLine();
                            DateTime firstDayConference       = new DateTime();
                            //validate date format
                            if (DateTime.TryParse(firstDayConferenceString, out firstDayConference))
                            {
                                Console.WriteLine("Building Scheduling...");
                                //get the best scheduling
                                List <Track> bestTrackList = schedulingController.ScheduleTalks(firstDayConference);
                                Console.Clear();
                                Console.WriteLine("This is the best scheduling of talks.");
                                Console.WriteLine("");
                                foreach (Track track in bestTrackList)
                                {
                                    Console.WriteLine("--------------" + track.Title + "--------------");
                                    Console.WriteLine("");
                                    foreach (Session session in track.SessionList)
                                    {
                                        Console.WriteLine("--------------" + session.Title + "--------------");
                                        Console.WriteLine("");
                                        foreach (Scheduling scheduling in session.SchedulingList)
                                        {
                                            Console.WriteLine(scheduling.StartHour.ToString("HH:mm") + "-" + scheduling.EndHour.ToString("HH:mm") + " > " + scheduling.Talk.Title + ", " + scheduling.Talk.Duration + " MIN");
                                        }
                                        Console.WriteLine("");
                                    }
                                }
                            }
                            else
                            {
                                Console.WriteLine("Invalid date! Please write a date in format YYYY/MM/DD");
                            }
                        }
                        catch (Exception exception)
                        {
                            Console.WriteLine(exception.Message);
                            Console.WriteLine("");
                            Console.WriteLine("Please try again.");
                        }
                        break;

                    case 3:
                        Talk talk = new Talk();
                        Console.Clear();
                        Console.WriteLine("Add a talk");
                        Console.WriteLine("Add a title to your talk: ");
                        talk.Title = Console.ReadLine();

                        Console.WriteLine("Is lightining talk? (1-Yes, 2-No) ");
                        string isLightiningString = Console.ReadLine();
                        while (!(isLightiningString == "1" || isLightiningString == "2"))
                        {
                            Console.WriteLine("Invalid value! Please write 1 to YES or 2 to NO.");
                            Console.WriteLine("Is lightining talk? (1-Yes, 2-No) ");
                            isLightiningString = Console.ReadLine();
                        }

                        if (isLightiningString == "1" ? true : false)
                        {
                            talk.IsLightning = true;
                            talk.Duration    = 5;
                        }
                        else
                        {
                            Console.WriteLine("Add a time, in minutes, to your talk: ");
                            string time = Console.ReadLine();
                            int    timeInt;
                            while (!int.TryParse(time, out timeInt) || (timeInt > 180))
                            {
                                Console.WriteLine("Invalid time! Please write a time only with numbers and lenght max 180 minutes.");
                                Console.WriteLine("Add in minutes a time to your talk: ");
                                time = Console.ReadLine();
                            }
                            talk.IsLightning = false;
                            talk.Duration    = timeInt;
                        }
                        try
                        {
                            if (talkController.AddTalk(talk))
                            {
                                Console.Clear();
                                Console.WriteLine("Talk add successfuly.");
                            }
                        }
                        catch (Exception talkException)
                        {
                            Console.Clear();
                            Console.WriteLine(talkException.Message);
                        }
                        break;

                    case 4:
                        List <Talk> talkList = talkController.ListAllTalks();
                        Console.Clear();
                        Console.WriteLine("List of talks");
                        Console.WriteLine("");
                        foreach (Talk talkObject in talkList)
                        {
                            Console.WriteLine(talkObject.Title + " - " + talkObject.Duration);
                        }
                        Console.WriteLine("----------------------------------------------------------------------");
                        Console.WriteLine(talkList.Count + " talks listed.");
                        Console.WriteLine("");
                        break;

                    default:
                        Console.WriteLine("Command not found.");
                        break;
                    }
                }
                else
                {
                    Console.WriteLine("You need write a valid number.");
                }
            }
        }