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 239fa71
Showing 1 changed file with 15 additions and 1 deletion.
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

0 comments on commit 239fa71

Please sign in to comment.