fix: round goal sessions up

This commit is contained in:
nyan404 committed 2026-08-25 03:26:41 +03:00
1 parent d3e3a4802c
commit 8e7fa97f27
3 files changed
+13 -2

No files matched your search

+1 -1
View File
@@ -27,7 +27,7 @@ class ApiError(ValueError):
# Лениво загружаемые синглотоны # Лениво загружаемые синглотоны
_IDENTITY_DIRECTORY: IdentityDirectory | None = None _IDENTITY_DIRECTORY: IdentityDirectory | None = None
_CALUCALUTION_STORE: CalculationStore | None = None _CALCULATION_STORE: CalculationStore | None = None
def _identity_directory() -> IdentityDirectory: def _identity_directory() -> IdentityDirectory:
+2 -1
View File
@@ -2,6 +2,7 @@ from __future__ import annotations
from dataclasses import dataclass, field from dataclasses import dataclass, field
from difflib import SequenceMatcher from difflib import SequenceMatcher
from math import ceil
import re import re
from typing import Literal from typing import Literal
@@ -150,7 +151,7 @@ def calculate_goal(
nonself_bonus = minutes_per_session * 0.5 / 5 if kitten_independence == "несамостоятельно" else 0 nonself_bonus = minutes_per_session * 0.5 / 5 if kitten_independence == "несамостоятельно" else 0
points_per_session = _points(minutes_per_session * ward_multiplier / 5 + nonself_bonus) points_per_session = _points(minutes_per_session * ward_multiplier / 5 + nonself_bonus)
remaining = _points(max(target_points - current_points, 0)) remaining = _points(max(target_points - current_points, 0))
sessions = 0 if remaining == 0 else int(-(-remaining / points_per_session)) sessions = 0 if remaining == 0 else ceil(remaining / points_per_session)
total_minutes = sessions * minutes_per_session total_minutes = sessions * minutes_per_session
total_hours_value = total_minutes / 60 total_hours_value = total_minutes / 60
total_hours = int(total_hours_value) if total_hours_value.is_integer() else round(total_hours_value, 2) total_hours = int(total_hours_value) if total_hours_value.is_integer() else round(total_hours_value, 2)
+10
View File
@@ -44,6 +44,16 @@ class ApiTests(unittest.TestCase):
self.assertEqual(response["result"]["total_hours"], 2) self.assertEqual(response["result"]["total_hours"], 2)
self.assertIn("Осталось добрать: 24", response["message"]) self.assertIn("Осталось добрать: 24", response["message"])
def test_calculate_and_store_uses_calculation_store(self):
with TemporaryDirectory() as directory:
with patch.dict("os.environ", {"BELKI_DATABASE_URL": "", "BELKI_HISTORY_DB": f"{directory}/history.sqlite3"}, clear=False):
api._CALCULATION_STORE = None
response = api.calculate_and_store({
"mode": "goal", "current_points": 0, "target_points": 25,
"minutes_per_session": 20, "skill": "ЛУ", "kitten_count": 1,
}, actor_id=None, source="web")
self.assertEqual(response["result"]["sessions"], 7)
def test_calculate_inspection_payload(self): def test_calculate_inspection_payload(self):
response = calculate_payload( response = calculate_payload(
{ {