<commit_before>"""
    Find Availability Problem

    Given:
        A list of standard company work hours [0, 8, 8, 8, 8, 8, 0]
        where the first '0' is Sunday and the last '0' is Saturday.

        A list of employees with an 'id', 'name', and optional employee-
        specific weekly hours overrides.
            [
                { 1, "01/01/2015", "12/31/2015"}, [0,4,4,8,8,4,0]},
                { 1, "01/01/2016", null}, [0,8,8,8,8,0,0]}
            ]

    Implement a 'find_availabile_work_hours(user_id, from, to)' function
    that outputs availability in the format:
        "12/06/2015",0
        "12/07/2015",4
        "12/08/2015",4
        "12/09/2015",8

    The program calling the 'find_availabile_work_hours()' function takes
    in data in the folling format:
        # example input for the find availability problem

        # company work hours
        0,8,8,8,8,8,0

        # employees
        1,<NAME>
        2,<NAME>

        # mark's availability
        1,"01/01/2015","12/31/2015",[0,8,8,4,10,10,0]
        1,"01/01/2016",null,[0,8,8,8,8,8,0]

        # anne's availability
        2,"03/16/2016","06/16/2016",[0,8,8,8,8,0,0]

        # find availability for user and dates
        1,"12/16/2015","01/15/2016"
"""
import calendar
import datetime


def day_index(date):
    """
        Returns the day of the week index given a datetime.date object
        based on Sunday = index 0
    """
    month = date.month
    day = date.day
    year = date.year

    index = calendar.weekday(year, month, day)
    return (index + 1) % 7


def date_object(date):
    """
        Returns a datetime.date() object based on the inputed date string
    """
    date_list = date.split('/')
    month = int(date_list[0])
    day = int(date_list[1])
    year = int(date_list[2])

    return datetime.date(year, month, day)


def availabile_list(avail_list, start, stop):
    """
        Return a list of avalible work hours for the given
        start and stop date based on the passed in data set.

        avail_list format = [
            ["01/01/2015", "12/31/2015", [0, 4, 4, 4, 4, 4, 0]],
            ["01/01/2016", None, [0, 8, 8, 8, 8, 8, 0]],
        ]
        TODO: Check for company holiday
    """
    start = date_object(start)
    stop = date_object(stop)
    current = start
    result = []

    while current <= stop:
        found = False

        for element in avail_list:
            emp_start = date_object(element[0])

            # Handling the None end date in avail_list
            if element[1]:
                emp_stop = date_object(element[1])
            else:
                emp_stop = stop

            if emp_start <= current and emp_stop >= current:
                result.append('"{:02d}/{:02d}/{}",{}'.format(
                    current.month,
                    current.day,
                    current.year,
                    element[2][day_index(current)]))
                found = True

        if found is False:
                result.append('"{:02d}/{:02d}/{}",0'.format(
                    current.month,
                    current.day,
                    current.year))
<commit_msg>10000ft take home challenge, Find Avalibilty Problem Adding company_holiday check, currently it always returns False<commit_after>"""
    Find Availability Problem

    Given:
        A list of standard company work hours [0, 8, 8, 8, 8, 8, 0]
        where the first '0' is Sunday and the last '0' is Saturday.

        A list of employees with an 'id', 'name', and optional employee-
        specific weekly hours overrides.
            [
                { 1, "01/01/2015", "12/31/2015"}, [0,4,4,8,8,4,0]},
                { 1, "01/01/2016", null}, [0,8,8,8,8,0,0]}
            ]

    Implement a 'find_availabile_work_hours(user_id, from, to)' function
    that outputs availability in the format:
        "12/06/2015",0
        "12/07/2015",4
        "12/08/2015",4
        "12/09/2015",8

    The program calling the 'find_availabile_work_hours()' function takes
    in data in the folling format:
        # example input for the find availability problem

        # company work hours
        0,8,8,8,8,8,0

        # employees
        1,<NAME>
        2,<NAME>

        # mark's availability
        1,"01/01/2015","12/31/2015",[0,8,8,4,10,10,0]
        1,"01/01/2016",null,[0,8,8,8,8,8,0]

        # anne's availability
        2,"03/16/2016","06/16/2016",[0,8,8,8,8,0,0]

        # find availability for user and dates
        1,"12/16/2015","01/15/2016"
"""
import calendar
import datetime


def day_index(date):
    """
        Returns the day of the week index given a datetime.date object
        based on Sunday = index 0
    """
    month = date.month
    day = date.day
    year = date.year

    index = calendar.weekday(year, month, day)
    return (index + 1) % 7


def date_object(date):
    """
        Returns a datetime.date() object based on the inputed date string
    """
    date_list = date.split('/')
    month = int(date_list[0])
    day = int(date_list[1])
    year = int(date_list[2])

    return datetime.date(year, month, day)


def company_holiday(date):
    """
        Return True if date is a company holiday
        else return False
    """
    return False


def availabile_list(avail_list, start, stop):
    """
        Return a list of avalible work hours for the given
        start and stop date based on the passed in data set.

        avail_list format = [
            ["01/01/2015", "12/31/2015", [0, 4, 4, 4, 4, 4, 0]],
            ["01/01/2016", None, [0, 8, 8, 8, 8, 8, 0]],
        ]
        TODO: Check for company holiday
    """
    start = date_object(start)
    stop = date_object(stop)
    current = start
    result = []

    while current <= stop:
        found = False

        if company_holiday(current):
            result.append('"{:02d}/{:02d}/{}",0'.format(
                current.month,
                current.day,
                current.year))
            continue

        for element in avail_list:
            emp_start = date_object(element[0])

            # Handling the None end date in avail_list
            if element[1]:
                emp_stop = date_object(element[1])
            else:
                emp_stop = stop

            if emp_start <= current and emp_stop >= current:
                result.append('"{:02d}/{:02d}/{}",{}'.format(
                    current.month,
                    current.day,
                    current.year,
                    element[2][day_index(current)]))
                found = True

        if found is False:
                result.append('"{:02d}/{:02d}/{}",0'.format(
                    current.month,
                    current.day,
                    current.year))

{'fraction_non_alphanumeric': 0.12657104835132338, 'fraction_numerical': 0.0706786928877717, 'mean_word_length': 1.8054749066777271, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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}}
{'dir': 'git-commits-cleaned', 'id': '1970362', 'n_tokens_mistral': 2399, 'n_tokens_neox': 2078, 'n_words': 584}