def worker_wip(machine_code):
    ### This needs to be updated to reflect the fact that the worker_id task will now deal with the issue
    ### of machines being manned (operator present) or unmanned (operator absent or otherwise not there).
    """ Function to create individual machine WIP dict """

    console.clear()
    print('For machine {} please enter thee following information: \n'.format(
        machine_code))

    # Machine wip dictionary
    # The attendance no longer necessary once the ID number routine complete
    machine_dict = {'Attendance': 'Absent', 'Style': 'null', 'WIP': 'null'}
    # Determine absence
    user_choice = get_user_choice(
        '{} : Is the operator present?'.format(machine_code),
        'Please select an option', (
            'Present',
            'Absent',
        ))
    # If operator not present
    if user_choice != 'Present':
        print wip_validation_fmt.format(
            machine_code, **machine_dict)  # print data back to user
        time.sleep(2)

        #check user satisfaction
        user_satisfied = get_user_choice(
            'Are you satisfied with data entered?', 'Select one',
            ('Yes', 'No'))
        if user_satisfied == 'No':
            return worker_wip(machine_code)  # re-enter worker wip data

        return machine_dict  # return the worker wip dict

    # If operator present
    machine_dict['Attendance'] = 'Present'
    prompt = 'Please enter current style name/number as per work order: '
    machine_dict['Style'] = get_user_input(prompt).strip().lower()
    prompt = 'Please enter the amount of WIP at time of checking: '
    machine_dict['WIP'] = get_user_special_float(prompt)

    print wip_validation_fmt.format(machine_code,
                                    **machine_dict)  # print data back to user
    time.sleep(4)

    user_satisfied = get_user_choice('Are you satisfied with data entered?',
                                     'Select one', ('Yes', 'No'))
    if user_satisfied == 'No':
        return worker_wip(machine_code)  #re-enter worker wip data

    return machine_dict  #return the worker wip dict
def worker_id(machine_code):
    """ Function prompts user for informaiton about the machine and the id of the operator working the machine 
	(if any). Returns dict of that information"""
    # This generates the worker routine for an individual operator. Rather than thinking about
    # present/absent the user will simply state is the machine is manned or unmanned. If it is
    # manned they will be prompted to enter the worker id of the person working on the machine.
    # The fact that manned/unmanned status will be dealt with here means that the Attendance
    #component of the wip task is now defunct (although the user may wish to change the
    # manned/unmanned status during the task if for example the worker was absent when the id
    # routine is run, but present once the wip task is undertaken.
    console.clear()
    print('For machine {} please enter thee following information: \n'.format(
        machine_code))

    worker_id_dict = {'mc_status': 'Unmanned', 'worker_id': 'null'}

    title = '{} : Please state is machine is manned or unmanned?'.format(
        machine_code)
    user_choice = get_user_choice(title, 'Please select an option',
                                  ('Manned', 'Unmanned'))

    # If machine unmanned
    if user_choice != 'Manned':
        print ID_validation_fmt.format(
            machine_code, **worker_id_dict)  # print data back to user
        time.sleep(2)

        #check user satisfaction
        user_satisfied = get_user_choice(
            'Are you satisfied with data entered?', 'Select one',
            ('Yes', 'No'))
        if user_satisfied == 'No':
            return worker_id(machine_code)  # re-enter the machine dict data

        return worker_id_dict  # return the machine dict

    worker_id_dict['mc_status'] = 'Manned'
    prompt = 'Please enter the id number of the worker on this machine as is appears on their ID card: '
    worker_id_dict['worker_id'] = get_user_input(prompt).strip().lower()
    print ID_validation_fmt.format(machine_code,
                                   **worker_id_dict)  # print data back to user
    time.sleep(4)

    user_satisfied = get_user_choice('Are you satisfied with data entered?',
                                     'Select one', ('Yes', 'No'))
    if user_satisfied == 'No':
        return worker_id(machine_code)  #re-enter worker wip data

    return worker_id_dict  #return the worker id dict
