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 4 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
61 changes: 45 additions & 16 deletions idelib/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,29 +471,46 @@ 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 visibility ranges:
* 0: Standard data sources. Always visible by default.
* 10: Optionally visible, of interest but only in certain situations.
* 20: Hidden by default, but possibly of use to the user.
* 30: Hidden by default, channel used indirectly (but human readable).
* 40: Hidden by default, channel used indirectly (not very human readable).
* 50: Diagnostic, always hide. Accessible via the idelib API.
"""
def test(x):
return debug or (x.visibility <= visibility
and not x.name.startswith("DEBUG"))

result = []
test = lambda x: debug or not x.name.startswith("DEBUG")
if plots:
result = [x for x in self.plots.values() if test(x)]

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):
continue
result.append(subc)

if plots:
result.extend(x for x in self.plots.values() if test(x))

if sort:
result.sort(key=lambda x: x.displayName)

return result


Expand Down Expand Up @@ -704,7 +721,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 +964,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 +991,15 @@ 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 visibility ranges:
* 0: Standard data sources. Always visible by default.
* 10: Optionally visible, of interest but only in certain situations.
* 20: Hidden by default, but possibly of use to the user.
* 30: Hidden by default, channel used indirectly (but human readable).
* 40: Hidden by default, channel used indirectly (not very human readable).
* 50: Diagnostic, always hide. Accessible via the idelib API.
"""
self.id = subchannelId
self.parent = parent
Expand All @@ -981,6 +1008,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 All @@ -996,7 +1024,7 @@ def __init__(self, parent, subchannelId, name=None, units=('', ''),
else:
self.axisName = name

# XXX: HACK HACK HACK REMOVE ME REMOVE ME
# HACK: Display tweak for names generated by certain FwRev
if self.name == "Control Pad P":
self.name = "Control Pad Pressure"
elif self.name == "Control Pad T":
Expand Down Expand Up @@ -2848,14 +2876,15 @@ class Plot(Transformable):
"""

def __init__(self, source, plotId, name=None, transform=None, units=None,
attributes=None):
attributes=None, visibility=0):
self.source = source
self.id = plotId
self.session = source.session
self.dataset = source.dataset
self.name = source.path() if name is None else name
self.units = source.units if units is None else units
self.attributes = attributes
self.visibility = visibility
self.setTransform(transform, update=False)


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
9 changes: 8 additions & 1 deletion idelib/schemata/mide_ide.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,14 @@
<UIntegerElement name="SubChannelRangeMax" id="0x52A8" multiple="0" minver="2">Maximum valid sensor value; may be used for data validation or initial axis scaling during display.</UIntegerElement>
<UIntegerElement name="SubChannelSensorRef" id="0x52A9" multiple="0" minver="2">Reference to a Sensor ID. Allows the association between SubChannels and a physical sensor to be expressed.</UIntegerElement>
<UIntegerElement name="SubChannelWarningRef" id="0x52AA" multiple="1" minver="2">Reference to a warning range, i.e. another sensor measuring something that affects the results of this one.</UIntegerElement>
<IntegerElement name="SubChannelVisibility" id="0x52AB" multiple="0" minver="2">Allow data channels to specify a visibility level; could have different visibility levels for e.g. 'advanced', 'on request' (channels which are not normally useful on their own, e.g. IRIG stream), 'hidden' (internal diagnostic or other dirty laundry).</IntegerElement>
<IntegerElement name="SubChannelVisibility" id="0x52AB" multiple="0" minver="2">Allow data channels to specify a visibility level. Inversely proportional to 'visibility.'
0: Always visible (default)
10: Optionally visible, things probably of interest to the user in certain situations
20: Hide by default, but possibly of use to the user
30: Hide by default, channel used indirectly (but human readable)
40: Hide by default, channel used indirectly (not very human readable)
50: Diagnostic, always hide. Accessible via the idelib API.
</IntegerElement>
<BinaryElement name="SubChannelPlotColor" id="0x52AC" multiple="0" minver="2">The RGB values of the default plotting color (3 bytes).</BinaryElement>
<UIntegerElement name="AccuracyRank" id="0x52AD" multiple="0" minver="3">Accuracy rank for sorting duplicate channels emitting the same data by accuracy. This is a unitless, arbitrary file- and type-local value. Higher values for channels with the same measurement are better, but values are not guaranteed to be consecutive and are not comparable across channels with different unit types.</UIntegerElement>
<StringElement name="ValuePrecision" id="0x52AE" multiple="0" minver="3">Effective precision of the channel payload, if different than implied by the native type resolution. Same format as TimeCodeScale. Mainly useful for time channels, which may be emitted as integer Unix epoch seconds for convenience but with actual precision greater than +/-0.5s.</StringElement>
Expand Down
Loading