PyWorkShift


NamePyWorkShift JSON
Version 1.1.0 PyPI version JSON
download
home_pagehttps://github.com/point85/PyShift
SummaryA work schedule library for shifts.
upload_time2024-12-21 02:00:15
maintainerNone
docs_urlNone
authorKent Randall
requires_python>=3.9
licenseNone
keywords shift work schedule shift calendar work calendar
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PyShift
The PyShift library project manages work schedules.  A work schedule consists of one or more teams who rotate through a sequence of shift and off-shift periods of time.  The PyShift project allows breaks during shifts to be defined as well as non-working periods of time (e.g. holidays and scheduled maintenance periods) that are applicable to the entire work schedule.

## Concepts

The Business Management Systems' DNO (Day, Night, Off) work schedule with three teams and two 12-hour shifts with a 3-day rotation is an example work schedule.  This schedule is explained in http://community.bmscentral.com/learnss/ZC/3T/c3tr12-1.

*Shift*

A shift is defined with a name, description, starting time of day and duration.  An off-shift period is associated with a shift.  In the example above for Team1, there are two shifts followed by one off-shift period.  Shifts can be overlapped (typically when a handoff of duties is important such as in the nursing profession).  A rotation is a sequence of shifts and off-shift days.  The DNO rotation is Day on, Night on and Night off.  An instance of a shift has a starting date and time of day and has an associated shift definition.

*Break*

A break is a defined working period of time during a shift, for example lunch.  A shift can have zero or more breaks.

*Team*

A team is defined with a name and description.  It has a rotation with a starting date.  The starting date shift will have an instance with that date and a starting time of day as defined by the shift.  The same rotation can be shared between more than one team, but with different starting times.

*Team Member*

A team member is a person assigned to a team.  The member is identified by a member ID (e.g. employee ID), name and description/title.

*Team Member Exception*

A team member exception is an addition and/or removal from the assigned members of a team for a specified shift instance.  The instance is identified by the starting date and time.

*Work Schedule*

A work schedule is defined with a name and description.  It has one or more teams.  Zero or more non-working periods can be defined.  A non-working period has a defined starting date and time of day and duration.  For example, the New Year's Day holiday starting at midnight for 24 hours, or three consecutive days for preventive maintenance of manufacturing equipment starting at the end of the night shift. 

After a work schedule is defined, the working time for all shifts can be computed for a defined time interval.  For example, this duration of time is the maximum available productive time as an input to the calculation of the utilization of equipment in a metric known as the Overall Equipment Effectiveness (OEE).

*Rotation*

A rotation is a sequence of working periods (segments).  Each segment starts with a shift and specifies the number of days on-shift and off-shift.  A work schedule can have more than one rotation.

*Non-Working Period*

A non-working period is a duration of time where no teams are working.  For example, a holiday or a period of time when a plant is shutdown for preventative maintenance.  A non-working period starts at a defined day and time of day and continues for the specified duration of time.

*Shift Instance*

A shift instance is the duration of time from a specified date and time of day and continues for the duration of the associated shift.  A team works this shift instance.

## Examples
The DNO schedule discussed above is defined as follows.

```python
        description = "This is a fast rotation plan that uses 3 teams and two 12-hr shifts to provide 24/7 coverage. "
        description = description + "Each team rotates through the following sequence every three days: 1 day shift, 1 night shift, and 1 day off."

        self.workSchedule = WorkSchedule("DNO Plan", description)

        # Day shift, starts at 07:00 for 12 hours
        day = self.workSchedule.createShift("Day", "Day shift", time(7, 0, 0), timedelta(hours=12))

        # Night shift, starts at 19:00 for 12 hours
        night = self.workSchedule.createShift("Night", "Night shift", time(19, 0, 0), timedelta(hours=12))

        # rotation
        rotation = self.workSchedule.createRotation("DNO", "DNO")
        rotation.addSegment(day, 1, 0)
        rotation.addSegment(night, 1, 1)
        referenceDate = date(2021, 11, 1)

        self.workSchedule.createTeam("Team 1", "First team", rotation, referenceDate)
        self.workSchedule.createTeam("Team 2", "Second team", rotation, referenceDate - timedelta(days=1))
        self.workSchedule.createTeam("Team 3", "Third team", rotation, referenceDate - timedelta(days=2))
```
To obtain the working time over three days starting at 07:00, the following method is called:

```python
        fromDateTime = datetime.combine(date(2021, 11, 2), time(7, 0, 0))
        duration = self.workSchedule.calculateWorkingTime(fromDateTime, fromDateTime + timedelta(days=3))
```

To obtain the shift instances for a date, the following method is called:

```python
shiftInstances = self.workSchedule.getShiftInstancesForDay(date(2021, 11, 2)) 
```

To print a work schedule, call the __str()__ method.  For example:

```python
        print(str(self.workSchedule))
```
with output:

