From f71f19c501630d1a385407904ce208a7196fbc1d Mon Sep 17 00:00:00 2001 From: tunjayoff Date: Sat, 21 Nov 2026 10:23:17 +0300 Subject: [PATCH] feat(schema): provider_name next to provider_id in Odds and OddsLine The bookmaker's name is derived from the built-in table sports.ODDS_PROVIDERS when the record is mapped (null for an unknown id); nothing stored changes and no request is made. An added field is free in schema v1, so schema_version stays 1. Regenerated: the JSON Schema golden, the generated tables and examples of 04-schema-v1.md, docs/api/openapi-v1.json and frontend/src/api/v1/schema.ts. --- CHANGELOG.md | 9 +++++++++ docs/api/openapi-v1.json | 13 +++++++++++++ docs/design/02-services.md | 7 ++++--- docs/design/03-implementation-plan.md | 8 ++++++-- docs/design/04-schema-v1.md | 23 +++++++++++++++++++---- docs/design/05-web-ui.md | 9 +++++---- frontend/src/api/v1/schema.ts | 2 ++ sofascore_scraper/schema/mappers.py | 12 ++++++++---- sofascore_scraper/schema/models.py | 8 ++++++++ tests/golden/schema/json_schema.json | 18 ++++++++++++++++++ tests/test_odds_slices.py | 12 +++++++++++- 11 files changed, 103 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5489aecc..682fe58e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,15 @@ below (see "Releasing" in the README). ## [Unreleased] +### Added + +- **The bookmaker's name in the odds records.** Schema v1's `Odds` and `OddsLine` have a new field + `provider_name` next to `provider_id`, for example `"bet365"` for provider 1: the same names as + `GET /api/v1/odds/providers`, taken from the built-in table when the record is built (no request to + SofaScore, nothing stored changes). It is null for a provider the table does not know. The odds routes + of API v1 return it, and the `odds` export dataset has a `provider_name` column after `provider_id`. + An added field is free in schema v1, so `schema_version` stays 1. + ## [3.2.0] - 2026-11-20 3.2.0 removes the four 2.x environment names that 3.1 still read with a warning; set without their new diff --git a/docs/api/openapi-v1.json b/docs/api/openapi-v1.json index 477b84dc..375f3a58 100644 --- a/docs/api/openapi-v1.json +++ b/docs/api/openapi-v1.json @@ -8832,6 +8832,18 @@ "title": "Provider Id", "description": "SofaScore's id of the bookmaker the odds come from. Which bookmakers SofaScore offers depends on the country it sees the request from; the platform stores no address or location of the machine." }, + "provider_name": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Provider Name", + "description": "Name of the bookmaker of `provider_id`, as SofaScore writes it (the same names as `GET /api/v1/odds/providers`); null when the platform's built-in list of bookmakers does not know the id." + }, "fetched_at_utc": { "anyOf": [ { @@ -8858,6 +8870,7 @@ "event_id", "key", "provider_id", + "provider_name", "fetched_at_utc", "markets" ], diff --git a/docs/design/02-services.md b/docs/design/02-services.md index 204333c4..1fe938b9 100644 --- a/docs/design/02-services.md +++ b/docs/design/02-services.md @@ -4929,9 +4929,10 @@ As built at `216c2f9` (P30 #186, FX-30 #180, B1 #190, B2 #191). `docs/api/openap reference data, and the platform never derives a country from the machine (`client.odds_country` comes only from the user). Open (`03-implementation-plan.md` section 19): an optional reference fetch of the listing, at most weekly, only when `client.odds_country` is set, through the client and the throttle and - never part of a match download, with every link stripped and the result merged over the table; and a - `provider_name` field in schema v1 (`Odds.provider_id` and `OddsLine.provider_id` are unchanged; an - additive change with the generated tables of `04-schema-v1.md`). The help text of `client.odds_provider` + never part of a match download, with every link stripped and the result merged over the table. Done on + 2026-11-21: schema v1's `Odds` and `OddsLine` carry `provider_name` next to the unchanged `provider_id`, + looked up in the same table when the record is mapped (null for an unknown id; `04-schema-v1.md`, "Odds + and standings"). The help text of `client.odds_provider` (`ssc describe config`, the config JSON Schema) names `1 = bet365 (international)` and the route. As built at `395b6e0` (3.1.1 and 3.1.2: #220, #226, #230). `docs/api/openapi-v1.json` and diff --git a/docs/design/03-implementation-plan.md b/docs/design/03-implementation-plan.md index 67c9e482..7cd1acba 100644 --- a/docs/design/03-implementation-plan.md +++ b/docs/design/03-implementation-plan.md @@ -4844,7 +4844,7 @@ Pinned, and kept on purpose (not defects of the target design): | Under an ASGI root path, `//api/v1` was answered without the access token | B2 #191 | done, B2 (#191); 3.0.0's default deployments never set a root path | | The web UI cannot be served under a path prefix; an aborted search's cancel relies on the proxy closing its upstream connection | B2 #191 | documented in `docs/deploy/README.md`; the prefix: not planned (section 17) | | The help text of `fetch.only_finished` in the web UI still names the 2.x match lists | the tenth revision | done, FX-34 (#194) (`05-web-ui.md` 6.16) | -| The Odds tab says "Bookmaker 1" (live validation M20); the providers' names are known only from SofaScore's per-country listing, which carries affiliate links | live validation, FX-24 gap 5 | done, B4 (#192): a built-in table and `GET /odds/providers`; a fetch of the listing and a schema field `provider_name`: open (section 19) | +| The Odds tab says "Bookmaker 1" (live validation M20); the providers' names are known only from SofaScore's per-country listing, which carries affiliate links | live validation, FX-24 gap 5 | done, B4 (#192): a built-in table and `GET /odds/providers`; the schema field `provider_name`: done (2026-11-21, section 20); a fetch of the listing: open (section 19) | | The changelog entries of #180 to #192 (in their descriptions; P30's and FX-33's list the removals) | #180 to #192 | the 3.1 release pull request (section 19); done, #195 | | The design documents were not updated by the live validation, FX-26, FX-27 and FX-16 | #174 to #176 | this revision (the ninth) | | The sync's fallback to `leagues.txt` when the follows table cannot be read; `services/stats.py` with one used function; the docstrings of `cli/commands/watch.py`, `services/live/supervisor.py` (`--watch`, `watcher:`) and `services/follow_sync.py` (the player list "not stored"); `_task_row` of `ssc config show` printing a task's options as they are | the tenth revision | done, FX-34 (#194): the fallback stays and is logged as an error; the module removed; the docstrings corrected; an option the task does not define shown as `***` | @@ -5674,7 +5674,11 @@ Open after 3.2.0 (the items of section 19's list that are not done, copied), in would need a new Store area, a schedule and link stripping for a list that rarely changes. The table is refreshed by hand when a provider is reported missing. - **A `provider_name` field in schema v1** (`Odds`, `OddsLine`). Additive, with the generated tables of - `04-schema-v1.md`; until then a consumer reads the names from `GET /odds/providers`. + `04-schema-v1.md`; until then a consumer reads the names from `GET /odds/providers`. **Done (this PR, + 2026-11-21).** `Odds` and `OddsLine` carry a nullable `provider_name` next to `provider_id`, filled by + `odds_from_payload` from the built-in table `sports.ODDS_PROVIDERS` (null for an unknown id), so the API's + odds records, the `odds` export dataset (column after `provider_id`) and the JSON Schema have it; + `schema_version` stays 1. - **A replacement for `stage_name` and `listed_in`.** P30 dropped only the two score columns of the events table: schema v1 reads `stage.name` from `stage_name`, and the listing rules (staleness, the reconcile of a season's pages, the planner's listed events) read `listed_in`. Dropping them needs a design first. diff --git a/docs/design/04-schema-v1.md b/docs/design/04-schema-v1.md index d454882d..95acd81d 100644 --- a/docs/design/04-schema-v1.md +++ b/docs/design/04-schema-v1.md @@ -80,6 +80,15 @@ slices of rugby, volleyball, floorball and minifootball after the owner's decisi #198, in 3.1.1; section 5). The trust routes, `cause` of the connection check and the follows default of API v1 (`02-services.md` 6) return no record of this schema. +Amended on 2026-11-21, after the 3.2.0 release (not a numbered revision of the design documents). `Odds` and +`OddsLine` have a new nullable field `provider_name`, next to `provider_id`: the bookmaker's name from the +built-in table `ODDS_PROVIDERS` (`sofascore_scraper/sports.py`, B4, #192), null for an id the table does not +know ("Odds and standings"). Adding a field is free (section 3), so `schema_version` stays 1. The name is +derived when the record is mapped, so nothing stored changes and no request is made; the `odds` export +dataset has the column `provider_name` after `provider_id` (tabular columns follow the model's field order). +The generated tables, the two examples and the JSON Schema golden (`tests/golden/schema/json_schema.json`) +were regenerated (`REGEN_SCHEMA_DOC=1`, `REGEN_SCHEMA_GOLDEN=1`). + ## 1. What the schema is, and what it is not The platform stores SofaScore's responses as they are (one file per response, see `01-storage.md`). The @@ -1031,7 +1040,10 @@ gives them, with a decimal derived as 1 + the fraction, rounded to three places `sofascore_scraper/schema/mappers.py:632`). The mappers are `odds_from_payload`, `odds_lines` and `standings_rows` (`:680-742`); `standings_rows` skips rows that have neither a team nor a position. The country SofaScore answered for is not a field of `Odds`: it is in the slice's meta (`meta.country`) when the user set `[client] -odds_country`, and the provider id is in `meta.provider_id` as well as in the record. `winning_odds` and +odds_country`, and the provider id is in `meta.provider_id` as well as in the record. The bookmaker's name +(`provider_name`, since 2026-11-21) is not stored either: the mapper looks the id up in the built-in table +`ODDS_PROVIDERS` of `sofascore_scraper/sports.py` (B4, #192; the same names as `GET /api/v1/odds/providers`) +each time it builds the record, and an id the table does not know gives null. `winning_odds` and `season_odds` have no model (their only samples were 404s); they are raw slices. Since FX-21 (#164) the five models are in `MODELS` (after `LiveEvent`, `sofascore_scraper/schema/models.py:859` at @@ -1054,12 +1066,14 @@ One read of an odds slice of an event: a snapshot. | `event_id` | integer | no | | the request that fetched it | Id of the Event. | | `key` | string, open set: `odds_all`, `odds_featured` | no | | slice registry (`sofascore_scraper/sports.py`) | Odds slice the record comes from: `odds_all` or `odds_featured`. | | `provider_id` | integer | yes | | the request that fetched it | SofaScore's id of the bookmaker the odds come from. Which bookmakers SofaScore offers depends on the country it sees the request from; the platform stores no address or location of the machine. | +| `provider_name` | string | yes | | derived from `provider_id` (`sofascore_scraper/sports.py`, `ODDS_PROVIDERS`) | Name of the bookmaker of `provider_id`, as SofaScore writes it (the same names as `GET /api/v1/odds/providers`); null when the platform's built-in list of bookmakers does not know the id. | | `fetched_at_utc` | string | yes | ISO 8601 UTC | time of the platform's request | When the odds were read. A read is a snapshot: odds change until the event ends, and only a later read shows a later price. | | `markets` | array of [OddsMarket](#oddsmarket) | no | | `markets`, or the values of `featured` | The markets, in SofaScore's order. | ```json example:Odds -{"event_id": 17144927, "key": "odds_all", "provider_id": 1, "fetched_at_utc": "2026-09-21T14:13:20Z", +{"event_id": 17144927, "key": "odds_all", "provider_id": 1, "provider_name": "bet365", + "fetched_at_utc": "2026-09-21T14:13:20Z", "markets": [{"market_id": 1, "name": "Full time", "group": "1X2", "period": "Full-time", "choice_group": null, "label": null, "is_live": true, "suspended": false, "choices": [{"name": "1", "fractional": "11/5", "decimal": 3.2, "initial_fractional": "13/10", @@ -1114,6 +1128,7 @@ The flat row of the `odds` export dataset: one outcome of one market of one snap | `event_id` | integer | no | | the request that fetched it | Id of the Event. | | `key` | string, open set: `odds_all`, `odds_featured` | no | | slice registry (`sofascore_scraper/sports.py`) | Odds slice the row comes from. | | `provider_id` | integer | yes | | the request that fetched it | As `Odds.provider_id`. | +| `provider_name` | string | yes | | derived from `provider_id` (`sofascore_scraper/sports.py`, `ODDS_PROVIDERS`) | As `Odds.provider_name`. | | `fetched_at_utc` | string | yes | ISO 8601 UTC | time of the platform's request | When the snapshot was read. | | `market_id` | integer | yes | | `marketId` | As `OddsMarket.market_id`. | | `market_name` | string | yes | | `marketName` | As `OddsMarket.name`. | @@ -1133,8 +1148,8 @@ The flat row of the `odds` export dataset: one outcome of one market of one snap ```json example:OddsLine -{"event_id": 17144927, "key": "odds_all", "provider_id": 1, "fetched_at_utc": "2026-09-21T14:13:20Z", - "market_id": 1, "market_name": "Full time", "market_group": "1X2", "market_period": "Full-time", +{"event_id": 17144927, "key": "odds_all", "provider_id": 1, "provider_name": "bet365", + "fetched_at_utc": "2026-09-21T14:13:20Z", "market_id": 1, "market_name": "Full time", "market_group": "1X2", "market_period": "Full-time", "choice_group": null, "label": null, "is_live": true, "suspended": false, "choice": "1", "fractional": "11/5", "decimal": 3.2, "initial_fractional": "13/10", "initial_decimal": 2.3, "change": 1, "winning": null} diff --git a/docs/design/05-web-ui.md b/docs/design/05-web-ui.md index 4b011c74..c67e3b60 100644 --- a/docs/design/05-web-ui.md +++ b/docs/design/05-web-ui.md @@ -1288,9 +1288,10 @@ market that the featured list names twice (`default`, `fullTime`) is shown once. with their raw view follow under "SofaScore's answer". The end-to-end test had found only the raw viewer with "readable view coming soon" (F11). **As built (B4, #192; G38; finding M20 of the live validation):** the heading names the bookmaker ("bet365"), from `GET /api/v1/odds/providers`, read once per page; an id -with no known name, or every id when the list cannot be read, stays numbered ("Bookmaker 5"). `Odds` still -carries only `provider_id`. The sub-key of an odds slice in the raw list and in the Data table shows the -name too. No betting link, campaign field or colour of SofaScore's provider listing is stored or shown. +with no known name, or every id when the list cannot be read, stays numbered ("Bookmaker 5"). Since +2026-11-21 the `Odds` record also carries `provider_name` from the same table; the tab still reads the +list. The sub-key of an odds slice in the raw list and in the Data table shows the name too. No betting +link, campaign field or colour of SofaScore's provider listing is stored or shown. **As built (FX-26, #174): the score of every sport.** The multi-sport pass of the live validation (2026-10-08, one finished match of each of 20 sports) found headers that showed less than the record holds @@ -2075,7 +2076,7 @@ state at `43ecdfc`. The rows of G33, G35 to G41 and G43 give the state at `216c2 | G35 | A team record route with gender and country (`GET /teams/{id}` or a participant route; `FollowRecord` has neither), for a team follow's header (F5, F26; FX-24 gap 2) | **Built** by B1 (#190): `GET /api/v1/teams/{team_id}` → `TeamRecord` (the stored participant: `sport`, `type`, `name`, `country_code`, `gender`, `national`, … and `followed`), from the catalog, no SofaScore request; 404 `not_found` until a match of the team is stored. `/catalog/suggest` team hits carry `gender` and `national` too. UI: the header of a team follow (6.4), with the search hit as the fallback. | done (B1) | | G36 | Whether a sport's participants are players (`participants: "individual" \| "team"` on `Sport`, F31; FX-24 gap 3) | **Built** by B1 (#190) as a required boolean `individual` on `Sport` (`SportSpec.individual`: tennis, badminton, table tennis, padel, snooker, darts, MMA; e-sports is a team sport). UI: `isIndividual()` reads the registry; `INDIVIDUAL_SPORTS` is gone (6.3), so R4 holds. | done (B1) | | G37 | The season's name in the log parameters of `sync_schedule` and `sync_season_outdated` (F8; FX-24 gap 4) | **Built** by B2 (#191): sync log lines carry `league_name`, `season_name`, `season_year` (`resolved_name`, `resolved_year` for an outdated season). UI: Job detail writes them and reads a season list only for an older server's lines (6.9). | done (B2) | -| G38 | An odds provider's name (F11; FX-24 gap 5) | **Built** by B4 (#192): `GET /odds/providers` (`listOddsProviders`: `id`, `name`, `country`, `configured`) from the built-in table `sports.ODDS_PROVIDERS`, no SofaScore request; the Odds tab, the Data table and the Settings row name the bookmaker (6.6, 6.16). `Odds.provider_id` stays the only field of the record; a `provider_name` in schema v1 and a fetch of SofaScore's provider listing are open (`03` section 19). | B4 (#192) | +| G38 | An odds provider's name (F11; FX-24 gap 5) | **Built** by B4 (#192): `GET /odds/providers` (`listOddsProviders`: `id`, `name`, `country`, `configured`) from the built-in table `sports.ODDS_PROVIDERS`, no SofaScore request; the Odds tab, the Data table and the Settings row name the bookmaker (6.6, 6.16). A `provider_name` next to `Odds.provider_id` in schema v1 was added on 2026-11-21; a fetch of SofaScore's provider listing is open (`03` section 20). | B4 (#192) | | G39 | Export by team or player: a participant field on `ExportFilter` (F13; FX-24 gap 6) | **Built** by B1 (#190): `ExportFilter.team_ids`, `player_ids` (one filter, ANDed with the others; a player's matches are those whose stored line-ups name the player), also `ssc export --team/--player`. UI: the export dialog sends teams and players as such (6.10). | done (B1) | | G40 | Coverage per follow in `/status` (`summary.follows[]` or `FollowRecord.coverage`), and a way to count a player's matches (F23; FX-24 gap 7) | **Built** by B2 (#191): `/status.summary.follows[]` (`events`, `finished`, `finished_details`, `coverage`, `counted`) for every follow; a player's from the match ids of the player's last match list, kept in `state.db` (`follow_events:player:`); `GET /events?follow=kind:id`. UI: the Follows list, a follow's facts and a player's Matches tab (6.2, 6.4); the `/events` counting stays only for an older server. | done (B2) | | G41 | Request counters in job progress (requests sent, expected requests per match), for an ETA in requests (F17; FX-24 gap 8) | **Built** by B2 (#191): `progress.requests` and `result.requests` (`sent`, `budget_wait_seconds`, `backoff_seconds`); the league detail phase plans by need, so the server's request-based ETA covers league downloads (no expected-requests field). UI: Job detail (6.9); the recent-pace rule stays. | done (B2) | diff --git a/frontend/src/api/v1/schema.ts b/frontend/src/api/v1/schema.ts index 542b562b..dadbd74a 100644 --- a/frontend/src/api/v1/schema.ts +++ b/frontend/src/api/v1/schema.ts @@ -831,6 +831,8 @@ export interface Odds { key: string /** SofaScore's id of the bookmaker the odds come from. Which bookmakers SofaScore offers depends on the country it sees the request from; the platform stores no address or location of the machine. */ provider_id: number | null + /** Name of the bookmaker of `provider_id`, as SofaScore writes it (the same names as `GET /api/v1/odds/providers`); null when the platform's built-in list of bookmakers does not know the id. */ + provider_name: string | null /** When the odds were read. A read is a snapshot: odds change until the event ends, and only a later read shows a later price. */ fetched_at_utc: string | null /** The markets, in SofaScore's order. */ diff --git a/sofascore_scraper/schema/mappers.py b/sofascore_scraper/schema/mappers.py index f1cae11f..d7e96016 100644 --- a/sofascore_scraper/schema/mappers.py +++ b/sofascore_scraper/schema/mappers.py @@ -57,7 +57,7 @@ Status, Tournament, ) -from sofascore_scraper.sports import SPORTS, PeriodFormat, SetFormat, SportSpec, get_sport, score_family +from sofascore_scraper.sports import SPORTS, PeriodFormat, SetFormat, SportSpec, get_sport, odds_provider, score_family from sofascore_scraper.status import StatusClass if TYPE_CHECKING: @@ -693,15 +693,19 @@ def odds_from_payload(event_id: int, key: str, payload: Any, *, provider_id: Opt featured = payload.get("featured") if isinstance(payload.get("featured"), Mapping) else {} markets = [market for market in (_odds_market(item, str(label)) for label, item in featured.items()) if market is not None] - return Odds(event_id=int(event_id), key=key, provider_id=_int(provider_id), fetched_at_utc=utc_text(fetched_at), - markets=tuple(markets)) + provider = _int(provider_id) + # Sağlayıcının adı yerleşik tablodan (B4, sports.ODDS_PROVIDERS); tabloda olmayan kimlik adsız kalır (null). + known = odds_provider(provider) if provider is not None else None + return Odds(event_id=int(event_id), key=key, provider_id=provider, provider_name=known.name if known else None, + fetched_at_utc=utc_text(fetched_at), markets=tuple(markets)) def odds_lines(odds: Odds) -> List[OddsLine]: """Bir Odds kaydının düz satırları: pazar ve seçenek başına bir satır, yükün sırasıyla.""" return [ OddsLine( - event_id=odds.event_id, key=odds.key, provider_id=odds.provider_id, fetched_at_utc=odds.fetched_at_utc, + event_id=odds.event_id, key=odds.key, provider_id=odds.provider_id, provider_name=odds.provider_name, + fetched_at_utc=odds.fetched_at_utc, market_id=market.market_id, market_name=market.name, market_group=market.group, market_period=market.period, choice_group=market.choice_group, label=market.label, is_live=market.is_live, suspended=market.suspended, choice=choice.name, fractional=choice.fractional, diff --git a/sofascore_scraper/schema/models.py b/sofascore_scraper/schema/models.py index 2936fd51..b06246ca 100644 --- a/sofascore_scraper/schema/models.py +++ b/sofascore_scraper/schema/models.py @@ -803,6 +803,11 @@ class Odds(Model): "SofaScore offers depends on the country it sees the request from; the " "platform stores no address or location of the machine.", source="the request that fetched it") + provider_name: Optional[str] = spec("Name of the bookmaker of `provider_id`, as SofaScore writes it (the same " + "names as `GET /api/v1/odds/providers`); null when the platform's " + "built-in list of bookmakers does not know the id.", + source="derived from `provider_id` (`sofascore_scraper/sports.py`, " + "`ODDS_PROVIDERS`)") fetched_at_utc: Optional[str] = spec("When the odds were read. A read is a snapshot: odds change until the " "event ends, and only a later read shows a later price.", unit="ISO 8601 UTC", fmt="date-time", @@ -821,6 +826,9 @@ class OddsLine(Model): key: str = spec("Odds slice the row comes from.", source="slice registry (`sofascore_scraper/sports.py`)", open_enum=True, known=("odds_all", "odds_featured")) provider_id: Optional[int] = spec("As `Odds.provider_id`.", source="the request that fetched it") + provider_name: Optional[str] = spec("As `Odds.provider_name`.", + source="derived from `provider_id` (`sofascore_scraper/sports.py`, " + "`ODDS_PROVIDERS`)") fetched_at_utc: Optional[str] = spec("When the snapshot was read.", unit="ISO 8601 UTC", fmt="date-time", source="time of the platform's request") market_id: Optional[int] = spec("As `OddsMarket.market_id`.", source="`marketId`") diff --git a/tests/golden/schema/json_schema.json b/tests/golden/schema/json_schema.json index 6be706a5..8a58e9fa 100644 --- a/tests/golden/schema/json_schema.json +++ b/tests/golden/schema/json_schema.json @@ -1980,6 +1980,7 @@ "event_id", "key", "provider_id", + "provider_name", "fetched_at_utc", "markets" ], @@ -2006,6 +2007,14 @@ "description": "SofaScore's id of the bookmaker the odds come from. Which bookmakers SofaScore offers depends on the country it sees the request from; the platform stores no address or location of the machine.", "x-source": "the request that fetched it" }, + "provider_name": { + "type": [ + "string", + "null" + ], + "description": "Name of the bookmaker of `provider_id`, as SofaScore writes it (the same names as `GET /api/v1/odds/providers`); null when the platform's built-in list of bookmakers does not know the id.", + "x-source": "derived from `provider_id` (`sofascore_scraper/sports.py`, `ODDS_PROVIDERS`)" + }, "fetched_at_utc": { "type": [ "string", @@ -2193,6 +2202,7 @@ "event_id", "key", "provider_id", + "provider_name", "fetched_at_utc", "market_id", "market_name", @@ -2233,6 +2243,14 @@ "description": "As `Odds.provider_id`.", "x-source": "the request that fetched it" }, + "provider_name": { + "type": [ + "string", + "null" + ], + "description": "As `Odds.provider_name`.", + "x-source": "derived from `provider_id` (`sofascore_scraper/sports.py`, `ODDS_PROVIDERS`)" + }, "fetched_at_utc": { "type": [ "string", diff --git a/tests/test_odds_slices.py b/tests/test_odds_slices.py index bc224322..5d9c68ad 100644 --- a/tests/test_odds_slices.py +++ b/tests/test_odds_slices.py @@ -364,6 +364,7 @@ def test_the_new_models_carry_their_contract(model: type) -> None: def test_odds_map_to_markets_and_flat_lines() -> None: odds = mappers.odds_from_payload(5, "odds_all", body("odds_all"), provider_id=1, fetched_at=1_790_000_000) assert odds is not None and odds.provider_id == 1 and odds.fetched_at_utc == "2026-09-21T14:13:20Z" + assert odds.provider_name == "bet365" # yerleşik tablodan (sports.ODDS_PROVIDERS), istek yok first = odds.markets[0] assert (first.market_id, first.name, first.group, first.period, first.is_live) == ( 1, "Full time", "1X2", "Full-time", True) @@ -372,11 +373,19 @@ def test_odds_map_to_markets_and_flat_lines() -> None: lines = mappers.odds_lines(odds) assert len(lines) == sum(len(market.choices) for market in odds.markets) == 6 assert lines[0].to_dict()["choice"] == "1" and lines[0].market_name == "Full time" + assert {(line.provider_id, line.provider_name) for line in lines} == {(1, "bet365")} featured = mappers.odds_from_payload(5, "odds_featured", body("odds_featured")) assert featured is not None and [m.label for m in featured.markets] == ["default", "asian", "fullTime"] + assert featured.provider_id is None and featured.provider_name is None assert mappers.odds_from_payload(5, "odds_changes", body("odds_changes")) is None assert mappers.odds_from_payload(5, "odds_all", ["x"]) is None assert mappers.odds_from_payload(5, "odds_all", {"markets": ["x", {"choices": [{"x": 1}, "y"]}]}).markets[0].choices == () + # Sağlayıcının adı kimlikten türetilir; tabloda olmayan kimliğin adı null + named = {pid: mappers.odds_from_payload(5, "odds_all", body("odds_all"), provider_id=pid) + for pid in (1528, 1781, 5)} + assert {pid: (o.provider_id, o.provider_name) for pid, o in named.items() if o is not None} == { + 1528: (1528, "bet365 Türkiye"), 1781: (1781, "bet365 UK"), 5: (5, None)} + assert [line.provider_name for line in mappers.odds_lines(named[5])] == [None] * 6 assert [mappers.fraction_decimal(v) for v in ("1/1", "0/1", "3/0", "x", None, "1/2/3")] == [ 2.0, 1.0, None, None, None, None] @@ -431,7 +440,8 @@ def test_the_odds_dataset_has_one_row_per_outcome_and_snapshot(fake: FakeSofaSco assert len(rows) == 6 + featured assert {row["key"] for row in rows} == {"odds_all", "odds_featured"} assert {row["event_id"] for row in rows} == {FINISHED} + assert {(row["provider_id"], row["provider_name"]) for row in rows} == {(1, "bet365")} result = ExportService(store).export(DatasetSpec(dataset="odds", format="csv"), tmp_path / "odds.csv") assert result.rows == len(rows) header = (tmp_path / "odds.csv").read_text(encoding="utf-8").splitlines()[0] - assert header.startswith("event_id,key,provider_id,fetched_at_utc,market_id,") + assert header.startswith("event_id,key,provider_id,provider_name,fetched_at_utc,market_id,")