Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
beat.backend.python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
beat
beat.backend.python
Commits
92d6cf3a
Commit
92d6cf3a
authored
7 years ago
by
Philip ABBET
Browse files
Options
Downloads
Patches
Plain Diff
Add a 'StdoutDataSink' class for debugging purposes
parent
7f0ee2b5
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
beat/backend/python/data.py
+75
-0
75 additions, 0 deletions
beat/backend/python/data.py
with
75 additions
and
0 deletions
beat/backend/python/data.py
+
75
−
0
View file @
92d6cf3a
...
...
@@ -47,6 +47,9 @@ from .dataformat import DataFormat
from
.algorithm
import
Algorithm
#----------------------------------------------------------
class
DataSource
(
object
):
"""
Interface of all the Data Sources
...
...
@@ -74,6 +77,9 @@ class DataSource(object):
pass
#----------------------------------------------------------
class
DataSink
(
object
):
"""
Interface of all the Data Sinks
...
...
@@ -103,6 +109,57 @@ class DataSink(object):
pass
#----------------------------------------------------------
class
StdoutDataSink
(
DataSink
):
"""
Data Sink that prints informations about the written data on stdout
Note: The written data is lost! Use ii for debugging purposes
"""
def
__init__
(
self
):
super
(
StdoutDataSink
,
self
).
__init__
()
self
.
dataformat
=
None
self
.
prefix
=
''
self
.
display_data
=
True
def
setup
(
self
,
dataformat
,
prefix
=
None
,
display_data
=
True
):
self
.
dataformat
=
dataformat
self
.
display_data
=
display_data
if
prefix
is
not
None
:
self
.
prefix
=
prefix
if
self
.
prefix
!=
''
:
self
.
prefix
+=
'
'
def
write
(
self
,
data
,
start_data_index
,
end_data_index
):
"""
Write a block of data
Parameters:
data (beat.core.baseformat.baseformat) The block of data to write
start_data_index (int): Start index of the written data
end_data_index (int): End index of the written data
"""
if
self
.
display_data
:
print
'
%s(%d -> %d): %s
'
%
(
self
.
prefix
,
start_data_index
,
end_data_index
,
str
(
data
))
else
:
print
'
%s(%d -> %d): <data>
'
%
(
self
.
prefix
,
start_data_index
,
end_data_index
)
def
isConnected
(
self
):
return
True
#----------------------------------------------------------
class
CachedDataSource
(
DataSource
):
"""
Data Source that load data from the Cache
"""
...
...
@@ -445,6 +502,9 @@ class CachedDataSource(DataSource):
self
.
preloaded
=
True
#----------------------------------------------------------
class
CachedDataSink
(
DataSink
):
"""
Data Sink that save data in the Cache
...
...
@@ -753,6 +813,9 @@ class CachedDataSink(DataSink):
return
(
self
.
filename
is
not
None
)
#----------------------------------------------------------
class
MemoryDataSource
(
DataSource
):
"""
Interface of all the Data Sources
...
...
@@ -796,6 +859,9 @@ class MemoryDataSource(DataSource):
return
(
0
,
0
)
#----------------------------------------------------------
class
MemoryDataSink
(
DataSink
):
"""
Data Sink that directly transmit data to associated MemoryDataSource
...
...
@@ -831,6 +897,9 @@ class MemoryDataSink(DataSink):
return
len
(
self
.
data_sources
)
>
0
#----------------------------------------------------------
def
load_data_index
(
cache_prefix
,
hash_path
):
"""
Loads a cached-data index if it exists. Returns empty otherwise.
...
...
@@ -885,6 +954,9 @@ def load_data_index(cache_prefix, hash_path):
return
sorted
(
retval
)
+
[
end_index
+
1
]
#----------------------------------------------------------
def
_foundCommonIndices
(
lst
):
"""
Returns the list of common indices, given a list of list of indices
"""
...
...
@@ -896,6 +968,9 @@ def _foundCommonIndices(lst):
return
common_indices
#----------------------------------------------------------
def
foundSplitRanges
(
lst
,
n_split
):
"""
Splits a list of lists of indices into n splits for parallelization
purposes.
"""
...
...
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