Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pygwinc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
gwinc
pygwinc
Commits
26a05c2e
Commit
26a05c2e
authored
4 years ago
by
Jameson Rollins
Browse files
Options
Downloads
Patches
Plain Diff
add ability to retrieve nested items from Budget and Trace objects
e.g. Budget['SubBuget.BudgetItem']
parent
940a4257
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
gwinc/nb.py
+22
-2
22 additions, 2 deletions
gwinc/nb.py
gwinc/trace.py
+17
-2
17 additions, 2 deletions
gwinc/trace.py
with
39 additions
and
4 deletions
gwinc/nb.py
+
22
−
2
View file @
26a05c2e
...
...
@@ -418,13 +418,33 @@ class Budget(Noise):
return
name
def
__getitem__
(
self
,
name
):
"""
Get a (possibly nested) sub-BudgetItem.
"""
try
:
name
,
rest
=
name
.
split
(
'
.
'
,
1
)
except
ValueError
:
rest
=
None
try
:
return
self
.
_noise_objs
[
name
]
o
=
self
.
_noise_objs
[
name
]
except
KeyError
:
try
:
return
self
.
_cal_objs
[
name
]
o
=
self
.
_cal_objs
[
name
]
except
KeyError
:
raise
KeyError
(
"
unknown noise or cal name
'
{}
"
.
format
(
name
))
if
rest
:
return
o
[
rest
]
else
:
return
o
def
get
(
self
,
key
,
default
=
None
):
"""
Get a (possibly nested) sub-BudgetItem.
"""
try
:
return
self
[
key
]
except
KeyError
:
return
default
def
keys
(
self
):
"""
Iterate over budget noise names.
"""
...
...
This diff is collapsed.
Click to expand it.
gwinc/trace.py
+
17
−
2
View file @
26a05c2e
...
...
@@ -61,8 +61,23 @@ class BudgetTrace:
raise
AttributeError
def
__getitem__
(
self
,
name
):
"""
get budget trace by name
"""
return
self
.
_bdict
[
name
]
"""
get budget trace by name
"""
try
:
name
,
rest
=
name
.
split
(
'
.
'
,
1
)
return
self
.
_bdict
[
name
][
rest
]
except
ValueError
:
return
self
.
_bdict
[
name
]
def
get
(
self
,
key
,
default
=
None
):
"""
get a (possibly nested) Trace item.
"""
try
:
return
self
[
key
]
except
KeyError
:
return
default
def
items
(
self
):
"""
iterator of budget (name, trace) tuples
"""
...
...
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