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
cf21e91e
Commit
cf21e91e
authored
7 years ago
by
Stefano Borini
Browse files
Options
Downloads
Patches
Plain Diff
Added documentation to the workflow reader
parent
47d90ffa
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
+81
-9
81 additions, 9 deletions
force_bdss/io/workflow_reader.py
with
81 additions
and
9 deletions
force_bdss/io/workflow_reader.py
+
81
−
9
View file @
cf21e91e
...
@@ -10,22 +10,56 @@ SUPPORTED_FILE_VERSIONS = ["1"]
...
@@ -10,22 +10,56 @@ SUPPORTED_FILE_VERSIONS = ["1"]
class
InvalidFileException
(
Exception
):
class
InvalidFileException
(
Exception
):
pass
"""
Raised if the file is invalid for some reason
"""
class
InvalidVersionException
(
InvalidFileException
):
class
InvalidVersionException
(
InvalidFileException
):
pass
"""
Raised if the version tag does not satisfy the currently
supported list.
"""
class
WorkflowReader
(
HasStrictTraits
):
class
WorkflowReader
(
HasStrictTraits
):
"""
Reads the workflow from a file.
"""
#: The bundle registry. The reader needs it to create the
#: bundle-specific model objects.
bundle_registry
=
Instance
(
BundleRegistryPlugin
)
bundle_registry
=
Instance
(
BundleRegistryPlugin
)
def
__init__
(
self
,
bundle_registry
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
bundle_registry
,
*
args
,
**
kwargs
):
"""
Initializes the reader.
Parameters
----------
bundle_registry: BundleRegistryPlugin
The bundle registry that provides lookup services
for a bundle identified by a given id.
"""
self
.
bundle_registry
=
bundle_registry
self
.
bundle_registry
=
bundle_registry
super
(
WorkflowReader
,
self
).
__init__
(
*
args
,
**
kwargs
)
super
(
WorkflowReader
,
self
).
__init__
(
*
args
,
**
kwargs
)
def
read
(
self
,
file
):
def
read
(
self
,
file
):
"""
Reads the file and returns a Workflow object.
If any problem is found, raises an InvalidFileException or a
derived, more specialized exception.
Parameters
----------
file: File
A file object containing the data of the workflow in the
appropriate json format.
Returns
-------
Workflow
An instance of the model tree, rooted at Workflow.
Raises
------
InvalidFileException
Raised if the file is corrupted or cannot be read by this reader.
"""
json_data
=
json
.
load
(
file
)
json_data
=
json
.
load
(
file
)
try
:
try
:
...
@@ -57,10 +91,23 @@ class WorkflowReader(HasStrictTraits):
...
@@ -57,10 +91,23 @@ class WorkflowReader(HasStrictTraits):
"
Unable to find key {}
"
.
format
(
e
))
"
Unable to find key {}
"
.
format
(
e
))
return
wf
return
wf
def
_extract_mco
(
self
,
json_data
):
def
_extract_mco
(
self
,
wf_data
):
"""
Extracts the MCO from the workflow dictionary data.
Parameters
----------
wf_data: dict
the content of the workflow key in the top level dictionary data.
Returns
-------
a BaseMCOModel instance of the bundle-specific MCO driver, or None
if no MCO is specified in the file (as in the case of premature
saving).
"""
registry
=
self
.
bundle_registry
registry
=
self
.
bundle_registry
mco_data
=
json
_data
.
get
(
"
multi_criteria_optimizer
"
)
mco_data
=
wf
_data
.
get
(
"
multi_criteria_optimizer
"
)
if
mco_data
is
None
:
if
mco_data
is
None
:
# The file was saved without setting an MCO.
# The file was saved without setting an MCO.
# The file is valid, we simply can't run any optimization yet.
# The file is valid, we simply can't run any optimization yet.
...
@@ -69,24 +116,49 @@ class WorkflowReader(HasStrictTraits):
...
@@ -69,24 +116,49 @@ class WorkflowReader(HasStrictTraits):
mco_id
=
mco_data
[
"
id
"
]
mco_id
=
mco_data
[
"
id
"
]
mco_bundle
=
registry
.
mco_bundle_by_id
(
mco_id
)
mco_bundle
=
registry
.
mco_bundle_by_id
(
mco_id
)
return
mco_bundle
.
create_model
(
return
mco_bundle
.
create_model
(
json_data
[
"
multi_criteria_optimizer
"
][
"
model_data
"
])
wf_data
[
"
multi_criteria_optimizer
"
][
"
model_data
"
])
def
_extract_data_sources
(
self
,
wf_data
):
"""
Extracts the data sources from the workflow dictionary data.
def
_extract_data_sources
(
self
,
json_data
):
Parameters
----------
wf_data: dict
the content of the workflow key in the top level dictionary data.
Returns
-------
list of BaseDataSourceModel instances. Each BaseDataSourceModel is an
instance of the bundle specific model class. The list can be empty.
"""
registry
=
self
.
bundle_registry
registry
=
self
.
bundle_registry
data_sources
=
[]
data_sources
=
[]
for
ds_entry
in
json
_data
[
"
data_sources
"
]:
for
ds_entry
in
wf
_data
[
"
data_sources
"
]:
ds_id
=
ds_entry
[
"
id
"
]
ds_id
=
ds_entry
[
"
id
"
]
ds_bundle
=
registry
.
data_source_bundle_by_id
(
ds_id
)
ds_bundle
=
registry
.
data_source_bundle_by_id
(
ds_id
)
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
return
data_sources
def
_extract_kpi_calculators
(
self
,
json_data
):
def
_extract_kpi_calculators
(
self
,
wf_data
):
"""
Extracts the KPI calculators from the workflow dictionary data.
Parameters
----------
wf_data: dict
the content of the workflow key in the top level dictionary data.
Returns
-------
list of BaseKPICalculatorModel instances. Each BaseKPICalculatorModel
is an instance of the bundle specific model class. The list can be
empty.
"""
registry
=
self
.
bundle_registry
registry
=
self
.
bundle_registry
kpi_calculators
=
[]
kpi_calculators
=
[]
for
kpic_entry
in
json
_data
[
"
kpi_calculators
"
]:
for
kpic_entry
in
wf
_data
[
"
kpi_calculators
"
]:
kpic_id
=
kpic_entry
[
"
id
"
]
kpic_id
=
kpic_entry
[
"
id
"
]
kpic_bundle
=
registry
.
kpi_calculator_bundle_by_id
(
kpic_id
)
kpic_bundle
=
registry
.
kpi_calculator_bundle_by_id
(
kpic_id
)
...
...
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