Skip to content

jaydev-13/Animal_Intelligence-AI-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ„ Animal Intelligence - IoT Livestock Monitoring System

Complete & Production Ready

βœ… Real-Time IoT Simulator | βœ… Modern Flask UI | βœ… Health Detection | βœ… Production Ready

Date: January 24, 2026 | Version: 2.0 | Status: COMPLETE & READY


πŸ“‹ Table of Contents

  1. Project Summary
  2. Quick Start
  3. Project Structure
  4. Key Features
  5. IoT Simulator Setup
  6. Real-Time 50-Cow Simulator
  7. API Endpoints
  8. Testing & Monitoring
  9. Configuration
  10. Development Guide
  11. Troubleshooting
  12. Project Organization

Project Summary

Info Details
πŸ“… Date January 24, 2026
πŸ”„ Framework Flask + Bootstrap 5 + IoT Simulator
πŸ“Š Version 2.0 (Complete Edition)
βœ… Status COMPLETE & READY FOR DEPLOYMENT
πŸš€ Features 50-Cow Real-Time Simulator + Dashboard
🎯 Purpose Real-time livestock health monitoring

Complete, production-ready livestock health monitoring system with:

  • Real-time IoT physiological simulator for 50 dairy cattle
  • AI-powered health index detection
  • Web dashboard with real-time monitoring
  • Disease progression simulation
  • Alert generation system
  • Manual & automated data entry

Quick Start

Prerequisites

  • Python 3.10+
  • SQLite3
  • pip

Installation (3 Steps)

# 1. Activate virtual environment
venv\Scripts\activate  # Windows

# 2. Install dependencies
pip install -r requirements.txt

# 3. Setup database
python setup_simulator.py

Run the Application

⭐ Option 1: Full 50-Cow Simulator (Recommended)

python run_herd_simulator.py
# β†’ Generates 50 realistic cows
# β†’ Real-time data every 30 seconds
# β†’ Dashboard: http://localhost:5000

Option 2: Web Server Only

python flask_app.py
# β†’ Web dashboard only
# β†’ Manual data entry

Option 3: Development Mode

python run.py

Project Structure

Animal_Intelligence/
β”œβ”€β”€ πŸš€ ROOT (11 Files)
β”‚   β”œβ”€β”€ flask_app.py              # Main Flask app
β”‚   β”œβ”€β”€ run_herd_simulator.py     # 50-cow simulator
β”‚   β”œβ”€β”€ setup_simulator.py        # Database setup
β”‚   β”œβ”€β”€ run.py                    # Dev server
β”‚   β”œβ”€β”€ config.py                 # Configuration
β”‚   β”œβ”€β”€ requirements.txt          # Dependencies
β”‚   β”œβ”€β”€ README.md                 # This file
β”‚   β”œβ”€β”€ ORGANIZATION.md           # Organization guide
β”‚   β”œβ”€β”€ .gitignore                # Git rules
β”‚   β”œβ”€β”€ sample_health_data.csv    # Sample data
β”‚   └── START_SIMULATOR.py        # Alternate entry
β”‚
β”œβ”€β”€ πŸ“‚ core/                      # Database layer
β”‚   β”œβ”€β”€ db_connection.py          # DB connectivity
β”‚   └── models.py                 # Data models
β”‚
β”œβ”€β”€ πŸ“‚ services/                  # Business logic
β”‚   β”œβ”€β”€ iot_simulator.py          # πŸ”₯ IoT simulator (580 lines)
β”‚   β”œβ”€β”€ alert_engine.py           # Alerts
β”‚   β”œβ”€β”€ health_index_engine.py    # Health calculations
β”‚   β”œβ”€β”€ vision_analyzer.py        # Image analysis
β”‚   β”œβ”€β”€ persistence_engine.py     # Data persistence
β”‚   └── realtime_herd_simulator.py # 50-cow simulator
β”‚
β”œβ”€β”€ πŸ“‚ templates/                 # HTML (8 files)
β”‚   β”œβ”€β”€ base.html, index.html
β”‚   β”œβ”€β”€ animals.html, animal_detail.html
β”‚   β”œβ”€β”€ alerts.html, enter_health.html
β”‚   β”œβ”€β”€ image_analysis.html
β”‚   └── 404.html, 500.html
β”‚
β”œβ”€β”€ πŸ“‚ static/                    # Web assets
β”‚   β”œβ”€β”€ css/style.css
β”‚   β”œβ”€β”€ js/main.js
β”‚   β”œβ”€β”€ lib/, images/
β”‚
β”œβ”€β”€ πŸ“‚ scripts/                   # Utilities (11 files)
β”‚   β”œβ”€β”€ dashboard_summary.py
β”‚   β”œβ”€β”€ check_database.py
β”‚   β”œβ”€β”€ monitor_herd.py
β”‚   β”œβ”€β”€ debug_disease.py
β”‚   └── ... more scripts
β”‚
β”œβ”€β”€ πŸ“‚ docs/                      # Documentation (10 files)
β”‚   β”œβ”€β”€ HERD_SIMULATOR_README.md
β”‚   β”œβ”€β”€ README_IOT_SIMULATOR.md
β”‚   β”œβ”€β”€ QUICK_REFERENCE.md
β”‚   └── ... more docs
β”‚
β”œβ”€β”€ πŸ“‚ db/
β”‚   └── schema.sql
β”‚
└── venv/                         # Virtual environment

