Ejemplo n.º 1
0
        public static List <WorkerConstrains> GetAllWorkersConstrains(int wsid)
        {
            List <WorkerConstrains> list = new List <WorkerConstrains>();

            try
            {
                List <Tuple <string, object> > args = new List <Tuple <string, object> >();
                args.Add(new Tuple <string, object>("WSID", wsid));
                var ds = GetDataSet("sp_GetAllWorkersConstrains", args);

                string curWorker = "";
                int    index     = -1;

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    var row = ds.Tables[0].Rows[i];

                    int    day   = (int)row["Day"];
                    int    shift = (int)row["ShiftTime"];
                    string id    = (string)row["WorkerId"];

                    if (curWorker != id)
                    {
                        index++;
                        curWorker = id;
                        var wc = new WorkerConstrains();
                        wc.WorkerID = id;
                        wc.Constrains[day][shift] = true;
                        list.Add(wc);
                    }
                    else
                    {
                        list[index].Constrains[day][shift] = true;
                    }
                }
            }
            catch { }

            return(list);
        }
Ejemplo n.º 2
0
        private static List <string> CalculateWorkersGrade(int stationId, int day, int shift, int maxWorkers)
        {
            List <string> workersByStation = new List <string>();
            var           ws = WorkersStations.FindAll(x => x.Item1 == stationId);

            foreach (var w in ws)
            {
                workersByStation.Add(w.Item2);
            }

            List <Tuple <string, double> > grades = new List <Tuple <string, double> >();

            foreach (var w in workersByStation)
            {
                double grade      = 0;
                int    shiftIndex = Shift.GetShiftIndex((DayOfWeek)day, (Entities.PartOfDay)shift);

                // check type
                Worker worker = workers.Find(x => x.IdNumber.TrimStart('0') == w);

                // check for meshek - work only in the morning
                if (worker.Type == WorkerTypes.Meshek && shift > 0)
                {
                    continue;
                }
                else if (worker.Type == WorkerTypes.Meshek)
                {
                    grade += 5;
                }
                // check for garin - not working on wednesday at noon
                if (worker.Type == WorkerTypes.Garin && shift == 1 && day == 3)
                {
                    continue;
                }
                else if (worker.Type == WorkerTypes.Garin)
                {
                    grade += 5;
                }


                if (worker.ShiftCounter >= 5)
                {
                    continue;
                }
                else
                {
                    grade += 1 - worker.ShiftCounter / 5f;
                }

                if (shift == 2 && worker.NightsCounter >= 7)
                {
                    continue;
                }
                else
                {
                    grade += 1 - worker.NightsCounter / 7f;
                }

                WorkerConstrains workerConstrains = workersConstrains.Find(x => x.WorkerID.TrimStart('0') == w);
                try
                {
                    if (workerConstrains.Constrains[day][shift] == true || IsWorkerWorkBeforeOrAfter(day, shift, stationId, w))
                    {
                        continue;
                    }
                }
                catch
                {
                }


                grades.Add(new Tuple <string, double>(w, grade));
            }

            grades = grades.OrderByDescending(x => x.Item2).ToList();

            List <string> intendedWorkers = new List <string>();

            for (int j = 0; j < maxWorkers && j < grades.Count; j++)
            {
                var temp  = grades.FindAll(x => x.Item2 == grades[0].Item2);
                int index = new Random().Next() % temp.Count;
                intendedWorkers.Add(temp[index].Item1);
                grades.Remove(temp[index]);
            }

            return(intendedWorkers);
        }