feat(parser): accept written Russian dates

This commit is contained in:
nyan404 committed 2026-08-25 03:59:50 +03:00
1 parent 61036641f8
commit 0aa1c202a2
4 files changed
+34 -1

No files matched your search

+24
View File
@@ -47,6 +47,7 @@ HELP_TEXT = (
"/осмотр дупло 6 Имя [ID] | вьюнок=1, паук=1\n\n" "/осмотр дупло 6 Имя [ID] | вьюнок=1, паук=1\n\n"
"Если убрать разделители |, бот поймёт строку и так, например:\n" "Если убрать разделители |, бот поймёт строку и так, например:\n"
"15.08 11:00 11:20 Дикая Вишня 1604614 Серолап 1617140\n" "15.08 11:00 11:20 Дикая Вишня 1604614 Серолап 1617140\n"
"Дату также можно написать словами: «15 августа».\n"
"Для статуса котёнка подойдут сокращения «сам» и «несам».\n\n" "Для статуса котёнка подойдут сокращения «сам» и «несам».\n\n"
"Перед отправкой бот покажет, что понял, и попросит подтвердить. Каждый заход вводится отдельно. Скриншоты прикрепляйте вручную.\n\n" "Перед отправкой бот покажет, что понял, и попросит подтвердить. Каждый заход вводится отдельно. Скриншоты прикрепляйте вручную.\n\n"
"Чтобы сбросить ввод, напишите /отмена.\n\n" "Чтобы сбросить ввод, напишите /отмена.\n\n"
@@ -75,6 +76,20 @@ _ROLE_TYPO_WORDS = (
"учитель", "учительница", "ведущий", "ведущая", "ученик", "ученица", "учитель", "учительница", "ведущий", "ведущая", "ученик", "ученица",
"котёнок", "бельчонок", "подопечный", "подопечная", "котёнок", "бельчонок", "подопечный", "подопечная",
) )
_RUSSIAN_MONTHS = {
"января": 1, "январь": 1, "янв": 1,
"февраля": 2, "февраль": 2, "фев": 2,
"марта": 3, "март": 3, "мар": 3,
"апреля": 4, "апрель": 4, "апр": 4,
"мая": 5, "май": 5,
"июня": 6, "июнь": 6, "июн": 6,
"июля": 7, "июль": 7, "июл": 7,
"августа": 8, "август": 8, "авг": 8,
"сентября": 9, "сентябрь": 9, "сен": 9, "сент": 9,
"октября": 10, "октябрь": 10, "окт": 10,
"ноября": 11, "ноябрь": 11, "ноя": 11,
"декабря": 12, "декабрь": 12, "дек": 12,
}
_INSPECTION_COUNT_RE = re.compile( _INSPECTION_COUNT_RE = re.compile(
r"(?i)(?<![\d.])(?P<count>\d{1,6})\s*(?:раз(?:а|ов)?|осмотр(?:а|ов)?)\b" r"(?i)(?<![\d.])(?P<count>\d{1,6})\s*(?:раз(?:а|ов)?|осмотр(?:а|ов)?)\b"
) )
@@ -134,6 +149,15 @@ def _normalise_natural_text(text: str) -> str:
text = text.replace("—", "-").replace("–", "-").replace("−", "-") text = text.replace("—", "-").replace("–", "-").replace("−", "-")
text = re.sub(r"(?i)\b(?:id|айди|№)\s*(?=\d)", "", text) text = re.sub(r"(?i)\b(?:id|айди|№)\s*(?=\d)", "", text)
text = _SPACED_ID_RE.sub(lambda match: match.group(1).replace(" ", ""), text) text = _SPACED_ID_RE.sub(lambda match: match.group(1).replace(" ", ""), text)
def normalise_written_date(match: re.Match[str]) -> str:
return f"{int(match.group('day'))}.{_RUSSIAN_MONTHS[match.group('month').casefold()]:02d}"
text = re.sub(
r"(?i)\b(?P<day>[12]?\d|3[01])(?:-?го)?\s+(?P<month>"
+ "|".join(_RUSSIAN_MONTHS) + r")\b",
normalise_written_date,
text,
)
text = re.sub(r"\b(\d{1,2})[/-](\d{1,2})\b", r"\1.\2", text) text = re.sub(r"\b(\d{1,2})[/-](\d{1,2})\b", r"\1.\2", text)
# A bare ``15.08`` is a date, not 15:08. Preserve the first dotted pair # A bare ``15.08`` is a date, not 15:08. Preserve the first dotted pair
# as the report date and treat later dotted pairs as clock values. # as the report date and treat later dotted pairs as clock values.
+1
View File
@@ -75,6 +75,7 @@
- 2026-08-25: shared domain limits now bound public calculation fan-out: at most 50 coaching kittens, 100 inspection resource rows, 100000 inspections, and 100000 units of one resource. API and VK reject oversized kitten lists before calculation. - 2026-08-25: shared domain limits now bound public calculation fan-out: at most 50 coaching kittens, 100 inspection resource rows, 100000 inspections, and 100000 units of one resource. API and VK reject oversized kitten lists before calculation.
- 2026-08-25: report copy now uses a plural construction for several kittens, normative `провёл(-ла)` for lessons, and a readable empty-resource line instead of a standalone `0`. - 2026-08-25: report copy now uses a plural construction for several kittens, normative `провёл(-ла)` for lessons, and a readable empty-resource line instead of a standalone `0`.
- 2026-08-25: free-form inspection parsing now distinguishes a labelled count (or a count immediately after the place) from date fragments and character IDs; it also understands explicit character labels and both `+N ресурс` and legacy `ресурс=N` loot notation. - 2026-08-25: free-form inspection parsing now distinguishes a labelled count (or a count immediately after the place) from date fragments and character IDs; it also understands explicit character labels and both `+N ресурс` and legacy `ресурс=N` loot notation.
- 2026-08-25: free-form coaching input additionally normalizes Russian written month names and common abbreviations (for example, `24 августа` and `1-го сент`) into the existing `ДД.ММ` date field.
- 2026-08-25: `/api/admin/auth` now permits five password attempts per source in a rolling 15-minute window and clears that local budget after a successful sign-in. Edge rate limiting and TLS remain required deployment controls. - 2026-08-25: `/api/admin/auth` now permits five password attempts per source in a rolling 15-minute window and clears that local budget after a successful sign-in. Edge rate limiting and TLS remain required deployment controls.
# Обновление 2026-08-16: несколько котят # Обновление 2026-08-16: несколько котят
+8
View File
@@ -157,6 +157,14 @@ class VkConversationTests(unittest.TestCase):
self.assertEqual((inspected["fields"]["escort_name"], inspected["fields"]["escort_id"]), ("Дикая Вишня", 1604614)) self.assertEqual((inspected["fields"]["escort_name"], inspected["fields"]["escort_id"]), ("Дикая Вишня", 1604614))
self.assertEqual((inspected["fields"]["kitten_name"], inspected["fields"]["kitten_id"]), ("Серопопик", 1346767)) self.assertEqual((inspected["fields"]["kitten_name"], inspected["fields"]["kitten_id"]), ("Серопопик", 1346767))
def test_natural_bulk_input_normalizes_russian_written_dates(self):
for date_text, expected in (("24 августа", "24.08"), ("1-го сент", "1.09")):
with self.subTest(date_text=date_text):
inspected = inspect_bulk_text(
f"ЛУ {date_text} 21:00-22:00 Дикая Вишня [1604614] Серопопик [1346767] сам"
)
self.assertEqual(inspected["fields"]["date"], expected)
def test_natural_zu_with_nonself_status_becomes_a_clarification_not_an_exception(self): def test_natural_zu_with_nonself_status_becomes_a_clarification_not_an_exception(self):
inspected = inspect_bulk_text("24.08 ЗУ 21:00 22:00 Белка [1] Ученик [2] несам") inspected = inspect_bulk_text("24.08 ЗУ 21:00 22:00 Белка [1] Ученик [2] несам")
self.assertEqual(inspected["status"], "needs_clarification") self.assertEqual(inspected["status"], "needs_clarification")
+1 -1
View File
@@ -79,7 +79,7 @@
<div class="bulk"> <div class="bulk">
<strong>Быстрый ввод</strong> <strong>Быстрый ввод</strong>
<p class="muted">Вставьте данные одной строкой — символы <code>|</code> не нужны. Мы распознаем заполненные поля и подскажем, что ещё указать.</p> <p class="muted">Вставьте данные одной строкой — символы <code>|</code> не нужны. Мы распознаем заполненные поля и подскажем, что ещё указать.</p>
<textarea id="bulkText" placeholder="15.08 11:00 11:20 Дикая Вишня 1604614 Серолап 1617140"></textarea> <textarea id="bulkText" placeholder="15 августа, 11:00–11:20, Дикая Вишня 1604614, Серолап 1617140"></textarea>
<button type="button" id="inspectBulk">Распознать данные</button> <button type="button" id="inspectBulk">Распознать данные</button>
<p class="muted bulk-status" id="bulkStatus"></p> <p class="muted bulk-status" id="bulkStatus"></p>
</div> </div>