added pet data for samples events
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
from app.models import ContactPerson, Address, Dewar, Proposal, Shipment, Puck, Sample, DewarType, DewarSerialNumber, Slot
|
||||
from datetime import datetime
|
||||
from app.models import ContactPerson, Address, Dewar, Proposal, Shipment, Puck, Sample, DewarType, DewarSerialNumber, Slot, SampleEvent
|
||||
from datetime import datetime, timedelta
|
||||
import random
|
||||
import time
|
||||
import hashlib
|
||||
@ -182,4 +182,58 @@ for puck in pucks:
|
||||
puck_id=puck.id
|
||||
)
|
||||
samples.append(sample)
|
||||
sample_id_counter += 1
|
||||
sample_id_counter += 1
|
||||
|
||||
# Define possible event types for samples
|
||||
event_types = ["Mounted", "Failed", "Unmounted", "Lost"]
|
||||
|
||||
|
||||
def generate_sample_events(samples, chance_no_event=0.2, chance_lost=0.1):
|
||||
"""Generate events for samples with timestamps increasing between different samples."""
|
||||
|
||||
events = []
|
||||
# Set the start time to yesterday at 9:33 AM
|
||||
start_time = datetime.now().replace(hour=9, minute=33, second=0, microsecond=0) - timedelta(days=1)
|
||||
|
||||
for sample in samples:
|
||||
current_time = start_time
|
||||
|
||||
# Skip some samples with no events
|
||||
if random.random() < chance_no_event:
|
||||
# Increment start_time for the next sample to reflect time passage
|
||||
start_time += timedelta(minutes=10)
|
||||
continue
|
||||
|
||||
# Determine initial event type
|
||||
event_type = "Failed" if random.random() < 0.05 else "Mounted"
|
||||
|
||||
# Append the initial event
|
||||
events.append(SampleEvent(
|
||||
sample_id=sample.id,
|
||||
event_type=event_type,
|
||||
timestamp=current_time
|
||||
))
|
||||
current_time += timedelta(seconds=50) # Increment the time for subsequent events
|
||||
|
||||
# Proceed if mounted and it's not the last sample
|
||||
if event_type == "Mounted" and sample is not samples[-1]:
|
||||
# Determine follow-up event
|
||||
if random.random() < chance_lost:
|
||||
events.append(SampleEvent(
|
||||
sample_id=sample.id,
|
||||
event_type="Lost",
|
||||
timestamp=current_time
|
||||
))
|
||||
else:
|
||||
events.append(SampleEvent(
|
||||
sample_id=sample.id,
|
||||
event_type="Unmounted",
|
||||
timestamp=current_time
|
||||
))
|
||||
|
||||
# Increment start_time for the next sample
|
||||
start_time += timedelta(minutes=10)
|
||||
|
||||
return events
|
||||
|
||||
sample_events = generate_sample_events(samples)
|
||||
|
Reference in New Issue
Block a user