Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
KWH40
fml40-reference-implementation
Commits
d14ad2b3
Commit
d14ad2b3
authored
Oct 29, 2020
by
Jiahang Chen
Browse files
fix path problem for jupyter notebook
parent
11ebd697
Pipeline
#350519
passed with stage
in 12 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
ml/tools.py
View file @
d14ad2b3
...
...
@@ -321,7 +321,7 @@ def make_feature_config(class_name, identifier="", name="", subFeatures=""):
return
config_json
def
make_thing_config
(
dt_id
,
name
,
roles
,
features
=
[]):
def
make_thing_config
(
dt_id
,
name
,
roles
,
features
=
[]
,
root
=
__file__
):
config_file
=
{
"thingId"
:
dt_id
,
"policyId"
:
dt_id
,
...
...
@@ -333,19 +333,19 @@ def make_thing_config(dt_id, name, roles, features=[]):
}
}
path
=
os
.
path
.
join
(
get_root
(),
"configs"
,
"{}.json"
.
format
(
name
))
path
=
os
.
path
.
join
(
get_root
(
root
),
"configs"
,
"{}.json"
.
format
(
name
))
with
open
(
path
,
'wb'
)
as
file
:
file
.
write
(
json
.
dumps
(
config_file
).
encode
(
'utf-8'
))
return
"{}.json"
.
format
(
name
)
def
load_config
(
config_file_name
):
def
load_config
(
config_file_name
,
root
=
__file__
):
"""Creates a json object from a json formatted file found at config_filepath.
:param config_filepath: Path to json formatted file.
"""
config_file_path
=
os
.
path
.
join
(
get_root
(),
"configs"
,
config_file_name
)
config_file_path
=
os
.
path
.
join
(
get_root
(
root
),
"configs"
,
config_file_name
)
with
open
(
config_file_path
)
as
config_file
:
config
=
json
.
load
(
config_file
)
return
config
...
...
path/path.py
View file @
d14ad2b3
...
...
@@ -2,7 +2,7 @@
import
sys
def
get_root
():
path
=
sys
.
modules
[
__name__
].
__file__
if
__name__
==
"__main__"
else
__
file_
_
def
get_root
(
file_path
):
path
=
sys
.
modules
[
__name__
].
__file__
if
__name__
==
"__main__"
else
file_
path
return
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
path
),
os
.
path
.
pardir
))
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