コード例 #1
0
def sort_print(key_name):  # sort
    coach_list = f.coach_read()
    old_list = []
    new_list = []

    for coach in coach_list:
        old_list.append(coach[key_name])

    # sort items of list
    while old_list:
        tmp = old_list[0]
        try:
            tmp = int(tmp)
            for i in old_list:
                if i > tmp:
                    tmp = i
        except:
            for i in old_list:
                if i < tmp:
                    tmp = i
        new_list.append(tmp)
        old_list.remove(tmp)

    print("\n\t★★★ Here the results ★★★\n")
    # display records after sort
    for sort_item in new_list:
        for coach in coach_list:
            if sort_item == coach[key_name]:
                print_records(coach)
                break
コード例 #2
0
def admin_modify_a():  # modify coach
    print("\n*** Modify Records of Coach ***")
    coach_list = f.coach_read()

    while 1:
        coach_id = input("\n\tEnter Coach ID to modify: ")
        # check coach id
        for coach in coach_list:
            if coach_id == coach["Coach ID"]:
                continue_modify = "m"
                while continue_modify == "m":
                    print(
                        "\n*** Which record do you want to modify?***\n\n\t1. Name\n\t2. Date Joined and Date Terminated\n\t3. Horly Rate (RM/h)\n\t4. Phone\n\t5. Adress\n\t6. Sport Center\n\t7. Sport"
                    )

                    num = input("\n\tEnter your choice: ")
                    modify_coach(num, coach, coach_id)

                    continue_modify = input(
                        "\n\tEnter \'m\' (continue to modify), or any key(back): "
                    )

                    if continue_modify != "m":
                        f.coach_write(coach_list)
                        print("\n\t★★★Complete★★★")
                        print_records(coach)
                        return

        print("\n\tThere is no " + coach_id + " in this sysmtem")
コード例 #3
0
def admin_modify_c():  # Modify Schedule
    print("\n*** Modify Record of Schedule ***")
    while 1:
        print("\n\tSelect Coach\n")
        schedule_list = f.schedule_read()
        for schedule in schedule_list:
            print("\t" + str(schedule_list.index(schedule) + 1) + ": ",
                  schedule["Coach ID"])
            print("\tDate:", schedule["Date"])
            print("\tStart Time:", schedule["Start Time"])
            print("\tEnd Time:", schedule["End Time"])
            print()

        num = input("\n\tChoose a number: ")
        try:
            num = int(num)
            for schedule in schedule_list:
                if num == (schedule_list.index(schedule) + 1):
                    coach_list = f.coach_read()
                    for coach in coach_list:
                        if coach["Coach ID"] == schedule["Coach ID"]:
                            date, start_time, end_time = date_time(coach)
                            schedule["Date"] = date
                            schedule["Start Time"] = start_time
                            schedule["End Time"] = end_time
                    f.schedule_write(schedule_list)
                    print("\n\t★★★Complete★★★")
                    print_records(schedule)
                    return
            print("\n\tThe number is out of range")
            continue
        except:
            print("\n\tPlease enter the number")
            continue
コード例 #4
0
def admin_add_c():  # Add Record of schedule
    schedule = {}
    schedule_list = f.schedule_read()
    while 1:
        print(
            "\n*** Add Records of Schedule ***\n\n\tPlease Enter the Coach ID to set up schedule"
        )

        coach_id = input("\tCoach ID: ")
        coach_list = f.coach_read()
        for coach in coach_list:
            if coach["Coach ID"] == coach_id:
                # get input of schedule
                date, start_time, end_time = date_time(coach)

                schedule["Coach ID"] = coach["Coach ID"]
                schedule["Sport Code"] = coach["Sport Code"]
                schedule["Date"] = date
                schedule["Start Time"] = start_time
                schedule["End Time"] = end_time

                # add schedule into schedule.txt
                schedule_list.append(schedule)
                f.schedule_write(schedule_list)
                print("\n\t★★★ Complete ★★★\n")
                print_records(schedule)
                return
        print("\n\tWe cannot find " + coach_id + ", please try again")
        continue
コード例 #5
0
def admin_search_a():  # Search Specific Records of Coach by Coach ID
    print("\n*** Search Specific Records of Coach by Coach ID ***")
    coach_list = f.coach_read()
    dict_key = "Coach ID"
    while 1:
        coach_id = input("\n\tEnter Coach ID: ")
        if search_print(coach_list, coach_id, dict_key):
            return
