Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
force-bdss
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Adham Hashibon
force-bdss
Commits
2f07430b
Commit
2f07430b
authored
7 years ago
by
Stefano Borini
Browse files
Options
Downloads
Patches
Plain Diff
Separated extraction methods for subsections of the file
parent
f381a451
No related branches found
No related tags found
1 merge request
!29
Extract io layer to writer/reader class
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
force_bdss/io/workflow_reader.py
+34
-7
34 additions, 7 deletions
force_bdss/io/workflow_reader.py
with
34 additions
and
7 deletions
force_bdss/io/workflow_reader.py
+
34
−
7
View file @
2f07430b
import
json
import
logging
from
traits.api
import
HasStrictTraits
,
Instance
...
...
@@ -26,35 +27,61 @@ class WorkflowReader(HasStrictTraits):
def
read
(
self
,
file
):
json_data
=
json
.
load
(
file
)
registry
=
self
.
bundle_registry
try
:
version
=
json_data
[
"
version
"
]
except
KeyError
:
logging
.
error
(
"
File missing version information
"
)
raise
InvalidFileException
(
"
Corrupted input file, no version
"
"
specified
"
)
if
version
not
in
SUPPORTED_FILE_VERSIONS
:
logging
.
error
(
"
File contains version {} that is not in the
"
"
list of supported versions {}
"
.
format
(
version
,
SUPPORTED_FILE_VERSIONS
)
)
raise
InvalidVersionException
(
"
File version {} not supported
"
.
format
(
json_data
[
"
version
"
]))
wf
=
Workflow
()
try
:
wf
.
multi_criteria_optimizer
=
self
.
_extract_mco
(
json_data
)
wf
.
data_sources
[:]
=
self
.
_extract_data_sources
(
json_data
)
wf
.
kpi_calculators
[:]
=
self
.
_extract_kpi_calculators
(
json_data
)
except
KeyError
as
e
:
logging
.
exception
(
"
Could not read file
"
)
raise
InvalidFileException
(
"
Could not read file. {}
"
.
format
(
e
))
def
_extract_mco
(
self
,
json_data
):
registry
=
self
.
bundle_registry
mco_id
=
json_data
[
"
multi_criteria_optimizer
"
][
"
id
"
]
mco_bundle
=
registry
.
mco_bundle_by_id
(
mco_id
)
wf
.
multi_criteria_optimizer
=
mco_bundle
.
create_model
(
return
mco_bundle
.
create_model
(
json_data
[
"
multi_criteria_optimizer
"
][
"
model_data
"
])
def
_extract_data_sources
(
self
,
json_data
):
registry
=
self
.
bundle_registry
data_sources
=
[]
for
ds_entry
in
json_data
[
"
data_sources
"
]:
ds_id
=
ds_entry
[
"
id
"
]
ds_bundle
=
registry
.
data_source_bundle_by_id
(
ds_id
)
wf
.
data_sources
.
append
(
ds_bundle
.
create_model
(
ds_entry
[
"
model_data
"
]))
data_sources
.
append
(
ds_bundle
.
create_model
(
ds_entry
[
"
model_data
"
]))
return
data_sources
def
_extract_kpi_calculators
(
self
,
json_data
):
registry
=
self
.
bundle_registry
kpi_calculators
=
[]
for
kpic_entry
in
json_data
[
"
kpi_calculators
"
]:
kpic_id
=
kpic_entry
[
"
id
"
]
kpic_bundle
=
registry
.
kpi_calculator_bundle_by_id
(
kpic_id
)
wf
.
kpi_calculators
.
append
(
kpic_bundle
.
create_model
(
kpic_entry
[
"
model_data
"
]))
return
wf
kpi_calculators
.
append
(
kpic_bundle
.
create_model
(
kpic_entry
[
"
model_data
"
]))
return
kpi_calculators
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