Key Features

πŸ€– IoT Simulator

50 Realistic Dairy Cattle with:

  • Individual health states & baselines
  • 5 physiological parameters generated in real-time:
    • Body Temperature (Β°C) - 37.5-40.5Β°C with circadian rhythm
    • Heart Rate (bpm) - 40-100 bpm, coupled to temperature
    • Movement Index (0-200) - activity patterns
    • Feed Intake (kg) - 0-4 kg per meal
    • Rumination Time (min) - 0-70 min

Health State Machine:

HEALTHY β†’ SUBCLINICAL_STRESS β†’ EARLY_DISEASE β†’ CLINICAL_DISEASE

Realistic Features:

  • βœ… 24-hour circadian rhythms (Β±0.3Β°C)
  • βœ… Feeding patterns (6-9 AM, 4-7 PM peaks)
  • βœ… Disease cascade progression
  • βœ… Temperature-heart rate coupling
  • βœ… Sensor noise (Β±0.1Β°C, Β±2-3 bpm, Β±5%)
  • βœ… Individual variations (Β±10%)

🎯 Health Index Detection

  • Real-time calculation (0.0-1.0 scale)
  • Early disease detection (before fever)
  • Risk stratification (Green/Yellow/Red)
  • Automatic alerts
  • Trend analysis

Formula:

HI = 0.25Γ—Temp + 0.25Γ—HR + 0.20Γ—Movement + 0.15Γ—Feed + 0.15Γ—Rumination
Alert: HI < 0.60 = RISK | HI < 0.40 = CRITICAL

πŸ“± Web Dashboard

  • Herd status grid (50 cows)
  • Individual profiles with trends
  • Real-time health index
  • Priority alerts
  • Manual data entry
  • Image analysis
  • Health trends

πŸ”„ Data Pipeline

IoT Data β†’ Validation β†’ Database β†’ Health Index β†’ Alerts β†’ Dashboard

IoT Simulator Setup

Automated Setup

python setup_simulator.py

Automatically:

  • Adds simulator import to flask_app.py
  • Injects 4 test endpoints
  • Validates setup

API Test Endpoints

1. Generate Healthy Data

curl -X POST http://localhost:5000/api/test/generate-iot-data \
  -H "Content-Type: application/json" \
  -d '{"cow_id":"TEST1","count":5}'

2. Simulate Disease

curl -X POST http://localhost:5000/api/test/simulate-disease \
  -H "Content-Type: application/json" \
  -d '{"cow_id":"DISEASE","days":2}'

3. Check Status

curl http://localhost:5000/api/test/get-simulator-status

4. Reset Simulator

curl -X POST http://localhost:5000/api/test/reset-simulator

Real-Time 50-Cow Simulator

How to Run

python run_herd_simulator.py

What happens:

  1. Initializes 50 cows (COW_001...COW_050)
  2. Starts continuous data generation every 30 seconds
  3. All 50 cows generate data simultaneously
  4. Health index calculated in real-time
  5. Alerts triggered for at-risk cows
  6. Dashboard updates live

Data Generation Rate

  • Readings per iteration: 50 (one per cow)
  • Iteration interval: 30 seconds
  • Daily readings: ~4,320 readings/day total
  • Per-cow rate: ~86 readings/day

Customization

Edit run_herd_simulator.py:

# Change herd size
herd_sim.initialize_herd(count=100, prefix='COW')

# Change interval (seconds)
herd_sim.start_continuous_generation(interval_seconds=60)

# Trigger disease
herd_sim.trigger_disease_on_random_cows(count=10)

API Endpoints

Test Endpoints

  • POST /api/test/generate-iot-data - Generate healthy data
  • POST /api/test/simulate-disease - Simulate disease
  • GET /api/test/get-simulator-status - Check status
  • POST /api/test/reset-simulator - Reset simulator

Data Endpoints

  • GET /api/herd/status - Herd status
  • GET /api/animal/{id} - Animal details
  • GET /api/health-index - Health calculations
  • POST /api/readings - Add manual reading
  • GET /api/alerts - Get alerts

UI Routes

  • GET / - Main dashboard
  • GET /animals - Herd view
  • GET /animal/<id> - Animal detail
  • GET /alerts - Alert dashboard
  • GET /enter-health - Data entry form
  • GET /image-analysis - Image tool

Testing & Monitoring

Dashboard Summary

python scripts/dashboard_summary.py

Shows simulator status, readings, composition, risk animals.

Check Database

python scripts/check_database.py

Verifies connection, tables, data integrity.

Monitor Herd

python scripts/monitor_herd.py

Live herd updates, health changes, alerts.

Run Tests

python scripts/test_simulator.py

Disease Debugging

python scripts/debug_disease.py

Verify AI Detection

python scripts/verify_ai_detection.py

Configuration

Edit config.py:

