34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
from django.core.management.base import BaseCommand
|
|
from monitor.models import BitcoinPrice
|
|
from datetime import datetime, timedelta, timezone
|
|
import random
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = 'Load sample Bitcoin price data'
|
|
|
|
def handle(self, *args, **options):
|
|
# Clear existing data
|
|
BitcoinPrice.objects.all().delete()
|
|
|
|
# Create sample data (last 7 days)
|
|
base_price = 45000
|
|
now = datetime.now(timezone.utc)
|
|
|
|
for i in range(168): # 7 days * 24 hours = 168 hours
|
|
timestamp = now - timedelta(hours=i)
|
|
# Random price variation ±5%
|
|
variation = random.uniform(0.95, 1.05)
|
|
price = round(base_price * variation, 2)
|
|
|
|
BitcoinPrice.objects.create(
|
|
timestamp=timestamp,
|
|
price_usd=price,
|
|
volume=random.uniform(20000000000, 40000000000),
|
|
market_cap=random.uniform(800000000000, 900000000000),
|
|
)
|
|
|
|
self.stdout.write(
|
|
self.style.SUCCESS(f'Successfully created {BitcoinPrice.objects.count()} sample records')
|
|
)
|