Skip to content

Commit 1a2420d

Browse files
Merge pull request #116 from alvin000009238/codex/reduce-subject-names-in-analysis
Shorten subject names to prefix before hyphen for charts and standards
2 parents 596bec5 + de42752 commit 1a2420d

2 files changed

Lines changed: 10 additions & 15 deletions

File tree

frontend/dashboard.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -267,17 +267,11 @@ function getScoreClass(score) {
267267
return 'low';
268268
}
269269

270-
// 縮短科目名稱
271-
export function shortenName(name) {
272-
const shortNames = {
273-
'英語文': '英文',
274-
'公民與社會': '公民',
275-
'選修化學-物質與能量': '化學',
276-
'選修物理-力學一': '物理',
277-
'選修化學': '化學',
278-
'選修物理': '物理'
279-
};
280-
return shortNames[name] || name;
270+
// 縮短科目名稱(僅保留 '-' 前的文字)
271+
export function shortenName(name = '') {
272+
const cleanedName = cleanSubjectName(String(name));
273+
const [baseName] = cleanedName.split('-');
274+
return baseName.trim() || cleanedName;
281275
}
282276

283277
// 生成五標表格

tests/frontend/dashboard.test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ describe('dashboard.js', () => {
1717
});
1818

1919
describe('shortenName', () => {
20-
it('should shorten known subjects', () => {
21-
assert.equal(shortenName('英語文'), '英文');
22-
assert.equal(shortenName('選修化學-物質與能量'), '化學');
20+
it('should keep only the text before hyphen', () => {
21+
assert.equal(shortenName('選修化學-物質構造與反應速率'), '選修化學');
22+
assert.equal(shortenName('選修物理-力學二與熱學'), '選修物理');
2323
});
2424

25-
it('should return original name if unknown', () => {
25+
it('should return original name when no hyphen exists', () => {
2626
assert.equal(shortenName('數學A'), '數學A');
27+
assert.equal(shortenName('英語文'), '英語文');
2728
});
2829
});
2930
});

0 commit comments

Comments
 (0)