To-do report: активных дней за последние 7 рядом с активностью за день снимка; подпись над столбиком не обрезается
All checks were successful
ci / test (push) Successful in 21s
ci / deploy (push) Successful in 1m42s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-15 14:44:12 +03:00
parent 715546bdae
commit 3fae6b2792
7 changed files with 49 additions and 34 deletions

View File

@@ -1,5 +1,5 @@
import Fastify, { type FastifyInstance } from "fastify";
import { buildSeries, rangeStart, type ActivityDay } from "./activity.js";
import { buildSeries, datesBetween, rangeStart, type ActivityDay } from "./activity.js";
import { buildTotals } from "./charts.js";
import { buildWorkbook } from "./export.js";
import { renderActivityPage, renderIndex, renderTodoPage, type ActivityPerson } from "./render.js";
@@ -78,11 +78,15 @@ export function buildApi(deps: EmployeeReportsDeps): FastifyInstance {
const snapshotDays = await deps.repo.listSnapshotDays();
const selected = pickSnapshot(snapshotDays, req.query.date);
const reportRows = selected ? await deps.repo.todoReport(selected.snapshotTs) : [];
// любая активность в инфополе: за день снимка по времени Нью-Йорка (события JobTread и чат)
const activity = selected ? await deps.repo.activityByUser(selected.day, deps.tz) : new Map();
// любая активность в инфополе: за день снимка и за 7 дней по него включительно (по времени Нью-Йорка; события JobTread и чат)
const from = rangeStart(selected?.day ?? todayIn(deps.tz, now()), 7);
const activity = selected ? await deps.repo.activityByUserDays(from, selected.day, deps.tz) : new Map();
const weekDates = selected ? datesBetween(from, selected.day) : [];
const rows = reportRows.map((r) => {
const a = activity.get(r.employee_name) ?? { total: 0, dailyLogs: 0 };
return { ...r, activity: { total: a.total, dailyLogs: a.dailyLogs, active: a.total >= deps.threshold } };
const byDay = activity.get(r.employee_name) ?? new Map();
const today = byDay.get(selected?.day ?? "") ?? { total: 0, dailyLogs: 0 };
const activeDays = weekDates.filter((d) => (byDay.get(d)?.total ?? 0) >= deps.threshold).length;
return { ...r, activity: { total: today.total, dailyLogs: today.dailyLogs, active: today.total >= deps.threshold, activeDays, windowDays: weekDates.length } };
});
const employee = rows.some((r) => r.employee_name === req.query.employee) ? req.query.employee : undefined;
const source = selected && employee ? await deps.repo.todoSource(selected.snapshotTs, employee) : [];