Spaces:
Paused
Paused
File size: 20,388 Bytes
911f7e1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | (function (root, factory) {
'use strict';
var api = factory();
if (typeof module === 'object' && module.exports) module.exports = api;
if (root) root.PracticeEngine = api;
})(typeof window !== 'undefined' ? window : globalThis, function () {
'use strict';
const roles = [
{ id: 'software', name: 'Graduate Software Engineer', label: '软件工程', description: '用项目经历讲清协作、排错与个人贡献。' },
{ id: 'data', name: 'Graduate Data Analyst', label: '数据分析', description: '用分析经历说明判断、沟通与结果。' },
{ id: 'product', name: 'Product Intern', label: '产品实习', description: '用用户需求与团队项目说明取舍和执行。' },
{ id: 'general', name: 'Graduate / Internship Role', label: '通用校招', description: '从课程、社团或兼职中寻找具体例子。' }
];
const focuses = [
{ id: 'teamwork', label: '团队协作', description: '清楚区分团队成果与自己的贡献。' },
{ id: 'problem', label: '解决问题', description: '说明如何发现问题、比较方案和采取行动。' },
{ id: 'leadership', label: '主动担当', description: '用具体行动说明如何推动事情发生。' },
{ id: 'learning', label: '学习成长', description: '解释如何运用反馈并调整做法。' }
];
const contexts = {
software: ['a software project', 'a technical problem in a project', 'your project team', 'a new development tool or technique'],
data: ['a data analysis project', 'a problem with data quality or analysis', 'people working on an analysis', 'a new analysis tool or method'],
product: ['a product or user research project', 'an unclear user need or product requirement', 'a project involving different stakeholders', 'a new research or product planning method'],
general: ['a university, society or work project', 'a difficult problem at university or work', 'a group at university or work', 'a new skill for a project or responsibility']
};
const hints = {
teamwork: ['先交代团队目标,再聚焦你做了什么。', '描述具体分歧,说明你如何倾听并推进决定。', '选一个需要协调分工或沟通的真实例子。'],
problem: ['说明问题为什么重要,再讲你的判断和行动。', '解释你考虑过哪些做法,以及选择的依据。', '可以谈没有完全成功的经历,关键是说明学到了什么。'],
leadership: ['不需要正式头衔;选一个你主动承担责任的例子。', '说明你如何争取支持,而不只是安排别人做事。', '讲清你承担的责任,以及如何确认进展。'],
learning: ['交代学习的原因、方法和实际应用。', '选一条具体反馈,讲清你如何修改做法。', '说明下一次你会如何把这次经验用起来。']
};
function getQuestions(roleId, focusId, count) {
const role = Object.prototype.hasOwnProperty.call(contexts, roleId) ? roleId : 'general';
const focus = Object.prototype.hasOwnProperty.call(hints, focusId) ? focusId : 'teamwork';
const c = contexts[role];
const sets = {
teamwork: [
`Tell me about a time you worked with others on ${c[0]}. What was your own contribution?`,
`Describe a disagreement within ${c[2]}. How did you help the group move forward?`,
`Tell me about a time communication became difficult during ${c[0]}. What did you do?`
],
problem: [
`Tell me about a time you dealt with ${c[1]}. How did you approach it?`,
`Describe a difficult decision you made during ${c[0]}. How did you compare the options?`,
`Tell me about an approach that did not work as planned during ${c[0]}. What did you change?`
],
leadership: [
`Tell me about a time you took the initiative in ${c[0]}. What prompted you to act?`,
`Describe a time you helped ${c[2]} make progress without having formal authority.`,
`Tell me about a time you took responsibility when ${c[0]} was falling behind.`
],
learning: [
`Tell me about a time you had to learn ${c[3]} quickly. How did you use what you learned?`,
`Describe feedback you received during ${c[0]}. How did you respond to it?`,
`Tell me about a mistake you made during ${c[0]}. What would you do differently now?`
]
};
const n = Number.isFinite(Number(count)) ? Math.max(1, Math.min(3, Math.floor(Number(count)))) : 3;
return sets[focus].slice(0, n).map((text, i) => ({ id: `${role}-${focus}-${i + 1}`, text, hint: hints[focus][i] }));
}
const criteria = [
{
key: 'S', label: '情境', title: 'Situation · 情境',
pattern: /\b(?:during|when|at university|in (?:my|our|a|the) (?:final|second|first|course|university|group|team|project|internship|society|part[- ]time))\b/i,
suggestion: '补充经历发生的背景:什么项目、面对什么困难、为什么重要。'
},
{
key: 'T', label: '任务', title: 'Task · 任务',
pattern: /\b(?:my (?:task|role|goal|responsibility)|our (?:task|goal|aim)|i was (?:responsible|asked|assigned)|we (?:needed|had) to|i (?:needed|had) to|the (?:goal|objective|task) was)\b/i,
suggestion: '讲清当时要实现的目标,以及你本人承担的责任。'
},
{
key: 'A', label: '行动', title: 'Action · 行动',
pattern: /\bi (?:personally |then |first |also |subsequently )?(?:built|created|developed|designed|implemented|tested|debugged|analysed|analyzed|checked|reviewed|compared|interviewed|organised|organized|scheduled|proposed|documented|wrote|introduced|spoke|asked|listened|explained|prioritised|prioritized|coordinated|contacted|investigated|revised|read|practised|practiced|learned|learnt|used|met|collected|split|mapped|changed|identified|researched|validated|presented)\b/i,
suggestion: '用“I…”说明你实际采取的两到三个步骤,并解释这样做的原因。'
},
{
key: 'R', label: '结果', title: 'Result · 结果',
pattern: /\b(?:as a result|the result was|this (?:led to|resulted in|helped|reduced|improved|enabled)|we (?:delivered|completed|finished|achieved)|our (?:team|project) (?:delivered|completed|achieved)|(?:reduced|increased|improved) .{0,55} by \d|i (?:learned|learnt) that)\b/i,
suggestion: '补充可观察到的结果或学到的经验;有真实数据再使用数字,不必编造。'
}
];
function sentences(text) {
// Keep each match verbatim: every quoted piece must exist in the submitted answer.
return text.match(/[^.!?\n]+(?:[.!?]+|$)/g) || [text];
}
function evidenceFor(text, pattern) {
const sentence = sentences(text).find(item => pattern.test(item));
if (!sentence) return '';
const trimmed = sentence.trim();
// Return a literal excerpt even when long; no invented ellipsis inside the quote.
if (trimmed.length <= 220) return trimmed;
const match = pattern.exec(trimmed);
const start = Math.max(0, match.index - 45);
return trimmed.slice(start, start + 220).trim();
}
function analyzeAnswer(answer) {
const text = typeof answer === 'string' ? answer.trim() : '';
const words = text.match(/[A-Za-z]+(?:['’\-][A-Za-z]+)*/g) || [];
const wordCount = words.length;
const letterCount = (text.match(/[A-Za-z]/g) || []).length;
const nonLatinCount = (text.match(/[\u3400-\u9FFF]/g) || []).length;
const englishEnough = letterCount >= 15 && letterCount > nonLatinCount;
const signals = criteria.map(c => {
const evidence = englishEnough ? evidenceFor(text, c.pattern) : '';
return { key: c.key, label: c.label, title: c.title, found: !!evidence, evidence, suggestion: c.suggestion };
});
const matched = signals.filter(s => s.found);
const missing = signals.filter(s => !s.found);
const strengths = matched.slice(0, 3).map(s => ({
title: `找到${s.label}的表达线索`,
detail: `这段文字包含与“${s.label}”相关的词语。请自行核对它是否清楚、具体且切题。`,
evidence: s.evidence
}));
const improvements = missing.map(s => ({ title: `检查${s.label}是否清楚`, detail: s.suggestion }));
if (!text) {
improvements.unshift({ title: '先写下一个经历', detail: '当前回答为空。可以从最近一次课程项目、社团活动或兼职经历开始。' });
} else if (!englishEnough) {
improvements.unshift({ title: '尝试用英文回答', detail: '本原型只检查有限的英文表达模式。当前文本没有足够英文内容,暂不作结构判断。' });
} else if (wordCount < 35) {
improvements.unshift({ title: '展开一个具体例子', detail: '当前回答较短。补充当时的目标、你的具体动作,以及之后发生了什么;长度本身不代表质量。' });
}
if (missing.length === 0) {
improvements.push({ title: '核对内容,而不只检查结构', detail: '四类线索都出现了,但关键词不能验证切题性或经历真实性。检查行动是否属于你本人,结果是否有事实支持。' });
}
let followUp;
if (!text || !englishEnough || wordCount < 12) {
followUp = 'Could you share one specific example in English, including what happened and what you personally did?';
} else if (!signals[2].found) {
followUp = 'What did you personally do in this situation, and why did you choose those steps?';
} else if (!signals[3].found) {
followUp = 'What happened after you took those steps? What evidence or feedback helped you judge the outcome?';
} else if (!signals[1].found) {
followUp = 'What exactly were you responsible for, and what did you need to achieve?';
} else if (!signals[0].found) {
followUp = 'Could you explain the context and why this situation mattered to the people involved?';
} else {
followUp = 'Looking back, what would you do differently next time, and how would you apply that lesson in this role?';
}
let note = '演示规则只查找有限的英文关键词和句式。检测到线索不等于表达充分,未检测到也不等于内容缺失;本工具不能判断回答是否切题、真实或具备岗位竞争力。';
if (!englishEnough && text) note = '当前文本不适合英文规则检查。' + note;
return { wordCount, signals, strengths, improvements, followUp, note };
}
function getCoachReply(kind, answer, questionText) {
const result = analyzeAnswer(answer);
const lead = '引导提示(预设规则,非 AI 对话):';
if (kind === 'evidence') {
const action = result.signals.find(s => s.key === 'A');
if (action.found) return `${lead}你写到:“${action.evidence}” 可以继续解释:为什么选择这个做法?有哪些观察或反馈说明它起了作用?只使用你确实知道的事实。`;
return `${lead}从回答中选一句比较笼统的话,例如“我们合作得很好”,再补充“我具体做了什么”和“之后发生了什么”。如果没有数字,可以使用按时交付、得到的反馈或发现的问题等真实证据。`;
}
if (kind === 'next') {
const target = result.signals.find(s => !s.found);
return `${lead}${target ? target.suggestion : '保留事实,删去重复内容,检查每个行动是否能说明你的判断。'} 然后写下一件下次回答时最想改进的事,再在修改版里尝试。`;
}
const missing = result.signals.filter(s => !s.found).map(s => s.label).join('、');
return `${lead}可以按“情境 → 任务 → 行动 → 结果”整理同一个真实经历。${missing ? `当前规则没有检测到${missing}的明显线索,你可以优先自行检查这些部分。` : '目前四类表达线索都出现了;请进一步核对是否具体并回应了问题。'}${questionText ? `回到题目“${String(questionText).slice(0, 260)}”,确认你的例子回答了它。` : ''}`;
}
function getDemoAnswer(question) {
const id = typeof question === 'string' ? question : question && question.id || 'software-teamwork-1';
const role = id.split('-')[0];
const focus = id.split('-')[1];
const number = Number(id.split('-')[2]) || 1;
const project = {
software: 'a university software project to build a student events website',
data: 'a university data project to explore travel survey results',
product: 'a university product project to improve a student booking service',
general: 'a university society project to organise a welcome event'
}[role] || 'a university group project';
const narratives = {
teamwork: `During ${project}, our team was behind schedule because we had different expectations about the final work. My task was to coordinate the next stage. I organised a short meeting and asked each person to explain their priorities. I documented the agreed tasks and checked progress with the team twice that week. We completed the agreed work before the presentation. I learned that making responsibilities explicit helped us avoid repeating the same discussion.`,
problem: `During ${project}, we found that part of our original plan would not work before the deadline. My task was to investigate the issue and suggest a realistic alternative. I compared two possible approaches and tested the smaller one first. I documented the limitations so the team could decide what to include. As a result, we delivered a smaller version that met the main project requirement. I learned that testing assumptions early would have saved us time.`,
leadership: `During ${project}, our team had not agreed who would coordinate the remaining work. We needed to prepare for a presentation the following week. I proposed a short planning meeting and asked each person what they could finish. I created a shared task list and reviewed progress with the group. We completed the presentation together. I learned that taking initiative works better when people help shape the plan.`,
learning: `During ${project}, I needed to learn a method I had not used before. My task was to apply it to one part of the project and explain it to the team. I read the introductory guide and practised with a small example. I asked a teammate to review my first attempt and revised it after their feedback. As a result, I completed my assigned part and could explain the main limitations. I learned that combining practice with early feedback helped me identify mistakes.`
};
const laterNarratives = {
teamwork: [
`During ${project}, two teammates disagreed about whether to add more features or finish the existing work. My task was to help the group agree on the next step. I asked each person to explain their concern, then compared both options against our deadline. I documented an agreement to finish the essential work first. As a result, we completed the main requirements and kept the extra ideas for a later version. I learned that agreeing on a shared criterion made the disagreement easier to resolve.`,
`During ${project}, important updates were spread across several messages and one teammate missed a change. My task was to clarify the current plan. I created a single shared task list and asked everyone to confirm their responsibilities. I summarised changes after each meeting. As a result, the team could find the latest decisions in one place and we completed the next milestone together. I learned that clear communication requires checking understanding, not just sending information.`
],
problem: [
`During ${project}, we had to decide whether to expand the scope or protect time for testing. My task was to recommend a workable plan. I compared the expected value, effort and risks of both options. I proposed keeping the essential requirements and using the remaining time to check the work. As a result, we delivered the main outcome with a clear explanation of its limitations. I learned that a smaller, well-checked result can be more useful than unfinished extras.`,
`During ${project}, our first approach produced a result that did not meet the assignment requirements. My task was to find out why and help revise it. I reviewed the requirements, compared them with our work and identified an assumption we had not checked. I tested a smaller revised approach before the team continued. As a result, we completed a version that addressed the main requirement. I learned that I should test the most uncertain assumption earlier.`
],
leadership: [
`During ${project}, progress slowed because the team had no shared plan and I was not the formal leader. We needed to agree what to finish first. I proposed a short meeting and asked teammates what support they needed. I created a draft plan based on their suggestions and invited changes instead of assigning tasks unilaterally. As a result, we completed the next stage with responsibilities everyone had agreed to. I learned that influence can come from making collaboration easier.`,
`During ${project}, our team was falling behind before the final presentation. My task was to coordinate a realistic recovery plan. I reviewed the remaining tasks with the group and identified which requirements were essential. I proposed smaller milestones and checked progress with each teammate. As a result, we delivered the essential work on time while clearly explaining what we had left out. I learned that raising a delay early gives a team more choices.`
],
learning: [
`During ${project}, a teammate told me that my explanation was difficult to follow. My task was to make the findings understandable for our presentation. I asked which parts were unclear and revised the explanation using one concrete example. I practised it with another teammate and checked what they understood. As a result, the team could explain the main finding consistently. I learned that useful feedback becomes more actionable when I ask for a specific example.`,
`During ${project}, I made the mistake of assuming a requirement without checking it with the team. My task was to correct the affected work before the presentation. I explained the mistake, reviewed the requirement with a teammate and revised my part. As a result, we completed the corrected version before presenting it. I learned that next time I should confirm uncertain assumptions at the beginning and arrange an earlier review.`
]
};
if (number > 1 && number <= 3 && Object.prototype.hasOwnProperty.call(laterNarratives, focus)) return laterNarratives[focus][number - 2];
return narratives[focus] || narratives.teamwork;
}
function getDemoFollowUp(answer, question) {
const prompt = analyzeAnswer(answer).followUp;
if (prompt.includes('one specific example')) return getDemoAnswer(question);
if (prompt.includes('personally do')) return 'I personally organised a short meeting, asked each teammate about their priorities and documented the next steps. I chose this approach because we needed a shared understanding before doing more work.';
if (prompt.includes('What happened after')) return 'As a result, we completed the agreed work before the presentation. I checked the outcome by reviewing the requirements with the team and asking whether anyone was still unclear about their part.';
if (prompt.includes('responsible for')) return 'My responsibility was to coordinate the next stage and make sure the essential tasks were clear. I needed to help the team agree a realistic plan and check progress before the deadline.';
if (prompt.includes('explain the context')) return 'This happened during a university group project shortly before our presentation. It mattered because the team depended on each person finishing their part, and a misunderstanding could delay the whole submission.';
return 'Next time, I would check assumptions and agree responsibilities earlier instead of waiting for confusion to build up. In this role, I would apply the same lesson by asking clarifying questions at the start and arranging a short review before the deadline.';
}
return { roles, focuses, getQuestions, analyzeAnswer, getCoachReply, getDemoAnswer, getDemoFollowUp };
});
|