Skip to content

Commit

Permalink
support no scoring information for EOI etc (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam-W1 authored Aug 7, 2024
1 parent c19e4ae commit b2e018f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
15 changes: 11 additions & 4 deletions api/routes/assessment_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,17 @@
from flask import request


def calculate_overall_score_percentage_for_application(app):
scoring_system = get_scoring_system_for_round_id(app["round_id"])
def calculate_overall_score_percentage_for_application(application):
scoring_system = get_scoring_system_for_round_id(application["round_id"])

# Deep copy the assessment mapping configuration for the specific fund and round
mapping = copy.deepcopy(Config.ASSESSMENT_MAPPING_CONFIG[f"{app['fund_id']}:{app['round_id']}"])
mapping = copy.deepcopy(Config.ASSESSMENT_MAPPING_CONFIG[f"{application['fund_id']}:{application['round_id']}"])
sub_criteria_to_criteria_weighting_map = {}
highest_possible_weighted_score_for_round = 0
if mapping["scored_criteria"] == []:
# We have no scoring config for this round (possibly an EOI)
current_app.logger.info(f"No scoring config found for {application['fund_id']}:{application['round_id']}")
return None

# Combine mapping and highest possible score calculation
for criterion in mapping["scored_criteria"]:
Expand All @@ -58,8 +62,11 @@ def calculate_overall_score_percentage_for_application(app):

application_weighted_score = sum(
sub_criteria_score * sub_criteria_to_criteria_weighting_map[sub_criteria]
for sub_criteria, sub_criteria_score in get_sub_criteria_to_latest_score_map(app["application_id"]).items()
for sub_criteria, sub_criteria_score in get_sub_criteria_to_latest_score_map(
application["application_id"]
).items()
)

return (application_weighted_score / highest_possible_weighted_score_for_round) * 100


Expand Down
13 changes: 7 additions & 6 deletions openapi/components.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ components:
id:
type: string
total_expected_cost:
type: number
type: string
nullable: true
location_json_blob:
type: object
Expand Down Expand Up @@ -74,7 +74,7 @@ components:
type: string
nullable: true
publish_datasets:
type: boolean
type: string
nullable: true
language:
type: string
Expand All @@ -86,8 +86,8 @@ components:
type: string
nullable: true
flags:
additionalProperties: true
type: array
items: {}
short_id:
type: string
date_submitted:
Expand All @@ -109,11 +109,11 @@ components:
asset_type:
type: string
datasets:
type: array
items: {}
type: boolean
nullable: true
joint_application:
type: boolean
type: string # TODO: this should be a boolean
# Note: Consumers of this API should interpret "True" and "False" as boolean values.
nullable: true
tag_associations:
type: array
Expand All @@ -122,6 +122,7 @@ components:
type: boolean
overall_score_percentage:
type: number
nullable: true
UpdateStatus:
type: object
properties:
Expand Down
13 changes: 7 additions & 6 deletions tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,12 +618,6 @@ def test_get_all_applications_assigned_by_user(flask_test_client):
COF_ROUND_2_ID = "c603d114-5364-4474-a0c4-c41cbf4d3bbd"
app = {"round_id": COF_ROUND_2_ID, "fund_id": COF_FUND_ID, "application_id": "app789"}
scoring_system = {"maximum_score": 5}
mapping_config = {
"scored_criteria": [
{"id": "criteria1", "weighting": 2, "sub_criteria": [{"id": "sub1"}, {"id": "sub2"}]},
{"id": "criteria2", "weighting": 1, "sub_criteria": [{"id": "sub3"}]},
]
}
sub_criteria_scores = {"sub1": 3, "sub2": 4, "sub3": 5}

mapping_config = {
Expand Down Expand Up @@ -670,3 +664,10 @@ def test_with_invalid_application_id(mocker, mock_get_scores, mock_get_scoring_s
mock_get_scores.side_effect = KeyError("Invalid application ID")
with pytest.raises(KeyError):
calculate_overall_score_percentage_for_application(app)


def test_no_scored_criteria_exists(mocker, mock_get_scores, mock_get_scoring_system):
mock_config = mocker.patch("api.routes.assessment_routes.Config")
mock_config.ASSESSMENT_MAPPING_CONFIG = {f"{COF_FUND_ID}:{COF_ROUND_2_ID}": {"scored_criteria": []}}
result = calculate_overall_score_percentage_for_application(app)
assert result is None, "The result should be 0 when there are no scored criteria"

0 comments on commit b2e018f

Please sign in to comment.