first commit
This commit is contained in:
108
scripts/initialize_sample_data.py
Executable file
108
scripts/initialize_sample_data.py
Executable file
@@ -0,0 +1,108 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
Script to initialize the database with sample data for development.
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
import django
|
||||
from datetime import timedelta
|
||||
from django.utils import timezone
|
||||
|
||||
# Add project to path
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
# Setup Django
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
|
||||
django.setup()
|
||||
|
||||
from monitor.models import BitcoinPrice, MarketAnalysis, NotificationPreference
|
||||
from monitor.services.historical_data import HistoricalDataFetcher
|
||||
from monitor.services.analyzer import MarketAnalyzer
|
||||
|
||||
|
||||
def initialize_sample_data():
|
||||
"""Initialize database with sample data."""
|
||||
print("🚀 Initializing Bitcoin Monitor with Sample Data")
|
||||
print("=" * 50)
|
||||
|
||||
# Check if data already exists
|
||||
if BitcoinPrice.objects.exists():
|
||||
print("⚠️ Database already contains data.")
|
||||
response = input("Clear existing data? (y/N): ")
|
||||
if response.lower() != 'y':
|
||||
print("Exiting...")
|
||||
return
|
||||
|
||||
# Load historical data
|
||||
print("\n📊 Loading historical Bitcoin data...")
|
||||
fetcher = HistoricalDataFetcher()
|
||||
|
||||
# Try to fetch real data
|
||||
historical_data = fetcher.fetch_historical_data(days=90) # 3 months
|
||||
|
||||
if not historical_data:
|
||||
print("⚠️ Could not fetch real data. Generating synthetic data...")
|
||||
historical_data = fetcher.generate_test_data(days=90)
|
||||
|
||||
# Save data
|
||||
save_stats = fetcher.save_historical_data(
|
||||
historical_data=historical_data,
|
||||
clear_existing=True
|
||||
)
|
||||
|
||||
print(f"✅ Saved {save_stats['saved']} price records")
|
||||
|
||||
# Run analysis
|
||||
print("\n📈 Running market analysis...")
|
||||
analyzer = MarketAnalyzer()
|
||||
|
||||
analyses_created = 0
|
||||
for period in ['hourly', 'daily', 'weekly']:
|
||||
analysis = analyzer.analyze_market(period)
|
||||
if analysis:
|
||||
analyses_created += 1
|
||||
print(f" Created {period} analysis: {analysis.status}")
|
||||
|
||||
print(f"✅ Created {analyses_created} market analyses")
|
||||
|
||||
# Setup notification preferences
|
||||
print("\n📧 Setting up notification preferences...")
|
||||
|
||||
test_emails = [
|
||||
'ali.c.zeybek@gmail.com',
|
||||
'alican@alicanzeybek.xyz',
|
||||
]
|
||||
|
||||
for email in test_emails:
|
||||
pref, created = NotificationPreference.objects.get_or_create(
|
||||
email_address=email,
|
||||
defaults={
|
||||
'receive_event_alerts': True,
|
||||
'receive_system_alerts': True,
|
||||
'receive_daily_digest': True,
|
||||
'is_active': True,
|
||||
}
|
||||
)
|
||||
|
||||
if created:
|
||||
print(f" Created preferences for {email}")
|
||||
else:
|
||||
print(f" Preferences already exist for {email}")
|
||||
|
||||
# Display summary
|
||||
print("\n" + "=" * 50)
|
||||
print("🎉 Sample Data Initialization Complete!")
|
||||
print("\nSummary:")
|
||||
print(f" • Bitcoin price records: {BitcoinPrice.objects.count()}")
|
||||
print(f" • Market analyses: {MarketAnalysis.objects.count()}")
|
||||
print(f" • Notification preferences: {NotificationPreference.objects.count()}")
|
||||
|
||||
print("\nNext steps:")
|
||||
print(" 1. Start the server: python manage.py runserver")
|
||||
print(" 2. Visit dashboard: http://localhost:8000/")
|
||||
print(" 3. Check admin: http://localhost:8000/admin/")
|
||||
print(" 4. Load more data: python manage.py load_historical_data --days 365")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
initialize_sample_data()
|
||||
Reference in New Issue
Block a user