Esempio n. 1
0
        public static Room getRoom(int studentAgeInMonths, Person tc)
        {
            DayCare daycare = DayCare.getInstance();
            Teacher t       = (Teacher)tc;
            String  group   = GroupByAge.findGroup(studentAgeInMonths);

            HashSet <Room> RoomsInCurrGroup;

            daycare.rooms.TryGetValue(group, out RoomsInCurrGroup);

            foreach (Room room in RoomsInCurrGroup)
            {
                if (room.teachers.Count < room.maxGroups)
                {
                    room.teachers.Add(t);
                    return(room);
                }
            }

            Room       newRoom = new Room();
            GroupByAge value;

            daycare.groups.TryGetValue(group, out value);
            newRoom.maxGroups = value.maxGroupsInRoom;
            newRoom.teachers.Add(t);
            RoomsInCurrGroup.Add(newRoom);

            return(newRoom);
        }
Esempio n. 2
0
 private DayCare()
 {
     students = new HashSet <Person>();
     teachers = new HashSet <Person>();
     groups   = GroupByAge.initializeGroups();
     rooms    = Room.initializeRooms();
 }
Esempio n. 3
0
        public static Person assignTeacher(Student student)
        {
            DayCare daycare            = DayCare.getInstance();
            int     studentAgeInMonths = ((DateTime.Now.Year - student.date_of_birth.Year) * 12) + DateTime.Now.Month - student.date_of_birth.Month;

            HashSet <Person> groupTeachers = null;
            String           group         = GroupByAge.findGroup(studentAgeInMonths);
            GroupByAge       value;

            if (daycare.groups.TryGetValue(group, out value))
            {
                groupTeachers = value.teachers;
            }

            foreach (Person teacher in groupTeachers)
            {
                Teacher t = (Teacher)teacher;
                if (t.students.Count < value.groupSize)
                {
                    t.students.Add(student);
                    return(t);
                }
            }


            HashSet <Person> availableTeachers = null;

            // if the teacher was not assigned
            if (daycare.groups.TryGetValue("availableResources", out GroupByAge res))
            {
                availableTeachers = res.teachers;
            }
            foreach (Person teacher in availableTeachers)
            {
                availableTeachers.Remove(teacher);
                groupTeachers.Add(teacher);
                Teacher t = (Teacher)teacher;
                t.students.Add(student);
                return(t);
            }

            return(null);
        }
Esempio n. 4
0
        public static Dictionary <string, GroupByAge> initializeGroups()
        {
            //if(DayCare.getInstance().groups != null)
            //{
            //    return DayCare.getInstance().groups;
            //}

            List <string> rules_data             = RulesDAO.readFile();
            Dictionary <string, GroupByAge> temp = new Dictionary <string, GroupByAge>();

            for (int i = 1; i < rules_data.Count; i++) // Loop through List with for
            {
                string[]   line = rules_data[i].Split(",");
                GroupByAge t    = new GroupByAge(line[0]);
                t.groupSize       = Convert.ToInt32(line[1]);
                t.maxGroupsInRoom = Convert.ToInt32(line[3]);
                temp.Add(line[0], t);
            }
            temp.Add("availableResources", new GroupByAge("availableResources"));
            groups = temp;
            return(groups);
        }