Employee restrictions

I am writing a C # program to handle scheduling. Now every employee needs the ability to have their own schedule constraints for ex:

Sally can only work on Monday, Wednesday, Friday from 9 am to 3 pm

Billy can only work on Tuesday, Thursday, Sunday from 17:00 to 21:00

Sally can only work on Monday, Wednesday, Friday from 9 am to 3 pm until she is, and then she can work at different times and days.

Here are some examples of restrictions that I should apply to each employee object. I wanted some suggestions on how to do this, as efficiently as possible and in general. Obviously, I will need to be able to access this data and be able to enforce these restrictions. For example, when an Ashman tries to make a schedule, he needs to see that when he plans Sally on Tuesday at 4 am, this is a problem. Also how should I store this data of each employee?

+2


source to share


7 replies


something like that:

public class Employee
{
    public string Name { get; set; }
    // other important info

    private List<WorkTime> _availability = new List<WorkTime>();
    public List<WorkTime> Availability
    {
        get { return _availability; }
        internal set { _availability = value; }
    }
}

public class WorkTime
{
    public DayOfWeek Day { get; private set; }
    public int StartHour { get; private set; }
    public int EndHour { get; private set; }

    public WorkTime(DayOfWeek day, int startHour, int endHour)
    {
        // validation here (e.g. day and time range during store hours, start<end, etc.)

        Day = day;
        StartHour = startHour;
        EndHour = endHour;
    }
}

      

and use LINQ (or foreach) to query through the collection of employees and per employee. Availability to find someone with a watch to do some shift.



It might also be helpful to create some utility (extension) function to compare WorkTime objects based on your business rules (for example IsAvailable compares two WorkTime objects and returns true if it's the same DoW and overlaps at least 4 hours)

and you will most likely store this in the database, so simulate tables with fields like properties in classes.

+1


source


I would go with Rules

using the strategy pattern .

public interface Rule
{
    bool Satisfies(Employee employee);
}

public class ScheduleRule : Rule
{
    ScheduleRule(Schedule schedule)
    { ... }

    bool Satisfies(Employee employee)
    {
        // Ensure the employee is available
    }
}

public class HolidayRule : Rule
{
    HolidayRule(Datetime date)
    { ... }

    bool Satisfies(Employee employee)
    {
        // Checks if the employee as volunteered for this holiday
    }
}

      

This template makes it easy to expand and repair.



Accessibility information (and other policy related information) may be kept by the employee (see Mike Jacob's answer). However, it can be kept by an employee or in a separate table.

You can also keep this availability information separate from the employee if you expect a lot of information related to the rules. In this case, Rules

another class can be targeted:

...
bool Satisfies(RuleInfo info)
...

      

+1


source


I suggest allowing the option to store "free time" as specific dates with time ranges or as a template. I worked on several scheduling systems that had very sophisticated ways of dealing with employee pooling and availability rules, and that's how we dealt with it.

Any coworker says that I need day X from y to z which is easy to check, or they can define patterns they wanted or didn't want (for example, I don't want to work on Friday) and then when planning, you can check if whether they applied a given rule (day off) to a specific shift or did not match a specific pattern.

Also how should I store this data of each employee?

You have a table to store exceptions for a specific employee. I need day X from y to z. You have an employee and a date and time. Pretty simple.

In terms of templates, you need to come up with some type of schema. And there are types or something.

So you can have a type like "weekly template" that will store full weekends for a week, which can be stored as a simple string representing weekends: 1000001. Assuming the first bit is Sunday, this would be mean the weekend. Then you can save the template as a string or whatever, and then based on the specific type, you know how to handle the string.

This can be a very complex or simple problem, it just depends on which setting you need to resolve. Hopefully this gives you enough ideas to get you started.

Automatic scheduling is much more complex depending on the rules / rules that need to be maintained.

0


source


"An architect is as efficient as possible and as a whole as possible"

These are not mutually exclusive, but effective and general are really difficult to implement, especially in a planning system. Scheduling is not a trivial problem.

Perhaps your question would be better phrased as "What books should I read to get started with this?" and / or make it a community wiki.

0


source


This is similar to the graph matching problem , and can also be modeled as a constraint constraint problem . You may find NSolver helpful, or Cassowary.Net

0


source


I did something similar to this and what I did was create a generic interface and then create separate implementations for different scenarios. The interface can have a check IsInSchedule (dateTime). Then you can create different implementations as needed.

0


source


Martin Fowler has an interesting article on recurring calendar events and the different approaches you can take; It was very helpful to me when I wrote something like this:

http://martinfowler.com/apsupp/recurring.pdf

0


source







All Articles