def configure_application(file_name):
    """ Creates and returns the top level dictionary and the task dictionaries. Additioanlly tests user satisfaction
        with the top level data entered and saves to json. It is intended that this is the function that is returned
        by the open_json function if the json does not already exist when opening the top_level_data."""
    # ¡¡ I am not sure if this is really the right way to program these type of functions that return other
    # functions. This seems to work, but doubtless there is some coding style best practice I have overlooked.
    print "First you need to conifgure the application for the number of operators to be observed"
    time.sleep(4)

    # create top level dictionary
    top_level_dict = {
        "Knitting": get_user_int("Please enter the number of Knitting Operators"),
        "Linking": get_user_int("Please enter the number of Linking Operators"),
    }

    print (Top_validation_fmt.format(**top_level_dict))  # print data back to user

    # check user satisfaction
    user_satisfied = get_user_choice("Are you satisfied with data entered?", "Select one", ("Yes", "No"))
    if user_satisfied == "No":
        return configure_application(file_name)

    # save to json
    write_to_json(top_level_dict, file_name)

    # Create and save the task dictionaries
    create_task_dicts(top_level_dict, task_dict)

    return top_level_dict
def populate_id_dict(id_dict, past_id_dict_file_name, top_level_dict,
                     department):
    """ Function to populate worker id dicts based upon previous saved versions """
    # This function populates the daily id dict but rather than asking the user for each piece of
    # information it takes the last known data for that machine and prompts the user to see if
    # they wish to make changes. If they do the the worker_id function is called. I have not yet
    # had the chance to see if this is working.
    if past_id_dict_file_name is None:
        return populate_first_id_dict(id_dict, top_level_dict, department)

    past_id_dict = open_json(past_id_dict_file_name, None, None)
    for machine_code in create_machine_code(top_level_dict, department):
        print ID_validation_fmt.format_2(
            machine_code,
            **past_id_dict[machine_code])  # print data back to user
        user_satisfied = get_user_choice(
            'Are you satisfied with data entered?', 'Select one',
            ('Yes', 'No'))
        if user_satisfied == 'Yes':
            id_dict[machine_code]['mc_status'] = past_id_dict[machine_code][
                'mc_status']
            id_dict[machine_code]['worker_id'] = past_id_dict[machine_code][
                'worker_id']
        else:
            update_id_dict = worker_id(machine_code)
            id_dict[machine_code]['mc_status'] = update_id_dict['mc_status']
            id_dict[machine_code]['worker_id'] = update_id_dict['worker_id']
    return id_dict
def configure_application(file_name):
    """ Creates and returns the top level dictionary and the task dictionaries. Additioanlly tests user satisfaction
        with the top level data entered and saves to json. It is intended that this is the function that is returned
        by the open_json function if the json does not already exist when opening the top_level_data."""
    #¡¡ I am not sure if this is really the right way to program these type of functions that return other
    # functions. This seems to work, but doubtless there is some coding style best practice I have overlooked.
    print 'First you need to conifgure the application for the number of operators to be observed'
    time.sleep(4)

    # create top level dictionary
    top_level_dict = {
        'Knitting':
        get_user_int('Please enter the number of Knitting Operators'),
        'Linking': get_user_int('Please enter the number of Linking Operators')
    }

    print(Top_validation_fmt.format(**top_level_dict)
          )  # print data back to user

    # check user satisfaction
    user_satisfied = get_user_choice('Are you satisfied with data entered?',
                                     'Select one', ('Yes', 'No'))
    if user_satisfied == 'No':
        return configure_application(file_name)

    # save to json
    write_to_json(top_level_dict, file_name)

    # Create and save the task dictionaries
    create_task_dicts(top_level_dict, task_dict)

    return top_level_dict
