Cached time string of measurement time stamp
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Anne de Jong 2023-04-03 13:16:39 +02:00
parent bdef0b45f3
commit f1348ede80

View File

@ -52,6 +52,7 @@ import os, time, wave, logging
from .lasp_common import SIQtys, Qty, getFreq from .lasp_common import SIQtys, Qty, getFreq
from .lasp_cpp import Window, DaqChannel, LASP_VERSION_MAJOR, AvPowerSpectra from .lasp_cpp import Window, DaqChannel, LASP_VERSION_MAJOR, AvPowerSpectra
from typing import List from typing import List
from functools import lru_cache
def getSampWidth(dtype): def getSampWidth(dtype):
@ -248,6 +249,9 @@ class Measurement:
except KeyError: except KeyError:
self._sens = np.ones(self.nchannels) self._sens = np.ones(self.nchannels)
# The time is cached AND ALWAYS ASSUMED TO BE AN IMMUTABLE OBJECT.
# It is also cached. Changing the measurement timestamp should not
# be done.
self._time = f.attrs['time'] self._time = f.attrs['time']
# Quantity stored as channel. # Quantity stored as channel.
@ -375,6 +379,7 @@ class Measurement:
self._comment = cmt self._comment = cmt
@property @property
@lru_cache()
def recTime(self): def recTime(self):
"""Returns the total recording time of the measurement, in float """Returns the total recording time of the measurement, in float
seconds.""" seconds."""
@ -385,6 +390,19 @@ class Measurement:
"""Returns the measurement time in seconds since the epoch.""" """Returns the measurement time in seconds since the epoch."""
return self._time return self._time
@property
@lru_cache()
def timestr(self):
"""
Return a properly formatted string of the measurement time, in order of
year-month-day hour etc.
"""
time_struct = time.localtime(self.time)
time_string = time.strftime('%Y-%m-%d %H:%M:%S', time_struct)
return time_string
def rms(self, channels=None, substract_average=False): def rms(self, channels=None, substract_average=False):
"""Returns the root mean square values for each channel """Returns the root mean square values for each channel