Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
firanka
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
firanka
Commits
63a4a02b
Commit
63a4a02b
authored
7 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
smarter builder
parent
48cd0d63
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
firanka/builder.py
+22
-6
22 additions, 6 deletions
firanka/builder.py
tests/test_builder.py
+3
-2
3 additions, 2 deletions
tests/test_builder.py
with
25 additions
and
8 deletions
firanka/builder.py
+
22
−
6
View file @
63a4a02b
...
...
@@ -15,7 +15,10 @@ __all__ = [
]
class
DiscreteKnowledgeBuilder
(
object
):
def
__init__
(
self
,
series
):
def
__init__
(
self
,
series
=
None
):
if
series
is
None
:
series
=
DiscreteSeries
([],
'
(0;0)
'
)
if
not
isinstance
(
series
,
DiscreteSeries
):
raise
TypeError
(
'
discrete knowledge builder supports only discrete series
'
)
...
...
@@ -34,11 +37,24 @@ class DiscreteKnowledgeBuilder(object):
self
.
new_data
[
index
]
=
value
def
update_series
(
self
):
"""
:return: a new DiscreteSeries instance
"""
def
as_series
(
self
):
"""
Update
:return: a new DiscreteSeries instance
"""
new_data
=
[]
cp_new_data
=
copy
.
copy
(
self
.
new_data
)
# Update
for
k
,
v
in
self
.
series
.
data
:
if
k
in
cp_new_data
:
v
=
cp_new_data
.
pop
(
k
)
new_data
.
append
((
k
,
v
))
new_data
=
copy
.
copy
(
self
.
series
.
data
)
for
k
,
v
in
self
.
new_data
.
items
():
new_data
.
a
d
d
((
k
,
v
))
# Add those that remained
for
k
,
v
in
cp_
new_data
.
items
():
new_data
.
a
ppen
d
((
k
,
v
))
return
DiscreteSeries
(
new_data
,
self
.
domain
)
This diff is collapsed.
Click to expand it.
tests/test_builder.py
+
3
−
2
View file @
63a4a02b
...
...
@@ -16,9 +16,10 @@ class TestBuilder(unittest.TestCase):
kb
.
put
(
3
,
4
)
kb
.
put
(
-
1
,
5
)
kb
.
put
(
0
,
2
)
kb
.
put
(
-
1
,
6
)
s2
=
kb
.
update
_series
()
s2
=
kb
.
as
_series
()
self
.
assertTrue
(
s2
.
domain
,
'
<-1;3>
'
)
self
.
assertEqual
(
s2
.
data
,[(
-
1
,
6
),
(
0
,
1
),
(
1
,
2
),
(
3
,
4
)])
self
.
assertEqual
(
s2
.
data
,[(
-
1
,
6
),
(
0
,
2
),
(
1
,
2
),
(
3
,
4
)])
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