fix(houseofrc): match a class by whole words, e.g. 4wd to 4WD Buggy (1.81.1)

This commit is contained in:
larssand committed 2026-11-08 16:07:48 +01:00
1 parent b0f2b92c04
commit cdeb6b0402
5 files changed
+22 -5

No files matched your search

+4
View File
@@ -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.
+2 -2
View File
@@ -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",
+1 -1
View File
@@ -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": {
+10 -2
View File
@@ -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 : "";
}
+5
View File
@@ -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");
});