# weighted_scores_vs_centers.py
# Prof. Lee, May 12 2020

# STUDENTS: Edit this line with your CMS scores
# To avoid arithmetic errors, have Python add the A3tests and A3fn scores
my_scores = {"A1":7, "A2": 44, "A3": 13+75 , "P1": 80, "A4": 85, "A5": 82}

"""Compares the weighted version of my_scores to the scores of 
hypothetical students who hit all the A centers, all the B centers,
and all the C centers,

... both for when Prelim 1's score is retained and when it is dropped.

This script does NOT take labs into account.

"""

# We didn't learn about dictionaries in class, but they are a very
# convenient data structure!  Think of them as like lists, but where
# the indices can be named "A1", "A2", and so on, instead of being
# fixed at 0, 1, 2...

CENTERS = {
    # format: A center, B center, C center
    "A1": [10, 7, 5],   # out of 10
    "A2": [48, 44, 36], # out of 50
    "A3": [96, 88, 82], # out of 100
    "A4": [97, 85, 70], # out of 100
    "A5": [98, 82, 70], # out of 100
    "P1": [95, 80, 55]  # out of 107
}
PTS_POSSIBLE = {"A1": 10, "A2": 50, "A3": 100, "P1": 107, "A4": 100, "A5": 100}

# item 0: wts including P1; item 1: wts not including P1
WEIGHTS = [
    {"A1": .04,"A2": .06,"A3": .1,"P1": .15,"A4": .325,"A5": .325,},
    {"A1": .04,"A2": .06,"A3": .1, "P1": 0.0, "A4": .4, "A5": .4}
]

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


def get_weighted_score(score_dict):
    """Returns tuple of (weighted score w/ prelim 1, weighed score w/out prelim 1).

    Precondition: score_dict is a dictionary of scores, with string 'N/A' 
    where score is not known, and the keys are "A1"..."A5" and "P1". 

    It thus represents a student's scores throughout the
     """
    inc_P1 = 0.0 # init
    wout_P1 = 0.0 # init
    for asst in score_dict:
        if type(score_dict[asst]) in [int, float]:
            percent = score_dict[asst]/PTS_POSSIBLE[asst]
            inc_P1 += percent*WEIGHTS[0][asst]
            wout_P1 += percent*WEIGHTS[1][asst]
    return (inc_P1, wout_P1)


# Initialize empty dictionaries for hypothetical students
center_A = {}; center_B = {}; center_C = {}
center_students = [center_A, center_B, center_C]
for asst in CENTERS:
    center_A[asst] = CENTERS[asst][0]
    center_B[asst] = CENTERS[asst][1]
    center_C[asst] = CENTERS[asst][2]
# A student is a dictionary of scores

center_weighted_scores_inc_P1 = []
center_weighted_scores_wout_P1 = []
for i in range(len(center_students)):
    student = center_students[i]
    (inc_P1, wout_P1) = get_weighted_score(student)
    center_weighted_scores_inc_P1.append(inc_P1)
    center_weighted_scores_wout_P1.append(wout_P1)

if __name__ == '__main__':

    wted_inc_P1, wted_wout_P1 = get_weighted_score(my_scores)
    print("A, B, C centers if P1 included: " + \
        str(list(map(lambda x: round(x, 3), center_weighted_scores_inc_P1))))
    print("My weighted score: " + str(round(wted_inc_P1,3)) + "\n")

    print("A, B, C centers if P1 not included: " + \
        str(list(map(lambda x: round(x, 3), center_weighted_scores_wout_P1))))
    print("My weighted score: " + str(round(wted_wout_P1,3)) + "\n")