Employee Activity: итог «Всего» как «Понедельно» на одном дне, серая доля чата, действия агента засчитываются менеджеру
All checks were successful
ci / test (push) Successful in 23s
ci / deploy (push) Successful in 1m43s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-15 22:09:47 +03:00
parent b975ae0bc3
commit 9b5f445ba1
7 changed files with 104 additions and 16 deletions

View File

@@ -8,6 +8,8 @@ const AXIS_H = 18;
/** Фон дня: тёмно-красный - активности меньше порога; зелёный - есть Daily Log; жёлтый - активность выше порога, но Daily Log нет; серый - нерабочий день без активности. */
/** Чёрный - завершённая неделя без единой активности. */
/** Цвет доли сообщений в чате внутри белого столбика активности. */
export const CHAT_SHARE_COLOR = "#cfd4dc";
export const COLORS: Record<DayStatus, string> = { green: "#2e7d32", yellow: "#e6b800", red: "#7f1d1d", off: "#d5d9e0", black: "#000000" };
const esc = (s: string): string => s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
@@ -30,7 +32,12 @@ export function renderPersonChart(days: ActivityDay[], threshold: number, yMax:
const cols = days
.map((d, i) => {
const h = d.total > 0 ? Math.max(3, Math.round((d.total / yMax) * (CHART_H - 14))) : 0;
const bar = h ? `<rect x="${i * CELL + 3}" y="${CHART_H - h}" width="${CELL - 6}" height="${h}" fill="#ffffff" stroke="#111827" stroke-width="0.8"/>` : "";
// светло-серая часть столбика (снизу) - доля сообщений в чатах (ассистент и проектные каналы) в активности дня
const chatH = h && d.counts.chat > 0 ? Math.max(1, Math.round((h * d.counts.chat) / d.total)) : 0;
const bar = h
? `<rect x="${i * CELL + 3}" y="${CHART_H - h}" width="${CELL - 6}" height="${h}" fill="#ffffff" stroke="#111827" stroke-width="0.8"/>` +
(chatH ? `<rect x="${i * CELL + 3.4}" y="${CHART_H - chatH - 0.4}" width="${CELL - 6.8}" height="${chatH}" fill="${CHAT_SHARE_COLOR}"/>` : "")
: "";
const num = d.total > 0 ? `<text x="${i * CELL + CELL / 2}" y="${CHART_H - h - 2}" text-anchor="middle" font-size="8" font-weight="700" fill="#111827" paint-order="stroke" stroke="#ffffff" stroke-width="2">${d.total}</text>` : "";
return `<g><title>${esc(describeDay(d, threshold))} (${weekday(d.date)})</title><rect x="${i * CELL}" y="0" width="${CELL}" height="${CHART_H}" fill="${COLORS[d.status]}" stroke="#ffffff" stroke-width="0.6"/>${bar}${num}</g>`;
})
@@ -50,7 +57,10 @@ export function buildTotals(series: ActivityDay[][]): DayTotal[] {
});
}
/** Итоговый график под всеми людьми: за каждый день столбик из зелёных (внизу) и жёлтых (над ними) людей. */
/**
* Итоговый график под всеми людьми («Всего»): те же правила, что у строки «Понедельно», но для одного дня. Колонка всегда высотой во всех людей:
* зелёные внизу, над ними жёлтые, затем красные; нерабочие дни без активности (серые) и чёрные недели добавляются выше, поэтому сумма равна числу людей.
*/
export function renderTotalChart(totals: DayTotal[], people: number): string {
const blackDay = (t: DayTotal) => people > 0 && t.black >= people; // неделя без активности у всех людей
const w = totals.length * CELL;
@@ -61,14 +71,16 @@ export function renderTotalChart(totals: DayTotal[], people: number): string {
}).join("");
const cols = totals
.map((t, i) => {
const gH = t.green * unit;
const yH = t.yellow * unit;
const tip = `${t.date} (${weekday(t.date)}): зелёных ${t.green}, жёлтых ${t.yellow}, красных ${t.red}${t.off ? `, без учёта (нерабочий день) ${t.off}` : ""}`;
const bg = blackDay(t) ? COLORS.black : "transparent";
return `<g><title>${esc(blackDay(t) ? `${t.date} (${weekday(t.date)}): неделя без единой активности` : tip)}</title><rect x="${i * CELL}" y="0" width="${CELL}" height="${TOTAL_H}" fill="${bg}"/>` +
(gH ? `<rect x="${i * CELL + 3}" y="${TOTAL_H - gH}" width="${CELL - 6}" height="${gH}" fill="${COLORS.green}"/>` : "") +
(yH ? `<rect x="${i * CELL + 3}" y="${TOTAL_H - gH - yH}" width="${CELL - 6}" height="${yH}" fill="${COLORS.yellow}"/>` : "") +
`</g>`;
const tip = `${t.date} (${weekday(t.date)}): зелёных ${t.green}, жёлтых ${t.yellow}, красных ${t.red}${t.off ? `, без учёта (нерабочий день) ${t.off}` : ""}${t.black ? `, чёрных ${t.black}` : ""}`;
let y = TOTAL_H;
const seg = (n: number, color: string): string => {
if (!n) return "";
const h = n * unit;
y -= h;
return `<rect x="${i * CELL + 2}" y="${y}" width="${CELL - 4}" height="${h}" fill="${color}"/>`;
};
const layers = seg(t.green, COLORS.green) + seg(t.yellow, COLORS.yellow) + seg(t.red, COLORS.red) + seg(t.off, COLORS.off) + seg(t.black, COLORS.black);
return `<g><title>${esc(blackDay(t) ? `${t.date} (${weekday(t.date)}): неделя без единой активности` : tip)}</title>${layers}</g>`;
})
.join("");
const yTicks = Array.from({ length: people + 1 }, (_, n) => `<text x="2" y="${TOTAL_H - n * unit - 2}" font-size="8" fill="#667085">${n}</text>`).join("");