Активность: неизвестное происхождение не считается, чёрные недели, строка «Понедельно»
События с неизвестным источником не считаются (миграция 011). Завершённая неделя без единой активности красится чёрным. В Employee Activity под итоговым графиком добавлена строка «Понедельно»: один столбец на неделю, средние зелёные, жёлтые и красные люди за рабочий день, высота равна числу людей. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import Fastify, { type FastifyInstance } from "fastify";
|
||||
import { buildSeries, datesBetween, rangeStart, type ActivityDay } from "./activity.js";
|
||||
import { buildSeries, buildWeeks, datesBetween, markBlackWeeks, rangeStart, weekStartOf, type ActivityDay } from "./activity.js";
|
||||
import { buildTotals } from "./charts.js";
|
||||
import { buildWorkbook } from "./export.js";
|
||||
import { renderActivityPage, renderIndex, renderTodoPage, type ActivityPerson } from "./render.js";
|
||||
@@ -39,34 +39,40 @@ export function buildApi(deps: EmployeeReportsDeps): FastifyInstance {
|
||||
app.get("/todo", async (_req, reply) => reply.redirect("todo/"));
|
||||
app.get("/activity", async (_req, reply) => reply.redirect("activity/"));
|
||||
|
||||
/** Ряды активности всех, кого поставили на учёт. */
|
||||
async function activityPersons(days: number): Promise<{ persons: ActivityPerson[]; from: string; to: string }> {
|
||||
/**
|
||||
* Ряды активности всех, кого поставили на учёт. Данные берутся с понедельника недели, в которую входит первый показанный день:
|
||||
* правило чёрной недели и понедельные столбики считаются по полным неделям.
|
||||
*/
|
||||
async function activityPersons(days: number): Promise<{ persons: ActivityPerson[]; from: string; to: string; weeks: ReturnType<typeof buildWeeks> }> {
|
||||
const to = todayIn(deps.tz, now());
|
||||
const from = rangeStart(to, days);
|
||||
const fetchFrom = weekStartOf(from);
|
||||
const tracked = await deps.repo.listTracked();
|
||||
const nonWorkdays = await deps.repo.nonWorkdays(from, to);
|
||||
const persons: ActivityPerson[] = [];
|
||||
const nonWorkdays = await deps.repo.nonWorkdays(fetchFrom, to);
|
||||
const full: ActivityDay[][] = [];
|
||||
for (const p of tracked) {
|
||||
const counts = await deps.repo.dailyCounts(p, from, to);
|
||||
persons.push({ name: p.name, days: buildSeries({ from, to, counts, nonWorkdays, threshold: deps.threshold }) });
|
||||
const counts = await deps.repo.dailyCounts(p, fetchFrom, to);
|
||||
full.push(markBlackWeeks(buildSeries({ from: fetchFrom, to, counts, nonWorkdays, threshold: deps.threshold }), to));
|
||||
}
|
||||
return { persons, from, to };
|
||||
const persons: ActivityPerson[] = tracked.map((p, k) => ({ name: p.name, days: full[k]!.filter((d) => d.date >= from) }));
|
||||
return { persons, from, to, weeks: buildWeeks(full, from, to) };
|
||||
}
|
||||
|
||||
app.get<{ Querystring: { days?: string } }>("/activity/", async (req, reply) => {
|
||||
const days = clampDays(req.query.days, deps.defaultDays);
|
||||
const { persons, from, to } = await activityPersons(days);
|
||||
const { persons, from, to, weeks } = await activityPersons(days);
|
||||
const sync = await deps.repo.syncState();
|
||||
return html(reply, renderActivityPage({ persons, from, to, days, threshold: deps.threshold, sync, today: to }));
|
||||
return html(reply, renderActivityPage({ persons, from, to, days, weeks, threshold: deps.threshold, sync, today: to }));
|
||||
});
|
||||
|
||||
app.get<{ Querystring: { days?: string } }>("/api/activity", async (req) => {
|
||||
const days = clampDays(req.query.days, deps.defaultDays);
|
||||
const { persons, from, to } = await activityPersons(days);
|
||||
const { persons, from, to, weeks } = await activityPersons(days);
|
||||
return {
|
||||
from,
|
||||
to,
|
||||
threshold: deps.threshold,
|
||||
weeks,
|
||||
persons: persons.map((p) => ({ name: p.name, days: p.days as ActivityDay[] })),
|
||||
totals: persons.length ? buildTotals(persons.map((p) => p.days)) : [],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user