fix: round goal sessions up
This commit is contained in:
1 parent
d3e3a4802c
commit
8e7fa97f27
3 files changed
+13
-2
No files matched your search
+1
-1
@@ -27,7 +27,7 @@ class ApiError(ValueError):
|
||||
|
||||
# Лениво загружаемые синглотоны
|
||||
_IDENTITY_DIRECTORY: IdentityDirectory | None = None
|
||||
_CALUCALUTION_STORE: CalculationStore | None = None
|
||||
_CALCULATION_STORE: CalculationStore | None = None
|
||||
|
||||
|
||||
def _identity_directory() -> IdentityDirectory:
|
||||
|
||||
+2
-1
@@ -2,6 +2,7 @@ from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from difflib import SequenceMatcher
|
||||
from math import ceil
|
||||
import re
|
||||
from typing import Literal
|
||||
|
||||
@@ -150,7 +151,7 @@ def calculate_goal(
|
||||
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)
|
||||
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_hours_value = total_minutes / 60
|
||||
total_hours = int(total_hours_value) if total_hours_value.is_integer() else round(total_hours_value, 2)
|
||||
|
||||
@@ -44,6 +44,16 @@ class ApiTests(unittest.TestCase):
|
||||
self.assertEqual(response["result"]["total_hours"], 2)
|
||||
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):
|
||||
response = calculate_payload(
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user