def get_score(teacher,tocompare): c = tocompare[0] valtocomp = tocompare[1] v = coldict[c] #keeps track of the total score scoreval = 0 #keeps track of the number of meaningful comparisons num_cats_compared = 0 #iterates through the different columns we want to compare if(c == 'SchoolName'): score = scr.compSchool(teacher[v],valtocomp) #If a meaningful comparison happened, update the score trackers if(score != None): scoreval += score num_cats_compared += 1 if(c == 'State'): score = scr.compState(teacher[v],valtocomp) if(score != None): scoreval += score num_cats_compared += 1 if(c == 'Grades'): score = scr.compGrades(teacher[v],valtocomp) if(score != None): scoreval += score num_cats_compared += 1 #Returns a tuple of the score and the number of meaningful comparisons return (round(scoreval,5),num_cats_compared)
def get_score(teacher,tocompare): #keeps track of the contributions of each characteristic scoredict = {} #keeps track of the total score scoreval =0 #keeps track of the number of meaningful comparisons num_cats_compared = 0 #iterates through the different columns we want to compare for c,v in coldict.iteritems(): if(c == 'SchoolName'): score = scr.compSchool(teacher[v],tocompare[v]) #If a meaningful comparison happened, update the score trackers if(score != None): scoredict[c]=score scoreval += score num_cats_compared += 1 elif(c == 'State'): score = scr.compState(teacher[v],tocompare[v]) if(score != None): scoredict[c]=score scoreval += score num_cats_compared += 1 elif(c == 'Grades'): score = scr.compGrades(teacher[v],tocompare[v]) if(score != None): scoredict[c]=score scoreval += score num_cats_compared += 1 '''Taken from http://desk.stinkpot.org:8080/tricks/index.php/2006/10/ find-the-key-for-the-minimum-or-maximum-value-in-a-python-dictionary/''' #Inverts the dictionary (swaps keys and values) so that we can #get the max value temp = dict(map(lambda scores: (scores[1],scores[0]),scoredict.items())) #Gets the largest contributor to score. Ties are broken arbitrarily try: largestcontributor = temp[max(temp)] except ValueError: largestcontributor = None #Returns a tuple of the score and the number of meaningful comparisons return (round(scoreval,5),num_cats_compared)