ShtukbaseStandard
файл пакета→ .shtukbase/packages/quality/checks/q02_indicator_fresh.ts

checks/q02_indicator_fresh.ts

32 строки, 1.9 КБ.

Файл как есть в пакете: код и комментарии в нём не переводятся.

  1. // QLT-R02. An indicator in «measuring» has a baseline, a last value and the date of the last measurement, and that
  2. // date is not older than two periods of its cadence (nightly — 1 day, weekly — 7 days); per-change and milestone
  3. // cadences have no fixed period and are not checked for age. Today is QUALITY_TODAY or the system date.
  4. import type { Project, Result } from '../../collections/checks/lib/speclib.ts';
  5. import { main } from '../../collections/checks/lib/runner.ts';
  6. import { addr, day, daysBetween, has, missing, state, today } from './lib/qlib.ts';
  7. export const RULE = { id: 'qlt-r02', title: '"Measuring" has a baseline and a fresh measurement', scope: 'indicators in the state "Measuring"' };
  8. const PERIOD: Record<string, number> = { nightly: 1, weekly: 7 };
  9. export function check(p: Project, res: Result): void {
  10. const reason = p.need('IND');
  11. if (!res.part('indicators', reason)) return;
  12. const now = today();
  13. const recs = p.records('IND').filter((r) => state(r) === 'measuring');
  14. res.scope = recs.map((r) => addr(r.id));
  15. for (const r of recs) {
  16. const a = addr(r.id), name = p.label(r, 'IND');
  17. const gap = missing(r, ['baseline', 'current', 'lastMeasured']);
  18. if (gap.length) {
  19. res.hole(a, `${name}: "Measuring" without ${gap.join(', ')}`, 'write the baseline and the last counted measurement or return it to "Instrumented"', 'no-baseline');
  20. continue;
  21. }
  22. const last = day(r.fm.lastMeasured);
  23. const period = PERIOD[String(r.fm.cadence ?? '')];
  24. if (!last) res.hole(a, `${name}: lastMeasured is not a date`, 'write a date YYYY-MM-DD', 'bad-date');
  25. else if (period && has(r, 'cadence') && daysBetween(last, now) > 2 * period)
  26. res.hole(a, `${name}: gone stale — the last measurement ${last}, but it must be measured ${r.fm.cadence}`, 'make a new measurement or return the indicator to "Instrumented"', 'stale');
  27. }
  28. }
  29. if (import.meta.main) main({ RULE, check });