/
Chaizee
/
ZenithCode_Incident-LLM-analytics
Обзор
Документация
Войти
/
Chaizee
/
ZenithCode_Incident-LLM-analytics
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
tests/test_core.py
146 строк
6 KB
Chaizee
fix: fix speed
12 июн 2026, 16:28
12 июн 2026, 16:28
b2745cc
Код
Авторство
О чём код?
import pandas as pd import polars as pl from src.analytics import build_analytics from src.semantic_search import SemanticIndex from src.data_polars import _coalesce_incident_text from src.severity import clamp_severity from src.problem_heuristics import adjust_classification, is_informational_inquiry from src.text_coalesce import is_excluded_municipality, is_meaningful_incident_text, looks_like_pi_response from src.text_utils import sanitize_russian def test_coalesce_text_polars(): df = pl.DataFrame( { "text_ak": ["", "x"], "text_ai": ["реальная жалоба на дорогу", ""], "text_aj": ["", ""], "text_g": ["", ""], } ) out = _coalesce_incident_text(df) assert out["incident_text"][0] == "реальная жалоба на дорогу" def test_coalesce_ignores_longer_pi_response(): pi = ( "Татьяна Н, здравствуйте, переходы и остановки чистят каждый день, " "вручную. Бригада не успевает за работой." ) df = pl.DataFrame( { "text_ai": ["нет тепла в квартире, батареи ледяные"], "text_aj": [pi], "text_g": [""], "text_ak": [""], } ) out = _coalesce_incident_text(df) assert out["incident_text"][0] == "нет тепла в квартире, батареи ледяные" def test_pi_response_detection(): assert looks_like_pi_response("[id17288950|Sergio Lenin], здравствуйте, уточните вопрос") assert looks_like_pi_response("Татьяна Н, здравствуйте, переходы чистят каждый день") assert not looks_like_pi_response("нет тепла, батареи ледяные, замерзнем") def test_informational_inquiry_not_problem(): assert is_informational_inquiry("Во сколько начало соревнований?") assert is_informational_inquiry("Здравствуйте! В фондах ОГИК музея есть книга?") assert is_informational_inquiry("Кто по нему будет ездить?") assert not is_informational_inquiry("Почему не работает отопление?") assert not is_informational_inquiry("Нет тепла в квартире, замерзнем") row = adjust_classification( "Во сколько начало соревнований?", {"is_problem": True, "severity": 5, "category": "ЖКХ"}, ) assert row["is_problem"] is False assert row["severity"] == 1 assert row["category"] == "Прочее" def test_meaningful_incident_text(): assert not is_meaningful_incident_text("'!!") assert not is_meaningful_incident_text("!!!") assert not is_meaningful_incident_text("---") assert is_meaningful_incident_text("нет тепла в квартире, батареи ледяные") def test_severity_clamp(): assert clamp_severity(99) == 5 assert clamp_severity(0) == 1 def test_analytics_empty_problems(): df = pd.DataFrame( { "municipality": ["А"], "settlement": ["с1"], "incident_text": ["t1"], "is_problem": [False], "severity": [1], "category": ["Прочее"], } ) r = build_analytics(df) assert r["problems_count"] == 0 assert list(r["chart"].columns) == ["municipality", "problem_count", "mean_severity"] assert r["chart"].empty def test_sanitize_russian(): assert "不清" not in sanitize_russian("дорога не чистится, 不清除将影响儿童安全, снег") assert "снег" in sanitize_russian("дорога не чистится, 不清除将影响儿童安全, снег") assert sanitize_russian("нет воды") == "нет воды" def test_analytics_critical_without_core_issue_column(): df = pd.DataFrame( { "municipality": ["А", "Б"], "settlement": ["с1", "с2"], "incident_text": ["мост рушится", "спасибо"], "is_problem": [True, False], "severity": [5, 1], "category": ["Дороги", "Прочее"], "incident_id": ["1", "2"], } ) r = build_analytics(df) assert r["critical_count"] == 1 assert "core_issue" in r["critical"].columns assert r["critical"]["core_issue"].iloc[0] == "Дороги" def test_excluded_municipality(): assert is_excluded_municipality("Омская область, другое") assert is_excluded_municipality("Омская область,Другое") assert not is_excluded_municipality("Омск г.о.") assert not is_excluded_municipality("Большереченский район") assert not is_excluded_municipality("Омская область, прочее") assert not is_excluded_municipality("другое") def test_semantic_index_build(): assert hasattr(SemanticIndex, "build") assert hasattr(SemanticIndex, "load") def test_analytics_top_with_category(): df = pd.DataFrame( { "municipality": ["А", "А", "Б"], "settlement": ["с1", "с1", "с2"], "incident_text": ["t1", "t2", "t3"], "is_problem": [True, True, False], "severity": [3, 5, 1], "category": ["Дороги", "Дороги", "Прочее"], } ) r = build_analytics(df) assert r["problems_count"] == 2 assert r["top10"]["municipality"].iloc[0] == "А" assert not r["critical"].empty