CoolFace
Apppublic

oscarzhang/health-timeseries-story-generator

sourceHugging Faceupdated 9mo agoView on Hugging Face
1likes
App README

๐ŸŒŸ Health Data Story Visualization System

Transform abstract health metrics into vivid, interactive stories that reveal the hidden patterns of human wellness.

ไธญๆ–‡็‰ˆ README | English README


๐ŸŽฏ Why This Project Matters

The Problem: Health data is often abstract, fragmented, and hard to understand. Researchers, developers, and healthcare professionals struggle to:

  • โ€”Visualize how health metrics change throughout a day
  • โ€”Test anomaly detection algorithms with realistic scenarios
  • โ€”Understand how data collection frequency affects detection accuracy
  • โ€”Demonstrate health insights to non-technical audiences

Our Solution: An AI-powered visualization system that generates realistic 24-hour health stories, complete with physiological data, visual scenes, and anomaly simulations. It's not just a toolโ€”it's a research platform for advancing wearable health technology.


โœจ What Makes This Special

๐Ÿงฌ Realistic Health Data Generation

  • โ€”Algorithmically generates 10 core health metrics (HR, HRV, RHR, RR, BT, Steps, Calories, SD, DSR, SL)
  • โ€”Based on scientifically-grounded models of human physiology
  • โ€”Supports custom user profiles (age, gender, activity level)

๐ŸŽจ AI-Powered Story Generation

  • โ€”Generate personalized 24-hour activity stories using AI
  • โ€”Support multiple themes (e.g., "A Chef's Day", "A Doctor's Shift", "A Thief's Day")
  • โ€”Multi-language support (English & Chinese)
  • โ€”Each story segment includes detailed activity descriptions and visual characteristics

๐Ÿ–ผ๏ธ Dynamic Scene Visualization

  • โ€”AI-generated images for each activity scene
  • โ€”Supports multiple AI providers (Google Gemini, 302.ai)
  • โ€”Default images for common scenarios
  • โ€”Real-time scene switching based on story timeline

๐Ÿ“Š Interactive Data Exploration

  • โ€”Real-time health metric visualization with adjustable sampling rates
  • โ€”Test how different collection frequencies affect anomaly detection
  • โ€”Discover the critical relationship between data granularity and health insights

โš ๏ธ Anomaly Simulation & Testing

  • โ€”Pre-defined anomaly types (M1: Severe Fatigue, M2: Heart Rate Abnormality, M3: Sleep Deprivation, S1: Persistent Stress, S2: Exercise Recovery, S3: Potential Infection)
  • โ€”One-click anomaly injection into stories
  • โ€”Validate detection algorithms with realistic scenarios
  • โ€”Understand the impact of sampling frequency on anomaly detection

๐Ÿ”ฌ Research Applications

For Researchers

  • โ€”Algorithm Validation: Test anomaly detection algorithms with controlled scenarios
  • โ€”Parameter Optimization: Find optimal data collection frequencies for different health conditions
  • โ€”Clinical Studies: Simulate patient scenarios for research and training
  • โ€”Dataset Generation: Generate synthetic health time series datasets for machine learning model training

For Developers

  • โ€”Product Development: Prototype health monitoring features
  • โ€”Quality Assurance: Test edge cases and rare scenarios
  • โ€”User Education: Create engaging demos for stakeholders
  • โ€”ML/DL Training Data: Create labeled datasets for health prediction models

For Healthcare Professionals

  • โ€”Patient Education: Visualize health data in an intuitive way
  • โ€”Training: Practice interpreting health metrics in various scenarios
  • โ€”Consultation: Demonstrate health insights to patients

๐Ÿ“Š Dataset Generation for Health Time Series Models

๐ŸŽฏ The Challenge: Data Scarcity in Health ML

Training machine learning models for health time series analysis faces a critical challenge: real-world health data is scarce, expensive to collect, and often lacks ground truth labels. This project addresses this gap by generating high-quality, labeled synthetic health datasets.

โœจ What You Can Generate

1. Normal Health Time Series Datasets
  • โ€”Multi-metric sequences: Generate 24-hour sequences with 10 synchronized health metrics
  • โ€”Diverse profiles: Create datasets for different age groups, genders, and activity levels
  • โ€”Realistic patterns: Data follows physiological models (circadian rhythms, activity-response curves)
  • โ€”Multiple scenarios: Generate data for various lifestyles (office workers, athletes, students, etc.)
  • โ€”Export formats: CSV, JSON for easy integration with ML frameworks (PyTorch, TensorFlow, scikit-learn)

Example Use Cases:

  • โ€”Train baseline models for normal health pattern recognition
  • โ€”Create reference datasets for anomaly detection
  • โ€”Generate training data for activity classification models
