Skip to content
Snippets Groups Projects
Commit eb4db884 authored by Martin Mareš's avatar Martin Mareš
Browse files

Import škol: Základní zjednodušování názvů

parent 7e095205
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,7 @@ import argparse ...@@ -11,6 +11,7 @@ import argparse
from collections import defaultdict from collections import defaultdict
import csv import csv
from dataclasses import dataclass from dataclasses import dataclass
import re
from sqlalchemy.orm import joinedload from sqlalchemy.orm import joinedload
import sys import sys
from typing import List, Dict, DefaultDict, Tuple, Optional from typing import List, Dict, DefaultDict, Tuple, Optional
...@@ -244,6 +245,15 @@ def get_old_schools() -> DefaultDict[str, List[ProtoSchool]]: ...@@ -244,6 +245,15 @@ def get_old_schools() -> DefaultDict[str, List[ProtoSchool]]:
return old_schools return old_schools
def simplify_name(name: str, town: str) -> str:
name = re.sub('základní škola', '', name, flags=re.IGNORECASE)
name = re.sub('mateřská škola', '', name, flags=re.IGNORECASE)
name = re.sub('střední škola', '', name, flags=re.IGNORECASE)
name = re.sub('gymnázium', 'G', name, flags=re.IGNORECASE)
name = re.sub(r',?\s*s\.r\.o\.', "", name)
return name + ', ' + town
def apply_single_change(old: Optional[ProtoSchool], new: Optional[ProtoSchool]) -> None: def apply_single_change(old: Optional[ProtoSchool], new: Optional[ProtoSchool]) -> None:
if new is None: if new is None:
assert old is not None assert old is not None
...@@ -253,10 +263,11 @@ def apply_single_change(old: Optional[ProtoSchool], new: Optional[ProtoSchool]) ...@@ -253,10 +263,11 @@ def apply_single_change(old: Optional[ProtoSchool], new: Optional[ProtoSchool])
print(f'\t{field}: {getattr(old, field)}') print(f'\t{field}: {getattr(old, field)}')
elif old is None: elif old is None:
assert new is not None assert new is not None
simple_name = simplify_name(new.official_name, new.town_name)
place = db.Place( place = db.Place(
level=4, level=4,
parent=new.town.place_id, parent=new.town.place_id,
name=new.official_name, name=simple_name,
type=db.PlaceType.school) type=db.PlaceType.school)
school = db.School( school = db.School(
place=place, place=place,
...@@ -271,6 +282,7 @@ def apply_single_change(old: Optional[ProtoSchool], new: Optional[ProtoSchool]) ...@@ -271,6 +282,7 @@ def apply_single_change(old: Optional[ProtoSchool], new: Optional[ProtoSchool])
if args.update: if args.update:
print(f'Škola #{school.place_id} (RED IZO {new.red_izo}): NOVÁ') print(f'Škola #{school.place_id} (RED IZO {new.red_izo}): NOVÁ')
print(f'\tname: {simple_name}')
for field in fields: for field in fields:
print(f'\t{field}: {getattr(new, field)}') print(f'\t{field}: {getattr(new, field)}')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment