diff --git a/bpeng/pna/score_calculation.py b/bpeng/pna/score_calculation.py index c097eae93dd79475b4034f4ca4797bed8a17c31e..8b58ca0b2ca7e7b35a97541974881156a2863d92 100644 --- a/bpeng/pna/score_calculation.py +++ b/bpeng/pna/score_calculation.py @@ -1,64 +1,39 @@ from .discrete_bar_graph import create_graph_factory -def calculate_score_weight(weights_list, details_list): - - score_weight_1 = 0 - score_weight_2 = 0 - score_weight_3 = 0 - score_weight_4 = 0 - - final_criteria_score = [] - - for i in weights_list: - if i[0] == 1: - score_weight_1 += i[1] - elif i[0] == 2: - score_weight_2 += i[1] - elif i[0] == 3: - score_weight_3 += i[1] - elif i[0] == 4: - score_weight_4 += i[1] - elif i[0] == 5: - continue - - if details_list['num_of_heating_violations'] == 'None': - score_weight_1 += 0 - elif details_list['num_of_heating_violations'] in range(1, 3): - score_weight_1 += 1 - elif details_list['num_of_heating_violations'] in range(3, 11): - score_weight_1 += 3 - elif details_list['num_of_heating_violations'] >= 11: - score_weight_1 += 5 - else: - score_weight_1 += 0 - - if details_list['num_of_dob_violations'] == 'None': - score_weight_4 += 5 - elif details_list['num_of_dob_violations'] in range(1, 4): - score_weight_4 += 4 - elif details_list['num_of_dob_violations'] in range(4, 20): - score_weight_4 += 3 - elif details_list['num_of_dob_violations'] in range(20, 100): - score_weight_4 += 4 - elif details_list['num_of_dob_violations'] >= 100: - score_weight_4 += 5 - else: - score_weight_4 += 0 - - if details_list['legal_ownership'] == 'Single': - score_weight_4 += 3 - elif details_list['legal_ownership'] == 'LLC': - score_weight_4 += 5 - elif details_list['legal_ownership'] == 'Corporate': - score_weight_4 += 5 - elif details_list['legal_ownership'] == 'Non-Profit': - score_weight_4 += 3 - else: - score_weight_4 += 0 - - final_criteria_score.append((1, score_weight_1)) - final_criteria_score.append((2, score_weight_2)) - final_criteria_score.append((3, score_weight_3)) - final_criteria_score.append((4, score_weight_4)) - - return final_criteria_score +def calculate_score_weight(weight_list, details_list): + + score_weight = [0, 0, 0, 0] + final_criteria_scores = [] + + for i in range(len(weight_list)): + index = weight_list[i][0]-1 + score_weight[index] += weight_list[i][1] + + heating_violations_score = [0, 1, 3, 5] + num = [0, 1, 3, 11] + for i in range(len(num)): + initial_value = heating_violations_score[i] + if not i == len(num)-1 and details_list['num_of_heating_violations'] < num[i+1]: + break + score_weight[0] += initial_value + + dob_violations_score = [5, 4, 3, 4, 5] + num = [0, 1, 4, 20, 100] + for i in range(len(num)): + initial_value = dob_violations_score[i] + if not i == len(num)-1 and details_list['num_of_dob_violations'] < num[i+1]: + break + score_weight[3] += initial_value + + ownership_scores = { + 'Single': 3, + 'LLC': 5, + 'Corporate': 5, + 'Non-Profit': 3 + } + score_weight[3] += ownership_scores[details_list['legal_ownership']] + + for index in range(len(score_weight)): + final_criteria_scores.append((index+1, score_weight[index])) + + return final_criteria_scores