2. Anomaly Detection Datasets
  • โ€”Labeled anomalies: Each data point tagged with anomaly type and severity
  • โ€”6 anomaly types: M1 (Fatigue), M2 (HR Abnormality), M3 (Sleep Deprivation), S1 (Stress), S2 (Recovery), S3 (Infection)
  • โ€”Controlled injection: Precisely control when, where, and how anomalies occur
  • โ€”Ground truth labels: Know exactly which time periods contain anomalies
  • โ€”Multiple severity levels: Generate mild, moderate, and severe anomaly cases

Example Use Cases:

  • โ€”Train supervised anomaly detection models
  • โ€”Benchmark anomaly detection algorithms
  • โ€”Create evaluation datasets with known ground truth
  • โ€”Test model sensitivity to different anomaly types
3. Sampling Frequency Variants
  • โ€”Same story, different frequencies: Generate the same scenario at 5-min, 10-min, 30-min, 1-hour intervals
  • โ€”Impact analysis: Study how sampling frequency affects model performance
  • โ€”Real-world simulation: Mimic different wearable device capabilities
  • โ€”Missing data patterns: Simulate realistic data gaps and missing values

Example Use Cases:

  • โ€”Optimize data collection strategies
  • โ€”Test model robustness to different sampling rates
  • โ€”Simulate battery-constrained scenarios
  • โ€”Research trade-offs between data quality and device lifetime
4. Multi-Day Sequences
  • โ€”Extended timelines: Generate 7-30 day sequences (planned feature)
  • โ€”Long-term patterns: Capture weekly rhythms and trends
  • โ€”Progressive anomalies: Simulate conditions that develop over days
  • โ€”Baseline establishment: Generate sufficient data for baseline calculation

Example Use Cases:

  • โ€”Train models for long-term health trend prediction
  • โ€”Study recovery patterns after anomalies
  • โ€”Research circadian rhythm variations
  • โ€”Develop personalized health baselines

๐Ÿ“ˆ Dataset Characteristics

Data Structure
{
  "timestamp": "2025-01-15T14:30:00Z",
  "user_profile": {
    "age": 28,
    "gender": "MALE",
    "activity_level": "MED"
  },
  "metrics": {
    "HR": 72,           // bpm
    "HRV": 45,          // ms
    "RHR": 65,          // bpm (daily)
    "RR": 16,           // brpm
    "BT": 36.5,         // ยฐC
    "Steps": 8500,      // steps
    "Calories": 450,    // kcal
    "SD": 480,          // minutes (daily)
    "DSR": 15,          // % (daily)
    "SL": 12            // minutes (daily)
  },
  "activity": {
    "sceneId": "OFFICE",
    "activityType": "Working",
    "intensity": "LOW",
    "startTime": "09:00",
    "endTime": "18:00"
  },
  "anomaly": {
    "type": null,       // or "M1", "M2", etc.
    "severity": null,   // or "MILD", "MODERATE", "SEVERE"
    "start_time": null,
    "end_time": null
  }
}
Dataset Sizes
  • โ€”Single day: ~1,440 data points (1-minute resolution) or ~144 points (10-minute resolution)
  • โ€”7 days: ~10,080 data points (1-minute) or ~1,008 points (10-minute)
  • โ€”30 days: ~43,200 data points (1-minute) or ~4,320 points (10-minute)
  • โ€”With anomalies: Configurable anomaly injection rates (e.g., 5%, 10%, 20% of time periods)

๐Ÿ”ง How to Generate Datasets

Step 1: Create Stories
javascript
// Generate multiple stories with different profiles
const stories = [
  generateStory({ age: 25, gender: 'MALE', activity: 'HIGH' }),
  generateStory({ age: 35, gender: 'FEMALE', activity: 'MED' }),
  generateStory({ age: 45, gender: 'MALE', activity: 'LOW' }),
  // ... more variations
];
Step 2: Inject Anomalies (Optional)
javascript
// Inject different anomaly types
stories.forEach(story => {
  injectAnomaly(story, {
    type: 'M2',           // Heart rate abnormality
    startTime: '14:00',
    duration: 60,        // minutes
    severity: 'MODERATE'
  });
});
Step 3: Export Data
javascript
// Export to CSV/JSON
exportToCSV(stories, {
  samplingRate: '10min',  // or '5min', '30min', '1hour'
  includeLabels: true,    // include anomaly labels
  format: 'long'          // or 'wide' format
});

๐ŸŽ“ Research Applications

For ML Researchers
  • โ€”Model Training: Generate large-scale datasets for deep learning models (LSTM, Transformer, CNN)
  • โ€”Data Augmentation: Create synthetic data to augment small real-world datasets
  • โ€”Transfer Learning: Generate source domain data for domain adaptation
  • โ€”Few-Shot Learning: Create support sets for meta-learning approaches
