Skip to content

Commit

Permalink
Project score is 0 if one model score is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieucan committed Apr 19, 2024
1 parent 9065809 commit b4e0f08
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/dbt_score/scoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ def score_model(self, model_results: ModelResultsType) -> float:

def score_aggregate_models(self, scores: list[float]) -> float:
"""Compute the score of a list of models."""
if 0.0 in scores:
# Any model with a CRITICAL violation makes the project score 0
return self.min_score
if len(scores) == 0:
return self.max_score
return sum(scores) / len(scores)
8 changes: 7 additions & 1 deletion tests/test_scorer.py → tests/test_scoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ def test_scorer_aggregate_empty():
assert scorer.score_aggregate_models([]) == 1.0


def test_scorer_aggregate_with_0():
"""Test scorer aggregation with one result that is 0.0."""
scorer = Scorer()
assert scorer.score_aggregate_models([1.0, 0.5, 0.0]) == 0.0


def test_scorer_aggregate_single():
"""Test scorer aggregation with a single results."""
scorer = Scorer()
Expand All @@ -127,4 +133,4 @@ def test_scorer_aggregate_multiple():
scorer = Scorer()
assert scorer.score_aggregate_models([1.0, 1.0, 1.0]) == 1.0
assert scorer.score_aggregate_models([0.0, 0.0, 0.0]) == 0.0
assert scorer.score_aggregate_models([0.0, 0.84, 0.42]) == 0.42
assert scorer.score_aggregate_models([0.1, 0.74, 0.42]) == 0.42

0 comments on commit b4e0f08

Please sign in to comment.