To-do report: активных дней за последние 7 рядом с активностью за день снимка; подпись над столбиком не обрезается
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -36,6 +36,8 @@ export interface TodoSourceRow {
|
||||
}
|
||||
|
||||
export interface UserActivity { total: number; dailyLogs: number }
|
||||
/** Активность пользователей JobTread: имя -> день -> счётчик. */
|
||||
export type UserActivityByDay = Map<string, Map<string, UserActivity>>;
|
||||
export interface SyncState { lastSuccessAt: string | null; lastError: string | null; lastLoaded: number }
|
||||
|
||||
/** Всё, что отчёты читают из Supabase. Подменяется в тестах. */
|
||||
@@ -48,8 +50,8 @@ export interface ReportsRepo {
|
||||
listSnapshotDays(): Promise<SnapshotDay[]>;
|
||||
todoReport(snapshotTs: string): Promise<TodoReportRow[]>;
|
||||
todoSource(snapshotTs: string, employee?: string): Promise<TodoSourceRow[]>;
|
||||
/** Активность по имени пользователя JobTread за один день (по часовому поясу `tz`). */
|
||||
activityByUser(day: string, tz: string): Promise<Map<string, UserActivity>>;
|
||||
/** Активность по именам пользователей JobTread по дням от `from` до `to` включительно (по часовому поясу `tz`). */
|
||||
activityByUserDays(from: string, to: string, tz: string): Promise<UserActivityByDay>;
|
||||
}
|
||||
|
||||
const EVENT_KINDS = ["todo_closed", "todo_created", "milestone_closed", "milestone_moved", "daily_log_created"] as const;
|
||||
@@ -147,28 +149,30 @@ export const CHAT_COUNTS_SQL = `
|
||||
group by 1
|
||||
`;
|
||||
|
||||
/** Активность по пользователям JobTread за день: события JobTread плюс чат (только у тех, кто есть в person). */
|
||||
export const USER_ACTIVITY_SQL = `
|
||||
/** Активность по пользователям JobTread по дням: события JobTread плюс чат (только у тех, кто есть в person). Параметры: от, до (включительно), часовой пояс. */
|
||||
export const USER_ACTIVITY_DAYS_SQL = `
|
||||
with ev as (
|
||||
select user_name, count(*)::int as n, (count(*) filter (where kind = 'daily_log_created'))::int as logs
|
||||
select user_name, (created_at at time zone $3)::date::text as day, count(*)::int as n,
|
||||
(count(*) filter (where kind = 'daily_log_created'))::int as logs
|
||||
from jt_event
|
||||
where kind is not null and user_name is not null
|
||||
and created_at >= ($1::date)::timestamp at time zone $2
|
||||
and created_at < (($1::date) + 1)::timestamp at time zone $2
|
||||
group by user_name
|
||||
and created_at >= ($1::date)::timestamp at time zone $3
|
||||
and created_at < (($2::date) + 1)::timestamp at time zone $3
|
||||
group by 1, 2
|
||||
),
|
||||
chat as (
|
||||
select mb.user_name, count(*)::int as n
|
||||
select mb.user_name, (s.received_at at time zone $3)::date::text as day, count(*)::int as n
|
||||
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 $2
|
||||
and s.received_at < (($1::date) + 1)::timestamp at time zone $2
|
||||
group by mb.user_name
|
||||
and s.received_at >= ($1::date)::timestamp at time zone $3
|
||||
and s.received_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.n, 0) + coalesce(chat.n, 0) as total, coalesce(ev.logs, 0) as logs
|
||||
from ev full join chat on chat.user_name = ev.user_name
|
||||
select coalesce(ev.user_name, chat.user_name) as user_name, coalesce(ev.day, chat.day) as day,
|
||||
coalesce(ev.n, 0) + coalesce(chat.n, 0) as total, coalesce(ev.logs, 0) as logs
|
||||
from ev full join chat on chat.user_name = ev.user_name and chat.day = ev.day
|
||||
`;
|
||||
|
||||
export function createRepo(db: Queryable): ReportsRepo {
|
||||
@@ -227,9 +231,13 @@ export function createRepo(db: Queryable): ReportsRepo {
|
||||
return rows.map((r) => ({ ...r, snapshot_ts: new Date(r.snapshot_ts).toISOString() })) as TodoSourceRow[];
|
||||
},
|
||||
|
||||
async activityByUser(day, tz) {
|
||||
const out = new Map<string, UserActivity>();
|
||||
for (const r of (await db.query(USER_ACTIVITY_SQL, [day, tz])).rows) out.set(r.user_name, { total: r.total, dailyLogs: r.logs });
|
||||
async activityByUserDays(from, to, tz) {
|
||||
const out: UserActivityByDay = new Map();
|
||||
for (const r of (await db.query(USER_ACTIVITY_DAYS_SQL, [from, to, tz])).rows) {
|
||||
const days = out.get(r.user_name) ?? new Map();
|
||||
days.set(r.day, { total: r.total, dailyLogs: r.logs });
|
||||
out.set(r.user_name, days);
|
||||
}
|
||||
return out;
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user