Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Odevzdávací Systém MO
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Mareš
Odevzdávací Systém MO
Commits
eb4db884
Commit
eb4db884
authored
1 year ago
by
Martin Mareš
Browse files
Options
Downloads
Patches
Plain Diff
Import škol: Základní zjednodušování názvů
parent
7e095205
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/init-schools
+13
-1
13 additions, 1 deletion
bin/init-schools
with
13 additions
and
1 deletion
bin/init-schools
+
13
−
1
View file @
eb4db884
...
@@ -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
'
,
'
ZŠ
'
,
name
,
flags
=
re
.
IGNORECASE
)
name
=
re
.
sub
(
'
mateřská škola
'
,
'
MŠ
'
,
name
,
flags
=
re
.
IGNORECASE
)
name
=
re
.
sub
(
'
střední škola
'
,
'
SŠ
'
,
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
'
\t
name:
{
simple_name
}
'
)
for
field
in
fields
:
for
field
in
fields
:
print
(
f
'
\t
{
field
}
:
{
getattr
(
new
,
field
)
}
'
)
print
(
f
'
\t
{
field
}
:
{
getattr
(
new
,
field
)
}
'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment