feat: ж/д слой + cant_swim в скоринг + профили вне модели
Определение специфических рекомендаций (матрица профилей §8):
1. Ж/д слой (закрыт мёртвый railway ×2.5 у РАС):
- /api/v1/water/{case_id} отдаёт railway=rail как LineString
(без service/industrial/military веток), кэш общий v2;
- railway_warning «перекрыть/проверить немедленно» по профилям;
- SearchMap: Polyline слой ж/д (тёмно-красный), счётчики 💧/🚂.
2. cant_swim → профиль не_умеет_плавать (water ×3.0, без изменения
радиуса, critical_warning «обследовать водоёмы НЕМЕДЛЕННО»):
- раньше чекбокс влиял только на текст, в скоринге был пробел;
- derive в analyze._derive_profiles — работает и для closed_cases.
3. unmodeled_profiles: ДЦП/слабое зрение/слух — честная пометка
«вне поведенческой модели» с пояснением (vector_tasks B12:
профили без аналога не выдавать за учтённые); блок на фронте
в карточке здоровья.
Площадь воды: сферический эксцесс, проверен на квадрате 53° (744017 м²
vs 743272 точного). Тесты: 202 passed (новый test_cant_swim_profile).
This commit is contained in:
@@ -0,0 +1,133 @@
|
||||
# cyextension/immutabledict.pyx
|
||||
# Copyright (C) 2005-2024 the SQLAlchemy authors and contributors
|
||||
# <see AUTHORS file>
|
||||
#
|
||||
# This module is part of SQLAlchemy and is released under
|
||||
# the MIT License: https://www.opensource.org/licenses/mit-license.php
|
||||
from cpython.dict cimport PyDict_New, PyDict_Update, PyDict_Size
|
||||
|
||||
|
||||
def _readonly_fn(obj):
|
||||
raise TypeError(
|
||||
"%s object is immutable and/or readonly" % obj.__class__.__name__)
|
||||
|
||||
|
||||
def _immutable_fn(obj):
|
||||
raise TypeError(
|
||||
"%s object is immutable" % obj.__class__.__name__)
|
||||
|
||||
|
||||
class ReadOnlyContainer:
|
||||
|
||||
__slots__ = ()
|
||||
|
||||
def _readonly(self, *a,**kw):
|
||||
_readonly_fn(self)
|
||||
|
||||
__delitem__ = __setitem__ = __setattr__ = _readonly
|
||||
|
||||
|
||||
class ImmutableDictBase(dict):
|
||||
def _immutable(self, *a,**kw):
|
||||
_immutable_fn(self)
|
||||
|
||||
@classmethod
|
||||
def __class_getitem__(cls, key):
|
||||
return cls
|
||||
|
||||
__delitem__ = __setitem__ = __setattr__ = _immutable
|
||||
clear = pop = popitem = setdefault = update = _immutable
|
||||
|
||||
|
||||
cdef class immutabledict(dict):
|
||||
def __repr__(self):
|
||||
return f"immutabledict({dict.__repr__(self)})"
|
||||
|
||||
@classmethod
|
||||
def __class_getitem__(cls, key):
|
||||
return cls
|
||||
|
||||
def union(self, *args, **kw):
|
||||
cdef dict to_merge = None
|
||||
cdef immutabledict result
|
||||
cdef Py_ssize_t args_len = len(args)
|
||||
if args_len > 1:
|
||||
raise TypeError(
|
||||
f'union expected at most 1 argument, got {args_len}'
|
||||
)
|
||||
if args_len == 1:
|
||||
attribute = args[0]
|
||||
if isinstance(attribute, dict):
|
||||
to_merge = <dict> attribute
|
||||
if to_merge is None:
|
||||
to_merge = dict(*args, **kw)
|
||||
|
||||
if PyDict_Size(to_merge) == 0:
|
||||
return self
|
||||
|
||||
# new + update is faster than immutabledict(self)
|
||||
result = immutabledict()
|
||||
PyDict_Update(result, self)
|
||||
PyDict_Update(result, to_merge)
|
||||
return result
|
||||
|
||||
def merge_with(self, *other):
|
||||
cdef immutabledict result = None
|
||||
cdef object d
|
||||
cdef bint update = False
|
||||
if not other:
|
||||
return self
|
||||
for d in other:
|
||||
if d:
|
||||
if update == False:
|
||||
update = True
|
||||
# new + update is faster than immutabledict(self)
|
||||
result = immutabledict()
|
||||
PyDict_Update(result, self)
|
||||
PyDict_Update(
|
||||
result, <dict>(d if isinstance(d, dict) else dict(d))
|
||||
)
|
||||
|
||||
return self if update == False else result
|
||||
|
||||
def copy(self):
|
||||
return self
|
||||
|
||||
def __reduce__(self):
|
||||
return immutabledict, (dict(self), )
|
||||
|
||||
def __delitem__(self, k):
|
||||
_immutable_fn(self)
|
||||
|
||||
def __setitem__(self, k, v):
|
||||
_immutable_fn(self)
|
||||
|
||||
def __setattr__(self, k, v):
|
||||
_immutable_fn(self)
|
||||
|
||||
def clear(self, *args, **kw):
|
||||
_immutable_fn(self)
|
||||
|
||||
def pop(self, *args, **kw):
|
||||
_immutable_fn(self)
|
||||
|
||||
def popitem(self, *args, **kw):
|
||||
_immutable_fn(self)
|
||||
|
||||
def setdefault(self, *args, **kw):
|
||||
_immutable_fn(self)
|
||||
|
||||
def update(self, *args, **kw):
|
||||
_immutable_fn(self)
|
||||
|
||||
# PEP 584
|
||||
def __ior__(self, other):
|
||||
_immutable_fn(self)
|
||||
|
||||
def __or__(self, other):
|
||||
return immutabledict(dict.__or__(self, other))
|
||||
|
||||
def __ror__(self, other):
|
||||
# NOTE: this is used only in cython 3.x;
|
||||
# version 0.x will call __or__ with args inversed
|
||||
return immutabledict(dict.__ror__(self, other))
|
||||
Reference in New Issue
Block a user