<jupyter_start><jupyter_text>Weekly shifts with random affectation This notebook is made to affect people randomly to week shifts.<jupyter_code># Module importation
import random
import datetime

import plotly
plotly.offline.init_notebook_mode()  #generate graph offline and within the notebook<jupyter_output><empty_output><jupyter_text>Define users and shifts<jupyter_code># User input the number of people to affect
nb_people = int(input('For how many people:'))
# For each people put a name
peoples = []
for guy in range(1, nb_people+1):
    peoples.append(str(input('Enter the name of the ' + str(guy) + 'th guy: ')))

print('You have {} people:'.format(nb_people))
for people in peoples:
    print(people)
# How many shifts to generate? 
nb_shifts = int(input('Enter the number of shifts (* nb people will give the number of weeks):'))

print('We\'ll generate {} weeks '.format(nb_shifts * nb_people))<jupyter_output><empty_output><jupyter_text>Generate the weekly shift planning<jupyter_code># Let's create a list of one shift for each people times the number of shifts.
# Everybody is affected the same number of times.
shifts = []

for people in peoples:
    for week in range(0, nb_shifts):
        shifts.append(people) 

# Now we randomly shuffle the list. 
random.shuffle(shifts)

# Building a planning with a dictionnary of the shifts and shifters
planning = []

today = datetime.datetime.today()
begin = today
end = begin + datetime.timedelta(days=7)

for shift in shifts:
    planning.append(dict(Task=shift, 
                         Start=begin.strftime("%Y-%m-%d"), 
                         Finish=end.strftime("%Y-%m-%d"),
                         Resource=shift,
                         name='W' + begin.strftime("%W")))
    begin = end
    end = begin + datetime.timedelta(days=7)

    
    
# Lets output the shifts list of dictionary 
import pprint
pprint.pprint(planning)<jupyter_output><empty_output><jupyter_text>Gantt graph of the planning<jupyter_code># Lets draw the Gantt graph of the shifts
import plotly.figure_factory as ff

fig = ff.create_gantt(planning, index_col='Resource', show_colorbar=True, 
                      title='Weekly shifts for the team members', showgrid_x=True,
                      bar_width=0.2, group_tasks=True, task_names='name')

plotly.offline.iplot(fig)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10046828437633035, 'fraction_numerical': 0.002979991485738612, 'mean_word_length': 3.8353909465020575, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '106708', 'license': 'MIT', 'n_tokens_mistral': 744, 'n_tokens_neox': 714, 'n_words': 220, 'path': 'Weekly shift random affectation.ipynb', 'repo_name': 'lafber/diversified-jupyter-notebook', 'size': '2349'}