A Python TUI (Terminal User Interface) application for analyzing Polar Loop fitness band data with heart rate graphics, trends, and comprehensive activity statistics. Built with clean architecture principles and modern Python practices.
- Smart Summary View: Clean tabular interface with key metrics
- Heart Rate Zones: Time distribution across different intensity zones
- Activity Overview: Calories, METs, active/sedentary time tracking
- Weekly Comparison: 7-day trend analysis with status indicators
- Device Status: Connected devices, HRV, and system information
- 24-Hour Trend Graphs: Visual heart rate patterns throughout the day
- Zone Distribution Charts: Time spent in Rest, Light, Moderate, Hard, Maximum zones
- Real-time Statistics: Current HR, averages, min/max values
- Hourly Breakdown: Statistics by time periods (Night, Morning, Afternoon, Evening)
- Heart Rate Variability: HRV analysis and trend assessments
- Smart File Tracking: SHA256 hash-based duplicate detection
- Automatic Processing: Only imports new or modified files
- Error Resilience: Failed imports don't block other files
- Import History: Complete audit trail of all data imports
- Force Reimport: Option to manually reprocess specific files
Built following Clean Architecture principles with clear separation of concerns:
- Repository Pattern: Abstracts data access (JSON reading and SQLite persistence)
- Service Layer: Encapsulates business logic for heart rate and statistics analysis
- Facade Pattern: Provides simplified API for complex subsystem operations
- Domain Models: Clean domain entities with Pydantic validation
src/
βββ domain/ # Domain models and value objects
β βββ models.py # HeartRate, Activity, PPI data models
β βββ value_objects.py # Heart rate zones, time ranges
βββ repository/ # Data access layer
β βββ base.py # Abstract repository interfaces
β βββ json_repository.py # JSON file readers
β βββ sqlite_repository.py # SQLite persistence
β βββ file_import_repository.py # Import tracking
βββ service/ # Business logic layer
β βββ data_import_service.py # Data import & transformation
β βββ heart_rate_service.py # HR analysis & trends
β βββ statistics_service.py # Metrics calculation
βββ infrastructure/ # Database & configuration
β βββ database.py # SQLite schema & connection
β βββ config.py # Application configuration
βββ presentation/ # TUI layer
β βββ app.py # Main application
β βββ views/ # Dashboard, heart rate views
β βββ components/ # Reusable UI components
βββ facade.py # Simplified API facade
βββ main.py # Application entry point
- Python 3.9 or higher
- Poetry (recommended) or pip
- Install Poetry:
curl -sSL https://install.python-poetry.org | python3 -
- Clone and install:
git clone <repository-url>
cd polar_loop
poetry install
pip install -r requirements.txt # If requirements.txt exists
# Or install dependencies manually:
pip install textual rich plotext sqlalchemy pydantic
- Log into your Polar Flow account
- Export your data as JSON files
- Place all
.json
files in theloop_data/
directory
# Using Poetry
poetry run polar-analyzer
# Or directly
poetry run python -m src.main
# Using pip
python -m src.main
- Dashboard Tab: Overview and summary tables
- Heart Rate Tab: Detailed graphs and analysis
- Activity Tab: Activity-specific metrics (future enhancement)
- Settings Tab: Device and configuration information
Key | Action |
---|---|
q |
Quit application |
r |
Refresh dashboard & check for new files |
d |
Toggle dark/light mode |
Tab |
Switch between tabs |
Shift+Tab |
Switch tabs in reverse |
- Detection: Scans
loop_data/
for JSON files - Validation: Calculates SHA256 hashes to detect changes
- Processing: Parses JSON into validated domain models
- Storage: Persists data to normalized SQLite tables
- Analysis: Services provide insights via repository queries
247ohr_*.json
- Heart rate dataactivity-*.json
- Activity and METs datappi_samples_*.json
- Heart rate variability dataproducts-devices*.json
- Device information- Other Polar Flow export files
- β Smart Detection: Only new/modified files are processed
- β Fast Startup: Subsequent runs skip existing data
- β
Live Updates: Press
r
to check for new files - β Error Recovery: Failed imports don't affect other files
# Format code
poetry run black src/
# Type checking
poetry run mypy src/
# Linting
poetry run ruff check src/
# Run tests
poetry run pytest
# Coverage
poetry run pytest --cov=src/
- Python 3.9+: Modern Python features
- Type Hints: Full type annotation coverage
- Clean Architecture: Domain-driven design
- SOLID Principles: Single responsibility, dependency inversion
- Error Handling: Comprehensive exception management
- textual
^0.47.0
- Modern TUI framework - rich
^13.7.0
- Terminal formatting and styling - plotext
^5.2.8
- Terminal plotting library - sqlalchemy
^2.0.23
- Database ORM - pydantic
^2.5.0
- Data validation and models
- pytest
^7.4.3
- Testing framework - black
^23.11.0
- Code formatter - mypy
^1.7.0
- Static type checker - ruff
^0.1.6
- Fast Python linter
We welcome contributions from the community! Whether you're interested in adding new features, fixing bugs, improving documentation, or enhancing the user experience, your help is appreciated.
- π Report Bugs: Found an issue? Create a detailed bug report
- π‘ Suggest Features: Have ideas for new functionality? Open a feature request
- π Improve Documentation: Help make the docs clearer and more comprehensive
- π§ͺ Add Tests: Improve test coverage and reliability
- π¨ Enhance UI/UX: Make the terminal interface more intuitive
- ποΈ Architecture: Help refine the clean architecture implementation
- π Analytics: Add new metrics and visualization capabilities
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature
- Make your changes: Follow the coding standards and architecture patterns
- Add tests: Ensure your changes are well-tested
- Update documentation: Keep docs current with your changes
- Submit a pull request: Describe your changes and their benefits
# Clone your fork
git clone https://github.com/neatnettech/polar-loop-analyzer.git
cd polar-loop-analyzer
# Set up development environment
poetry install --with dev
# Run tests to ensure everything works
poetry run pytest
# Start coding! π
- Follow PEP 8 guidelines
- Use type hints throughout
- Write docstrings for public methods
- Maintain clean architecture patterns
- Add unit tests for new functionality
- π¬ Discussions: Share ideas and ask questions in GitHub Discussions
- π Issues: Report bugs or request features via GitHub Issues
- π§ Contact: Reach out to maintainers for collaboration opportunities
- β Star the Repo: Show your support and help others discover the project
Together, let's build the best Polar Loop data analysis tool for the fitness community! πββοΈβ€οΈπ