Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Roelofsen, Hans
benb_utils
Commits
a81c36c8
Commit
a81c36c8
authored
Nov 09, 2021
by
Roelofsen, Hans
Browse files
updates to methods
parent
6499858e
Changes
2
Hide whitespace changes
Inline
Side-by-side
fix_bt.py
View file @
a81c36c8
import
numbers
def
fix_bt
(
code_in
,
as_mnp
=
False
):
def
fix_bt
(
code_in
,
as_mnp
=
False
,
verbose
=
False
):
"""
Parser for Beheertype codes to repair abbreviated codes and/or MNP extension
eg. 02.01 --> N02.01 if as_mnp==False
...
...
@@ -19,42 +20,51 @@ def fix_bt(code_in, as_mnp=False):
:param as_mnp: return MNP style beheertypecode, default=False
:return: beheertypecode
"""
if
verbose
:
print
(
'from {}'
.
format
(
code_in
),
end
=
' '
)
if
isinstance
(
code_in
,
numbers
.
Number
):
code_in
=
str
(
code_in
)
# Identify parts of code
parts
=
code_in
.
split
(
"."
)
if
len
(
parts
)
==
1
:
raise
AssertionError
(
"Unexpected BT code: {}"
.
format
(
code_in
))
raise
AssertionError
(
"
1.
Unexpected BT code: {}"
.
format
(
code_in
))
elif
len
(
parts
)
==
2
:
top
,
sub
=
parts
neer
=
None
elif
len
(
parts
)
==
3
:
top
,
sub
,
neer
=
parts
else
:
raise
AssertionError
(
"Unexpected BT code: {}"
.
format
(
code_in
))
raise
AssertionError
(
"
2.
Unexpected BT code: {}"
.
format
(
code_in
))
# Verify TOP and add "N" is required
if
top
.
isdigit
():
top
=
"N{0}"
.
format
(
top
.
zfill
(
2
))
else
:
assert
top
[
0
].
isupper
(),
"Unexpected BT Code format: {}"
.
format
(
code_in
)
assert
top
[
0
].
upper
()
in
[
'N'
,
'W'
,
'S'
,
'T'
,
'A'
,
'L'
],
"3. Unexpected BT Code: {}"
.
format
(
code_in
)
if
top
[
0
].
islower
():
top
=
top
.
capitalize
()
assert
top
[
1
].
isdigit
(),
'3. Unexpected BT code: {}'
.
format
(
code_in
)
assert
top
[
2
].
isdigit
(),
'3. Unexpected BT code: {}'
.
format
(
code_in
)
assert
len
(
top
)
==
3
,
"3. Unexpected BT Code: {}"
.
format
(
code_in
)
# Verify SUB
assert
sub
.
isdigit
and
len
(
sub
)
==
2
,
"Unexpected BT Code
format
: {}"
.
format
(
code_in
)
assert
sub
.
isdigit
and
len
(
sub
)
==
2
,
"
4.
Unexpected BT Code: {}"
.
format
(
code_in
)
# Verify NEER and check if it is neergeschaald or not
keep_neer
=
False
if
neer
:
assert
neer
.
isdigit
and
len
(
neer
)
==
2
,
"Unexpected BT Code
format
: {}"
.
format
(
code_in
)
assert
neer
.
isdigit
and
len
(
neer
)
==
2
,
"
5.
Unexpected BT Code: {}"
.
format
(
code_in
)
if
int
(
neer
)
>
0
:
keep_neer
=
True
# Construct output
head
=
"{}.{}"
.
format
(
top
,
sub
)
if
keep_neer
:
return
"{}.{}"
.
format
(
head
,
neer
)
output
=
"{}.{}"
.
format
(
head
,
neer
)
elif
as_mnp
:
return
"{}.00"
.
format
(
head
)
output
=
"{}.00"
.
format
(
head
)
else
:
return
head
output
=
head
if
verbose
:
print
(
'to {}'
.
format
(
output
))
return
output
\ No newline at end of file
snl_beheertypen.py
View file @
a81c36c8
...
...
@@ -7,11 +7,12 @@ import os
from
pathlib
import
Path
import
pandas
as
pd
# TODO: dit moet vast handiger kunnen! Idee is natuurlijk om een Pandas DF te kunnen importeren vanuit een andere repo
def
get_snl_beheertypen_list
(
benb_dir
):
"""
return snl beheertypen list as pandas df
:param benb_dir: directory of benb_utils
:return: pandas dataframe
"""
os
.
chdir
(
benb_dir
)
return
pd
.
read_csv
(
r
'./resources/snl_beheertypen.csv'
,
sep
=
','
,
comment
=
'#'
,
quotechar
=
'"'
)
\ No newline at end of file
return
pd
.
read_csv
(
os
.
path
.
join
(
benb_dir
,
r
'resources/snl_beheertypen.csv'
),
sep
=
','
,
comment
=
'#'
,
quotechar
=
'"'
)
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment