JHOP is a Python-based web application designed to help users log their sleep patterns and manage alarms dynamically. It uses FastAPI as the backend framework, SQLite for storing data, and Nix/Poetry for reproducible development and builds.
- Sleep Tracking: Log sleep times with different categories (e.g., "night sleep" or "nap") and store them in a database for future reference.
- Dynamic Alarm Management: Automatically calculates alarm times based on sleep patterns or allows users to set them manually.
- Predefined Defaults:
- A default alarm time of 9:00 AM if insufficient sleep data is provided.
- Expected durations for specific sleep types (e.g., 7 hours for "night").
- Endpoints:
- Log sleep activity (
POST /sleep
). - Retrieve the latest sleep entry (
GET /sleep/latest
). - Manage alarms (
POST
,GET
,DELETE /alarm
).
- Log sleep activity (
- Python 3.12+
- Nix (for reproducible builds and shells)
- Poetry (dependency management)
- Clone the repository:
git clone <repository-url> cd jhop
- Enter the development shell:
nix develop
- Run the application:
poetry run start
- Database Path: Set using the environment variable
JHOP_DB_PATH
(defaults todata/sleeps.db
). - Development Shells:
default
: Installs application and dependencies.poetry
: For working withpyproject.toml
and modifying dependencies.
main.py
: Contains the application logic and endpoints.tests/
: Directory to write and run test cases.pyproject.toml
: Poetry configuration file.flake.nix
: Nix configuration for reproducible builds.
JHOP uses pytest
and pytest-asyncio
for testing. To run tests:
pytest
Contributions are welcome! To get started:
- Fork this repository.
- Create a feature branch (
git checkout -b feature-name
). - Commit changes and submit a pull request.