31 lines
1.2 KiB
Python
31 lines
1.2 KiB
Python
import random
|
|
from django.utils import timezone
|
|
from .models import CarWash
|
|
from apps.em.models import Equipment
|
|
from apps.utils.snowflake import idWorker
|
|
|
|
|
|
def generate_carwash_data(num_objects):
|
|
station = Equipment.objects.get(id='3519522742859161600')
|
|
vehicle_numbers = ['ABC123', 'DEF456', 'GHI789', 'JKL012', 'MNO345']
|
|
start_times = [timezone.now() - timezone.timedelta(seconds=n)
|
|
for n in range(10, 61, 10)]
|
|
end_times = [start_time + timezone.timedelta(
|
|
seconds=random.randint(15, 45)) for start_time in start_times]
|
|
pressures = [round(random.uniform(3.0, 5.0), 2)
|
|
for _ in range(num_objects)]
|
|
fluxes = [round(random.uniform(10.0, 15.0), 2) for _ in range(num_objects)]
|
|
for i in range(num_objects):
|
|
start_time = start_times[i % len(start_times)]
|
|
end_time = end_times[i % len(end_times)]
|
|
CarWash.objects.create(
|
|
id=idWorker.get_id(),
|
|
station=station,
|
|
vehicle_number=vehicle_numbers[i % len(vehicle_numbers)],
|
|
start_time=start_time,
|
|
end_time=end_time,
|
|
duration=(end_time-start_time).total_seconds(),
|
|
pressure=pressures[i],
|
|
flux=fluxes[i]
|
|
)
|