For Health AI Developers
  • โ€”Algorithm Benchmarking: Standardized datasets for comparing detection algorithms
  • โ€”A/B Testing: Generate controlled scenarios for testing model improvements
  • โ€”Edge Case Testing: Create rare but critical scenarios (e.g., sudden cardiac events)
  • โ€”Privacy-Preserving Research: Use synthetic data instead of sensitive real patient data
For Data Scientists
  • โ€”Feature Engineering: Explore relationships between metrics in controlled settings
  • โ€”Model Validation: Test models on known ground truth before deploying on real data
  • โ€”Sampling Strategy Research: Optimize data collection frequency for cost-effectiveness
  • โ€”Anomaly Detection Research: Study detection algorithms with labeled anomalies

๐Ÿ“Š Example Research Questions You Can Answer

  1. 1."What's the minimum sampling frequency needed to detect a 60-minute tachycardia?"
  2. 2.Generate M2 anomalies at different sampling rates
  3. 3.Test detection accuracy
  4. 4.Find the optimal trade-off
  1. 1."How does model performance change with different anomaly severities?"
  2. 2.Generate datasets with mild, moderate, severe anomalies
  3. 3.Train models on each
  4. 4.Compare F1-scores, precision, recall
  1. 1."Can we detect exercise recovery patterns with 30-minute sampling?"
  2. 2.Generate S2 anomalies
  3. 3.Create datasets at 5-min, 10-min, 30-min intervals
  4. 4.Evaluate model performance at each frequency
  1. 1."What's the best architecture for multi-metric health anomaly detection?"
  2. 2.Generate labeled datasets with multiple anomaly types
  3. 3.Train different architectures (LSTM, Transformer, CNN)
  4. 4.Compare performance

๐Ÿš€ Future Dataset Features

  • โ€”[ ] Multi-day sequences (7-30 days) for long-term pattern learning
  • โ€”[ ] Batch generation API for large-scale dataset creation
  • โ€”[ ] Custom anomaly definitions via configuration files
  • โ€”[ ] Noise injection to simulate sensor errors
  • โ€”[ ] Missing data patterns to test robustness
  • โ€”[ ] Temporal alignment for multi-user datasets
  • โ€”[ ] Pre-computed datasets for common research scenarios

๐Ÿš€ Key Features

1. Intelligent Story Generation

  • โ€”AI creates realistic 24-hour activity sequences
  • โ€”Each story includes:
  • โ€”Time-stamped activity segments
  • โ€”Activity types and intensities
  • โ€”Scene classifications (20+ scene types)
  • โ€”Multi-language descriptions

2. Physiological Data Modeling

  • โ€”Heart Rate (HR): 40-200 bpm, varies by activity intensity
  • โ€”Heart Rate Variability (HRV): 0-200 ms, reflects stress and recovery
  • โ€”Resting Heart Rate (RHR): Measured daily at 6:00 AM
  • โ€”Respiratory Rate (RR): 8-40 brpm, responds to activity and stress
  • โ€”Body Temperature (BT): 35-40ยฐC, follows circadian rhythm
  • โ€”Steps & Calories: Activity-based calculations
  • โ€”Sleep Metrics (SD, DSR, SL): Measured daily, reflects sleep quality

3. Sampling Frequency Impact Analysis

  • โ€”Adjust collection frequency (5 min, 10 min, 30 min, 1 hour)
  • โ€”Observe how frequency affects:
  • โ€”Ability to detect short-term anomalies (e.g., M2: 60-minute tachycardia)
  • โ€”Accuracy of trend detection (e.g., S2: 24-hour recovery patterns)
  • โ€”Data visualization quality

4. Anomaly Detection Framework

  • โ€”M1 - Severe Fatigue: HRV < 30ms, RHR > 85bpm, DSR < 10% (3 days)
  • โ€”M2 - Heart Rate Abnormality: HR > 120bpm or < 50bpm in non-active state (60 min)
  • โ€”M3 - Sleep Deprivation: SD < 360 min (3 days)
  • โ€”S1 - Persistent Stress: HRV < 40ms, RHR > 80bpm (5 days)
  • โ€”S2 - Exercise Recovery: RHR โ†‘ > 10%, HRV โ†“ > 20% after intense exercise (24 hours)
  • โ€”S3 - Potential Infection: BT > 37.3ยฐC, RHR โ†‘ > 10%, RR > 20 brpm (24 hours)

