Skip to content

YukihiroSM/islobbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

68 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ‹οΈβ€β™‚οΈ ISLOB Bot

A Telegram fitness tracking and coaching bot that helps users monitor their training, sleep, stress levels, and overall well-being.

πŸ“‹ Overview

ISLOB Bot is a comprehensive fitness tracking solution that interacts with users through Telegram. The bot collects data about users' training sessions, sleep patterns, stress levels, and general well-being through regular check-ins and quizzes. It provides personalized statistics, visualizations, and insights to help users optimize their fitness journey.

✨ Features

  • πŸŒ… Morning Quizzes: Daily check-ins to track sleep quality, weight, and overall feelings
  • πŸ’ͺ Training Tracking: Log training sessions with details on duration, intensity, and discomfort
  • πŸ“Š Post-Training Feedback: Collect data on stress and soreness after workouts
  • πŸ”” Automated Notifications: Customizable reminders for morning check-ins and training sessions
  • πŸ“ˆ Statistics Visualization: Visual representation of sleep patterns, stress levels, and training intensity
  • 🧠 AI-Powered Insights: Utilizes OpenAI's GPT models to analyze fitness data and provide personalized recommendations

πŸ› οΈ Tech Stack

  • 🐍 Backend: Python with SQLAlchemy ORM
  • πŸ—„οΈ Database: PostgreSQL
  • πŸ€– Bot Framework: python-telegram-bot
  • πŸ“Š Data Visualization: Matplotlib, Seaborn, Pandas
  • 🧠 AI Integration: OpenAI API (GPT models)
  • ⏱️ Scheduling: APScheduler
  • πŸ”„ Database Migrations: Alembic

πŸš€ Installation

πŸ“‹ Prerequisites

  • Python 3.8+
  • PostgreSQL
  • Telegram Bot Token (from BotFather)
  • OpenAI API Key

βš™οΈ Setup

  1. Clone the repository:

    git clone https://github.com/YukihiroSM/islobbot.git
    cd islobbot
    
  2. Create a virtual environment and install dependencies:

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    pip install -r requirements.txt
    
  3. Create a .env file in the project root with the following variables:

    TOKEN=your_telegram_bot_token
    DATABASE_URL=postgresql://username:password@localhost/islobbot
    ADMIN_CHAT_IDS=["your_telegram_chat_id"]
    OPENAI_API_KEY=your_openai_api_key
    OPENAI_ASSISTANT_ID=your_openai_assistant_id
    
  4. Initialize the database:

    python init_db.py
    
  5. Run the bot:

    python main.py
    

πŸ—ƒοΈ Database Schema

The database consists of several main tables:

  • πŸ‘€ Users: Stores user information and preferences
  • πŸ”” NotificationPreference: Manages notification settings for each user
  • πŸ‹οΈβ€β™‚οΈ Training: Records training sessions with details
  • πŸŒ… MorningQuiz: Stores daily check-in data

πŸ’¬ Conversations Flow

The bot implements several conversation flows:

1. Introduction Conversation

  • 🎯 Purpose: Onboards new users and collects initial information
  • πŸ”„ Flow:
    • Starts with the /start command
    • Collects the user's full name
    • Asks for preferred morning notification time
    • Sets up morning notification preferences
    • Directs user to the main menu

2. Morning Quiz Conversation

  • 🎯 Purpose: Daily check-in for sleep, weight, and well-being
  • πŸ”„ Flow:
    • Triggered by a scheduled morning notification
    • Asks how the user feels (1-10 scale)
    • Collects sleep duration (hours:minutes)
    • Records user's current weight
    • Asks if the user plans to train today
    • If yes, collects expected training time
    • Creates training notifications if needed
    • Saves all data to the database

3. Training Start Conversation

  • 🎯 Purpose: Initiates a training session
  • πŸ”„ Flow:
    • Triggered when user selects "Start Training"
    • Asks for pre-training feeling (1-10 scale)
    • Records training start time
    • Sends training PDF document (personalized or default)
    • Updates notification statuses
    • Provides "End Training" button

4. Training Finish Conversation

  • 🎯 Purpose: Completes a training session and collects feedback
  • πŸ”„ Flow:
    • Triggered when user selects "End Training"
    • Asks for training hardness rating (1-10 scale)
    • Asks if user experienced any pain/discomfort
    • If yes, notifies admin users about the issue
    • Records training duration and end time
    • Updates notification statuses
    • Displays motivational message
    • Returns to main menu

5. After Training Conversation

  • 🎯 Purpose: Follow-up on stress and soreness levels after training
  • πŸ”„ Flow:
    • Triggered by scheduled notification the day after training
    • Asks for stress level (1-10 scale)
    • Asks if user is experiencing muscle soreness
    • Records responses in the database
    • Returns to main menu

