Skip to content

Commit

Permalink
Format reporting unit name to exclude zip code and prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismostert committed Apr 10, 2024
1 parent b8becff commit 03db6c7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/csv_write.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import csv
import re
from typing import Dict, List, Optional

from eml import EML, CheckResult
Expand All @@ -21,6 +22,9 @@
]
PROTOCOL_VERSION = "EP2024"

ZIP_CODE_PATTERN = re.compile(r"\(postcode: \d{4} [A-Z]{2}\)")
STEMBUREAU_PREFIX_PATTERN = re.compile(r"^Stembureau Stembureau")


def _write_header(writer, metadata: EmlMetadata, description: str) -> None:
writer.writerow(["Versie controleprotocol", PROTOCOL_VERSION])
Expand Down Expand Up @@ -68,14 +72,24 @@ def _format_percentage_deviation(percentage: float) -> str:
return f"{sign}{percentage_int}%"


def _format_reporting_unit_name(reporting_unit_name: Optional[str]) -> str:
return (
STEMBUREAU_PREFIX_PATTERN.sub(
"Stembureau", ZIP_CODE_PATTERN.sub("", reporting_unit_name)
).strip()
if reporting_unit_name
else ""
)


def _id_cols(metadata: EmlMetadata, id: str) -> List[Optional[str]]:
return [
metadata.election_id,
metadata.contest_identifier,
metadata.authority_id,
metadata.authority_name,
_format_id(id),
metadata.reporting_unit_names.get(id),
_format_reporting_unit_name(metadata.reporting_unit_names.get(id)),
]


Expand Down
2 changes: 1 addition & 1 deletion test/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_create_csv_files_a_b():
"Gemeentenummer;0505\n"
"\n"
"Verkiezingnummer;Kieskringnummer;Gemeentenummer;Gemeentenaam;Stembureaunummer;Stembureaunaam;Stembureau met nul stemmen;Stembureau >=3% ongeldig;Stembureau >=3% blanco;Stembureau >=15 of >=2% verschil tussen toegelaten kiezers en uitgebrachte stemmen;Stembureau met lijst >=50% afwijking;Mogelijk verwisselde kandidaten;Al herteld;Samenvatting\n"
"TK2023;14;0505;Dordrecht;1;Stembureau Binnenstad (postcode: 3331 DA);;;;ja (28);;;ja;In dit stembureau is er een groot verschil tussen het aantal toegelaten kiezers en het aantal uitgebrachte stemmen (28). Er is wel herteld.\n"
"TK2023;14;0505;Dordrecht;1;Stembureau Binnenstad;;;;ja (28);;;ja;In dit stembureau is er een groot verschil tussen het aantal toegelaten kiezers en het aantal uitgebrachte stemmen (28). Er is wel herteld.\n"
)
assert content == expected

Expand Down

0 comments on commit 03db6c7

Please sign in to comment.