Exemplo n.º 1
0
        private static float GetUserWeight(string _user, Shift.UserShiftPreference _preference, int _hours)
        {
            // get the user
            User user = GetUserByID(_user);

            // TODO: Think of a better weight
            return ((float)_preference) * (1 / ((_hours * user.HourlySalary) / user.MaxRevenue));
        }
Exemplo n.º 2
0
        private static void CalculateShift(Shift _shift, ref Dictionary<string, int> _hours)
        {
            // variable to store the individual weights for each user
            Dictionary<string, float> weightPerUser = new Dictionary<string, float>();

            foreach(Shift.UserShift us in _shift.possibleUsers)
            {
                // check if the user is eligible for the shift
                if(_shift.ShiftFaculty != GetUserByID(us.User).Faculty)
                {
                    Debug.WriteLine("Faculty mismatch between User and Shift detected!");
                    continue;
                }

                // check if the user has no entry in the hours dictionary
                if(!_hours.ContainsKey(us.User)) { _hours[us.User] = 0; }

                // calculate the weight for the user and add it
                weightPerUser.Add(us.User, GetUserWeight(us.User, us.Preference, _hours[us.User]));
            }

            // iterate over all keys
            foreach(string key in weightPerUser.Keys.ToArray())
            {
                // check if the user has no weight
                if(weightPerUser[key] <= 0.0f)
                {
                    // remove the user
                    weightPerUser.Remove(key);
                }
            }

            // check if there is anyone left to fill the shift
            if(weightPerUser.Count == 0)
            {
                // TODO: Think of a better way to signal that nobody can take the shift
                _shift.UserID = "NOONE";
                return;
            }

            // get the user with the highest weight
            KeyValuePair<string, float> p = weightPerUser.Max();

            // set him as the one who will take the shift
            _shift.UserID = p.Key;

            // increase his time
            _hours[p.Key] = _hours[p.Key] + _shift.Hours;
        }