Skip to content

Commit

Permalink
Revise score calculation in calculate_safety_score
Browse files Browse the repository at this point in the history
  • Loading branch information
erdem committed Aug 16, 2024
1 parent 8cfb9f2 commit ba5d0f0
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
4 changes: 3 additions & 1 deletion src/calculators.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import List, Optional

from typeguard import typechecked


Expand Down Expand Up @@ -36,7 +37,8 @@ def calculate_safety_score(
inverse_accident_history = 1 / (accident_history + 1)
score = inverse_traffic_density
score += road_quality * inverse_accident_history
score += lighting_conditions * average_speed
score += lighting_conditions
score += average_speed

if incident_reports is not None:
score -= incident_reports
Expand Down
5 changes: 1 addition & 4 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ def main():
try:
if args.file:
input_data = load_json_file(args.file)
if args.json:
import ipdb

ipdb.set_trace()
elif args.json:
input_data = load_json(args.json)
else:
print("No argument provided, check `python src/main.py --help")
Expand Down
2 changes: 1 addition & 1 deletion src/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class OverallCommuteQualitySchema(BaseModel):

@model_validator(mode="before")
@classmethod
def set_commute_quality(cls, data: dict) -> dict:
def determine_commute_quality(cls, data: dict) -> dict:
score = data.get("quality_score")
if score is None:
raise ValueError("quality_score is required to determine `commute_quality`")
Expand Down
10 changes: 5 additions & 5 deletions tests/functional/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ def test_valid_input_path(run_cli_command, valid_input_path):
assert error == ""

result = json.loads(output)
assert result["quality_score"] == 88.35474254742546
assert result["commute_quality"] == "Good"
assert result["quality_score"] == 44.388075880758805
assert result["commute_quality"] == "Average"


def test_valid_input_json(run_cli_command, valid_input_json):
Expand All @@ -19,8 +19,8 @@ def test_valid_input_json(run_cli_command, valid_input_json):
assert error == ""

result = json.loads(output)
assert result["quality_score"] == 88.35474254742546
assert result["commute_quality"] == "Good"
assert result["quality_score"] == 44.388075880758805
assert result["commute_quality"] == "Average"


def test_valid_input_without_optionals(run_cli_command, valid_input_without_optionals_path):
Expand All @@ -30,7 +30,7 @@ def test_valid_input_without_optionals(run_cli_command, valid_input_without_opti
assert error == ""

result = json.loads(output)
assert result["quality_score"] == 31.519445362371297
assert result["quality_score"] == 25.25277869570463
assert result["commute_quality"] == "Average"


Expand Down
10 changes: 5 additions & 5 deletions tests/unit/test_calculators.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from src.calculators import (
calculate_comfort_index,
calculate_traffic_flow_efficiency,
calculate_safety_score,
calculate_overall_commute_quality_score,
calculate_safety_score,
calculate_traffic_flow_efficiency,
)


Expand All @@ -19,9 +19,9 @@ def test_calculate_traffic_flow_efficiency():


def test_calculate_safety_score():
assert calculate_safety_score(8, 7, 2, 50, [0.3, 0.4, 0.3]) == 353.6666666666667
assert calculate_safety_score(9, 8, 1, 60, [0.2, 0.2, 0.1], 3, 5) == 478.5
assert calculate_safety_score(7, 6, 3, 40, [0.5, 0.5], 1) == 241.75
assert calculate_safety_score(8, 7, 2, 50, [0.3, 0.4, 0.3]) == 60.666666666666664
assert calculate_safety_score(9, 8, 1, 60, [0.2, 0.2, 0.1], 3, 5) == 66.5
assert calculate_safety_score(7, 6, 3, 40, [0.5, 0.5], 1) == 47.75


def test_calculate_overall_commute_quality_score():
Expand Down

0 comments on commit ba5d0f0

Please sign in to comment.