def worker_wip(machine_code):
    ### This needs to be updated to reflect the fact that the worker_id task will now deal with the issue
    ### of machines being manned (operator present) or unmanned (operator absent or otherwise not there).
    """ Function to create individual machine WIP dict """

    console.clear()
    print ("For machine {} please enter thee following information: \n".format(machine_code))

    # Machine wip dictionary
    # The attendance no longer necessary once the ID number routine complete
    machine_dict = {"Attendance": "Absent", "Style": "null", "WIP": "null"}
    # Determine absence
    user_choice = get_user_choice(
        "{} : Is the operator present?".format(machine_code), "Please select an option", ("Present", "Absent")
    )
    # If operator not present
    if user_choice != "Present":
        print wip_validation_fmt.format(machine_code, **machine_dict)  # print data back to user
        time.sleep(2)

        # check user satisfaction
        user_satisfied = get_user_choice("Are you satisfied with data entered?", "Select one", ("Yes", "No"))
        if user_satisfied == "No":
            return worker_wip(machine_code)  # re-enter worker wip data

        return machine_dict  # return the worker wip dict

    # If operator present
    machine_dict["Attendance"] = "Present"
    prompt = "Please enter current style name/number as per work order: "
    machine_dict["Style"] = get_user_input(prompt).strip().lower()
    prompt = "Please enter the amount of WIP at time of checking: "
    machine_dict["WIP"] = get_user_special_float(prompt)

    print wip_validation_fmt.format(machine_code, **machine_dict)  # print data back to user
    time.sleep(4)

    user_satisfied = get_user_choice("Are you satisfied with data entered?", "Select one", ("Yes", "No"))
    if user_satisfied == "No":
        return worker_wip(machine_code)  # re-enter worker wip data

    return machine_dict  # return the worker wip dict
def worker_id(machine_code):
    """ Function prompts user for informaiton about the machine and the id of the operator working the machine 
	(if any). Returns dict of that information"""
    # This generates the worker routine for an individual operator. Rather than thinking about
    # present/absent the user will simply state is the machine is manned or unmanned. If it is
    # manned they will be prompted to enter the worker id of the person working on the machine.
    # The fact that manned/unmanned status will be dealt with here means that the Attendance
    # component of the wip task is now defunct (although the user may wish to change the
    # manned/unmanned status during the task if for example the worker was absent when the id
    # routine is run, but present once the wip task is undertaken.
    console.clear()
    print ("For machine {} please enter thee following information: \n".format(machine_code))

    worker_id_dict = {"mc_status": "Unmanned", "worker_id": "null"}

    title = "{} : Please state is machine is manned or unmanned?".format(machine_code)
    user_choice = get_user_choice(title, "Please select an option", ("Manned", "Unmanned"))

    # If machine unmanned
    if user_choice != "Manned":
        print ID_validation_fmt.format(machine_code, **worker_id_dict)  # print data back to user
        time.sleep(2)

        # check user satisfaction
        user_satisfied = get_user_choice("Are you satisfied with data entered?", "Select one", ("Yes", "No"))
        if user_satisfied == "No":
            return worker_id(machine_code)  # re-enter the machine dict data

        return worker_id_dict  # return the machine dict

    worker_id_dict["mc_status"] = "Manned"
    prompt = "Please enter the id number of the worker on this machine as is appears on their ID card: "
    worker_id_dict["worker_id"] = get_user_input(prompt).strip().lower()
    print ID_validation_fmt.format(machine_code, **worker_id_dict)  # print data back to user
    time.sleep(4)

    user_satisfied = get_user_choice("Are you satisfied with data entered?", "Select one", ("Yes", "No"))
    if user_satisfied == "No":
        return worker_id(machine_code)  # re-enter worker wip data

    return worker_id_dict  # return the worker id dict
def populate_id_dict(id_dict, past_id_dict_file_name, top_level_dict, department):
    """ Function to populate worker id dicts based upon previous saved versions """
    # This function populates the daily id dict but rather than asking the user for each piece of
    # information it takes the last known data for that machine and prompts the user to see if
    # they wish to make changes. If they do the the worker_id function is called. I have not yet
    # had the chance to see if this is working.
    if past_id_dict_file_name is None:
        return populate_first_id_dict(id_dict, top_level_dict, department)

    past_id_dict = open_json(past_id_dict_file_name, None, None)
    for machine_code in create_machine_code(top_level_dict, department):
        print ID_validation_fmt.format_2(machine_code, **past_id_dict[machine_code])  # print data back to user
        user_satisfied = get_user_choice("Are you satisfied with data entered?", "Select one", ("Yes", "No"))
        if user_satisfied == "Yes":
            id_dict[machine_code]["mc_status"] = past_id_dict[machine_code]["mc_status"]
            id_dict[machine_code]["worker_id"] = past_id_dict[machine_code]["worker_id"]
        else:
            update_id_dict = worker_id(machine_code)
            id_dict[machine_code]["mc_status"] = update_id_dict["mc_status"]
            id_dict[machine_code]["worker_id"] = update_id_dict["worker_id"]
    return id_dict