ivideon: update some crowd schemes

This commit is contained in:
t0xa 2025-09-08 12:05:00 +03:00
parent d5ecc2d577
commit 5fc6421d78
4 changed files with 161 additions and 0 deletions

View file

@ -0,0 +1,21 @@
@startuml Telegram Subscription Management Activity
|PM Manager|
start
if (Действие?) then (Добавить связку)
:Ввести email и chat_id;
|API|
:Добавить запись в\ncrowd.telegram_subscriptions\n{"email": "...", "chat_id": ...};
|PM Manager|
:Добавить бота в Telegram чат\n(совместно с пользователем);
else (Удалить связку)
:Выбрать email для удаления;
|API|
:Удалить запись из\ncrowd.telegram_subscriptions;
endif
|Notification System|
:send_queue_overflow() отправляет\nуведомление в Telegram\nпо связке email → chat_id;
stop
@enduml

View file

@ -0,0 +1,53 @@
@startuml
!define FILE_ICON <<(F,#e8bd14)>>
class crowd.frontend.impl.crowd_subscriptionPY.CrowdSubscription{
+ ID_REGEX: str
{field} + COLLECTION: str = db.crowd().crowd_subscription
+ FIND_RESULTS_PAGE_LIMIT: int = 100
+ create(email, camera_id, email_enabled=True)
+ find(user, emails, cameras, limit, skip)
}
class crowd.backend.notificationsPY FILE_ICON{
+ send_queue_overflow(zone,\n queue_info,\n queue_size,\n detection_time,\n image_url,\n escalation_level=None\n)
}
database mongoDB.crowd.crowd_subscription{
}
database mongoDB.crowd.telegram_subscriptions{
}
json crowd_subscription_entry{
"owner_id": "owner_id",
"created_at": "timestamp",
"subscriber_id": "user_id",
"subscriber_login": "email",
"telegram_confirmed": "False",
"camera_id": "camera_id",
"email_enabled": "email_enabled"
}
json telegram_sub_entry{
"email": "user@email.com",
"chat_id": "telegram_chat_id"
}
CrowdSubscription::COLLECTION -- crowd_subscription
telegram_subscriptions .. telegram_sub_entry
crowd_subscription .. crowd_subscription_entry
crowd_subscription_entry -[thickness=2]- telegram_sub_entry : "subscriber_login ::: email"
note left of notificationsPY
Функция отправки уведомлений
(в том числе и в телегу)
end note
note right of telegram_subscriptions
Сюда мы сейчас руками добавляем
записи-связки с crowd_subscription
end note
@enduml

View file

@ -0,0 +1,40 @@
@startuml PM Telegram Setup Sequence
actor "Dev" as DEV
actor "PM" as PM
participant "misc тачка" as MISC
participant "MongoDB\ncrowd.telegram_subscriptions" as DB
actor "User" as USER
participant "Telegram Bot" as BOT
participant "send_queue_overflow()" as NOTIF
PM -> USER: Коннектится с пользаком и\nсоздает с ним чат chat_id
PM -> BOT: Добавляют бота уведомлений в чат chat_id
PM -> DEV: Дает chat_id разрабам
DEV -> MISC: ssh
activate MISC
DEV -> DB: Создает запись
activate DB
note left of DB
{
"email": "demostandsalemsk@ivideon.com",
"chat_id": 89767978
}
end note
DB --> DEV: запись создана
deactivate MISC
deactivate DB
== Как все работает ==
NOTIF -> DB: найти chat_id по email
activate DB
DB --> NOTIF: chat_id: 89767978
NOTIF -> BOT: отправить уведомление в chat_id
BOT -> USER: уведомление в Telegram
deactivate DB
@enduml

View file

@ -0,0 +1,47 @@
@startuml CrowdSubscription Create Sequence
actor "client" as U
participant "CrowdSubscription" as CS
participant "API5" as API
participant "MongoDB\ncrowd_subscription" as DB
U -> CS: create(email, camera_id, email_enabled=True)
CS -> API: get_api_client()
activate API
CS -> API: User.get_id(login=email)
API --> CS: user_id
CS -> API: Camera({'id': camera_id}).get(projection)
API --> CS: camera data
deactivate API
CS -> DB: find_one(проверка на существующую подписку)
DB --> CS: existing_doc or None
alt Подписка уже есть
CS --> U: raise CrowdSubscriptionAlreadyExists
else Подписки нет
CS -> CS: create document
note right of CS
{
owner_id: camera['owner_id']
created_at: time.time()
subscriber_id: user_id
subscriber_login: email
telegram_confirmed: False
camera_id: camera_id
email_enabled: email_enabled
}
end note
CS -> DB: insert_with_random_id(doc)
DB --> CS: inserted_doc
CS --> U: CrowdSubscription(data=doc)
end
@enduml