6. PDF Assignment Conversation

  • 🎯 Purpose: Allows admins to assign training PDF documents to users
  • πŸ”„ Flow:
    • Triggered when admin selects "Training PDF"
    • Displays list of users
    • Admin selects a user
    • Admin uploads PDF document
    • System assigns PDF to selected user
    • Notifies user about new training document
    • Returns to main menu

πŸ“Š Statistics Visualization

The statistics system generates visualizations with the following characteristics:

  • πŸ“Š Sleep data is displayed as a bar chart
  • πŸ“ˆ Stress, hardness, and feelings are displayed as line plots
  • πŸ“… All plots use day.month (DD.MM) format for x-axis labels

πŸ“Š Data Collection and Analysis

The statistics system collects and analyzes several types of user data:

  • 😴 Sleep Duration: Tracked daily through morning quizzes
  • 😊 Feelings/Well-being: Self-reported ratings on a 1-10 scale
  • πŸ’ͺ Training Hardness: User-reported difficulty of each workout
  • πŸ˜“ Stress Levels: Post-training stress measurements
  • πŸ”΄ Muscle Soreness: Tracked after training sessions (marked with X on hardness plots)

πŸ“Š Visualization Components

The system generates a comprehensive visualization with four main components arranged in a 2x2 grid:

  1. 😴 Sleep Chart (Bottom Left): Bar chart displaying sleep duration in hours for each day
  2. πŸ˜“ Stress Chart (Top Left): Line plot showing stress levels over time
  3. πŸ’ͺ Training Hardness Chart (Top Right): Line plot with special X markers for sessions that caused muscle soreness
  4. 😊 Feelings Chart (Bottom Right): Line plot tracking overall well-being

All charts use a consistent date format (DD.MM) on the x-axis for easy readability, and the system employs a clean, whitegrid theme with pastel colors for improved visual aesthetics.

⏱️ Time Periods

Statistics can be generated for different time periods:

  • πŸ“… Weekly: Data from the past 7 days
  • πŸ“† Monthly: Data from the past 28 days

🧠 AI-Powered Insights

The statistics system leverages OpenAI's Assistant API to analyze the collected data and provide personalized insights about:

  • πŸ‹οΈβ€β™‚οΈ Training patterns and their effectiveness
  • 😴 Sleep quality and its impact on performance
  • πŸ˜“ Stress levels and recovery patterns
  • πŸ“ˆ Overall fitness progress and trends

These AI-generated insights are presented alongside the statistical visualizations to provide users with a comprehensive understanding of their fitness journey.

βš™οΈ Technical Implementation

The visualization system is built using:

  • 🐼 Pandas: For data manipulation and analysis
  • πŸ“Š Matplotlib: For creating the visualization framework and grid layout
  • 🎨 Seaborn: For enhanced visual aesthetics with a pastel color palette
  • 🧠 OpenAI API: For AI-powered analysis of fitness data

The system follows a consistent visual style with a clean, whitegrid theme and pastel colors for improved readability and user experience. The implementation specifically uses bar charts for sleep data visualization while maintaining line plots for other metrics, as per the project's design preferences.

🧠 AI Integration

The system leverages an existing OpenAI Assistant for analyzing fitness metrics. This integration requires:

  1. πŸ€– Assistant Setup: An OpenAI Assistant must be configured specifically for fitness data analysis with the following capabilities:

    • Understanding training patterns and their impact on user well-being
    • Analyzing sleep quality and its correlation with training performance
    • Monitoring stress levels and suggesting recovery strategies
    • Tracking overall progress and providing motivational feedback
  2. βš™οΈ Environment Configuration: The Assistant ID must be configured in the .env file:

    OPENAI_ASSISTANT_ID=your_openai_assistant_id
    
  3. πŸ”„ Data Processing Overview: The system collects user data from morning quizzes and training sessions, which is then used to generate personalized insights and recommendations.

🌟 Benefits of AI Integration

  • 🎯 Personalized Insights: The AI analyzes individual patterns that might not be obvious from charts alone
  • πŸ”„ Holistic Analysis: Considers the relationship between different metrics (sleep, stress, training intensity)
  • πŸ’‘ Actionable Recommendations: Provides specific suggestions to improve training outcomes
  • πŸš€ Motivational Support: Offers encouragement based on progress and achievements

To use this feature, you must configure an OpenAI Assistant and set the OPENAI_ASSISTANT_ID in your .env file.

πŸš€ Deployment

The project includes Docker configuration for easy deployment:

  1. Build and run with Docker Compose:
    docker-compose up -d
    

This will start the bot and PostgreSQL database in containers.

πŸ‘¨β€πŸ’» Development

πŸ”„ Database Migrations

The project uses Alembic for database migrations:

# Create a new migration
alembic revision --autogenerate -m "description"

# Apply migrations
alembic upgrade head

πŸ“ Code Style

The project follows PEP 8 style guidelines. You can format your code using Black:

black .

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors