/phone-sensors-ml

Repo for CSE Phone Sensors project group

Primary LanguagePython

Upcycled Phone Sensors: Reusing old smartphones for acoustic monitoring

This repository contains the backend code for the project "Upcycled Phone Sensors". The project aims to reuse old smartphones for acoustic monitoring with BirdNET.

Project Overview

This project aims to provide a solution for reusing old smartphones for acoustic monitoring.

The project consists of two main components:

  1. Android App: An Android app that records audio clips and uploads them to the server for processing.
  2. Server (this repo): A backend server that processes the audio clips using BirdNET and stores the results in a database.

Overview

Technical Overview

This project is developed using the following technologies:

Database Schema

db_schema

Deployment

Prerequisites

Deploy with Docker Compose

  1. Clone the repository:
git clone https://github.com/Microwave-WYB/phone-sensors.git
  1. To deploy with default settings, you do not need any .env files, please mke sure you delete any existing .env files, unless you want to override the default settings.

  2. Start the services using Docker Compose:

docker-compose up -d

This will start all required services. The API server will be available at http://localhost:8000.

Job Management with Redis Queue

This project uses Redis Queue for job management. The job queue is used for processing audio files uploaded by users. By default, the server container will launch one worker process to process jobs from the queue.

To scale the number of worker processes, you can specify the number of worker processes using the PS_NUM_WORKERS environment variable in the .env file. For example, to start 3 worker processes:

PS_NUM_WORKERS=3

To monitor the job queue, you can use the RQ Dashboard hosted at http://localhost:8000/rq.

Development

Prerequisites

Setup

  1. Clone the repository:
git clone https://github.com/Microwave-WYB/phone-sensors.git
  1. Create a virtual environment (Optional):
poetry env use 3.12 # or 3.11
  1. Install the dependencies:
poetry install --no-root

Managing dependencies

This project uses Poetry for dependency management. To add a new dependency, run:

poetry add <package-name>

# or, to add to a specific group
poetry add --dev <package-name>

To remove a dependency, run:

poetry remove <package-name>

You should commit both pyproject.toml and poetry.lock files after making changes to the dependencies.

To bump the release version of the project, run:

poetry version <major|minor|patch>

Debugging the server

To run the server locally, you will still need the database and redis server running. You can start the database and redis server using Docker Compose:

docker-compose up -d db redis pgadmin

Then, create a .env file or copy from .env.example and set the environment variables:

cp .env.example .env

Take a look at the .env file copied, make sure you uncomment the variables under # Development: for local development.

Finally, run the server:

poetry run python main.py

This should start the server at http://localhost:8000. You may specify a different port by setting the PORT environment variable in the .env file.

Before you push any changes:

You must aim to pass all of the following checks before pushing any changes. Failing to do so will result in the CI pipeline failing.

  1. Run the tests:
poetry run pytest
  1. Format the code:
poetry run black phone_sensors
  1. Check for typing:
poetry run pyright phone_sensors
  1. Check for linting:
poetry run pylint --rcfile=pylintrc phone_sensors