From 0b1f2c1063cb058278d200e03878ba5ae8faed49 Mon Sep 17 00:00:00 2001 From: Nyan404 Date: Mon, 21 Sep 2026 22:31:28 +0300 Subject: [PATCH] feat(admin): show inspection score breakdown --- MEMORY.md | 4 ++++ app/belki/domain.py | 12 +++++++++--- structure_and_data.md | 1 + tests/test_api.py | 5 +++++ web/admin.html | 8 ++++++-- 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/MEMORY.md b/MEMORY.md index 17fc217..6aa8a6e 100644 --- a/MEMORY.md +++ b/MEMORY.md @@ -78,3 +78,7 @@ The final gateway Dockerfile must copy `nginx.conf` into the release image, not # 2026-09-08: private MinIO image storage `app/belki/image_host.py` now uses private distributed MinIO rather than `nyan.nyan404.ru`. The five internal S3 endpoints are tried in order for each operation; uploads are stored under an unguessable 128-bit object ID and public URLs resolve only through `https://cat.nyan404.ru/api/images/`. Keep the MinIO bucket private. `belki-image-store` is a standalone out-of-band Secret with only `GetObject`/`PutObject` plus required `GetBucketLocation` for `belki-images`; never merge it into CI-recreated `belki-runtime` or commit credentials. Existing legacy img.nyan404.ru URLs remain stored as historical links and cannot be recovered by this change. + +# 2026-09-21: admin inspection score breakdown + +Inspection results persist the base score for the number of inspections and each resource's calculated contribution in addition to the total. `/admin` displays these details in a dedicated `Баллы` column without changing the VK/public report text; legacy rows fall back to the stored total. diff --git a/app/belki/domain.py b/app/belki/domain.py index b551389..3506efb 100644 --- a/app/belki/domain.py +++ b/app/belki/domain.py @@ -285,6 +285,8 @@ class InspectionReport: class InspectionResult: """Результат расчёта баллов за осмотр.""" points: int + inspection_points: int = 0 + resource_points: tuple[dict[str, int | str], ...] = field(default_factory=tuple) def _inspection_resource_value(name: str) -> int: @@ -325,6 +327,10 @@ def calculate_inspection(report: InspectionReport) -> InspectionResult: Формула: осмотры × 2 + сумма (количество × ценность_ресурса) """ - points = report.inspections * 2 - points += sum(amount * _inspection_resource_value(name) for name, amount in report.resources) - return InspectionResult(points=points) + inspection_points = report.inspections * 2 + resource_points = tuple( + {"name": name, "amount": amount, "points": amount * _inspection_resource_value(name)} + for name, amount in report.resources + ) + points = inspection_points + sum(item["points"] for item in resource_points) + return InspectionResult(points=points, inspection_points=inspection_points, resource_points=resource_points) diff --git a/structure_and_data.md b/structure_and_data.md index e501cd8..2d252f6 100644 --- a/structure_and_data.md +++ b/structure_and_data.md @@ -119,6 +119,7 @@ - 2026-08-25: mobile adaptation is a required acceptance criterion for all frontend changes; validate narrow-width layout, touch usability, focus/error states, and absence of horizontal overflow alongside desktop rendering. - 2026-08-25: `/belki` now applies a dedicated narrow-width layout: single-column forms and application types, full-width actions, compact panels/dialogs, 16px form text to avoid mobile browser zoom, and responsive tabs without horizontal overflow. - 2026-08-25: removed unreferenced root-level legacy BBCode copies `belki.md`, `belki2.md`, and `belkifix.md`; the first two were byte-identical and the third differed only by a closing BBCode tag. They were neither served nor referenced by the calculator, bot, or documentation. +- 2026-09-21: `InspectionResult` now keeps the base inspection score and per-resource score entries alongside the total. The `/admin` report table renders these values in a dedicated `Баллы` column; older history rows still show their stored total when detailed fields are absent. The public report message remains unchanged. # Обновление 2026-08-16: несколько котят Калькулятор прокачки принимает `extra_kittens` из веб-формы, API и VK-команды. Общая выплата сопровождающему не суммирует полную ставку на каждого котёнка: первый подопечный использует базовый коэффициент, второй — множитель 1,5, каждый следующий — дополнительный множитель 1,15. Сайт добавляет строки дополнительных котят динамически; VK поддерживает сегмент `доп. котята: Имя [ID], Имя2 [ID]`. diff --git a/tests/test_api.py b/tests/test_api.py index c5221a5..3e4821c 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -102,6 +102,11 @@ class ApiTests(unittest.TestCase): ) self.assertIn("осмотрел(-а) дупло 6 раз", response["message"]) self.assertEqual(response["result"]["points"], 15) + self.assertEqual(response["result"]["inspection_points"], 12) + self.assertEqual(response["result"]["resource_points"], ( + {"name": "вьюнок", "amount": 2, "points": 2}, + {"name": "паук", "amount": 1, "points": 1}, + )) def test_bulk_inspection_payload_explains_missing_fields(self): response = inspect_bulk_payload({"text": "/лу 15.08 11:00 11:20 | Белка [1] | Котёнок [2]"}) diff --git a/web/admin.html b/web/admin.html index 6437121..2f6824f 100644 --- a/web/admin.html +++ b/web/admin.html @@ -74,6 +74,9 @@ .photos img { display: block; width: 100%; height: 100%; object-fit: cover; } .photos button:hover { outline: 2px solid var(--accent); outline-offset: 2px; } .message { max-width: 460px; margin: 0; white-space: pre-wrap; color: #514b45; font: inherit; font-size: .84rem; line-height: 1.5; } + .points-cell { min-width: 170px; font-variant-numeric: tabular-nums; } + .points-details { display: grid; gap: 3px; color: var(--muted); font-size: .82rem; line-height: 1.35; } + .points-details strong { margin-top: 4px; color: var(--ink); font-size: .9rem; } .delete { min-height: 34px; padding: 6px 10px; border-color: #d9b8b2; background: transparent; color: var(--danger); font-size: .82rem; } .delete:hover { border-color: var(--danger); background: #fff1ef; color: var(--danger); } .empty { padding: 44px 20px; text-align: center; color: var(--muted); } @@ -136,7 +139,7 @@ Скачать XLSX -
КотКотятаФотоДата (UTC+3)СообщениеАвторID
Загрузка истории…
+
КотКотятаФотоДата (UTC+3)БаллыСообщениеАвторID
Загрузка истории…