Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Dynamic Exposure
OpenBuildingMap
rabotnik-obm
Commits
c13648b1
Commit
c13648b1
authored
Aug 13, 2021
by
Marius Kriegerowski
Browse files
Add blank lines after doc-strings
parent
ff3abd15
Changes
1
Hide whitespace changes
Inline
Side-by-side
rabotnikobm/occupancy/mapping.py
View file @
c13648b1
...
...
@@ -23,6 +23,7 @@ from collections import defaultdict
def
group_tags
(
occupancy_mapping
:
list
[
dict
[
str
,
str
]])
->
dict
[
str
,
dict
[
str
,
str
]]:
"""Extract groups of identical tags and group them in nested dicts."""
grouped_tag_mapping
=
defaultdict
(
dict
)
for
row
in
occupancy_mapping
:
...
...
@@ -62,6 +63,7 @@ class OccupancyMapper:
@
classmethod
def
read_csv
(
cls
,
fn
:
str
)
->
list
[
dict
[
str
,
str
]]:
"""Read content from csv into list of dicts."""
with
open
(
fn
)
as
csvfile
:
mapping
=
list
(
csv
.
DictReader
(
csvfile
))
...
...
@@ -70,6 +72,7 @@ class OccupancyMapper:
@
classmethod
def
from_csv
(
cls
,
fn
:
str
)
->
OccupancyMapper
:
"""Read a csv and initialize a `OccupancyMapper`."""
occupancy_mapping
=
cls
.
read_csv
(
fn
)
occupancy_mapping_grouped
=
group_tags
(
occupancy_mapping
)
...
...
@@ -88,6 +91,8 @@ class OverridingOccupancy:
self
.
mapping
=
mapping
def
apply
(
self
,
occupancies
:
list
[
str
]):
"""Apply the loaded mapping to a list of `occupancies`."""
for
candidate
,
occupancy
in
self
.
mapping
.
items
():
if
candidate
in
occupancies
:
return
occupancy
...
...
@@ -98,6 +103,7 @@ class OverridingOccupancy:
@
classmethod
def
read_csv
(
cls
,
fn
:
str
)
->
dict
[
str
,
str
]:
"""Read content from csv into list of dicts."""
with
open
(
fn
)
as
csvfile
:
mapping
=
{
k
.
strip
():
v
.
strip
()
for
(
k
,
v
)
in
csv
.
reader
(
csvfile
)}
...
...
@@ -106,6 +112,6 @@ class OverridingOccupancy:
@
classmethod
def
from_csv
(
cls
,
fn
:
str
)
->
OverridingOccupancy
:
"""Read a csv and initialize a `OverridingOccupancy` instance."""
occupancy_mapping
=
cls
.
read_csv
(
fn
)
occupancy_mapping
=
cls
.
read_csv
(
fn
)
return
cls
(
mapping
=
occupancy_mapping
)
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment