fix(sports): fill the handball city from the home club #206
No files matched your search
@@ -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 });
|
||||
|
||||
@@ -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<string, unknown> | 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<string, unknown> | 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<string, unknown>): FixtureData | null {
|
||||
const prova = fpaProva(str(r.PROVA) ?? "");
|
||||
const day = str(r.JOG_DATA);
|
||||
|
||||
@@ -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 } });
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user