# bezpecnost: crime and road accidents (Bratislavský kraj, okres Senec)

First assembled by hand on 16 Sep 2026. Since 10 Oct 2026 it is rebuilt by `scripts/fetch_bezpecnost.py`.
Okres Senec = LAU1 `SK0108`, ISDN territorial code `5108`. Bratislavský kraj = `SK010`, MV SR sheet `BL`.
Background shared with the health file: `zdravie-bezpecnost-README.md` (section "Safety").
Since 25 Oct 2026 the same script also writes `nehody-cesty`: each accident on motorways and class I and II roads
in okres Senec, with the road, the kilometre and the time (`nehody-cesty-README.md`), and since 26 Oct 2026
`nehodove-useky`, the police's accident blackspots on those roads (`nehodove-useky-README.md`).

## Rebuild

```bash
python scripts/fetch_bezpecnost.py            # ~1.5 min; writes bezpecnost.json + .csv, nehody-cesty.json + .csv, nehodove-useky.json + .csv
python scripts/fetch_bezpecnost.py --isdn-month 2026-08 --out /tmp/b.json --csv /tmp/b.csv \
  --nehody-json /tmp/n.json --nehody-csv /tmp/n.csv --useky-json /tmp/u.json --useky-csv /tmp/u.csv   # pin the partial-year rows
```

