| 123456789101112131415161718192021222324252627282930313233343536 |
- // Generated by scripts/build-workshop-skill.mjs; maintain the Skill course-assessment.mjs source.
- /** v3 course scores live in an existing report table, separately from 0–100 peer reviews. */
- export const COURSE_ASSESSMENT_ID = 'course-priority';
- export const COURSE_ASSESSMENT_COLUMNS = Object.freeze(['机会', '证据强度', '可做性', '商业价值', '依据一句话', '排序']);
- const invalid = () => { throw Object.assign(Error('COURSE_ASSESSMENT_INVALID'), { code: 'COURSE_ASSESSMENT_INVALID' }); };
- const key = value => typeof value === 'string' ? value.replace(/\s/gu, '') : '';
- const text = value => typeof value === 'string' && Boolean(value.trim());
- const score = value => {
- if (value === null || value === '' || ['待确认', '未知', '未评分', '—'].includes(value)) return null;
- if (typeof value === 'string' && /^[123]$/.test(value.trim())) value = Number(value.trim());
- if (!Number.isInteger(value) || value < 1 || value > 3) invalid();
- return value;
- };
- export function courseAssessmentRows(section) {
- if (section?.id !== COURSE_ASSESSMENT_ID) return null;
- if (section.kind !== 'table' || !Array.isArray(section.data?.cols)
- || section.data.cols.length !== COURSE_ASSESSMENT_COLUMNS.length
- || section.data.cols.some((column, i) => key(column) !== key(COURSE_ASSESSMENT_COLUMNS[i]))
- || !Array.isArray(section.data.rows) || !section.data.rows.length) invalid();
- return section.data.rows.map(row => {
- if (!Array.isArray(row) || row.length !== 6) invalid();
- const [candidate, evidence, feasibility, business, basis, order] = row;
- if (!text(candidate) || !text(basis) || typeof order !== 'string') invalid();
- const scores = [evidence, feasibility, business].map(score);
- const unknown = scores.some(value => value === null);
- const low = scores.includes(1);
- if ((unknown || low) && /^(?:第\s*)?[123一二三]\s*(?:名|位)?$/.test(order.trim())) invalid();
- return { candidate, scores, basis, order, unknown, low,
- status: low ? '不进入前三' : unknown ? '未知项待补' : '可参与排序' };
- });
- }
- export function validateCourseAssessment(report) {
- for (const chapter of report?.chapters || []) for (const section of chapter.sections || []) courseAssessmentRows(section);
- }
|