51 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Python
		
	
	
	
			
		
		
	
	
			51 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Python
		
	
	
	
| import random
 | |
| from django.utils import timezone
 | |
| from .models import CarWash, VehicleAccess
 | |
| 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]
 | |
|         )
 | |
| 
 | |
| 
 | |
| def generate_vehicleaccess_data(num_objects):
 | |
|     vehicle_numbers = ['ABC123', 'DEF456', 'GHI789', 'JKL012', 'MNO345']
 | |
|     emission_standards = ['国五', '国六']
 | |
|     types = [1, 2]
 | |
|     access_times = [timezone.now() - timezone.timedelta(minutes=n)
 | |
|                     for n in range(10, 61, 10)]
 | |
|     door_name = '大门'
 | |
|     for i in range(num_objects):
 | |
|         access_time = access_times[i % len(access_times)]
 | |
|         VehicleAccess.objects.create(
 | |
|             id=idWorker.get_id(),
 | |
|             type=types[i % len(types)],
 | |
|             vehicle_number=vehicle_numbers[i % len(vehicle_numbers)],
 | |
|             emission_standard=emission_standards[i % len(emission_standards)],
 | |
|             door_name=door_name,
 | |
|             access_time=access_time,
 | |
|             create_time=access_time
 | |
|         )
 |