๐Ÿ› ๏ธ Technology Stack

  • โ€”Frontend: React 19 + TypeScript + Vite
  • โ€”Visualization: Recharts for data visualization
  • โ€”AI Integration:
  • โ€”Story Generation: 302.ai Chat API (Qwen/Qwen2.5-Coder-32B-Instruct)
  • โ€”Image Generation: Google Gemini API, 302.ai SDXL Lightning
  • โ€”UI Components: Lucide React Icons
  • โ€”Data Processing: Custom algorithms for health metric generation

๐Ÿ“ฆ Quick Start

Prerequisites

  • โ€”Node.js 18+
  • โ€”API Keys (optional, for AI features):
  • โ€”Google Gemini API key (for image generation)
  • โ€”302.ai API key (for story and image generation)

Installation

bash
# Clone the repository
git clone <repository-url>
cd health-data-story-visualization-system

# Install dependencies
npm install

# Set up environment variables (optional)
# Create .env.local file with:
# VITE_GEMINI_API_KEY=your_gemini_api_key
# VITE_API_302_KEY=your_302_api_key

# Start development server
npm run dev

Visit http://localhost:5173 to see the application.


๐ŸŽ“ Use Cases

Scenario 1: Testing Anomaly Detection Algorithm

  1. 1.Generate a default 24-hour story
  2. 2.Inject M2 anomaly (heart rate abnormality) at 14:00
  3. 3.Adjust sampling frequency to 10 minutes
  4. 4.Verify if the algorithm can detect the anomaly
  5. 5.Compare results with 5-minute vs 30-minute sampling

Scenario 2: Demonstrating Health Insights

  1. 1.Generate "A Chef's Day" story
  2. 2.Show how heart rate varies during different activities
  3. 3.Highlight the relationship between activity intensity and HRV
  4. 4.Export data for presentation

Scenario 3: Research on Sampling Frequency

  1. 1.Generate multiple stories with different activity patterns
  2. 2.Inject the same anomaly (e.g., S2: Exercise Recovery)
  3. 3.Test detection accuracy at different sampling frequencies
  4. 4.Document findings for research paper

Scenario 4: Generating Training Datasets for ML Models

  1. 1.Generate 100+ stories with diverse user profiles
  2. 2.Inject various anomaly types at different severities
  3. 3.Export data at multiple sampling frequencies (5-min, 10-min, 30-min)
  4. 4.Use datasets to train LSTM/Transformer models for anomaly detection
  5. 5.Benchmark model performance on synthetic vs. real data

๐Ÿ”ฎ Future Vision

This project is just the beginning. We envision:

Short-term Goals

  • โ€”[ ] Support multi-day stories (7-30 days)
  • โ€”[ ] Add more anomaly types and severity levels
  • โ€”[ ] Implement real-time anomaly detection algorithms
  • โ€”[ ] Export data in multiple formats (CSV, JSON, Excel)

Long-term Vision

  • โ€”[ ] Clinical Integration: Connect with real patient data (anonymized)
  • โ€”[ ] Machine Learning: Train models on generated scenarios
  • โ€”[ ] Collaborative Research: Open platform for researchers to share scenarios
  • โ€”[ ] Mobile App: Native mobile experience for on-the-go analysis
  • โ€”[ ] API Service: Provide health data generation as a service

๐Ÿค How You Can Support

For Researchers

  • โ€”Use the platform for your research and share findings
  • โ€”Contribute scenarios and anomaly definitions
  • โ€”Provide feedback on data accuracy and realism
  • โ€”Collaborate on research papers and publications

For Developers

  • โ€”Contribute code to improve features and performance
  • โ€”Report bugs and suggest improvements
  • โ€”Build integrations with other health platforms
  • โ€”Create plugins for custom anomaly types

For Healthcare Professionals

  • โ€”Validate the physiological models
  • โ€”Suggest clinical scenarios to add
  • โ€”Test the system with real-world use cases
  • โ€”Share insights on health metric interpretation

For Everyone

  • โ€”Star the repository if you find it useful
  • โ€”Share the project with others who might benefit
  • โ€”Provide feedback on user experience
  • โ€”Support the project's continued development

๐Ÿ“„ License

[Specify your license here]


๐Ÿ™ Acknowledgments

  • โ€”Inspired by the need to make health data more accessible and understandable
  • โ€”Built with the goal of advancing wearable health technology research
  • โ€”Thanks to all contributors and supporters

๐Ÿ“ง Contact & Collaboration

Interested in collaborating or have questions?

  • โ€”Open an issue for bug reports or feature requests
  • โ€”Start a discussion for research collaboration
  • โ€”Reach out for partnership opportunities

Together, we can make health data visualization more intuitive, research more accessible, and health insights more actionable.

This project represents a step forward in making health data meaningful. Your support helps us continue this important work.