```python		
Schedule: DNO Plan (This is a fast rotation plan that uses 3 teams and two 12-hr shifts to provide 24/7 coverage. Each team rotates through the following sequence every three days: 1 day shift, 1 night shift, and 1 day off.)
Rotation duration: 9D:0H:0M, Scheduled working time: 3D:0H:0M
Shifts: 
   (1) Day (Day shift), Start: 07:00:00 (0D:12H:0M), End: 19:00:00
   (2) Night (Night shift), Start: 19:00:00 (0D:12H:0M), End: 07:00:00
Teams: 
   (1) Team 1 (First team), Rotation start: 2021-11-01, DNO (DNO)
Rotation periods: [Day (on), Night (on), DAY_OFF (off)], Rotation duration: 3D:0H:0M, Days in rotation: 3.0, Scheduled working time: 1D:0H:0M, Percentage worked: 33.333%, Average hours worked per week: : 56.000
   (2) Team 2 (Second team), Rotation start: 2021-10-31, DNO (DNO)
Rotation periods: [Day (on), Night (on), DAY_OFF (off)], Rotation duration: 3D:0H:0M, Days in rotation: 3.0, Scheduled working time: 1D:0H:0M, Percentage worked: 33.333%, Average hours worked per week: : 56.000
   (3) Team 3 (Third team), Rotation start: 2021-10-30, DNO (DNO)
Rotation periods: [Day (on), Night (on), DAY_OFF (off)], Rotation duration: 3D:0H:0M, Days in rotation: 3.0, Scheduled working time: 1D:0H:0M, Percentage worked: 33.333%, Average hours worked per week: : 56.000
Total team coverage: : 100.00%
```

To print shift instances between two dates, the following method is called:

 ```python
self.workSchedule.printShiftInstances(date(2021, 11, 1), date(2021, 11, 3))
```
with output:

```python
Working shifts
[1] Day: 2021-11-01
   (1) Team: Team 1, Shift: Day, Start: 2021-11-01 07:00:00, End: 2021-11-01 19:00:00
   (2) Team: Team 2, Shift: Night, Start: 2021-11-01 19:00:00, End: 2021-11-02 07:00:00
[2] Day: 2021-11-02
   (1) Team: Team 3, Shift: Day, Start: 2021-11-02 07:00:00, End: 2021-11-02 19:00:00
   (2) Team: Team 1, Shift: Night, Start: 2021-11-02 19:00:00, End: 2021-11-03 07:00:00
[3] Day: 2021-11-03
   (1) Team: Team 2, Shift: Day, Start: 2021-11-03 07:00:00, End: 2021-11-03 19:00:00
   (2) Team: Team 3, Shift: Night, Start: 2021-11-03 19:00:00, End: 2021-11-04 07:00:00
```
 
For a second example, the 24/7 schedule below has two rotations for four teams in two shifts.  It is used by manufacturing companies.

```python
        self.workSchedule = WorkSchedule("Manufacturing Company - four twelves",
            "Four 12 hour alternating day/night shifts")

        # day shift, start at 07:00 for 12 hours
        day = self.workSchedule.createShift("Day", "Day shift", time(7, 0, 0), timedelta(hours=12))

        # night shift, start at 19:00 for 12 hours
        night = self.workSchedule.createShift("Night", "Night shift", time(19, 0, 0), timedelta(hours=12))

        # 7 days ON, 7 OFF
        dayRotation = self.workSchedule.createRotation("Day", "Day")
        dayRotation.addSegment(day, 7, 7)

        # 7 nights ON, 7 OFF
        nightRotation = self.workSchedule.createRotation("Night", "Night")
        nightRotation.addSegment(night, 7, 7)

        self.workSchedule.createTeam("A", "A day shift", dayRotation, date(2014, 1, 2))
        self.workSchedule.createTeam("B", "B night shift", nightRotation, date(2014, 1, 2))
        self.workSchedule.createTeam("C", "C day shift", dayRotation, date(2014, 1, 9))
        self.workSchedule.createTeam("D", "D night shift", nightRotation, date(2014, 1, 9))
```

When printed out for a week of shift instances, the output is:

