<jupyter_start><jupyter_text>MSDS 432, Assignment 8 - Greedy Algorithm  Author: <NAME><jupyter_code>%matplotlib inline
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from time import time
from datetime import datetime
import matplotlib.style as style
import calendar
np.random.seed(323) # static seed so results are reproducible
style.use('seaborn-poster') # sets the size of the charts
style.use('ggplot') # set the theme for matplotlib
%%javascript
IPython.OutputArea.prototype._should_scroll = function(lines) {
    return false;
}<jupyter_output><empty_output><jupyter_text>Guard Scheduling<jupyter_code>guards = ['Tom', 'Jim', 'Barry', 'Erin', 'Jacob', 'Dan']
pay = {p: 15 if p <= 8 else 20 for p in range(1, 13)}
schedule = {d:[[h, [None, 0]] for h in range(0, 24)] for d in calendar.day_name}
guard, onDuty, prevPay = 0, 1, 0
for day in schedule.keys():
    for hour in schedule[day]:
        task = hour[1]
        if task[0] is None:
            curPay = pay[onDuty]
            
            if curPay > prevPay:
                if guard == len(guards)-1:
                    guard = 0
                else:
                    guard += 1
                    
                onDuty = 1
                curPay = pay[onDuty]
                
            task[0] = guards[guard]
            task[1] = curPay
            
            onDuty += 1
            prevPay = curPay
            
            hour = task<jupyter_output><empty_output><jupyter_text>Schedule<jupyter_code>schedule<jupyter_output><empty_output><jupyter_text>Results<jupyter_code>results = pd.DataFrame(columns = ['Time', 'Guard', 'Pay'])

curDay, slot = 1, 0
for d in schedule.keys():
    for hour in schedule[d]:
        date = datetime.strptime('{0} {1} {2}:00'.format(day, curDay, hour[0]), '%A %d %H:%M')
        guard = hour[1][0]
        pay = hour[1][1]
        results.loc[slot] = [date, guard, pay]
        slot += 1
    curDay += 1

results.set_index('Time', inplace=True)<jupyter_output><empty_output><jupyter_text>Summary<jupyter_code>df = results.groupby(['Guard', 'Pay'])['Guard'].count().unstack('Pay').fillna(0)
df.plot.bar()
plt.ylabel('Total Hours Worked / Hourly Rate')

plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13177947108919766, 'fraction_numerical': 0.020618556701030927, 'mean_word_length': 2.757575757575758, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '134564', 'license': 'MIT', 'n_tokens_mistral': 785, 'n_tokens_neox': 734, 'n_words': 189, 'path': '08_GreedyAlgorithm.ipynb', 'repo_name': 'bmoretz/MSDS-DataEngineering', 'size': '2239'}