Untitled

                Never    
"""Assignment Seven : Filter List - Kevin Xue"""
 
 
def print_menu():
    """prints the menu"""
    print("Main Menu")
    print("---------")
    print("1 - Process a new data file")
    print("2 - Choose units")
    print("3 - Edit room filter")
    print("4 - Show summary statistics")
    print("5 - Show temperature by date and time")
    print("6 - Show histogram of temperatures")
    print("7 - Quit")
 
 
def sensor_setup():
    tup_1 = ("4213", "STEM Center")
    tup_2 = ("4201", "Foundations Lab")
    tup_3 = ("4204", "CS Lab")
    tup_4 = ("4218", "Workshop Room")
    tup_5 = ("4205", "Tiled Room")
    tup_6 = ("Out", "Outside")
    sensor_list = [tup_1, tup_2, tup_3, tup_4, tup_5, tup_6]
    return sensor_list
 
 
def active_setup():
    active_list = ['4201', '4204', '4205', '4213', '4218', 'Out']
    return active_list
 
 
def print_filter(active_sensors):
    sensor_list = sensor_setup()
    recursive_sort(sensor_list)
    my_dict = dict(sensor_list)
    for j in active_sensors:
        #print('my dict: ' + my_dict[j])
        my_dict[j] = my_dict[j] + " [Active]"
    for i, k in my_dict.items():
        print(i + ":", k)
 
 
def change_filter(str_input_2, active_sensors):
    removed = False
    
    #print("46: " + active_sensors)
    print_filter(active_sensors)
    print("")
    
    #print('string input 2: ' + str_input_2)
    if str_input_2 == '4201' or str_input_2 == '4204' or str_input_2 == '4205' or str_input_2 == '4213' or str_input_2 == '4218' \
            or str_input_2 == "Out":
        for i in active_sensors:
            if str_input_2 == str(i):
                active_sensors.remove(str_input_2)
                removed = True
        if(removed == False):
            active_sensors.append(str_input_2)
    print_filter(active_sensors)
    print("")
    #str_input_2 = input(str_question_2)
 
 
def recursive_sort(list_to_sort):
    """recursively sorts lists"""
    k = 0
    for i in range(len(list_to_sort) - 1):
        if list_to_sort[i][0] > list_to_sort[i + 1][0] or list_to_sort[i][0] == 'Out':
            list_to_sort[i], list_to_sort[i + 1] = list_to_sort[i + 1], list_to_sort[i]
            k = k + 1
    if k == 0:
        return list_to_sort
    else:
        return recursive_sort(list_to_sort)
 
 
def main():
    """acquires user input"""
    print("STEM Center Temperature Project")
    print("Kevin Xue")
    print("")
    print_menu()
    print("")
    str_question = "What is your choice? : "
    str_input = input(str_question)
    active_sensors = active_setup()
    if str_input == '7':
        print("Thank you for using the STEM Center Temperature Project")
    while str_input != "7":
        try:
            float(str_input)
            if str_input == "1":
                print("New File Function Called")
                print("")
                print_menu()
                print("")
                str_input = input(str_question)
            elif str_input == "2":
                print("Choose Units Function Called")
                print("")
                print_menu()
                print("")
                str_input = input(str_question)
            elif str_input == "3":
                print("Change Filter Function Called")
                str_input_2 = ''
                while str_input_2 != 'x':
                    print("")
                    str_question_2 = "Type the sensor number to toggle (e.g.4201) or x to end "
                    str_input_2 = input(str_question_2)
                    change_filter(str_input_2, active_sensors)
                    print("")
                str_input = input(str_question)
            elif str_input == "4":
                print("Summary Statistics Function Called")
                print("")
                print_menu()
                print("")
                str_input = input(str_question)
            elif str_input == "5":
                print("Print Temp by Day/Time Function Called")
                print("")
                print_menu()
                print("")
                str_input = input(str_question)
            elif str_input == "6":
                print("Print Histogram Function Called")
                print("")
                print_menu()
                print("")
                str_input = input(str_question)
            elif float(str_input) <= 0 or float(str_input) >= 8:
                print("Invalid Choice")
                print("")
                print_menu()
                print("")
                str_input = input(str_question)
        except ValueError:
            print("*** Please enter a number only ***")
            print("")
            print_menu()
            print("")
            str_input = input(str_question)
 
 
if __name__ == "__main__":
    main()

Raw Text