```python
Schedule: Manufacturing Company - four twelves (Four 12 hour alternating day/night shifts)
Rotation duration: 56D:0H:0M, Scheduled working time: 14D:0H:0M
Shifts: 
   (1) Day (Day shift), Start: 07:00:00 (0D:12H:0M), End: 19:00:00
   (2) Night (Night shift), Start: 19:00:00 (0D:12H:0M), End: 07:00:00
Teams: 
   (1) A (A day shift), Rotation start: 2014-01-02, Day (Day)
Rotation periods: [Day (on), Day (on), Day (on), Day (on), Day (on), Day (on), Day (on), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off)], Rotation duration: 14D:0H:0M, Days in rotation: 14.0, Scheduled working time: 3D:12H:0M, Percentage worked: 25.000%, Average hours worked per week: : 42.000
   (2) B (B night shift), Rotation start: 2014-01-02, Night (Night)
Rotation periods: [Night (on), Night (on), Night (on), Night (on), Night (on), Night (on), Night (on), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off)], Rotation duration: 14D:0H:0M, Days in rotation: 14.0, Scheduled working time: 3D:12H:0M, Percentage worked: 25.000%, Average hours worked per week: : 42.000
   (3) C (C day shift), Rotation start: 2014-01-09, Day (Day)
Rotation periods: [Day (on), Day (on), Day (on), Day (on), Day (on), Day (on), Day (on), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off)], Rotation duration: 14D:0H:0M, Days in rotation: 14.0, Scheduled working time: 3D:12H:0M, Percentage worked: 25.000%, Average hours worked per week: : 42.000
   (4) D (D night shift), Rotation start: 2014-01-09, Night (Night)
Rotation periods: [Night (on), Night (on), Night (on), Night (on), Night (on), Night (on), Night (on), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off)], Rotation duration: 14D:0H:0M, Days in rotation: 14.0, Scheduled working time: 3D:12H:0M, Percentage worked: 25.000%, Average hours worked per week: : 42.000
Total team coverage: : 100.00%
Working shifts
[1] Day: 2021-11-01
   (1) Team: A, Shift: Day, Start: 2021-11-01 07:00:00, End: 2021-11-01 19:00:00
   (2) Team: B, Shift: Night, Start: 2021-11-01 19:00:00, End: 2021-11-02 07:00:00
[2] Day: 2021-11-02
   (1) Team: A, Shift: Day, Start: 2021-11-02 07:00:00, End: 2021-11-02 19:00:00
   (2) Team: B, Shift: Night, Start: 2021-11-02 19:00:00, End: 2021-11-03 07:00:00
[3] Day: 2021-11-03
   (1) Team: A, Shift: Day, Start: 2021-11-03 07:00:00, End: 2021-11-03 19:00:00
   (2) Team: B, Shift: Night, Start: 2021-11-03 19:00:00, End: 2021-11-04 07:00:00
[4] Day: 2021-11-04
   (1) Team: C, Shift: Day, Start: 2021-11-04 07:00:00, End: 2021-11-04 19:00:00
   (2) Team: D, Shift: Night, Start: 2021-11-04 19:00:00, End: 2021-11-05 07:00:00
[5] Day: 2021-11-05
   (1) Team: C, Shift: Day, Start: 2021-11-05 07:00:00, End: 2021-11-05 19:00:00
   (2) Team: D, Shift: Night, Start: 2021-11-05 19:00:00, End: 2021-11-06 07:00:00
[6] Day: 2021-11-06
   (1) Team: C, Shift: Day, Start: 2021-11-06 07:00:00, End: 2021-11-06 19:00:00
   (2) Team: D, Shift: Night, Start: 2021-11-06 19:00:00, End: 2021-11-07 07:00:00
[7] Day: 2021-11-07
   (1) Team: C, Shift: Day, Start: 2021-11-07 07:00:00, End: 2021-11-07 19:00:00
   (2) Team: D, Shift: Night, Start: 2021-11-07 19:00:00, End: 2021-11-08 07:00:00
```

For a third example, the work schedule below with one 24 hour shift over an 18 day rotation for three platoons is used by Kern County, California firefighters.

```python
        # Kern Co, CA
        self.workSchedule = WorkSchedule("Kern Co.", "Three 24 hour alternating shifts")

        # shift, start 07:00 for 24 hours
        shift = self.workSchedule.createShift("24 Hour", "24 hour shift", time(7, 0, 0), timedelta(hours=24))

        # 2 days ON, 2 OFF, 2 ON, 2 OFF, 2 ON, 8 OFF
        rotation = self.workSchedule.createRotation("24 Hour", "2 days ON, 2 OFF, 2 ON, 2 OFF, 2 ON, 8 OFF")
        rotation.addSegment(shift, 2, 2)
        rotation.addSegment(shift, 2, 2)
        rotation.addSegment(shift, 2, 8)

        self.workSchedule.createTeam("Red", "A Shift", rotation, date(2017, 1, 8))
        self.workSchedule.createTeam("Black", "B Shift", rotation, date(2017, 2, 1))
        self.workSchedule.createTeam("Green", "C Shift", rotation, date(2017, 1, 2))
```

When printed out for a week of shift instances, the output is:
```python
Schedule: Kern Co. (Three 24 hour alternating shifts)
Rotation duration: 54D:0H:0M, Scheduled working time: 18D:0H:0M
Shifts: 
   (1) 24 Hour (24 hour shift), Start: 07:00:00 (1D:0H:0M), End: 07:00:00
Teams: 
   (1) Red (A Shift), Rotation start: 2017-01-08, 24 Hour (2 days ON, 2 OFF, 2 ON, 2 OFF, 2 ON, 8 OFF)
Rotation periods: [24 Hour (on), 24 Hour (on), DAY_OFF (off), DAY_OFF (off), 24 Hour (on), 24 Hour (on), DAY_OFF (off), DAY_OFF (off), 24 Hour (on), 24 Hour (on), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off)], Rotation duration: 18D:0H:0M, Days in rotation: 18.0, Scheduled working time: 6D:0H:0M, Percentage worked: 33.333%, Average hours worked per week: : 56.000
   (2) Black (B Shift), Rotation start: 2017-02-01, 24 Hour (2 days ON, 2 OFF, 2 ON, 2 OFF, 2 ON, 8 OFF)
Rotation periods: [24 Hour (on), 24 Hour (on), DAY_OFF (off), DAY_OFF (off), 24 Hour (on), 24 Hour (on), DAY_OFF (off), DAY_OFF (off), 24 Hour (on), 24 Hour (on), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off)], Rotation duration: 18D:0H:0M, Days in rotation: 18.0, Scheduled working time: 6D:0H:0M, Percentage worked: 33.333%, Average hours worked per week: : 56.000
   (3) Green (C Shift), Rotation start: 2017-01-02, 24 Hour (2 days ON, 2 OFF, 2 ON, 2 OFF, 2 ON, 8 OFF)
Rotation periods: [24 Hour (on), 24 Hour (on), DAY_OFF (off), DAY_OFF (off), 24 Hour (on), 24 Hour (on), DAY_OFF (off), DAY_OFF (off), 24 Hour (on), 24 Hour (on), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off)], Rotation duration: 18D:0H:0M, Days in rotation: 18.0, Scheduled working time: 6D:0H:0M, Percentage worked: 33.333%, Average hours worked per week: : 56.000
Total team coverage: : 100.00%
Working shifts
[1] Day: 2021-11-01
   (1) Team: Green, Shift: 24 Hour, Start: 2021-11-01 07:00:00, End: 2021-11-02 07:00:00
[2] Day: 2021-11-02
   (1) Team: Green, Shift: 24 Hour, Start: 2021-11-02 07:00:00, End: 2021-11-03 07:00:00
[3] Day: 2021-11-03
   (1) Team: Black, Shift: 24 Hour, Start: 2021-11-03 07:00:00, End: 2021-11-04 07:00:00
[4] Day: 2021-11-04
   (1) Team: Black, Shift: 24 Hour, Start: 2021-11-04 07:00:00, End: 2021-11-05 07:00:00
[5] Day: 2021-11-05
   (1) Team: Green, Shift: 24 Hour, Start: 2021-11-05 07:00:00, End: 2021-11-06 07:00:00
[6] Day: 2021-11-06
   (1) Team: Green, Shift: 24 Hour, Start: 2021-11-06 07:00:00, End: 2021-11-07 07:00:00
[7] Day: 2021-11-07
   (1) Team: Red, Shift: 24 Hour, Start: 2021-11-07 07:00:00, End: 2021-11-08 07:00:00
```