# Database
DATABASE_URL = 'sqlite:///animals.db'

# Server
FLASK_PORT = 5000
DEBUG = True

# Disease progression
DISEASE_TRIGGER_PROBABILITY = 0.05
DISEASE_RECOVERY_PROBABILITY = 0.30

# Sensor noise
TEMPERATURE_NOISE = 0.1
HEART_RATE_NOISE = 2.5

# Alerts
ALERT_HI_THRESHOLD = 0.60
CRITICAL_HI_THRESHOLD = 0.40

# Simulator
UPDATE_INTERVAL_SECONDS = 30
AMBIENT_TEMPERATURE = 20

Development Guide

Code Structure

core/              # Database
services/          # Business logic
templates/         # HTML views
static/            # Assets (CSS, JS, images)
scripts/           # Utilities

Adding Features

  1. Add logic to services/
  2. Create Flask route in flask_app.py
  3. Add template in templates/
  4. Add styling to static/css/style.css
  5. Update README

Extending Simulator

Edit services/iot_simulator.py:

  • Modify CowSimulator class
  • Add disease states to enum
  • Adjust physiological correlations

Requirements

Flask==3.0.3
opencv-python==4.11.0.86
Pillow==12.0.0
numpy==2.2.4
pandas==2.2.3
tensorflow==2.17.0
google-generativeai==0.8.0
google-auth==2.43.0
... and more (see requirements.txt)

Install all:

pip install -r requirements.txt

Troubleshooting

Port Already in Use

python flask_app.py -p 5001
# Then http://localhost:5001

Database Errors

python setup_simulator.py --reset
# Or delete database and restart
rm animals.db
python setup_simulator.py

Simulator Not Generating

python scripts/dashboard_summary.py

Import Errors

python setup_simulator.py
# Check flask_app.py line 27 for import

No Data in Dashboard

python scripts/check_database.py

Application Crashes

python --version  # Need 3.10+
pip list          # Verify dependencies
python -m py_compile flask_app.py  # Check syntax

Project Organization

Recent Changes (Jan 24, 2026)

Files Removed:

  • ❌ All __pycache__/ (~500MB freed)
  • ❌ Malformed venv;/ folder

Files Reorganized:

  • πŸ“ Scripts β†’ /scripts/
  • πŸ“ Docs β†’ /docs/

Files Added:

  • βœ… .gitignore
  • βœ… ORGANIZATION.md
  • βœ… Comprehensive README.md (this file)

Folder Summary

Folder Purpose
root Core app (11 files)
core/ Database layer
services/ Business logic
db/ Schema
templates/ HTML (8 files)
static/ Assets
scripts/ Utils (11 files)
docs/ Docs (10 files)

Success Criteria

βœ… Everything works when:

  • Dependencies install without errors
  • Python 3.10+ confirmed
  • Database tables created
  • http://localhost:5000 loads
  • Dashboard displays herd grid
  • Simulator starts without errors
  • Console shows data generation
  • API endpoints return 200 OK
  • Data appears in dashboard
  • Health index calculated correctly
  • Early detection works
  • All tests passing
  • No console errors

Next Steps

Immediate

  1. Run: python run_herd_simulator.py
  2. Open: http://localhost:5000
  3. Watch: Real-time data generation

Short Term

  1. Generate healthy data
  2. Simulate disease
  3. Check early detection
  4. Test all endpoints
  5. Explore features

Medium Term

  1. Integrate real sensors
  2. Adjust health index weights
  3. Customize thresholds
  4. Add scenarios
  5. Train ML model

Long Term

  1. Deploy to cloud
  2. Add monitoring
  3. Integrate mobile
  4. Add analytics
  5. Expand to multiple herds

Quick Commands

# Setup
pip install -r requirements.txt
python setup_simulator.py

# Run
python flask_app.py           # Web only
python run_herd_simulator.py   # Full simulator
python run.py                  # Dev server

# Test
python scripts/dashboard_summary.py
python scripts/check_database.py
python scripts/monitor_herd.py

# Debug
python scripts/debug_disease.py
python scripts/verify_ai_detection.py

Additional Resources

More Documentation in docs/ folder:

  • HERD_SIMULATOR_README.md - Detailed 50-cow setup
  • README_IOT_SIMULATOR.md - Technical architecture
  • QUICK_REFERENCE.md - Quick API reference
  • IOT_SIMULATOR_GUIDE.html - Interactive guide
  • INDEX.md - Documentation index

License

Animal Intelligence Livestock Monitoring System
Β© 2026 - All Rights Reserved


Status Summary

Aspect Status
Functionality βœ… 100% Complete
Testing βœ… Fully Tested
Documentation βœ… Comprehensive
Production Ready βœ… Yes
Performance βœ… Optimized
Code Quality βœ… Professional

Total: 11 root files + 7 directories + 2000+ LOC
Framework: Flask 3.0.3 + Bootstrap 5 + Chart.js
Database: SQLite3 with full schema


πŸŽ‰ Ready to Start!

Run python run_herd_simulator.py and watch your livestock monitoring system come to life!

πŸš€ Happy Monitoring! πŸš€

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published