Exemplo n.º 1
0
        private static List <ResApplicationForm> createAndAssignPools(List <ResApplicationForm> pool, int year) //returns a list of applications that have been accepted, and need to be removed
        {
            List <ResApplicationForm> accepted = new List <ResApplicationForm>();

            foreach (ResApplicationForm a0 in pool) //create pools of potentials
            {
                if (!a0.confirmed && !macKayFull())
                {
                    List <ResApplicationForm> potentials            = new List <ResApplicationForm>();
                    List <Double>             potentialCoefficients = new List <Double>();
                    double coefficient;
                    foreach (ResApplicationForm a1 in pool)
                    {
                        if (!a1.confirmed && !a0.applicationID.Equals(a1.applicationID) && !macKayFull())
                        {
                            if (substanceRequire(a0, a1) && substanceRequire(a1, a0))       //the two fulfill substance boolean
                            {
                                if ((coefficient = areCompatible(a0, a1)) > reqCoefficient) //the two fulfill coefficent requirement
                                {
                                    potentials.Add(a1);
                                    potentialCoefficients.Add(coefficient);
                                }
                            }
                        }
                    }
                    if (potentials.Count() == 0) //has no potential roommates, may be reconsidered after adding Dunn overflow
                    {
                    }
                    else
                    {
                        int highestIndex = 0;
                        for (int i = 1; i < potentials.Count; i++)
                        {
                            if (potentialCoefficients[i] > potentialCoefficients[highestIndex])
                            {
                                highestIndex = i;
                            }
                        }
                        a0.confirmed = true;
                        ResApplicationForm a1 = potentials[highestIndex];
                        a1.confirmed = true;
                        accepted.Add(a0);
                        accepted.Add(a1);
                        numUsedDoubles++;
                        //pair the two, assign to MacKay
                        String roomID0  = Server.getEmptyRoomID(mackayName, year.ToString());
                        String roomNum0 = Server.getRoomNum(roomID0, year.ToString());
                        String roomID1  = Server.getAdjoiningID(roomID0, roomNum0);
                        Server.assignRoom(a0.studentID, roomID0);
                        Server.assignRoom(a1.studentID, roomID1);
                    }
                }
            }
            foreach (ResApplicationForm a0 in accepted) //cleaning the pool
            {
                pool.Remove(a0);
            }
            return(accepted);
        }
