From 5fc6421d78a5a80808b2e3ea272bcf17b6480cee Mon Sep 17 00:00:00 2001 From: t0xa Date: Mon, 8 Sep 2025 12:05:00 +0300 Subject: [PATCH] ivideon: update some crowd schemes --- .../Crowd/notifications/9205_activity.puml | 21 ++++++++ .../Crowd/notifications/9205_overview.puml | 53 +++++++++++++++++++ .../puml/Crowd/notifications/9205_pm_seq.puml | 40 ++++++++++++++ .../notifications/9205_sub_sequence.puml | 47 ++++++++++++++++ 4 files changed, 161 insertions(+) create mode 100644 ivideon/puml/Crowd/notifications/9205_activity.puml create mode 100644 ivideon/puml/Crowd/notifications/9205_overview.puml create mode 100644 ivideon/puml/Crowd/notifications/9205_pm_seq.puml create mode 100644 ivideon/puml/Crowd/notifications/9205_sub_sequence.puml diff --git a/ivideon/puml/Crowd/notifications/9205_activity.puml b/ivideon/puml/Crowd/notifications/9205_activity.puml new file mode 100644 index 0000000..49d3019 --- /dev/null +++ b/ivideon/puml/Crowd/notifications/9205_activity.puml @@ -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 diff --git a/ivideon/puml/Crowd/notifications/9205_overview.puml b/ivideon/puml/Crowd/notifications/9205_overview.puml new file mode 100644 index 0000000..ec6e227 --- /dev/null +++ b/ivideon/puml/Crowd/notifications/9205_overview.puml @@ -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 diff --git a/ivideon/puml/Crowd/notifications/9205_pm_seq.puml b/ivideon/puml/Crowd/notifications/9205_pm_seq.puml new file mode 100644 index 0000000..b07b783 --- /dev/null +++ b/ivideon/puml/Crowd/notifications/9205_pm_seq.puml @@ -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 diff --git a/ivideon/puml/Crowd/notifications/9205_sub_sequence.puml b/ivideon/puml/Crowd/notifications/9205_sub_sequence.puml new file mode 100644 index 0000000..1b07d67 --- /dev/null +++ b/ivideon/puml/Crowd/notifications/9205_sub_sequence.puml @@ -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