Raw downloads are cached in `raw/bezpecnost/` (not committed). Index pages and ŠÚ SR STATdata are fetched on every
run (STATdata's answers in `raw/bezpecnost/statdata/`, with their `manifest.json`); since 25 Oct 2026 a host that does
not answer after four tries falls back to its cached copy, with a warning.
Dated files (XML, PDF maps, ISDN pages) are re-used from the cache. Use `--refresh` to download them again.
Needs `httpx`, `beautifulsoup4`, `pdfplumber`.

## Files

| File | Content |
|---|---|
| `bezpecnost.json` | `meta` (`generated`, `last_update`, `town_population_end_2025`, `notes`) and three tables, each with `source`/`index` and `rows` |
| `bezpecnost.csv` | the three tables in long form: one row per section × year/period × indicator. Columns `section, territory, year, period, partial_year, indicator, value, unit, source_url, last_update`. UTF-8, CRLF, empty = null. Since 26 Oct 2026 a row keeps its `last_update` until its value or source changes |

## Sources

| Table | Source | URL |
|---|---|---|
| `kriminalita_bratislavsky_kraj` | MV SR, Štatistika kriminality v SR, SpreadsheetML XML, sheet `BL`, 1.1.–31.12. | `https://www.minv.sk/swift_data/source/policia/statistiky_<Y>/12_december/1xml_statistika_podla_druhu_kriminality_1_31.12.<Y>.xml` (2019–2023), `…/1statistika_podla_druhu_kriminality_1_31.12.<Y>.xml` (2024–). Index: https://www.minv.sk/?statistika-kriminality-v-slovenskej-republike-xml |
| `objasnenost_okres_senec` | MV SR, Mapy trestných činov, okresy, Q4 A3 PDFs | `https://www.minv.sk/swift_data/source/policia/statistiky_<Y>/mapy_kriminality/4_q/okresy_{celkova,nasilna,majetkova}_kriminalita_4_stvrtrok_<Y>_a3.pdf`. Index: https://www.minv.sk/?mapy-trestnych-cinov-v-slovenskej-republike-za-rok-2025 |
| `dopravne_nehody_okres_senec` | MV SR ISDN, "Prehľad nehôd v cestnej doprave", územný okres Senec, from 1 January | `https://www.minv.sk/?statistika-1&rok=<Y>&mesiac=<M>` → iframe folder → `https://www.minv.sk/lnisdn/statistika/<folder>/statistika/mesacna/dnvr/dnvr-5108.html`. Latest month: https://www.minv.sk/?kompletna-statistika |
| population | ŠÚ SR STATdata `om7101rr` (open data, CC BY 4.0): `U_OM_0056` mid-year for `SK010` and `SK0108`, `U_OM_0057` for Senec at 31.12.2025; one request (until 9 Nov 2026 DATAcube `om7102rr` IN010114 and `om7101rr` IN010115) | `https://statdata.statistics.sk/public/api/dc/opendata/cube/dataset/om7101rr/rows/e_nuts15%2CASC%2CSK0108508217%2CSK0108%2CSK010~e_nuts14%2CASC%2Call~e_indic%2CASC%2CU_OM_0056%2CU_OM_0057~e_sex%2CASC%2CTOTAL~e_unit%2CASC%2Call/columns/e_year%2CASC%2C2019%2C…%2C2025/context/-?lang=SK&type=CSV` |

## Fields

- **kraj rows:** `year`. `registered_total` / `cleared_total` = zistené / objasnené. `clearance_rate_pct` = MV SR's own "t.j. %", an integer. The same three fields exist for `violent_*` (NÁSILNÁ) and `property_*` (MAJETKOVÁ). `kraj_mid_year_population`. `*_per_1000` = count ÷ mid-year population × 1000, rounded to 2 dp. `source_xml`.
- **okres clearance rows:** `year`, `clearance_total_pct`, `clearance_violent_pct`, `clearance_property_pct` (% as printed, 2 dp).
- **accident rows:**
  - `period`, `year`, `partial_year`. `yoy_change` compares with the same period of the previous year.
  - `accidents_total`, `killed`, `seriously_injured`, `lightly_injured`, `under_alcohol` come from row "Počet nehôd celkom".
  - `accidents_with_injury_or_death` comes from row "neh. s násl. na živote alebo zdraví".
  - `in_built_up_area` / `outside_built_up_area` come from rows "v obci" / "mimo obec".
  - `on_motorway` comes from row "diaľnica" and counts D and R roads together.
  - `on_road_outside_km_system` comes from row "komunikácia v km systéme nesledovaná": accidents on roads the police
    do not keep in the kilometre system, most of the town's streets among them; none of them is in `nehody-cesty`.
  - `at_level_crossing` comes from row "železničné priecestie" (26 Oct 2026; 0 to 2 a year).
  - `material_damage_eur` = "škoda v 10 €" × 10.
  - `okres_mid_year_population`, `accidents_per_1000_okres`, `killed_per_100k_okres` (2 dp) are null on a partial year. `source`.

## Method

- XML: the rows CELKOVÁ / NÁSILNÁ / MAJETKOVÁ KRIMINALITA of sheet `BL`. The file title is checked to be a 1.1.–31.12. file.
- Maps:
  - The PDFs use a font whose glyphs are ASCII + 29. The script decodes the text and finds the `SC` label.
  - It drops every number equal to a Bratislava I–V legend value (`xx,xx%`).
  - It takes the number nearest to the label within 30 pt. If none is found, the value is null.
  - Whole numbers are printed without decimals (`50`).
- ISDN: the December page gives each full year. The newest published month gives the current year to date. That one row is replaced on every run.

## Caveats

- Okres-level crime **counts** are not open data, only the clearance % on the maps. The map reading has medium confidence, because the maps do not tie a number to its label.
- ISDN figures are for the *územný* okres. The *policajný* okres tables differ slightly. Okres Senec includes a D1 stretch, which adds about 30 accidents a year.
- The kraj population jumps in 2021 (census rebase), so the per-1000 series breaks there.
- Crime rows cover full calendar years only. The 2026 XML page lists no file yet (10 Oct 2026).
- `meta.town_population_end_2025` keeps its literal key.

## Regression, 10 Oct 2026

A run pinned with `--isdn-month 2026-08` reproduces every value of the 16 Sep hand-built file, with one exception. `objasnenost_okres_senec` 2023 `clearance_violent_pct` was null and is now **50.0**: the map prints it as the integer `50`, and the hand read only matched decimals. The method text was updated to match.

The published file uses ISDN 2026-09, so the 2026 row now covers 1.1.–30.9.2026. Its new values are 169 accidents (+31), 3 killed, 6 seriously injured, 65 lightly injured, and €1 595 360 damage. No new full year: 2025 was already complete.

## Rebuild, 26 Oct 2026

The run that added `nehodove-useky` reproduced every value of the 10 Oct file; `on_road_outside_km_system` and
`at_level_crossing` were added for every year (16 rows). ŠÚ SR's DATAcube did not answer, so the population came from
the cached copy of 10 Oct, unchanged. The ISDN's latest month was still September 2026.

## STATdata, 9 Nov 2026

ŠÚ SR's DATAcube (`data.statistics.sk`) stopped answering in autumn 2026, and STATdata replaced it. The population now
comes from STATdata's open data through `fetch_datacube.py`'s helpers, in one request to `om7101rr`. `om7102rr` is not
on STATdata (404). `om7101rr` also holds the okres and the kraj, and its mid-year population (`U_OM_0056`) equals
`om7102rr` IN010114 for both, every year 2019–2025. The town's end of 2025 (`U_OM_0057`) is 20 260, as before.

Terms (read 9 Nov 2026): STATdata's terms of use (`https://statdata.statistics.sk/public/ui/dc/domov/terms-of-use`)
allow copying, redistribution and commercial use under CC BY 4.0, with ŠÚ SR named as the source and no suggestion
that ŠÚ SR endorses the use; NKOD records STATdata's open-data downloads as CC BY 4.0. The same terms forbid robots
and crawlers for collecting data: the script reads only the open-data URLs STATdata generates for reuse, one request
per cube, 3 s apart.

The live run changed no number. Its first run, pinned with `--isdn-month 2026-09`, gave the same files; the ISDN's
latest month was still September 2026. Three things changed:
- `source_url` of the 15 population rows in the CSV, which is now the STATdata request.
- Those rows' `last_update` (9 Nov 2026), and so the JSON `last_update` of every kraj row and every accident row.
- The texts `population_source` and the second note, which name `om7101rr` instead of `om7102rr`.

## License

Published by Som Senec under the Creative Commons Attribution 4.0 International licence (CC BY 4.0): https://creativecommons.org/licenses/by/4.0/. You may use it for any purpose, commercial use included, if you credit "Som Senec, somsenec.sk". The source documents that each record links to keep their own terms.
