<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># weighted_scores_vs_centers.py
# Prof. Lee, LJL2, May 24 2021 (at final-exam grades release)

"""Compares the weighted version of my_scores to the scores of 
hypothetical students who hit all the A centers, B centers, ... and other grades
named in GRADE_TO_CENTERS_INDEX

This script does NOT take labs into account."""

# STUDENTS: Edit this line to contain your official scores
my_scores = {"A1": 1110,  # &lt;-- put your A1 **Part B** score
            "A2": 1110, 
            "A3": 1110, 
            "P1": 1110, 
            "A4": 1110, 
            "A5": 1110,
            "A6": 1110,
            "P2": 1110,
            "F": 1110}

PTS_POSSIBLE = {"A1": 10, 
                "A2": 83, 
                "A3": 100, 
                "A4": 69, 
                "A5": 80, 
                "A6": 85,
                "P1": 88, 
                "P2": 80,
                 "F":118}

# maps grade names to indices in CENTERS.
# Only include names you want to print out.
# GRADE_TO_CENTERS_INDEX = {"A": 0, "B": 1, "C": 2, "def. below C-": 3} 
GRADE_TO_CENTERS_INDEX = {"A": 0, "B": 1, "C": 2, "def. below C-": 3} 

GRADE_DESCRIPTION = {"A": "center of As", 
                     "B": "center of Bs", 
                     "C": "center of Cs", 
                     "C-": "line for definitely below C-"}
CENTERS = {
    # format: A center, B center, C center, def. below C- line.
    "A1": [10, 8, 5, 3],   
    "A2": [80, 70, 64, 59],
    "A3": [95, 82, 73, 60],
    "A4": [66, 60, 50, 30],
    "A5": [75, 68, 55, 35],
    "A6": [83, 70, 46, 29],
    "P1": [83, 75, 65, 49],
    "P2": [76, 60, 50, 31],
    "F": [105, 80, 60, 46]
}



# A list of pairs, 
#   * first item is the name of the weighting scheme
#   * the second is a dictionary giving the weighting scheme
# We allow for multiple weight schemes because we have had to have multiple weight
#  schemes in the past.
WEIGHTS = [
    ("2021SP official weighting scheme", 
        {"A1": 4,
        "A2": 6,
        "A3": 7,
        "P1": 15,
        "A4": 8,
        "A5": 7, 
        "A6": 8, 
        "P2": 15, 
        "F": 30})
]

# DEBUG: check weights have right sum
# for grade_choice in range(len(WEIGHTS)):
#     sum = 0
#     for k in WEIGHTS[grade_choice]:
#         sum += WEIGHTS[grade_choice][k]
#     print("DEBUG: weight checks sum to 100? " + str(sum))


def get_weighted_score(score_dict):
    """Returns tuple of weighted scores, allowing for multiple weighting schemes.

    Precondition: score_dict is a dictionary of scores, with string 'N/A' 
    where score is not known. It's meant to represent an individual student's
    scores.
    """
    accums = [0.0]*len(WEIGHTS) # start w/ 0.0 for all weighting schemes

    for asst in score_dict:
        if type(score_dict[asst]) in [int, float]:
            percent = score_dict[asst]/PTS_POSSIBLE[asst]
            # print("DEBUG: percent is: " +str(percent))
            for weight_scheme_i in range(len(WEIGHTS)):
                accums[weight_scheme_i] += percent*WEIGHTS[weight_scheme_i][1][asst]
                # print("\tIn loop: accums is: " + str(accums[weight_scheme_i]))
    return tuple(accums)

if __name__ == '__main__':

    # keys will be the grade names, meaning representative students
    hypothetical_students = {}
    # Initialize empty dictionaries for hypothetical students
    for grade_name in GRADE_TO_CENTERS_INDEX:
            hypothetical_students[grade_name] = {}

    # fill in the representative student's dictionaries
    for asst in CENTERS:
        for grade_name in hypothetical_students:
            hypothetical_students[grade_name][asst] = \
                CENTERS[asst][GRADE_TO_CENTERS_INDEX[grade_name]]

    # DEBUG
    # for student in hypothetical_students:
    #     print("Show what the hypothetical students' grades/assignment are")
    #     print(student)
    #     print(hypothetical_students[student])
    # print("\n\n")

    others_wted_scores = []
    for student in hypothetical_students:
        others_wted_scores.append(get_weighted_score(hypothetical_students[student]))
    # if there were two weighting schemes, this might look like
    # [(90, 95), (80, 85), (70, 75)]

    my_wted_score = get_weighted_score(my_scores)

    for weight_scheme_i in range(len(WEIGHTS)):
        print("Reporting for the following weighting scheme: " + \
                WEIGHTS[weight_scheme_i][0])    
        print("Format: ") 
        print(', '.join([name for name in GRADE_DESCRIPTION.values()]))

        print(str(list(map(lambda x: round(x[weight_scheme_i], 3), others_wted_scores)))) #@ 

        print("My weighted score: " + \
            str(round(my_wted_score[weight_scheme_i],3)) + "\n")

</pre></body></html>