Активность: сообщения в проектных каналах Slack считаются действием; загрузка в data_collector, миграция 014
Some checks failed
ci / test (push) Failing after 24s
ci / deploy (push) Has been skipped

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-15 20:59:43 +03:00
parent 61001a0e46
commit a88b0c9ebf
12 changed files with 279 additions and 20 deletions

View File

@@ -140,15 +140,26 @@ export const EVENT_COUNTS_SQL = `
`;
/**
* Сообщения сотрудника в чате с ассистентом. Пока в журнале нет автора (до миграции 008) считаем, что писал сам менеджер канала.
* Сообщения сотрудника в чате с ассистентом и в проектных каналах Slack. Пока в журнале ассистента нет автора (до миграции 008) считаем,
* что писал сам менеджер канала. Сообщение проектного канала, которое уже есть в журнале ассистента, считается один раз.
*/
export const CHAT_COUNTS_SQL = `
select (m.received_at at time zone $4)::date::text as day, count(*)::int as n
from slack_message_log m
where m.manager_person_id = $1
and (m.sender_slack_user_id is null or m.sender_slack_user_id = $5)
and m.received_at >= ($2::date)::timestamp at time zone $4
and m.received_at < (($3::date) + 1)::timestamp at time zone $4
with msgs as (
select m.received_at as at
from slack_message_log m
where m.manager_person_id = $1
and (m.sender_slack_user_id is null or m.sender_slack_user_id = $5)
union all
select c.posted_at
from slack_channel_message c
join project_channel pc on pc.channel_id = c.channel_id and pc.track_activity
where c.user_id = $5
and not exists (select 1 from slack_message_log l where l.channel_id = c.channel_id and l.message_ts = c.message_ts)
)
select (at at time zone $4)::date::text as day, count(*)::int as n
from msgs
where at >= ($2::date)::timestamp at time zone $4
and at < (($3::date) + 1)::timestamp at time zone $4
group by 1
`;
@@ -163,14 +174,25 @@ export const USER_ACTIVITY_DAYS_SQL = `
and created_at < (($2::date) + 1)::timestamp at time zone $3
group by 1, 2
),
chat as (
select mb.user_name, (s.received_at at time zone $3)::date::text as day, count(*)::int as n
msgs as (
select mb.user_name, s.received_at as at
from slack_message_log s
join person p on p.id = s.manager_person_id
join jt_membership mb on mb.id = p.jt_membership_id
where (s.sender_slack_user_id is null or s.sender_slack_user_id = p.slack_user_id)
and s.received_at >= ($1::date)::timestamp at time zone $3
and s.received_at < (($2::date) + 1)::timestamp at time zone $3
union all
select mb.user_name, c.posted_at
from slack_channel_message c
join project_channel pc on pc.channel_id = c.channel_id and pc.track_activity
join person p on p.slack_user_id = c.user_id
join jt_membership mb on mb.id = p.jt_membership_id
where not exists (select 1 from slack_message_log l where l.channel_id = c.channel_id and l.message_ts = c.message_ts)
),
chat as (
select user_name, (at at time zone $3)::date::text as day, count(*)::int as n
from msgs
where at >= ($1::date)::timestamp at time zone $3
and at < (($2::date) + 1)::timestamp at time zone $3
group by 1, 2
)
select coalesce(ev.user_name, chat.user_name) as user_name, coalesce(ev.day, chat.day) as day,