feat: carwash模拟数据

This commit is contained in:
caoqianming 2024-02-21 08:56:00 +08:00
parent 8916349240
commit 00dfebd0c9
3 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,18 @@
# Generated by Django 3.2.12 on 2024-02-20 05:14
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('enp', '0005_carwash'),
]
operations = [
migrations.AddField(
model_name='carwash',
name='duration',
field=models.PositiveIntegerField(blank=True, null=True, verbose_name='洗车时长(s)'),
),
]

30
apps/enp/mock.py Normal file
View File

@ -0,0 +1,30 @@
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]
)

View File

@ -133,6 +133,7 @@ class CarWash(BaseModel):
vehicle_number = models.CharField('车牌号', max_length=10, default='')
start_time = models.DateTimeField('洗车时间', null=True, blank=True)
end_time = models.DateTimeField('洗车完成时间', null=True, blank=True)
duration = models.PositiveIntegerField('洗车时长(s)', null=True, blank=True)
pressure = models.DecimalField(
'洗车压力(Mpa)', max_digits=10, decimal_places=4, null=True, blank=True)
flux = models.DecimalField(