diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 4390d5c..76e0d8d 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -11,29 +11,28 @@ on: jobs: build: runs-on: ubuntu-latest - defaults: - run: - shell: bash -el {0} steps: - uses: actions/checkout@v3 - name: Set up Python 3.10 uses: actions/setup-python@v3 with: python-version: "3.10" - - name: Install conda - uses: conda-incubator/setup-miniconda@v3 - with: - activate-environment: WADAS - environment-file: wadas/conda_env_setup.yml - auto-activate-base: false - - run: | - conda info - conda list + - name: Install system dependencies + run: sudo apt-get install -y libmariadb-dev + - name: Create venv and install dependencies + run: | + python -m venv .venv + source .venv/bin/activate + pip install --upgrade pip + pip install -r requirements.txt - name: Login to Hugging Face run: | - hf auth login --token ${{ secrets.WADAS_OFFICIAL_HUGGINGF_AUTH }} --add-to-git-credential + source .venv/bin/activate + pip install huggingface_hub[cli] + huggingface-cli login --token ${{ secrets.WADAS_OFFICIAL_HUGGINGF_AUTH }} - name: Run tests run: | + source .venv/bin/activate python -m pytest test -sv --cov=. --cov-report=html # To enforce minimum coverage, uncomment the following line: # python -m pytest test -sv --cov=. --cov-report=html --cov-fail-under=80 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 70eb360..a030763 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,19 +23,12 @@ repos: rev: v1.0.0 hooks: - id: check-json5 -- repo: https://github.com/PyCQA/flake8 - rev: 7.1.1 - hooks: - - id: flake8 - additional_dependencies: [ - 'flake8-blind-except', - 'flake8-bugbear', - 'flake8-comprehensions', - 'flake8-implicit-str-concat', - 'flake8-logging-format', - 'pydocstyle>=5.0.0', - ] - exclude: ^wadas/ui/.*|demo/.* +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.3.5 + hooks: + - id: ruff + args: [--no-fix] + exclude: ^wadas/ui/.*|demo/.* - repo: https://github.com/pycqa/isort rev: 5.13.2 hooks: diff --git a/requirements.txt b/requirements.txt index 0e4644b..d162fc5 100644 Binary files a/requirements.txt and b/requirements.txt differ diff --git a/wadas/_version.py b/wadas/_version.py index 0cb32e6..f9fc846 100644 --- a/wadas/_version.py +++ b/wadas/_version.py @@ -17,5 +17,5 @@ # Date: 2024-08-14 # Description: module to keep track of WADAS version -__version__ = "v1.0.0.a5" +__version__ = "v1.0.0.a6" __dbversion__ = __version__ diff --git a/wadas/conda_env_setup.yml b/wadas/conda_env_setup.yml index a948f62..f3971ac 100644 --- a/wadas/conda_env_setup.yml +++ b/wadas/conda_env_setup.yml @@ -29,6 +29,7 @@ dependencies: - openssl=3.4.0 - cryptography=42.0.8 - pyopenssl=24.2.1 + - setuptools>=65 - pip: - cv2-enumerate-cameras==1.1.15 - intel-npu-acceleration-library==1.4.0 @@ -42,3 +43,4 @@ dependencies: - wadas-runtime==0.2.6 - opencv-python==4.10.0.84 - shapely==2.0.7 + - setuptools>=65 diff --git a/wadas/domain/actuator.py b/wadas/domain/actuator.py index 163bd0f..a998873 100644 --- a/wadas/domain/actuator.py +++ b/wadas/domain/actuator.py @@ -76,6 +76,8 @@ def from_json(cls, s: str) -> "Command": class ActuatorBatteryStatus: actuator_id: str voltage: float + temperature: float + humidity: float time_stamp: datetime.datetime = field(default_factory=datetime.datetime.now) def to_json(self) -> str: @@ -84,6 +86,8 @@ def to_json(self) -> str: "actuator_id": self.actuator_id, "voltage": self.voltage, "time_stamp": self.time_stamp.isoformat(), + "temperature": self.temperature, + "humidity": self.humidity, } ) diff --git a/wadas/domain/actuator_server_app.py b/wadas/domain/actuator_server_app.py index 33f67a6..95e6d50 100644 --- a/wadas/domain/actuator_server_app.py +++ b/wadas/domain/actuator_server_app.py @@ -193,6 +193,10 @@ async def receive_battery_status(actuator_id: str, payload: dict = Body(...)): if voltage is None: raise HTTPException(status_code=400, detail="Missing 'volt' in payload") + # We accept the possibility that temperature or humidity are null if sensor is not plugged + temperature = payload.get("payload", {}).get("temperature") + humidity = payload.get("payload", {}).get("humidity") + # Timestamp set by server ts = datetime.datetime.now() @@ -201,9 +205,21 @@ async def receive_battery_status(actuator_id: str, payload: dict = Body(...)): actuator_id=actuator_id, voltage=voltage, time_stamp=ts, + temperature=temperature, + humidity=humidity, ) actuator.battery_status = battery_status - logger.info("Received actuator %s battery status: %s", actuator_id, voltage) + + if temperature and humidity: + logger.info( + "Received actuator %s battery status: %s V, temperature: %s °, humidity: %s %%", + actuator_id, + voltage, + temperature, + humidity, + ) + else: + logger.info("Received actuator %s battery status: %s V.", actuator_id, voltage) # Persist in DB if db := DataBase.get_enabled_db(): diff --git a/wadas/domain/database.py b/wadas/domain/database.py index 7c3b9c1..54e96bc 100644 --- a/wadas/domain/database.py +++ b/wadas/domain/database.py @@ -499,6 +499,14 @@ def update_db_version(self): """ ) ) + elif cur_db_version <= "v1.0.0.a5": + DataBase.run_query( + text("ALTER TABLE actuator_battery_status ADD COLUMN temperature FLOAT NULL;") + ) + DataBase.run_query( + text("ALTER TABLE actuator_battery_status ADD COLUMN humidity FLOAT NULL;") + ) + DataBase.run_query(text(f"UPDATE db_metadata SET version='{__dbversion__}';")) logger.info("Database updated from %s to %s", cur_db_version, __dbversion__) except Exception: @@ -950,6 +958,8 @@ def domain_to_orm(domain_object, foreign_key=None): actuator_id=foreign_key[0], time_stamp=domain_object.time_stamp, voltage=domain_object.voltage, + temperature=domain_object.temperature, + humidity=domain_object.humidity, ) elif isinstance(domain_object, ActuatorTemperatureStatus): return ORMActuatorTemperature( diff --git a/wadas/domain/db_model.py b/wadas/domain/db_model.py index 54ddc69..1785af7 100644 --- a/wadas/domain/db_model.py +++ b/wadas/domain/db_model.py @@ -208,6 +208,8 @@ class ActuatorBatteryStatus(Base): actuator_id = Column(Integer, ForeignKey("actuators.id"), primary_key=True, nullable=False) time_stamp = Column(MySQLDATETIME6(timezone=True), primary_key=True, nullable=False) voltage = Column(Float) + temperature = Column(Float, nullable=True) + humidity = Column(Float, nullable=True) class ActuatorTemperatureStatus(Base):