From cdeb6b0402ea7f89f9ade26fccd3b7a2047c0824 Mon Sep 17 00:00:00 2001 From: larssand Date: Sun, 8 Nov 2026 16:07:48 +0100 Subject: [PATCH] fix(houseofrc): match a class by whole words, e.g. 4wd to 4WD Buggy (1.81.1) --- CHANGELOG.md | 4 ++++ package-lock.json | 4 ++-- package.json | 2 +- src/houseofrc_logic.js | 12 ++++++++++-- tests/houseofrc_logic.test.js | 5 +++++ 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbb5c69..b221d3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ The application version is maintained in `package.json` and displayed in the adm No changes recorded yet. +## 1.81.1 + +- **Fetch from House of RC:** a House of RC class is now also matched to ours when its name is a whole word of exactly one of our classes, e.g. "4wd" → "4WD Buggy". An exact name still wins, and when two classes fit you choose yourself. + ## 1.81.0 - **House of RC with the club's key:** RaceCore now uses House of RC's timing API. With the key of the club running the event (an organization key), **Test connection** shows the club ("Connected as Jämtlands MK (organization 233)"), and the race wizard's **🏠 Fetch from House of RC** lists the club's own events, past and coming. diff --git a/package-lock.json b/package-lock.json index e0c54a7..9b8748d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "rc-racecore", - "version": "1.81.0", + "version": "1.81.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "rc-racecore", - "version": "1.81.0", + "version": "1.81.1", "hasInstallScript": true, "dependencies": { "better-sqlite3": "^12.11.1", diff --git a/package.json b/package.json index dea8848..398a46d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rc-racecore", - "version": "1.81.0", + "version": "1.81.1", "private": true, "description": "RC RaceCore live timing and race control with AMMC ingest and SQLite persistence", "engines": { diff --git a/src/houseofrc_logic.js b/src/houseofrc_logic.js index 6c0d5dc..acd064a 100644 --- a/src/houseofrc_logic.js +++ b/src/houseofrc_logic.js @@ -105,7 +105,15 @@ export function applyHouseOfRcEntries(drivers, plan, { classId, selected, makeDr return { driverIds, entryIds }; } -// Our class for a House of RC class: same name (ignoring case and spaces), else none. +// Our class for a House of RC class: the same name (ignoring case and spaces), else the one +// class whose name holds the other as whole words ("4wd" ~ "4WD Buggy"), else none. export function matchHouseOfRcClass(classes = [], name = "") { - return classes.find((item) => sameText(item.name, name))?.id || ""; + const exact = classes.find((item) => sameText(item.name, name)); + if (exact) return exact.id; + const words = (text) => String(text || "").toLocaleLowerCase().split(/[^\p{L}\p{N}.]+/u).filter(Boolean); + const wanted = words(name); + if (!wanted.length) return ""; + const holds = (outer, inner) => inner.length <= outer.length && outer.some((_word, index) => inner.every((word, offset) => outer[index + offset] === word)); + const candidates = classes.filter((item) => { const own = words(item.name); return holds(own, wanted) || holds(wanted, own); }); + return candidates.length === 1 ? candidates[0].id : ""; } diff --git a/tests/houseofrc_logic.test.js b/tests/houseofrc_logic.test.js index c3cc489..2a39851 100644 --- a/tests/houseofrc_logic.test.js +++ b/tests/houseofrc_logic.test.js @@ -67,4 +67,9 @@ test("House of RC entries: matched on member, transponder or name; other class a assert.deepEqual([dan.name, dan.transponder, dan.club, dan.houseOfRcId], ["Dan Ny", "666", "Sundsvall RC", "8"]); assert.equal(matchHouseOfRcClass([{ id: "c1", name: "Offroad 2WD foam" }], "offroad 2wd Foam"), "c1"); assert.equal(matchHouseOfRcClass([{ id: "c1", name: "Touring" }], "F1"), ""); + const ours = [{ id: "s", name: "Stock 17.5T" }, { id: "b2", name: "2WD Buggy" }, { id: "b4", name: "4WD Buggy" }, { id: "x2", name: "2wd" }]; + assert.equal(matchHouseOfRcClass(ours, "4wd"), "b4", "a whole word of one class"); + assert.equal(matchHouseOfRcClass(ours, "2wd"), "x2", "an exact name wins"); + assert.equal(matchHouseOfRcClass(ours, "Buggy"), "", "two candidates: let the user choose"); + assert.equal(matchHouseOfRcClass(ours, "17.5"), "", "part of a word is no match"); });