This repository contains the backend code for the project "Upcycled Phone Sensors". The project aims to reuse old smartphones for acoustic monitoring with BirdNET.
This project aims to provide a solution for reusing old smartphones for acoustic monitoring.
The project consists of two main components:
- Android App: An Android app that records audio clips and uploads them to the server for processing.
- Server (this repo): A backend server that processes the audio clips using BirdNET and stores the results in a database.
This project is developed using the following technologies:
- Web Framework: FastAPI
- Database: PostgreSQL with PostGIS extension for geospatial data
- ORM: SQLModel for defining the database schema and integrating with FastAPI
- Containerization: Docker and Docker Compose for deployment
- Clone the repository:
git clone https://github.com/Microwave-WYB/phone-sensors.git
-
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. -
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
.
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
.
- Docker
- Docker Compose
- Python >= 3.11 (3.12 recommended)
- Poetry for dependency management
- Clone the repository:
git clone https://github.com/Microwave-WYB/phone-sensors.git
- Create a virtual environment (Optional):
poetry env use 3.12 # or 3.11
- Install the dependencies:
poetry install --no-root
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>
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.
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.
- Run the tests:
poetry run pytest
- Format the code:
poetry run black phone_sensors
- Check for typing:
poetry run pyright phone_sensors
- Check for linting:
poetry run pylint --rcfile=pylintrc phone_sensors