コード例 #6
0
def admin_display_d():
    feedback_list = f.feedback_read()
    coach_list = f.coach_read()
    print("\n*** Here are all records of feedback ***\n")
    for feedback in feedback_list:
        for coach in coach_list:
            if feedback["Coach ID"] == coach["Coach ID"]:
                print("\tCoach Name:", coach["Coach ID"])
                print("\tFeedback:", feedback["Description"])
                print("")
コード例 #7
0
def view_details_a():
    print("\n*** View Detail of Coach ***\n")

    coach_list = f.coach_read()

    for coach in coach_list:
        print("\tCoach: " + str(coach["Name"]))
        print("\tSport Center: " + str(coach["Sport Center Name"]))
        print("\tSport: " + str(coach["Sport Name"]))
        print("\tSport Fees: " + str(coach["Horly Rate (RM/h)"]) + "(RM/h)")
        print("\tOverall performance (Rating): " + str(coach["Rating"]))
        print()
コード例 #8
0
def view_details_b(student_id):
    print("\n*** View Detail of Self-Record ***\n")
    student_list = f.student_read()
    for student in student_list:
        if student["Student ID"] == student_id:
            print("\tYour Email: " + student["Student ID"])
            print("\tYour Name: " + student["Name"])

            coach_list = f.coach_read()
            for coach in coach_list:
                if coach["Coach ID"] == student["Coach ID"]:
                    print("\tCoach Name: " + coach["Name"])
                    print("\tSport Center: " + coach["Sport Center Name"])
                    print("\tSport: " + coach["Sport Name"])
                    print("\tSport Fees: " + str(coach["Horly Rate (RM/h)"]) +
                          "(RM/h)")
コード例 #9
0
def admin_search_b(
):  # Search Specific Records of Coach by overall performance (Rating)
    print(
        "\n*** Search Specific Records of Coach by overall performance (Rating) ***"
    )
    coach_list = f.coach_read()
    dict_key = "Rating"
    while 1:
        rating = input("\n\tEnter overall performance (Rating): ")
        try:
            rating = int(rating)
            if search_print(coach_list, rating, dict_key):
                return
        except:
            print("\n\tPlease Enter the Number.")
            continue
コード例 #10
0
def view_details_c(student_id):
    coach_id = ""
    coach_name = ""
    student_list = f.student_read()
    for student in student_list:
        if student["Student ID"] == student_id:
            coach_id = student["Coach ID"]

    coach_list = f.coach_read()
    for coach in coach_list:
        if coach["Coach ID"] == coach_id:
            coach_name = coach["Name"]

    schedule_list = f.schedule_read()
    print("\n\t*** The schedule of your Coach 【" + coach_name +
          " 】is Below ***\n")
    for schedule in schedule_list:
        if schedule["Coach ID"] == coach_id:
            print("\tDate: " + str(schedule["Date"]))
            print("\tStart Time: " + str(schedule["Start Time"]))
            print("\tEnd Time: " + str(schedule["End Time"]))
            print()
コード例 #11
0
def select_coach(student):
    coach_list = f.coach_read()

    print("\n\tSelect Coach")
    for coach in coach_list:
        print("\t"+str(coach_list.index(coach)+1) + ": ",
              str(coach["Name"]), "("+str(coach["Sport Name"])+")")

    while 1:
        num = input("\n\tChoose a number: ")
        try:
            num = int(num)
            for coach in coach_list:
                if num == (coach_list.index(coach)+1):
                    student["Coach ID"] = coach["Coach ID"]
                    coach_name = coach["Name"]
                    return coach_name
            print("\n\tThe number is out of range")
            continue
        except:
            print("\n\tPlease enter the number")
            continue
