Better logging and added BHI160 sensor

This commit is contained in:
dario
2024-01-13 22:54:13 +01:00
parent 4def93041e
commit 29db73ccd4
6 changed files with 44 additions and 16 deletions

View File

@@ -1,7 +1,7 @@
import numpy as np
import pandas as pd
from typing import Any, Tuple
from typing import Any, Tuple, List
from numpy.typing import ArrayLike
from abc import abstractmethod
@@ -56,7 +56,7 @@ class Logger(Advanceable):
def _on_reset(self):
self.__df = pd.DataFrame.from_dict({'time': [self.get_time()]}).astype(np.float64)
def write(self, attrib: str, value: Any, domain: str = 'all'):
def write(self, attrib: str | List[str], value: Any | List[Any] | List[ArrayLike], domain: str = 'all'):
"""Writes a value to the logger.
Args:
@@ -64,12 +64,16 @@ class Logger(Advanceable):
value (Any): The value to log.
domain (str, optional): The domain the value belongs to. Defaults to 'any'.
"""
name = f'{domain}/{attrib}'
if not isinstance(attrib, str):
for attr, val in zip(attrib, value):
self.write(attr, val, domain=domain)
else:
name = f'{domain}/{attrib}'
if name not in self.__df.columns:
self.__df[name] = pd.Series([pd.NA] * len(self.__df))
if name not in self.__df.columns:
self.__df[name] = pd.Series([pd.NA] * len(self.__df))
self.__df.at[self.__idx, name] = value
self.__df.at[self.__idx, name] = value
def get_dataframe(self) -> pd.DataFrame:
return self.__df