Git Product home page Git Product logo

schedule-generator's Introduction

schedule-generator

This is schedule generator for shift and set based employees.

What the project does

Schedule-generator is a program written on Python that generates schedule of shift-based employees and outputs .xlsx template ready to be uploaded to Microsoft Teams shifts plug-in.

External libraries used:

  • OpenPyXL
  • SimplePyGUI

It coninsts of following .py files:

  • sched-gen-gui.py
  • functions.py
  • schedule.py

sched-gen-gui.py

As the name of the file suggests it is a GUI file of a schedule-generator. It uses PySimpleGUI as a builder. It consists of a 4 input fields, calculate and exit buttons.

Window that stays open_2

2 out of 4 input fields take Excel file in, one of which should be .xlsx file that contains information about employees (see below).

employees file - Excel

Another one should be empty shifts template Excel file, which you can download from shifts plug-in itself.

Rest two input fields are 'Year' and 'Month'. Year should be full 4 digits number, e.g.: 2021, 2001, 1997. Month should be integer, too. E.g.: 1, 4, 5, 10, 12.

functions.py

Functions.py file stores custom functions. Basically there are two functions defined there and a class. It requires two libraries: datetime and time.

yeardays function:

def yeardays(year):
    """Generate all days of the year."""
    for d in range(365):
        yield dt.date(year,1,1) + dt.timedelta(days=d)

get_shiftset function:

def get_shiftset(d):
    """Determine if a day belongs to Set 1 or 2."""
    set_day = (d - dt.date(d.year,1,1)).days % 6
    return "Set 1" if set_day < 3 else "Set 2"

Managers() class (As this was ment for Managers schedule in my company I have called this class Managers(), however, think of it as an Employee() class):

class Manager():
    """
    Class of manager (employee).
    self.name - Stores name of a manager (employee);
    self.shift_type - Stores shift type of an employee (Morning, Afternoon, or Night);
    self.mset - Stores set of an employee (should be 1 or 2);
    self.email - Stores email of an employee;
    self.shifts - Empty list upon creation of a new class. Later stores all the generated shift dates of an employee.
    self.role - Empty upon creation. Can be assigned later.
    """

    def __init__(self, name, shift_type, mset, email):
        self.name = name
        self.shift_type = shift_type
        self.mset = mset
        self.email = email
        self.shifts = []
        self.role = []m

Schedule.py

This is where all the magic happens. Lets go one by one. It imports OpenPyXL library and functions.py

One main function is defined in this file that takes manager_file, yearInput, monthInput, teams_file as arguments. This function later is called in sched-gen-gui.py to generate schedule.

Main function first opens empleyees.xlsx file, creates Manager() class for each of the employees and stores them in a list managers = [].

  # Transfer information from Managers excel

    for row in range(2, max_row + 1):
        name = sheet['A' + str(row)].value
        shift_type = sheet['B' + str(row)].value
        mset = sheet['C' + str(row)].value
        email = sheet['D' + str(row)].value

        # Put Retreived info into the Manager class
        manager = Manager(name, shift_type, mset, email)

        # Append every manager into the managers List
        managers.append(manager)

Then generates set days by given year and month. Each of this generated set days are assigned to the manager in manager.shift list.

# Generate set days of the given month of the given year
user_year = yearInput

    while False:
      if user_year == None or type(user_year) != int():
        False
      else:
        True


    user_month = monthInput

    while False:
      if user_month == None or type(user_month) != int():
        False
      else:
        True

    year = user_year

    month = user_month
    
    
for manager in managers:
        for day in yeardays(year):
            if day.month == month and get_shiftset(day) == "Set 1" and manager.mset == 1:
                manager.shifts.append(day)
            elif day.month == month and get_shiftset(day) == "Set 2" and manager.mset == 2:
                manager.shifts.append(day)

Before transferring all of this data to the shifts template it transforms dates to the excel date format.

# Change Python Date to Excel Date
    for manager in managers:
        for i in range(len(manager.shifts)):
            manager.shifts[i] = str(manager.shifts[i]).replace("-", "/")

Finally, it transfers all the managers with their shift dates into Shifts template file, which can be directly updloaded to the teams widget.

# Transferring managers info to excel column

    for manager in managers:
        amount = len(manager.shifts)
        tsheet.insert_rows(idx=2, amount=amount + 1)
        for row in range(2, amount + 2):
            tsheet['A' + str(row)] = manager.name
            tsheet['B' + str(row)] = manager.email
            tsheet['D' + str(row)] = manager.shifts[row - 2]
            tsheet['F' + str(row)] = manager.shifts[row - 2]

            if manager.shift_type.lower() == 'morning':
                tsheet['E' + str(row)] = '07:00'
                tsheet['G' + str(row)] = '15:00'
                tsheet['H' + str(row)] = '2. Blue'
            elif manager.shift_type.lower() == 'afternoon':
                tsheet['E' + str(row)] = '15:00'
                tsheet['G' + str(row)] = '23:00'
                tsheet['H' + str(row)] = '3. Green'
            elif manager.shift_type.lower() == 'night':
                tsheet['E' + str(row)] = '00:00'
                tsheet['G' + str(row)] = '07:00'
                tsheet['H' + str(row)] = '5. Pink'

Contact.

For more questions please contact me at: [email protected]

schedule-generator's People

Contributors

nodri09 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

schedule-generator's Issues

Fantastic!

There is so much to like about this project and how you created it.

Your readme is top-notch. You've got a screenshot of your GUI right at the top. Code that's formatted. You follow the PySimpleGUI coding conventions. Wow! ๐Ÿ’ช ๐Ÿง™โ€โ™‚๏ธ

Way to go! Professional looking all the way.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.