For a another example, a restaurant shift that starts at 7 am on August 8, 2024, team member #1 called in sick and is to be replaced by member #10:
```python
self.workSchedule = WorkSchedule("Restaurant", "Two shifts")

# day shift (12 hours)
day = self.workSchedule.createShift("Day", "Green", time(6, 0, 0), timedelta(hours=12))
        
# day shift rotation, 1 days ON, 0 OFF
dayRotation = self.workSchedule.createRotation("Day", "One day on, 6 off")
dayRotation.addSegment(day, 1, 6)

# day teams
greenStart = date(2024, 7, 28)
sundayDay = self.workSchedule.createTeam("SundayDay", "Sunday day", dayRotation, greenStart)

# chef members
one = TeamMember("Chef, One", "Chef", "1")
two = TeamMember("Chef, Two", "Chef", "2")
three = TeamMember("Chef, Three", "Chef", "3")        
        
# day members (one and two are in sundayDay.assignedMembers)
sundayDay.addMember(one) 
sundayDay.addMember(two) 
        
# replace one with three for this shift instance start
exceptionShift = datetime.combine(date(2024, 8, 11), time(7, 0, 0))
replacement = TeamMemberException(exceptionShift)
replacement.removal = one
replacement.addition = three
sundayDay.addMemberException(replacement)     
        
#  two and three are the team members for this shift instance
members = sundayDay.getMembers(exceptionShift)  
```

