Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/weekly-refresh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:
repository: GetTechAPI/TechAPI
path: techapi
token: ${{ secrets.TECHENGINEBOT_TOKEN || secrets.TECHAPI_TOKEN || secrets.GITHUB_TOKEN }}
fetch-depth: 0

- uses: actions/setup-python@v6
with:
Expand Down
20 changes: 15 additions & 5 deletions app/services/scoring/phones.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,17 @@ def _display(display: dict[str, Any], scales: dict[str, ReferenceScale]) -> floa


def _value(
overall: float | None, msrp_usd: int | None, scales: dict[str, ReferenceScale]
overall: float | None,
msrp_usd: int | None,
scales: dict[str, ReferenceScale],
weights: dict[str, float],
) -> float | None:
if overall is None or not msrp_usd:
return None
affordability = capability(float(msrp_usd), scales["msrp_usd"])
if affordability is None:
return None
return round(overall * 0.5 + affordability * 0.5, 1)
return combine([(overall, weights["overall"]), (affordability, weights["affordability"])])


def score_phone(
Expand All @@ -153,9 +156,16 @@ def score_phone(
scales,
)
display = _display(phone.display, scales)
components = [s for s in (perf.index, camera, battery, display) if s is not None]
overall = round(sum(components) / len(components), 1) if components else None
value = _value(overall, phone.msrp_usd, scales)
overall_weights = cfg.weights["phone_overall"]
overall = combine(
[
(perf.index, overall_weights["performance"]),
(camera, overall_weights["camera"]),
(battery, overall_weights["battery"]),
(display, overall_weights["display"]),
]
)
value = _value(overall, phone.msrp_usd, scales, cfg.weights["value"])
return PhoneScore(
algorithm_version=settings.scoring_algorithm_version,
overall=overall,
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/test_scoring_phones.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

from __future__ import annotations

from dataclasses import replace
from datetime import date

from app.models.smartphone import Smartphone
from app.models.soc import SoC
from app.services.scoring import ALGORITHM_VERSION, DatasetStats, score_phone
from app.services.scoring.config import load_config


def _soc(**overrides: object) -> SoC:
Expand Down Expand Up @@ -92,6 +94,24 @@ def test_value_requires_msrp() -> None:
assert score_phone(_phone(msrp_usd=None), _soc()).value is None


def test_overall_and_value_use_configured_weights() -> None:
cfg = load_config()
weights = {name: values.copy() for name, values in cfg.weights.items()}
weights["phone_overall"] = {
"performance": 1.0,
"camera": 0.0,
"battery": 0.0,
"display": 0.0,
}
weights["value"] = {"overall": 1.0, "affordability": 0.0}
configured = replace(cfg, weights=weights)

score = score_phone(_phone(), _soc(), config=configured)

assert score.overall == score.performance
assert score.value == score.overall


def test_relative_fields_filled_only_with_stats() -> None:
soc = _soc()
plain = score_phone(_phone(), soc)
Expand Down
Loading