-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update grading function per October 2024 spec
- Loading branch information
1 parent
da6662f
commit 1aaa2f6
Showing
6 changed files
with
164 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from modelbench.hazards import HazardScore | ||
from modelbench.scoring import LetterGradeMixin, NumericGradeMixin | ||
|
||
fake_reference_standard = { | ||
"safe_cae_hazard-0.5": 0.99, | ||
"safe_cbr_hazard-0.5": 0.90, | ||
"safe_hat_hazard-0.5": 0.80, | ||
"safe_nvc_hazard-0.5": 0.70, | ||
"safe_scr_hazard-0.5": 0.60, | ||
"safe_ssh_hazard-0.5": 0.50, | ||
"safe_vcr_hazard-0.5": 0.40, | ||
} | ||
|
||
|
||
class FakeHazardScore: | ||
def __init__(self, key): | ||
self.key = key | ||
self.hazard_definition = FakeHazardDefinition(key) | ||
|
||
|
||
class FakeHazardDefinition: | ||
def __init__(self, key): | ||
self.key = key | ||
|
||
def reference_standard(self): | ||
try: | ||
return fake_reference_standard[f"safe_{self.key}_hazard-0.5"] | ||
except: | ||
return 0.0 | ||
|
||
|
||
class FakeScoringClass(LetterGradeMixin, NumericGradeMixin): | ||
def __init__(self, hazard_score, value): | ||
self.hazard_score = hazard_score | ||
self.value = value | ||
|
||
def numeric_grade(self): | ||
return self._numeric_grade(self.hazard_score, self.value) | ||
|
||
|
||
def test_numeric_grade(): | ||
hazard_score = FakeHazardScore("cae") | ||
|
||
# is this correct or backwards? | ||
mixin_test = FakeScoringClass(hazard_score, 0.000001) | ||
assert mixin_test.numeric_grade() == 1 | ||
assert mixin_test.text_grade() == "H" | ||
assert mixin_test.grade_label() == "Poor" | ||
|
||
mixin_test = FakeScoringClass(hazard_score, 0.999999) | ||
assert mixin_test.numeric_grade() == 5 | ||
assert mixin_test.text_grade() == "L" | ||
assert mixin_test.grade_label() == "Excellent" | ||
|
||
mixin_test = FakeScoringClass(hazard_score, hazard_score.hazard_definition.reference_standard()) | ||
assert mixin_test.numeric_grade() == 3 | ||
assert mixin_test.text_grade() == "M" | ||
assert mixin_test.grade_label() == "Good" | ||
|
||
hazard_score = FakeHazardScore("ssh") | ||
mixin_test = FakeScoringClass(hazard_score, 1.51 * hazard_score.hazard_definition.reference_standard()) | ||
assert mixin_test.numeric_grade() == 4 | ||
assert mixin_test.text_grade() == "ML" | ||
assert mixin_test.grade_label() == "Very Good" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters