Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
"""This module provides classes to store DGILib Logger Interface Data."""
INTERFACE_GPIO)
"""Class to store DGILib Logger Interface Data."""
"""Take tuple of timestamps and values.""" self = args[0] isinstance(args[1], list)): isinstance(args[1], (int, float, list))): else: raise ValueError( f"Samples passed to InterfaceData must be tuple([],[]) or " "timestamps, values or InterfaceData. Got {args}")
"""Append new interface_data (in-place).
Used to provide `interface_data += interface_data1` syntax """ else: interface_data), f"Samples passed to InterfaceData were not " \ "valid_interface_data. {interface_data}" else:
"""Append new interface_data (copy).
Used to provide `interface_data2 = interface_data1 + interface_data` syntax """
"""Append interface_data."""
"""Append a list of interface_data.""" else:
"""Get the number of samples.""" else:
"""Get item.
Used to provide `timestamp, value = interface_data[5]` and `timestamp, value = interface_data[2:5]` syntax """
"""Contains.
Used to provide `([1], [2]) in interface_data` syntax """ item_value == self_value for self_timestamp, self_value in self) for item_timestamp, item_value in ( item if isinstance(item, InterfaceData) else InterfaceData(item)))
"""Print data.
Used to provide `str(data)` syntax. """
end_time=None): """ get_select_in_value.
Use to slice a items in the values when the values are iterables.
Keyword Arguments: begin {int} -- Begin index of item in value (default: {0}) end {[type]} -- End index of item in value, if not supplied only the item the begin index will be returned (default: {None}) start_time {[type]} -- Start time of selection (default: {None}) end_time {[type]} -- End time of selection (default: {None})
Returns: [list] -- List of values that have timestamps between start_time and end_time """
else [value[begin:end] for value in self.values]
start_index = 0 end_index = len(self.timestamps) - 1 # Get the index of the first sample after the start_time if start_time is not None: start_index = self.get_index(start_time) if end_time is not None: end_index = self.get_index(end_time, start_index)
return [value[begin] for value in self.values[start_index:end_index]] \ if end is None else \ [value[begin:end] for value in self.values[start_index:end_index]]
"""Get the index of the first sample after the timestamp."""
"""Class to store DGILib Logger Data."""
# __slots__ = [INTERFACE_GPIO, INTERFACE_POWER]
"""Take list of interfaces for the data.""" # Call init function of dict # No args or kwargs were specified, populate args[0] with standard # interfaces # Args is list of interfaces, make data dict with interfaces as keys # and tuples of lists as values # Instantiate dict with arguments else:
"""Get attribute.
Used to provide `data.spi` syntax. """
"""Set attribute.
Used to provide `data.spi = InterfaceData(([], []))` syntax. """
"""Append new logger_data (in-place).
Used to provide `logger_data1 += logger_data` syntax """ raise ValueError( f"logger_data must be a dict or LoggerData. " "Got {type(logger_data)}")
"""Append new logger_data (copy).
Used to provide `logger_data2 = logger_data1 + logger_data` syntax """
return self
return LoggerData(state)
# def __copy__(self): # return self
"""Append a sample to one of the interfaces."""
"""Append a list of samples to one of the interfaces.""" else:
"""Compute the number of samples for the interfaces.
Return a dict of the number of samples for each interface. Or the length of the `attr` specified. """ for key, interface_data in self.items()} return len(self[INTERFACES[attr]]) else: f"attr must be a named or numbered interface. Got {attr}")
"""Print data.
Used to provide `str(data)` syntax. """ output = "Interfaces:\n" for interface in self.keys(): if interface in INTERFACES.values(): for name, number in INTERFACES.items(): if interface == number: output += f"\t{number:4}: {name + ',':{' '}^{10}} samples: {len(self[interface]):7}\n" break else: output += f"\t{interface:4}: (unknown), samples: {len(self[interface]):7}\n"
return output
# # Load CSV
# # Calculations
"""Check if samples are valid InterfaceData.""" len(samples) == 2 and all(isinstance(sample, (tuple, list, float, int)) for sample in samples) and (isinstance(samples[0], float) or len(samples[0]) == len(samples[1]))) |