From 96539a1f605993ddee999bfd1052d8d5f6935b4f Mon Sep 17 00:00:00 2001 From: spark Date: Fri, 6 Nov 2026 21:12:40 +0000 Subject: [PATCH] fix(sports): fill the handball city from the home club The sheet names the hall. The town is the home club's locality, so Oriental is Lisboa and Albicastrense is Castelo Branco. The federation's own card is not used for a national team. --- apps/api/src/sports/place.test.ts | 9 ++++++++- apps/api/src/sports/providers.ts | 21 ++++++++++++++++----- apps/api/src/sports/service.ts | 5 ++++- docs/ARCHITECTURE.md | 6 ++++-- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/apps/api/src/sports/place.test.ts b/apps/api/src/sports/place.test.ts index ca02387..f6a1ba6 100644 --- a/apps/api/src/sports/place.test.ts +++ b/apps/api/src/sports/place.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from "vitest"; -import { clubCity, splitStoredPlace } from "./providers.js"; +import { clubCity, fpaClubPlace, splitStoredPlace } from "./providers.js"; describe("home club place", () => { it("reads the town from the club's own name or from a stadium that names the town", () => { @@ -19,6 +19,13 @@ describe("home club place", () => { expect(clubCity({ fullName: "Clube Desportivo Feirense - Futebol, SAD", stadium: "Estádio Marcolino Castro" })).toBeNull(); }); + it("takes the handball club's town, and not the federation's address", () => { + expect(fpaClubPlace({ CLU_NOME: "Clube Oriental Lisboa", CLU_ABREV: "CLUBE ORIENTAL LISBOA", REC_NOME: "PAV. LOIOS", CLUBE_LOCALIDADE: "Lisboa" })).toEqual({ venue: "PAV. LOIOS", city: "Lisboa" }); + expect(fpaClubPlace({ CLU_NOME: "Associacao Desportiva Albicastrense", CLU_ABREV: "AD ALBICASTRENSE", REC_NOME: "MUN. CASTELO BRANCO", CLUBE_LOCALIDADE: "Castelo Branco" })).toEqual({ venue: "MUN. CASTELO BRANCO", city: "Castelo Branco" }); + expect(fpaClubPlace({ CLU_NOME: "Federacao Andebol Portugal", CLU_ABREV: "F.A.P.", CLUBE_LOCALIDADE: "Lisboa" })).toBeNull(); + expect(fpaClubPlace({ CLU_NOME: "Vitória Sport Clube", CLU_ABREV: "VITÓRIA SC", REC_NOME: "DESP. UNIDADE VIMARANENSE", CLUBE_LOCALIDADE: null })).toEqual({ venue: "DESP. UNIDADE VIMARANENSE", city: null }); + }); + it("splits a venue that was stored with the town after a comma", () => { expect(splitStoredPlace("Estádio Dr. Magalhães Pessoa, Leiria", null)).toEqual({ venue: "Estádio Dr. Magalhães Pessoa", city: "Leiria" }); expect(splitStoredPlace("Estádio Cidade de Coimbra", null)).toEqual({ venue: "Estádio Cidade de Coimbra", city: null }); diff --git a/apps/api/src/sports/providers.ts b/apps/api/src/sports/providers.ts index 4c42f0c..254ba17 100644 --- a/apps/api/src/sports/providers.ts +++ b/apps/api/src/sports/providers.ts @@ -464,11 +464,7 @@ export class FpaProvider { private async readClub(clubId: string): Promise<{ venue: string | null; city: string | null } | null> { const data = await get(this.fetcher, `${FpaProvider.WS}/getClube/${encodeURIComponent(clubId)}`, { accept: "application/json" }, "json"); const row = (Array.isArray(data) ? data[0] : data) as Record | undefined; - if (!row || typeof row !== "object") return null; - const venue = str(row.REC_NOME); - const city = str(row.CLUBE_LOCALIDADE); - if (!venue && !city) return null; - return { venue, city }; + return fpaClubPlace(row); } /** An HTML page in whatever charset it declares (the match report is windows-1252). */ @@ -851,6 +847,21 @@ export function fpaProva(prova: string): { code: string; name: string } | null { return m ? { code: m[1]!, name: m[2]!.replace(/\s{2,}/g, " ") } : null; } +/** + * The club card (`getClube`): the hall is REC_NOME, the town is CLUBE_LOCALIDADE. + * The federation's own card (F.A.P., Lisboa) is not a home club, so a seleção does not inherit that town. + */ +export function fpaClubPlace(row: Record | null | undefined): { venue: string | null; city: string | null } | null { + if (!row) return null; + const abbrev = str(row.CLU_ABREV) ?? ""; + const name = str(row.CLU_NOME) ?? ""; + const federation = /^f\.?a\.?p\.?$/i.test(abbrev) || /federa[cç][aã]o/i.test(name); + const venue = str(row.REC_NOME); + const city = federation ? null : str(row.CLUBE_LOCALIDADE); + if (!venue && !city) return null; + return { venue, city }; +} + function fpaFixture(r: Record): FixtureData | null { const prova = fpaProva(str(r.PROVA) ?? ""); const day = str(r.JOG_DATA); diff --git a/apps/api/src/sports/service.ts b/apps/api/src/sports/service.ts index 5f6a50a..9317f17 100644 --- a/apps/api/src/sports/service.ts +++ b/apps/api/src/sports/service.ts @@ -1312,7 +1312,10 @@ export class SportsService { let place = splitStoredPlace(f.venue ?? null, f.city ?? null); if (provider === "FPA" && f.home.clubId && !place.city) { const club = await this.fpa.club(f.home.clubId); - if (club?.city) place = { ...place, city: club.city }; + if (club?.city) { + place = { ...place, city: club.city }; + await this.deps.db.sportsTeam.updateMany({ where: { id: homeTeamId, OR: [{ city: null }, { city: "" }] }, data: { city: club.city } }); + } if (club?.venue) { await this.deps.db.sportsTeam.updateMany({ where: { id: homeTeamId, venue: null }, data: { venue: club.venue } }); } diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 5959c8c..3136f10 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -287,8 +287,10 @@ every 6 hours (`SPORTS_SYNC=off` turns it off). It is shared by every organisati town written in the club's own name or in a stadium that names it ("Municipal de Amarante", "Cidade de Coimbra"). A person's name in the stadium ("Dr. Machado de Matos") is not a town. Stadium and town are stored apart (`venue` and `city`) on the club and on the match, and choosing the match fills both on the event. The same - split is what UEFA (`stadium.city`), the EHF (`cityName`) and the FPA (`CLUBE_LOCALIDADE`, often empty; the - hall is `LOCAL` / `REC_NOME`) already publish. On start the worker reads + split is what UEFA (`stadium.city`) and the EHF (`cityName`) already publish. Handball keeps the hall from the + agenda (`LOCAL`, the same line as Recinto on the match sheet). The town is the home club's `CLUBE_LOCALIDADE` + (`getClube`: Oriental → Lisboa, Albicastrense → Castelo Branco). The federation's own card is not a club, so a + seleção does not take Lisboa from F.A.P. A club that leaves the locality blank stays without a city. On start the worker reads every season the federation still lists, under the name that league had that year (Liga NOS, Liga Sagres, LigaPro), so a past season keeps the squad and the shirt numbers of that year. When that read finishes, the newest photographs already analysed are queued again for faces (thirty thousand per start). The archive's people list -- 2.47.3