diff --git a/advisor.py b/advisor.py index 5724dce..875ed6d 100644 --- a/advisor.py +++ b/advisor.py @@ -38,8 +38,8 @@ def missing_materials( def crafts_to_next_level(xp_remaining: int, xp_per_item: float) -> int: if xp_remaining <= 0 or xp_per_item <= 0: - return 1 - return max(1, int((xp_remaining + xp_per_item - 1) // xp_per_item)) + return 0 + return int((xp_remaining + xp_per_item - 1) // xp_per_item) def advise_skill( diff --git a/static/app.js b/static/app.js index f684f34..d79b46d 100644 --- a/static/app.js +++ b/static/app.js @@ -804,8 +804,11 @@ function renderSkillAdvisorCard() { const eta = rec.eta_minutes_to_level > 0 ? t("skills.advisorEta", { minutes: fmt(rec.eta_minutes_to_level) }) : "—"; - const crafts = rec.crafts_to_next_level || 1; + const crafts = rec.crafts_to_next_level ?? 0; const goalLabel = t("skills.advisorAdoptGoalFor", { name: rec.display_name, count: fmt(crafts) }); + const goalCell = crafts > 0 + ? `` + : ``; return ` ${esc(rec.display_name)} ${rec.xp_per_minute.toFixed(1)} @@ -813,7 +816,7 @@ function renderSkillAdvisorCard() { ${esc(mats)} ${esc(eta)} - + ${goalCell} `; }).join(""); @@ -878,7 +881,8 @@ async function adoptAdvisorItemGoal(activityKey, crafts) { if (!adv?.supported || !activityKey) return; const rec = adv.recommendations?.find((r) => r.activity_key === activityKey); const name = rec?.display_name || activityKey.replace(/_/g, " "); - const count = crafts > 0 ? crafts : 1; + const count = Number(crafts); + if (!count || count <= 0) return; const res = await fetch(`${apiBase()}/goals`, { method: "POST", headers: { "Content-Type": "application/json" }, diff --git a/test_advisor.py b/test_advisor.py index a70979b..714ba85 100644 --- a/test_advisor.py +++ b/test_advisor.py @@ -41,6 +41,8 @@ class AdvisorTests(unittest.TestCase): def test_crafts_to_next_level(self) -> None: self.assertEqual(crafts_to_next_level(100, 12.5), 8) + self.assertEqual(crafts_to_next_level(0, 12.5), 0) + self.assertEqual(crafts_to_next_level(10, 0), 0) def test_item_goal_from_recipe_not_in_inventory(self) -> None: from db import create_goal, get_connection, import_save, init_db