From fcaf55e57bf6369024988eec17c13033fa24b468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6?= <14975046+skjnldsv@users.noreply.github.com> Date: Tue, 17 Nov 2026 15:02:37 +0100 Subject: [PATCH 1/2] fix(hr): clearer Bradford bars, team names and durations on Insights MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bradford bars were scaled to the highest score, so a score of 2 filled the bar. They are now scaled to the serious threshold (900), coloured by level, and a "Review due" (500+) or "Serious" (900+) chip next to the score says the level in words. People without a manager were listed as a team called "No manager"; the group is now "People without a manager". Durations under one hour read "under an hour" instead of "0 hours". The sick leave list drops its rank column and keeps the sort by days. Its type picker is labelled "Leave type counted" and starts on the sick leave type instead of a "Sick leave (default)" placeholder. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: John Molakvoæ <14975046+skjnldsv@users.noreply.github.com> --- SPECIFICATION.md | 18 +++--- lib/Service/InsightsService.php | 2 +- src/utils/bradford.spec.ts | 24 ++++++++ src/utils/bradford.ts | 24 ++++++++ src/utils/duration.spec.ts | 28 +++++++++ src/utils/duration.ts | 26 +++++++++ src/views/hr/HrInsights.vue | 68 ++++++++++++---------- src/views/hr/HrSickLeave.vue | 22 ++----- tests/Unit/Service/InsightsServiceTest.php | 3 +- 9 files changed, 160 insertions(+), 55 deletions(-) create mode 100644 src/utils/bradford.spec.ts create mode 100644 src/utils/bradford.ts create mode 100644 src/utils/duration.spec.ts create mode 100644 src/utils/duration.ts diff --git a/SPECIFICATION.md b/SPECIFICATION.md index 1ffcd736..4ee11199 100644 --- a/SPECIFICATION.md +++ b/SPECIFICATION.md @@ -1367,10 +1367,13 @@ The HR area (visible only to HR-group members) provides: decision, and a per-manager table (decisions, median, escalations). Only leave that went to a manager is counted, so HR-recorded absences (booked without a decision) never flatter the figure. Escalation rate = escalated ÷ requests that - needed a decision. + needed a decision. Durations under one hour read *under an hour*, not *0 hours*. - **Bradford Factor** — recorded sick leave scored per employee as - *spells² × days*, ranked, coloured amber/red at the conventional 500/900 review - thresholds. A well-being prompt, deliberately not shown to line managers. + *spells² × days*, ranked, against the conventional review thresholds: 500 + (amber, *Review due*) and 900 (red, *Serious*). Each bar is scaled to 900, so + it fills at the serious threshold whatever the other scores are, and the level + is written next to the score, not shown by colour alone. A well-being prompt, + deliberately not shown to line managers. - **Leave utilisation** — annual `used ÷ entitlement`, company-wide and per team, plus a watchlist of employees with no non-sick leave in the last ~90 days (computed from a rolling one-year window), longest-neglected first. @@ -1380,7 +1383,7 @@ The HR area (visible only to HR-group members) provides: the figure each person reads on their own balance. Nothing is at risk once the date has passed, or in a year other than the current one. Teams are grouped by the manager each employee reports to; those without a manager form - one group. All of it is HR-only — it names people and includes health-adjacent + one group, *People without a manager*. All of it is HR-only: it names people and includes health-adjacent figures. 5. **Export:** CSV and Excel (`.xlsx`) export of raw requests and of the balances report, with date-range and group filters (the group filter narrows to the @@ -1504,9 +1507,10 @@ the SPA). All list endpoints paginate and accept filters. **HR reporting** - `GET /api/reports/balances` — balances report (filters). - `GET /api/reports/trends` — aggregated stats for charts. -- `GET /api/reports/sick-leave` — sick-leave overview, every employee ranked by days - lost. Counts the leave type keyed `sick` by default; `typeId` counts another type - instead, which the *Sick leave* view exposes as a type picker. The response carries +- `GET /api/reports/sick-leave`: sick-leave overview, every employee sorted by days + lost (the view shows no rank numbers). Counts the leave type keyed `sick` by + default; `typeId` counts another type instead, which the *Sick leave* view exposes + as a type picker labelled *Leave type counted*, starting on the type keyed `sick`. The response carries the types it aggregated, so the page can name what it is counting rather than implying "sickness" is a fixed concept — and can say so plainly when an instance has no matching type instead of showing a table of zeroes. diff --git a/lib/Service/InsightsService.php b/lib/Service/InsightsService.php index 2a09fdce..75e406fa 100644 --- a/lib/Service/InsightsService.php +++ b/lib/Service/InsightsService.php @@ -365,7 +365,7 @@ private function buildTeams(array $uids): array { $teams[] = [ 'managerUid' => $manager === '' ? null : $manager, 'name' => $manager === '' - ? $this->l->t('No manager') + ? $this->l->t('People without a manager') : $this->l->t("%s's team", [$this->displayName($manager)]), 'uids' => $members, ]; diff --git a/src/utils/bradford.spec.ts b/src/utils/bradford.spec.ts new file mode 100644 index 00000000..6004e41a --- /dev/null +++ b/src/utils/bradford.spec.ts @@ -0,0 +1,24 @@ +/** + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import { describe, expect, it } from 'vitest' +import { bradfordLevel } from './bradford.ts' + +describe('bradfordLevel', () => { + it('stays low under the review threshold', () => { + expect(bradfordLevel(0)).toBe('low') + expect(bradfordLevel(2)).toBe('low') + expect(bradfordLevel(499)).toBe('low') + }) + + it('asks for a review from 500', () => { + expect(bradfordLevel(500)).toBe('review') + expect(bradfordLevel(899)).toBe('review') + }) + + it('is serious from 900', () => { + expect(bradfordLevel(900)).toBe('serious') + expect(bradfordLevel(5000)).toBe('serious') + }) +}) diff --git a/src/utils/bradford.ts b/src/utils/bradford.ts new file mode 100644 index 00000000..ce23fbc8 --- /dev/null +++ b/src/utils/bradford.ts @@ -0,0 +1,24 @@ +/** + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +/** The conventional Bradford Factor score from which a review is due. */ +export const BRADFORD_REVIEW = 500 + +/** The conventional Bradford Factor score from which the case is serious. */ +export const BRADFORD_SERIOUS = 900 + +export type BradfordLevel = 'low' | 'review' | 'serious' + +/** + * Where a Bradford Factor score stands against the review thresholds. + * + * @param score spells² × days + */ +export function bradfordLevel(score: number): BradfordLevel { + if (score >= BRADFORD_SERIOUS) { + return 'serious' + } + return score >= BRADFORD_REVIEW ? 'review' : 'low' +} diff --git a/src/utils/duration.spec.ts b/src/utils/duration.spec.ts new file mode 100644 index 00000000..6e36f299 --- /dev/null +++ b/src/utils/duration.spec.ts @@ -0,0 +1,28 @@ +/** + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import { describe, expect, it } from 'vitest' +import { formatHours } from './duration.ts' + +describe('formatHours', () => { + it('says under an hour below one hour', () => { + expect(formatHours(0)).toBe('under an hour') + expect(formatHours(0.9)).toBe('under an hour') + }) + + it('counts whole hours below two days', () => { + expect(formatHours(1)).toBe('1 hour') + expect(formatHours(5.4)).toBe('5 hours') + expect(formatHours(47.9)).toBe('48 hours') + }) + + it('counts days from two days on', () => { + expect(formatHours(48)).toBe('2 days') + expect(formatHours(60)).toBe('2.5 days') + }) + + it('shows a dash when there is nothing to measure', () => { + expect(formatHours(null)).toBe('–') + }) +}) diff --git a/src/utils/duration.ts b/src/utils/duration.ts new file mode 100644 index 00000000..50db51e6 --- /dev/null +++ b/src/utils/duration.ts @@ -0,0 +1,26 @@ +/** + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import { n, t } from '@nextcloud/l10n' +import { formatNumber } from './locale.ts' + +/** + * A duration: "under an hour" below one hour, in hours below two days, in days + * from there. + * + * @param h the hours, null when there is nothing to measure + */ +export function formatHours(h: number | null): string { + if (h === null || h === undefined) { + return '–' + } + if (h < 1) { + return t('absence', 'under an hour') + } + if (h < 48) { + return n('absence', '%n hour', '%n hours', Math.round(h)) + } + const days = Math.round(h / 24 * 10) / 10 + return n('absence', '{days} day', '{days} days', days, { days: formatNumber(days) }) +} diff --git a/src/views/hr/HrInsights.vue b/src/views/hr/HrInsights.vue index 62ae9fe8..59565bfc 100644 --- a/src/views/hr/HrInsights.vue +++ b/src/views/hr/HrInsights.vue @@ -25,9 +25,9 @@