Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
sdc
importer_test_data
Commits
f21d947a
Commit
f21d947a
authored
Feb 25, 2020
by
Carl Schaffer
Browse files
adding initial version of data accessor
parent
e792ab3b
Changes
2
Hide whitespace changes
Inline
Side-by-side
data_accessor.py
0 → 100644
View file @
f21d947a
from
os
import
walk
from
os.path
import
join
,
dirname
,
abspath
,
basename
_datadir
=
abspath
(
join
(
dirname
(
__file__
),
"data"
))
class
AttrDict
(
dict
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
AttrDict
,
self
).
__init__
(
*
args
,
**
kwargs
)
self
.
__dict__
=
self
class
TestDataAccessor
():
"""Class to facilitate easy access to test data. Data is stored in a separate folder and accessed as attributes e.g.
TestDataAccessor().chrotel.l1_data will give you a list of filenames for chrotel level 1 data.
"""
def
__init__
(
self
):
print
(
_datadir
)
_container
=
AttrDict
()
for
root
,
dirs
,
files
in
walk
(
_datadir
):
if
files
:
instr
=
basename
(
dirname
(
root
))
data_type
=
basename
(
root
)
files
=
[
join
(
root
,
f
)
for
f
in
files
]
if
instr
not
in
_container
:
_container
[
instr
]
=
AttrDict
()
_container
[
instr
][
data_type
]
=
files
print
(
instr
,
data_type
,
files
)
self
.
_container
=
_container
def
__getattr__
(
self
,
item
):
return
self
.
_container
[
item
]
def
__str__
(
self
):
from
pprint
import
pformat
return
pformat
(
self
.
_container
)
importer_test_data/__init__.py
0 → 100644
View file @
f21d947a
from
data_accessor
import
TestDataAccessor
test_data
=
TestDataAccessor
()
Write
Preview
Markdown
is supported
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