コード例 #12
0
def feedback_star(student_id):
    coach_id = ""
    coach_name = ""

    # read coach id whose chach teaches the student.
    student_list = f.student_read()
    for student in student_list:
        if student["Student ID"] == student_id:
            coach_id = student["Coach ID"]

    # read coach name
    coach_list = f.coach_read()
    for coach in coach_list:
        if coach["Coach ID"] == coach_id:
            coach_name = coach["Name"]

    print("\n*** Please give us your feedback on your coach【" + coach_name +
          "】***\n")
    print("\t1: \"very poor performance\"\n\t5: \"excellent performance\"")

    count = 0
    actial_rating = 0
    rating_ave = 0
    rating_int = 0
    feedback = {}

    rating_list = f.rating_read()
    for rating in rating_list:
        if rating["Coach ID"] == coach_id:
            # get feedback
            feedback["Coach ID"] = rating["Coach ID"]
            feedback["Description"] = input(
                "\n\tPlease give him/her feedbacks: ")

            # read count and actual rating(float)
            count = rating["Count"]
            actial_rating = float(rating["Actual Rating"])

            while 1:
                new_rating = input("\tEnter from 1 to 5: ")
                try:
                    new_rating = int(new_rating)
                    if new_rating > 0 and new_rating <= 5:
                        # calculate average rating
                        total_num = actial_rating * count
                        total_num += new_rating
                        count += 1
                        rating_ave = total_num / count

                        # Round float to integer
                        if rating_ave >= 1 and rating_ave < 1.5:
                            rating_int = 1
                        elif rating_ave >= 1.5 and rating_ave < 2.5:
                            rating_int = 2
                        elif rating_ave >= 2.5 and rating_ave < 3.5:
                            rating_int = 3
                        elif rating_ave >= 3.5 and rating_ave < 4.5:
                            rating_int = 4
                        elif rating_ave >= 4.5 and rating_ave <= 5.0:
                            rating_int = 5

                        rating["Rating"] = rating_int

                        print("\t★★★ Thank you !! ★★★\n")
                        break
                    else:
                        print("\n\tThe number is out of range!!")
                        continue

                except:
                    print("\n\tWrong input")
                    continue

            # Update count and actual rating(the first desimal point)
            rating["Count"] = count
            rating["Actual Rating"] = "{:.1f}".format(rating_ave)
            f.rating_write(rating_list)

    # add feedback into feedback textfile
    feedback_list = f.feedback_read()
    feedback_list.append(feedback)
    f.feedback_write(feedback_list)

    # Update rating in the coach.txt file
    for coach in coach_list:
        if coach["Coach ID"] == coach_id:
            coach["Rating"] = rating_int
            f.coach_write(coach_list)
コード例 #13
0
def admin_add_a():  # Add Record of Coach
    coach = {}
    print(
        "\n*** Add Records of Coach ***\n\n\tPlease Fill in your information below"
    )
    coach["Coach ID"] = input("\n\tCoach ID: ")
    coach["Name"] = input("\tName: ")

    # Add Date
    check_date(coach)

    # check whether Horly Rate (RM/h) is number or not
    while 1:
        hourly_rate = input("\tHorly Rate (RM/h): ")
        try:
            hourly_rate = int(hourly_rate)
            if hourly_rate >= 100 and hourly_rate <= 500:
                coach["Horly Rate (RM/h)"] = hourly_rate
                break
            else:
                print(
                    "\n\tHorly Rate should be 100(RM/h)-500RM(RM/h).Please try again."
                )
                continue
        except:
            print("\n\tPlease Enter the number")
            continue

    coach["Phone"] = input("\tPhone: ")
    coach["Adress"] = input("\tAdress: ")

    # Check whether the input of Sport center code exits or not
    flag = 0
    while flag == 0:
        sport_center_code = input("\tSport Center Code: ")
        sport_center_list = f.sport_center_read()
        for sport_center in sport_center_list:
            if sport_center["Sport Center Code"] == sport_center_code:
                coach["Sport Center Code"] = sport_center_code
                coach["Sport Center Name"] = sport_center["Sport Center Name"]
                flag = 1
        if flag == 1:
            break
        else:
            print("\n\tThere is no", sport_center_code, "in this system")
            continue

    # Check whether the input of sport code exits or not
    flag = 0
    while flag == 0:
        sport_code = input("\tSport Code: ")
        sport_list = f.sport_read()
        for sport in sport_list:
            if sport["Sport Code"] == sport_code:
                coach["Sport Code"] = sport_code
                coach["Sport Name"] = sport["Sport Name"]
                flag = 1
        if flag == 1:
            break
        else:
            print("\n\tThere is no", sport_code, "in this system")
            continue

    coach["Rating"] = 0

    # add records
    coach_list = f.coach_read()
    coach_list.append(coach)
    f.coach_write(coach_list)

    # print records
    print("\n\t★★★ Complete ★★★\n")
    print_records(coach)
コード例 #14
0
def admin_display_a():  # Display All Records Coachs
    coach_list = f.coach_read()

    print("\n*** Here are all records of coach ***\n")
    for coach in coach_list:
        print_records(coach)