## Project Structure
PyShift has the following structure:
 * '/' - doc.zip (DOxygen documentation), setup.py, README.md
 * `/workschedule` - Python source files
 * `/workschedule/locales` - .mo and .po text translation files for locales
 * `/test` - unit test Python source files 
 * `/scripts` - Windows shell script to create compiled message translation files



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/point85/PyShift",
    "name": "PyWorkShift",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "shift, work schedule, shift calendar, work calendar",
    "author": "Kent Randall",
    "author_email": "Kent Randall <point85.llc@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/c0/ef/05fe8c4638036a4cdf7b43be3a3610c92af2c0e75ece7a95bdbbeee95234/pyworkshift-1.1.0.tar.gz",
    "platform": null,
    "description": "# PyShift\r\nThe PyShift library project manages work schedules.  A work schedule consists of one or more teams who rotate through a sequence of shift and off-shift periods of time.  The PyShift project allows breaks during shifts to be defined as well as non-working periods of time (e.g. holidays and scheduled maintenance periods) that are applicable to the entire work schedule.\r\n\r\n## Concepts\r\n\r\nThe Business Management Systems' DNO (Day, Night, Off) work schedule with three teams and two 12-hour shifts with a 3-day rotation is an example work schedule.  This schedule is explained in http://community.bmscentral.com/learnss/ZC/3T/c3tr12-1.\r\n\r\n*Shift*\r\n\r\nA shift is defined with a name, description, starting time of day and duration.  An off-shift period is associated with a shift.  In the example above for Team1, there are two shifts followed by one off-shift period.  Shifts can be overlapped (typically when a handoff of duties is important such as in the nursing profession).  A rotation is a sequence of shifts and off-shift days.  The DNO rotation is Day on, Night on and Night off.  An instance of a shift has a starting date and time of day and has an associated shift definition.\r\n\r\n*Break*\r\n\r\nA break is a defined working period of time during a shift, for example lunch.  A shift can have zero or more breaks.\r\n\r\n*Team*\r\n\r\nA team is defined with a name and description.  It has a rotation with a starting date.  The starting date shift will have an instance with that date and a starting time of day as defined by the shift.  The same rotation can be shared between more than one team, but with different starting times.\r\n\r\n*Team Member*\r\n\r\nA team member is a person assigned to a team.  The member is identified by a member ID (e.g. employee ID), name and description/title.\r\n\r\n*Team Member Exception*\r\n\r\nA team member exception is an addition and/or removal from the assigned members of a team for a specified shift instance.  The instance is identified by the starting date and time.\r\n\r\n*Work Schedule*\r\n\r\nA work schedule is defined with a name and description.  It has one or more teams.  Zero or more non-working periods can be defined.  A non-working period has a defined starting date and time of day and duration.  For example, the New Year's Day holiday starting at midnight for 24 hours, or three consecutive days for preventive maintenance of manufacturing equipment starting at the end of the night shift. \r\n\r\nAfter a work schedule is defined, the working time for all shifts can be computed for a defined time interval.  For example, this duration of time is the maximum available productive time as an input to the calculation of the utilization of equipment in a metric known as the Overall Equipment Effectiveness (OEE).\r\n\r\n*Rotation*\r\n\r\nA rotation is a sequence of working periods (segments).  Each segment starts with a shift and specifies the number of days on-shift and off-shift.  A work schedule can have more than one rotation.\r\n\r\n*Non-Working Period*\r\n\r\nA non-working period is a duration of time where no teams are working.  For example, a holiday or a period of time when a plant is shutdown for preventative maintenance.  A non-working period starts at a defined day and time of day and continues for the specified duration of time.\r\n\r\n*Shift Instance*\r\n\r\nA shift instance is the duration of time from a specified date and time of day and continues for the duration of the associated shift.  A team works this shift instance.\r\n\r\n## Examples\r\nThe DNO schedule discussed above is defined as follows.\r\n\r\n```python\r\n        description = \"This is a fast rotation plan that uses 3 teams and two 12-hr shifts to provide 24/7 coverage. \"\r\n        description = description + \"Each team rotates through the following sequence every three days: 1 day shift, 1 night shift, and 1 day off.\"\r\n\r\n        self.workSchedule = WorkSchedule(\"DNO Plan\", description)\r\n\r\n        # Day shift, starts at 07:00 for 12 hours\r\n        day = self.workSchedule.createShift(\"Day\", \"Day shift\", time(7, 0, 0), timedelta(hours=12))\r\n\r\n        # Night shift, starts at 19:00 for 12 hours\r\n        night = self.workSchedule.createShift(\"Night\", \"Night shift\", time(19, 0, 0), timedelta(hours=12))\r\n\r\n        # rotation\r\n        rotation = self.workSchedule.createRotation(\"DNO\", \"DNO\")\r\n        rotation.addSegment(day, 1, 0)\r\n        rotation.addSegment(night, 1, 1)\r\n        referenceDate = date(2021, 11, 1)\r\n\r\n        self.workSchedule.createTeam(\"Team 1\", \"First team\", rotation, referenceDate)\r\n        self.workSchedule.createTeam(\"Team 2\", \"Second team\", rotation, referenceDate - timedelta(days=1))\r\n        self.workSchedule.createTeam(\"Team 3\", \"Third team\", rotation, referenceDate - timedelta(days=2))\r\n```\r\nTo obtain the working time over three days starting at 07:00, the following method is called:\r\n\r\n```python\r\n        fromDateTime = datetime.combine(date(2021, 11, 2), time(7, 0, 0))\r\n        duration = self.workSchedule.calculateWorkingTime(fromDateTime, fromDateTime + timedelta(days=3))\r\n```\r\n\r\nTo obtain the shift instances for a date, the following method is called:\r\n\r\n```python\r\nshiftInstances = self.workSchedule.getShiftInstancesForDay(date(2021, 11, 2)) \r\n```\r\n\r\nTo print a work schedule, call the __str()__ method.  For example:\r\n\r\n```python\r\n        print(str(self.workSchedule))\r\n```\r\nwith output:\r\n\r\n```python\t\t\r\nSchedule: DNO Plan (This is a fast rotation plan that uses 3 teams and two 12-hr shifts to provide 24/7 coverage. Each team rotates through the following sequence every three days: 1 day shift, 1 night shift, and 1 day off.)\r\nRotation duration: 9D:0H:0M, Scheduled working time: 3D:0H:0M\r\nShifts: \r\n   (1) Day (Day shift), Start: 07:00:00 (0D:12H:0M), End: 19:00:00\r\n   (2) Night (Night shift), Start: 19:00:00 (0D:12H:0M), End: 07:00:00\r\nTeams: \r\n   (1) Team 1 (First team), Rotation start: 2021-11-01, DNO (DNO)\r\nRotation periods: [Day (on), Night (on), DAY_OFF (off)], Rotation duration: 3D:0H:0M, Days in rotation: 3.0, Scheduled working time: 1D:0H:0M, Percentage worked: 33.333%, Average hours worked per week: : 56.000\r\n   (2) Team 2 (Second team), Rotation start: 2021-10-31, DNO (DNO)\r\nRotation periods: [Day (on), Night (on), DAY_OFF (off)], Rotation duration: 3D:0H:0M, Days in rotation: 3.0, Scheduled working time: 1D:0H:0M, Percentage worked: 33.333%, Average hours worked per week: : 56.000\r\n   (3) Team 3 (Third team), Rotation start: 2021-10-30, DNO (DNO)\r\nRotation periods: [Day (on), Night (on), DAY_OFF (off)], Rotation duration: 3D:0H:0M, Days in rotation: 3.0, Scheduled working time: 1D:0H:0M, Percentage worked: 33.333%, Average hours worked per week: : 56.000\r\nTotal team coverage: : 100.00%\r\n```\r\n\r\nTo print shift instances between two dates, the following method is called:\r\n\r\n ```python\r\nself.workSchedule.printShiftInstances(date(2021, 11, 1), date(2021, 11, 3))\r\n```\r\nwith output:\r\n\r\n```python\r\nWorking shifts\r\n[1] Day: 2021-11-01\r\n   (1) Team: Team 1, Shift: Day, Start: 2021-11-01 07:00:00, End: 2021-11-01 19:00:00\r\n   (2) Team: Team 2, Shift: Night, Start: 2021-11-01 19:00:00, End: 2021-11-02 07:00:00\r\n[2] Day: 2021-11-02\r\n   (1) Team: Team 3, Shift: Day, Start: 2021-11-02 07:00:00, End: 2021-11-02 19:00:00\r\n   (2) Team: Team 1, Shift: Night, Start: 2021-11-02 19:00:00, End: 2021-11-03 07:00:00\r\n[3] Day: 2021-11-03\r\n   (1) Team: Team 2, Shift: Day, Start: 2021-11-03 07:00:00, End: 2021-11-03 19:00:00\r\n   (2) Team: Team 3, Shift: Night, Start: 2021-11-03 19:00:00, End: 2021-11-04 07:00:00\r\n```\r\n \r\nFor a second example, the 24/7 schedule below has two rotations for four teams in two shifts.  It is used by manufacturing companies.\r\n\r\n```python\r\n        self.workSchedule = WorkSchedule(\"Manufacturing Company - four twelves\",\r\n            \"Four 12 hour alternating day/night shifts\")\r\n\r\n        # day shift, start at 07:00 for 12 hours\r\n        day = self.workSchedule.createShift(\"Day\", \"Day shift\", time(7, 0, 0), timedelta(hours=12))\r\n\r\n        # night shift, start at 19:00 for 12 hours\r\n        night = self.workSchedule.createShift(\"Night\", \"Night shift\", time(19, 0, 0), timedelta(hours=12))\r\n\r\n        # 7 days ON, 7 OFF\r\n        dayRotation = self.workSchedule.createRotation(\"Day\", \"Day\")\r\n        dayRotation.addSegment(day, 7, 7)\r\n\r\n        # 7 nights ON, 7 OFF\r\n        nightRotation = self.workSchedule.createRotation(\"Night\", \"Night\")\r\n        nightRotation.addSegment(night, 7, 7)\r\n\r\n        self.workSchedule.createTeam(\"A\", \"A day shift\", dayRotation, date(2014, 1, 2))\r\n        self.workSchedule.createTeam(\"B\", \"B night shift\", nightRotation, date(2014, 1, 2))\r\n        self.workSchedule.createTeam(\"C\", \"C day shift\", dayRotation, date(2014, 1, 9))\r\n        self.workSchedule.createTeam(\"D\", \"D night shift\", nightRotation, date(2014, 1, 9))\r\n```\r\n\r\nWhen printed out for a week of shift instances, the output is:\r\n\r\n```python\r\nSchedule: Manufacturing Company - four twelves (Four 12 hour alternating day/night shifts)\r\nRotation duration: 56D:0H:0M, Scheduled working time: 14D:0H:0M\r\nShifts: \r\n   (1) Day (Day shift), Start: 07:00:00 (0D:12H:0M), End: 19:00:00\r\n   (2) Night (Night shift), Start: 19:00:00 (0D:12H:0M), End: 07:00:00\r\nTeams: \r\n   (1) A (A day shift), Rotation start: 2014-01-02, Day (Day)\r\nRotation periods: [Day (on), Day (on), Day (on), Day (on), Day (on), Day (on), Day (on), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off)], Rotation duration: 14D:0H:0M, Days in rotation: 14.0, Scheduled working time: 3D:12H:0M, Percentage worked: 25.000%, Average hours worked per week: : 42.000\r\n   (2) B (B night shift), Rotation start: 2014-01-02, Night (Night)\r\nRotation periods: [Night (on), Night (on), Night (on), Night (on), Night (on), Night (on), Night (on), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off)], Rotation duration: 14D:0H:0M, Days in rotation: 14.0, Scheduled working time: 3D:12H:0M, Percentage worked: 25.000%, Average hours worked per week: : 42.000\r\n   (3) C (C day shift), Rotation start: 2014-01-09, Day (Day)\r\nRotation periods: [Day (on), Day (on), Day (on), Day (on), Day (on), Day (on), Day (on), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off)], Rotation duration: 14D:0H:0M, Days in rotation: 14.0, Scheduled working time: 3D:12H:0M, Percentage worked: 25.000%, Average hours worked per week: : 42.000\r\n   (4) D (D night shift), Rotation start: 2014-01-09, Night (Night)\r\nRotation periods: [Night (on), Night (on), Night (on), Night (on), Night (on), Night (on), Night (on), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off)], Rotation duration: 14D:0H:0M, Days in rotation: 14.0, Scheduled working time: 3D:12H:0M, Percentage worked: 25.000%, Average hours worked per week: : 42.000\r\nTotal team coverage: : 100.00%\r\nWorking shifts\r\n[1] Day: 2021-11-01\r\n   (1) Team: A, Shift: Day, Start: 2021-11-01 07:00:00, End: 2021-11-01 19:00:00\r\n   (2) Team: B, Shift: Night, Start: 2021-11-01 19:00:00, End: 2021-11-02 07:00:00\r\n[2] Day: 2021-11-02\r\n   (1) Team: A, Shift: Day, Start: 2021-11-02 07:00:00, End: 2021-11-02 19:00:00\r\n   (2) Team: B, Shift: Night, Start: 2021-11-02 19:00:00, End: 2021-11-03 07:00:00\r\n[3] Day: 2021-11-03\r\n   (1) Team: A, Shift: Day, Start: 2021-11-03 07:00:00, End: 2021-11-03 19:00:00\r\n   (2) Team: B, Shift: Night, Start: 2021-11-03 19:00:00, End: 2021-11-04 07:00:00\r\n[4] Day: 2021-11-04\r\n   (1) Team: C, Shift: Day, Start: 2021-11-04 07:00:00, End: 2021-11-04 19:00:00\r\n   (2) Team: D, Shift: Night, Start: 2021-11-04 19:00:00, End: 2021-11-05 07:00:00\r\n[5] Day: 2021-11-05\r\n   (1) Team: C, Shift: Day, Start: 2021-11-05 07:00:00, End: 2021-11-05 19:00:00\r\n   (2) Team: D, Shift: Night, Start: 2021-11-05 19:00:00, End: 2021-11-06 07:00:00\r\n[6] Day: 2021-11-06\r\n   (1) Team: C, Shift: Day, Start: 2021-11-06 07:00:00, End: 2021-11-06 19:00:00\r\n   (2) Team: D, Shift: Night, Start: 2021-11-06 19:00:00, End: 2021-11-07 07:00:00\r\n[7] Day: 2021-11-07\r\n   (1) Team: C, Shift: Day, Start: 2021-11-07 07:00:00, End: 2021-11-07 19:00:00\r\n   (2) Team: D, Shift: Night, Start: 2021-11-07 19:00:00, End: 2021-11-08 07:00:00\r\n```\r\n\r\nFor a third example, the work schedule below with one 24 hour shift over an 18 day rotation for three platoons is used by Kern County, California firefighters.\r\n\r\n```python\r\n        # Kern Co, CA\r\n        self.workSchedule = WorkSchedule(\"Kern Co.\", \"Three 24 hour alternating shifts\")\r\n\r\n        # shift, start 07:00 for 24 hours\r\n        shift = self.workSchedule.createShift(\"24 Hour\", \"24 hour shift\", time(7, 0, 0), timedelta(hours=24))\r\n\r\n        # 2 days ON, 2 OFF, 2 ON, 2 OFF, 2 ON, 8 OFF\r\n        rotation = self.workSchedule.createRotation(\"24 Hour\", \"2 days ON, 2 OFF, 2 ON, 2 OFF, 2 ON, 8 OFF\")\r\n        rotation.addSegment(shift, 2, 2)\r\n        rotation.addSegment(shift, 2, 2)\r\n        rotation.addSegment(shift, 2, 8)\r\n\r\n        self.workSchedule.createTeam(\"Red\", \"A Shift\", rotation, date(2017, 1, 8))\r\n        self.workSchedule.createTeam(\"Black\", \"B Shift\", rotation, date(2017, 2, 1))\r\n        self.workSchedule.createTeam(\"Green\", \"C Shift\", rotation, date(2017, 1, 2))\r\n```\r\n\r\nWhen printed out for a week of shift instances, the output is:\r\n```python\r\nSchedule: Kern Co. (Three 24 hour alternating shifts)\r\nRotation duration: 54D:0H:0M, Scheduled working time: 18D:0H:0M\r\nShifts: \r\n   (1) 24 Hour (24 hour shift), Start: 07:00:00 (1D:0H:0M), End: 07:00:00\r\nTeams: \r\n   (1) Red (A Shift), Rotation start: 2017-01-08, 24 Hour (2 days ON, 2 OFF, 2 ON, 2 OFF, 2 ON, 8 OFF)\r\nRotation periods: [24 Hour (on), 24 Hour (on), DAY_OFF (off), DAY_OFF (off), 24 Hour (on), 24 Hour (on), DAY_OFF (off), DAY_OFF (off), 24 Hour (on), 24 Hour (on), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off)], Rotation duration: 18D:0H:0M, Days in rotation: 18.0, Scheduled working time: 6D:0H:0M, Percentage worked: 33.333%, Average hours worked per week: : 56.000\r\n   (2) Black (B Shift), Rotation start: 2017-02-01, 24 Hour (2 days ON, 2 OFF, 2 ON, 2 OFF, 2 ON, 8 OFF)\r\nRotation periods: [24 Hour (on), 24 Hour (on), DAY_OFF (off), DAY_OFF (off), 24 Hour (on), 24 Hour (on), DAY_OFF (off), DAY_OFF (off), 24 Hour (on), 24 Hour (on), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off)], Rotation duration: 18D:0H:0M, Days in rotation: 18.0, Scheduled working time: 6D:0H:0M, Percentage worked: 33.333%, Average hours worked per week: : 56.000\r\n   (3) Green (C Shift), Rotation start: 2017-01-02, 24 Hour (2 days ON, 2 OFF, 2 ON, 2 OFF, 2 ON, 8 OFF)\r\nRotation periods: [24 Hour (on), 24 Hour (on), DAY_OFF (off), DAY_OFF (off), 24 Hour (on), 24 Hour (on), DAY_OFF (off), DAY_OFF (off), 24 Hour (on), 24 Hour (on), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off), DAY_OFF (off)], Rotation duration: 18D:0H:0M, Days in rotation: 18.0, Scheduled working time: 6D:0H:0M, Percentage worked: 33.333%, Average hours worked per week: : 56.000\r\nTotal team coverage: : 100.00%\r\nWorking shifts\r\n[1] Day: 2021-11-01\r\n   (1) Team: Green, Shift: 24 Hour, Start: 2021-11-01 07:00:00, End: 2021-11-02 07:00:00\r\n[2] Day: 2021-11-02\r\n   (1) Team: Green, Shift: 24 Hour, Start: 2021-11-02 07:00:00, End: 2021-11-03 07:00:00\r\n[3] Day: 2021-11-03\r\n   (1) Team: Black, Shift: 24 Hour, Start: 2021-11-03 07:00:00, End: 2021-11-04 07:00:00\r\n[4] Day: 2021-11-04\r\n   (1) Team: Black, Shift: 24 Hour, Start: 2021-11-04 07:00:00, End: 2021-11-05 07:00:00\r\n[5] Day: 2021-11-05\r\n   (1) Team: Green, Shift: 24 Hour, Start: 2021-11-05 07:00:00, End: 2021-11-06 07:00:00\r\n[6] Day: 2021-11-06\r\n   (1) Team: Green, Shift: 24 Hour, Start: 2021-11-06 07:00:00, End: 2021-11-07 07:00:00\r\n[7] Day: 2021-11-07\r\n   (1) Team: Red, Shift: 24 Hour, Start: 2021-11-07 07:00:00, End: 2021-11-08 07:00:00\r\n```\r\n\r\nFor a another example, a restaurant shift that starts at 7 am on August 8, 2024, team member #1 called in sick and is to be replaced by member #10:\r\n```python\r\nself.workSchedule = WorkSchedule(\"Restaurant\", \"Two shifts\")\r\n\r\n# day shift (12 hours)\r\nday = self.workSchedule.createShift(\"Day\", \"Green\", time(6, 0, 0), timedelta(hours=12))\r\n        \r\n# day shift rotation, 1 days ON, 0 OFF\r\ndayRotation = self.workSchedule.createRotation(\"Day\", \"One day on, 6 off\")\r\ndayRotation.addSegment(day, 1, 6)\r\n\r\n# day teams\r\ngreenStart = date(2024, 7, 28)\r\nsundayDay = self.workSchedule.createTeam(\"SundayDay\", \"Sunday day\", dayRotation, greenStart)\r\n\r\n# chef members\r\none = TeamMember(\"Chef, One\", \"Chef\", \"1\")\r\ntwo = TeamMember(\"Chef, Two\", \"Chef\", \"2\")\r\nthree = TeamMember(\"Chef, Three\", \"Chef\", \"3\")        \r\n        \r\n# day members (one and two are in sundayDay.assignedMembers)\r\nsundayDay.addMember(one) \r\nsundayDay.addMember(two) \r\n        \r\n# replace one with three for this shift instance start\r\nexceptionShift = datetime.combine(date(2024, 8, 11), time(7, 0, 0))\r\nreplacement = TeamMemberException(exceptionShift)\r\nreplacement.removal = one\r\nreplacement.addition = three\r\nsundayDay.addMemberException(replacement)     \r\n        \r\n#  two and three are the team members for this shift instance\r\nmembers = sundayDay.getMembers(exceptionShift)  \r\n```\r\n\r\n## Project Structure\r\nPyShift has the following structure:\r\n * '/' - doc.zip (DOxygen documentation), setup.py, README.md\r\n * `/workschedule` - Python source files\r\n * `/workschedule/locales` - .mo and .po text translation files for locales\r\n * `/test` - unit test Python source files \r\n * `/scripts` - Windows shell script to create compiled message translation files\r\n\r\n\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A work schedule library for shifts.",
    "version": "1.1.0",
    "project_urls": {
        "Homepage": "https://github.com/point85/PyShift",
        "Issues": "https://github.com/point85/PyShift/issues"
    },
    "split_keywords": [
        "shift",
        " work schedule",
        " shift calendar",
        " work calendar"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "366f4a360c032b125c91616c32eb62703f2dee86c8484443f883528fb82a35a4",
                "md5": "0c1c7bb5daa22c65a304cda2c48091cc",
                "sha256": "237927837f9553f66adfb6009b3727ed3e0bb0e2cc4a4fa02126415591653617"
            },
            "downloads": -1,
            "filename": "PyWorkShift-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0c1c7bb5daa22c65a304cda2c48091cc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 18049,
            "upload_time": "2024-12-21T02:00:13",
            "upload_time_iso_8601": "2024-12-21T02:00:13.139949Z",
            "url": "https://files.pythonhosted.org/packages/36/6f/4a360c032b125c91616c32eb62703f2dee86c8484443f883528fb82a35a4/PyWorkShift-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c0ef05fe8c4638036a4cdf7b43be3a3610c92af2c0e75ece7a95bdbbeee95234",
                "md5": "d57a74f1dceed29128ed938aeb1891ed",
                "sha256": "860518edcfc24436526292b8b54000c612dccf384f2c3f67b209ba0909f4bf34"
            },
            "downloads": -1,
            "filename": "pyworkshift-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "d57a74f1dceed29128ed938aeb1891ed",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 17394,
            "upload_time": "2024-12-21T02:00:15",
            "upload_time_iso_8601": "2024-12-21T02:00:15.530008Z",
            "url": "https://files.pythonhosted.org/packages/c0/ef/05fe8c4638036a4cdf7b43be3a3610c92af2c0e75ece7a95bdbbeee95234/pyworkshift-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-21 02:00:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "point85",
    "github_project": "PyShift",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pyworkshift"
}
        
Elapsed time: 0.38340s