Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES-223: Implement SubChannelVisibility feature #150

Merged
merged 5 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 31 additions & 12 deletions idelib/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,27 +471,37 @@ def hasSession(self, sessionId):
return False
if sessionId is None:
return True
return sessionId >= 0 and sessionId < len(self.sessions)


def getPlots(self, subchannels=True, plots=True, debug=True, sort=True):
return 0 <= sessionId < len(self.sessions)


def getPlots(self, subchannels=True, plots=True, debug=True, sort=True,
visibility=0):
""" Get all plotable data sources: sensor SubChannels and/or Plots.

:keyword subchannels: Include subchannels if `True`.
:keyword plots: Include Plots if `True`.
:keyword debug: If `False`, exclude debugging/diagnostic channels.
:keyword sort: Sort the plots by name if `True`.
:keyword sort: Sort the plots by name if `True`.
:keyword visibility: The plots' maximum level of visibility,
for display purposes. Standard data sources are 0; optional
sources (typically internally-used data) are 1; and sources
greater than 1 generally contain data for diagnostic purposes.
"""
result = []
test = lambda x: debug or not x.name.startswith("DEBUG")
def test(x):
return debug or not x.name.startswith("DEBUG")

if plots:
result = [x for x in self.plots.values() if test(x)]
else:
result = []

if subchannels:
for c in self._channels.values():
for i in range(len(c.subchannels)):
subc = c.getSubChannel(i)
if test(subc):
result.append(subc)
if not test(subc) or subc.visibility > visibility:
continue
result.append(subc)
if sort:
result.sort(key=lambda x: x.displayName)
return result
Expand Down Expand Up @@ -704,7 +714,7 @@ def __init__(self, dataset, channelId=None, parser=None, sensor=None,
self.dataset = dataset
self.sampleRate = sampleRate
self.attributes = attributes

self._unitsStr = None

self.cache = bool(cache)
Expand Down Expand Up @@ -947,12 +957,13 @@ class SubChannel(Channel):

def __init__(self, parent, subchannelId, name=None, units=('', ''),
transform=None, displayRange=None, sensorId=None,
warningId=None, axisName=None, attributes=None, color=None):
warningId=None, axisName=None, attributes=None, color=None,
visibility=0):
""" Constructor. This should generally be done indirectly via
`Channel.addSubChannel()`.

:param sensor: The parent sensor.
:param channelId: The channel's ID, unique within the file.
:param subchannelId: The channel's ID, unique within the file.
:param parser: The channel's payload data parser.
:keyword name: A custom name for this channel.
:keyword units: The units measured in this channel, used if units
Expand All @@ -973,6 +984,13 @@ def __init__(self, parent, subchannelId, name=None, units=('', ''),
name is "Accelerometer X (low-g)").
:keyword attributes: A dictionary of arbitrary attributes, e.g.
``Attribute`` elements parsed from the file.
:keyword visibility: The subchannel's level of visibility, for
display purposes. The lower the value, the more 'visible' the
subchannel. Standard data subchannels are 0 (visible by
default); subchannels containing data that is primarily used
internally (e.g., GPS time sync) are 1 (can be displayed, but
are not by default); and subchannels with visibility values
greater than 1 are typically diagnostic data and never viewed.
"""
self.id = subchannelId
self.parent = parent
Expand All @@ -981,6 +999,7 @@ def __init__(self, parent, subchannelId, name=None, units=('', ''),
self.dataset = parent.dataset
self.axisName = axisName
self.attributes = attributes
self.visibility = visibility

self._unitsStr = None

Expand Down
1 change: 1 addition & 0 deletions idelib/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,7 @@ class ChannelParser(ElementHandler):
"SubChannelSensorRef": "sensorId",
"SubChannelWarningRef": "warningId",
"SubChannelPlotColor": "color",
"SubChannelVisibility": "visibility",

# Generic attribute elements.
"Attribute": "attributes"
Expand Down
Loading