Skip to content
Snippets Groups Projects
Commit 729b5928 authored by JuanPi Carbajal's avatar JuanPi Carbajal
Browse files

serialui: get many samples form logger

parent ebbb9a64
No related branches found
No related tags found
No related merge requests found
Pipeline #238412 passed
......@@ -160,7 +160,7 @@ def logger_present():
def connect_logger(port=None):
""" Connect the default logger the given serial port name.
""" Connect the default logger to the given serial port name.
The default logger is :obj:`.wbsLogger`.
......@@ -181,6 +181,13 @@ def connect_logger(port=None):
print(f'Connected to {p.description}')
break
def disconnect_logger(port=None):
""" Disconnect the default logger.
The default logger is :obj:`.wbsLogger`.
"""
wbsLogger.close()
# -------------
# Getters
......@@ -732,3 +739,42 @@ def data_clear():
delete_samples = data_clear
""" Alias for :func:`~.data_clear`. """
def get_data_to_pandas(*, from_sample=0, resample=True):
""" Get series of smaples and return a :class:`pandas.DataFrame`
Each sample is retieved using :func:`~.get_sample` on the default logger.
Retrieving many samples can take a long time.
Arguments
---------
from_sample: int
Index of the starting sample. It should be lower than :func:`~.get_sample_count`[1]
resample: bool
Whether the data frame should eb resample to the sampling interval of the
logger, as returned by :func:`~.get_sampling_interval`.
Returns
-------
:class:`pandas.DataFrame`
See also
--------
:func:`~.get_sample`
:func:`~.get_sampling_interval`
"""
n_total = s.get_sample_count()[1]
df = []
for n in range(from_sample, n_total):
df.append(s.get_sample(sample=n)._asdict())
df = pd.DataFrame.from_records(df).set_index('datetime')
if resample:
sampling = s.get_sampling_interval()
s_str = f'{sampling[0]:d}{sampling[1]}'
df = df.rolling(s_str).mean().resample(s_str).mean()
return df
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment