ShtukbaseStandard
包文件→ .shtukbase/packages/quality/checks/q03_measurement.ts

checks/q03_measurement.ts

28 行, 1.5 KB.

文件按包中的原样显示:代码及其注释不做翻译。

  1. // QLT-R03. A measurement counts only when it has its indicator, date, value, sample size and source; the sample
  2. // size is a positive number and the date is a date.
  3. import type { Project, Result } from '../../collections/checks/lib/speclib.ts';
  4. import { main } from '../../collections/checks/lib/runner.ts';
  5. import { addr, day, missing, num } from './lib/qlib.ts';
  6. export const RULE = { id: 'qlt-r03', title: 'A measurement counts: indicator, date, value, sample, source', scope: 'all measurements' };
  7. export function check(p: Project, res: Result): void {
  8. const reason = p.need('MEAS');
  9. if (!res.part('measurements', reason)) return;
  10. const recs = p.records('MEAS');
  11. res.scope = recs.map((r) => addr(r.id));
  12. for (const r of recs) {
  13. const a = addr(r.id), name = p.label(r, 'MEAS');
  14. const gap = missing(r, ['indicator', 'date', 'value', 'n', 'source']);
  15. if (gap.length) {
  16. res.hole(a, `${name}: the measurement does not count — missing ${gap.join(', ')}`, 'add the indicator, the date, the value, the sample (n) and the source', 'not-counted');
  17. continue;
  18. }
  19. if (!day(r.fm.date)) res.hole(a, `${name}: the date is not a date`, 'write a date YYYY-MM-DD', 'bad-date');
  20. if (num(r.fm.value) === null) res.hole(a, `${name}: the value is not a number`, 'write a number in value', 'bad-value');
  21. const n = num(r.fm.n);
  22. if (n === null || n <= 0) res.hole(a, `${name}: the sample n is not a positive number`, 'write the sample size', 'bad-n');
  23. }
  24. }
  25. if (import.meta.main) main({ RULE, check });