Exemplo n.º 2
0
 private static bool substanceRequire(ResApplicationForm a0, ResApplicationForm a1)
 {
     if ((!a0.smokes || a1.liveWithSmoke) && (!a0.drinks || a1.liveWithDrink) && (!a0.marijuana || a1.liveWithMarijuana))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 3
0
 private static bool roommateRequestMatch(ResApplicationForm a0, ResApplicationForm a1)
 {
     if (a0.studentID.Equals(a1.roommateID) && a0.roommateID.Equals(a1.studentID) &&
         a0.gender.Equals(a1.gender) && a0.preferBuilding.Equals(a1.preferBuilding) &&
         !a0.roommateID.Equals("") & !a1.roommateID.Equals(""))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 4
0
        private static double areCompatible(ResApplicationForm a0, ResApplicationForm a1)
        {
            double howGood = 0;

            if (a0.schoolYear.Equals(a1.schoolYear))
            {
                howGood += 2;
            }
            if (a0.country.Equals(a1.country))
            {
                howGood += 2;
            }
            if (a0.socialLevel.Equals(a1.socialLevel))
            {
                howGood += 2;
            }
            if (a0.volumeLevel.Equals(a1.volumeLevel))
            {
                howGood += 2;
            }
            if (a0.bedtime.Equals(a1.bedtime))
            {
                howGood += 1;
            }
            if (a0.wakeUp.Equals(a1.wakeUp))
            {
                howGood += 1;
            }
            if (a0.overnightVisitors.Equals(a1.overnightVisitors))
            {
                howGood += 1;
            }
            if (a0.cleanliness.Equals(a1.cleanliness))
            {
                howGood += 1;
            }
            if (a0.studiesInRoom.Equals(a1.studiesInRoom))
            {
                howGood += 1;
            }
            foreach (String h0 in a0.hobbies)
            {
                foreach (String h1 in a1.hobbies)
                {
                    if (h0.Equals(h1))
                    {
                        howGood += 0.25;
                    }
                }
            }
            foreach (String s0 in a0.sports)
            {
                foreach (String s1 in a1.sports)
                {
                    if (s0.Equals(s1))
                    {
                        howGood += 0.25;
                    }
                }
            }
            foreach (String m0 in a0.music)
            {
                foreach (String m1 in a1.music)
                {
                    if (m0.Equals(m1))
                    {
                        howGood += 0.25;
                    }
                }
            }

            return(howGood);
        }
Exemplo n.º 5
0
        public static List <ResApplicationForm> runQueryApplication(int schoolYear) //collects the most recent year of applications
        {
            String schoolString = schoolYear.ToString();

            setCommandApplication("Application", schoolString);

            List <ResApplicationForm> applications = new List <ResApplicationForm>();

            MessageBox.Show(command.CommandText);
            command.CommandType = System.Data.CommandType.Text;
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                ResApplicationForm a0            = new ResApplicationForm();
                String             applicationID = reader.GetInt32(0).ToString();
                a0.applicationID     = applicationID;
                a0.studentID         = reader.GetString(1).Trim();
                a0.firstName         = reader.GetString(2).Trim();
                a0.lastName          = reader.GetString(3).Trim();
                a0.otherName         = reader.GetString(4).Trim();
                a0.schoolYear        = schoolYear;
                a0.gender            = reader.GetString(6).Trim();
                a0.email             = reader.GetString(7).Trim();
                a0.streetAddress     = reader.GetString(8).Trim();
                a0.city              = reader.GetString(9).Trim();
                a0.region            = reader.GetString(10).Trim();
                a0.country           = reader.GetString(11).Trim();
                a0.postalCode        = reader.GetString(12).Trim();
                a0.phoneCountryCode  = reader.GetString(13).Trim();
                a0.phoneAreaCode     = reader.GetString(14).Trim();
                a0.phoneNumber       = reader.GetString(15).Trim();
                a0.preferBuilding    = reader.GetString(16).Trim();
                a0.smokes            = reader.GetBoolean(17);
                a0.liveWithSmoke     = reader.GetBoolean(18);
                a0.drinks            = reader.GetBoolean(19);
                a0.liveWithDrink     = reader.GetBoolean(20);
                a0.marijuana         = reader.GetBoolean(21);
                a0.liveWithMarijuana = reader.GetBoolean(22);
                a0.socialLevel       = reader.GetString(23).Trim();
                a0.bedtime           = reader.GetString(24).Trim();
                a0.wakeUp            = reader.GetString(25).Trim();
                a0.volumeLevel       = reader.GetString(26).Trim();
                a0.overnightVisitors = reader.GetBoolean(27);
                a0.cleanliness       = reader.GetString(28).Trim();
                a0.studiesInRoom     = reader.GetBoolean(29);
                a0.roommateRequest   = reader.GetBoolean(30);
                a0.roommateName      = reader.GetString(31).Trim();
                a0.roommateID        = reader.GetString(32).Trim();
                a0.mealPlan          = reader.GetString(33).Trim();

                applications.Add(a0);
            }
            reader.Close();

            foreach (ResApplicationForm a0 in applications)
            {
                setCommandApplication("Sport", a0.applicationID); //gets Sports table
                reader = command.ExecuteReader();
                List <String> sports = new List <String>();
                while (reader.Read())
                {
                    sports.Add(reader.GetString(1));
                }
                a0.sports = sports.ToArray();
                reader.Close();

                setCommandApplication("musicType", a0.applicationID); //gets Music table
                reader = command.ExecuteReader();
                List <String> music = new List <String>();
                while (reader.Read())
                {
                    music.Add(reader.GetString(1));
                }
                a0.music = music.ToArray();
                reader.Close();

                setCommandApplication("Hobby", a0.applicationID); //gets Hobbies table
                reader = command.ExecuteReader();
                List <String> hobbies = new List <String>();
                while (reader.Read())
                {
                    hobbies.Add(reader.GetString(1));
                }
                a0.hobbies = hobbies.ToArray();
                reader.Close();
            }

            return(applications);
        }