Bugfix in measurementset
This commit is contained in:
parent
6d5899c880
commit
fd8366c362
@ -91,6 +91,15 @@ class MeasurementType(Enum):
|
|||||||
# Measurement serves as impedance tube calibration (long tube case)
|
# Measurement serves as impedance tube calibration (long tube case)
|
||||||
muZCalLong = 1 << 3
|
muZCalLong = 1 << 3
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
match self:
|
||||||
|
case MeasurementType.NotSpecific: return '-'
|
||||||
|
case MeasurementType.ILReference: return 'Insertion loss reference'
|
||||||
|
case MeasurementType.CALGeneral: return 'General calibration'
|
||||||
|
case MeasurementType.muZCalShort: return 'ASCEE μZ short length calibration'
|
||||||
|
case MeasurementType.muZCalLong: return 'ASCEE μZ long length calibration'
|
||||||
|
case _: raise ValueError("Not a MeasurementType")
|
||||||
|
|
||||||
|
|
||||||
def getSampWidth(dtype):
|
def getSampWidth(dtype):
|
||||||
"""Returns the width of a single sample in **bytes**.
|
"""Returns the width of a single sample in **bytes**.
|
||||||
|
@ -4,8 +4,9 @@ on a group of measurements at the same time.
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
__all__ = ['MeasurementSet']
|
__all__ = ['MeasurementSet']
|
||||||
from .lasp_measurement import Measurement
|
from .lasp_measurement import Measurement, MeasurementType
|
||||||
from typing import List
|
from typing import List
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
class MeasurementSet(list):
|
class MeasurementSet(list):
|
||||||
@ -14,7 +15,8 @@ class MeasurementSet(list):
|
|||||||
is used to operate on multiple measurements at once.
|
is used to operate on multiple measurements at once.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def __init__(self, mlist: List[Measurement] =[]):
|
|
||||||
|
def __init__(self, mlist: List[Measurement]=[]):
|
||||||
"""
|
"""
|
||||||
Initialize a measurement set
|
Initialize a measurement set
|
||||||
|
|
||||||
@ -27,6 +29,48 @@ class MeasurementSet(list):
|
|||||||
|
|
||||||
super().__init__(mlist)
|
super().__init__(mlist)
|
||||||
|
|
||||||
|
def getNewestReferenceMeasurement(self, mtype: MeasurementType):
|
||||||
|
"""Return the newest (in time) measurement in the current list of a certain type. Returns None in case no measurement could be found.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
mtype (MeasurementType): The type required.
|
||||||
|
"""
|
||||||
|
mnewest = None
|
||||||
|
for m in self:
|
||||||
|
if m.measurementType() == mtype:
|
||||||
|
if mnewest is None:
|
||||||
|
mnewest = m
|
||||||
|
else:
|
||||||
|
if mnewest.time < m.time:
|
||||||
|
mnewest = m
|
||||||
|
return mnewest
|
||||||
|
|
||||||
|
def getNewestReferenceMeasurements(self):
|
||||||
|
"""Returns a dictionary with newest measurement of each type that is not specific returns None in case no measurement is found."""
|
||||||
|
newest = {}
|
||||||
|
for m in self:
|
||||||
|
mtype = m.measurementType()
|
||||||
|
if mtype == MeasurementType.NotSpecific:
|
||||||
|
continue
|
||||||
|
if not mtype in newest:
|
||||||
|
newest[mtype] = m
|
||||||
|
else:
|
||||||
|
if m.time > newest[mtype].time:
|
||||||
|
newest[mtype] = m
|
||||||
|
return newest
|
||||||
|
|
||||||
|
def newestReferenceOlderThan(self, secs):
|
||||||
|
"""Returns a dictionary of references with the newest reference, that is still
|
||||||
|
older than `secs` seconds. """
|
||||||
|
curtime = time.time()
|
||||||
|
newest = self.getNewestReferenceMeasurements()
|
||||||
|
newest_older_than = {}
|
||||||
|
for key, m in newest.items():
|
||||||
|
if curtime - m.time >= secs:
|
||||||
|
newest_older_than[key] = m
|
||||||
|
return newest_older_than
|
||||||
|
|
||||||
|
|
||||||
def measTimeSame(self):
|
def measTimeSame(self):
|
||||||
"""
|
"""
|
||||||
Returns True if all measurements have the same measurement
|
Returns True if all measurements have the same measurement
|
||||||
@ -50,7 +94,6 @@ class MeasurementSet(list):
|
|||||||
"""
|
"""
|
||||||
return self.measTimeSame() and self.measChannelsSame()
|
return self.measTimeSame() and self.measChannelsSame()
|
||||||
|
|
||||||
|
|
||||||
def measChannelsSame(self):
|
def measChannelsSame(self):
|
||||||
"""
|
"""
|
||||||
This method is used to check whether a set of measurements can be
|
This method is used to check whether a set of measurements can be
|
||||||
|
Loading…
Reference in New Issue
Block a user