Refine event types and update related models and logic
Standardized event types with stricter validation using `Literal`. Adjusted related data and logic to align with new types, including changes to PGROUP assignments, event timeline increments, and schema updates. Cleaned up unused code and clarified database initialization behavior.
This commit is contained in:
@ -191,7 +191,7 @@ def generate_unique_id(length=16):
|
||||
dewars = [
|
||||
Dewar(
|
||||
id=1,
|
||||
pgroups="p20001, p20002",
|
||||
pgroups="p20001",
|
||||
dewar_name="Dewar One",
|
||||
dewar_type_id=1,
|
||||
dewar_serial_number_id=2,
|
||||
@ -207,7 +207,7 @@ dewars = [
|
||||
),
|
||||
Dewar(
|
||||
id=2,
|
||||
pgroups="p20001, p20002",
|
||||
pgroups="p20002",
|
||||
dewar_name="Dewar Two",
|
||||
dewar_type_id=3,
|
||||
dewar_serial_number_id=1,
|
||||
@ -255,7 +255,7 @@ dewars = [
|
||||
),
|
||||
Dewar(
|
||||
id=5,
|
||||
pgroups="p20001, p20002",
|
||||
pgroups="p20003",
|
||||
dewar_name="Dewar Five",
|
||||
dewar_type_id=1,
|
||||
dewar_serial_number_id=1,
|
||||
@ -692,10 +692,10 @@ for puck in pucks:
|
||||
sample_id_counter += 1
|
||||
|
||||
# Define possible event types for samples
|
||||
event_types = ["Mounted", "Failed", "Unmounted", "Lost"]
|
||||
event_types = ["Mounting", "Failed", "Unmounting", "Lost"]
|
||||
|
||||
|
||||
def generate_sample_events(samples, chance_no_event=0.2, chance_lost=0.1):
|
||||
def generate_sample_events(samples, chance_no_event=0.02, chance_lost=0.01):
|
||||
"""Generate events for samples with timestamps
|
||||
increasing between different samples."""
|
||||
|
||||
@ -711,11 +711,11 @@ def generate_sample_events(samples, chance_no_event=0.2, chance_lost=0.1):
|
||||
# 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)
|
||||
start_time += timedelta(minutes=1)
|
||||
continue
|
||||
|
||||
# Determine initial event type
|
||||
event_type = "Failed" if random.random() < 0.05 else "Mounted"
|
||||
event_type = "Failed" if random.random() < 0.005 else "Mounting"
|
||||
|
||||
# Append the initial event
|
||||
events.append(
|
||||
@ -728,7 +728,7 @@ def generate_sample_events(samples, chance_no_event=0.2, chance_lost=0.1):
|
||||
) # 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]:
|
||||
if event_type == "Mounting" and sample is not samples[-1]:
|
||||
# Determine follow-up event
|
||||
if random.random() < chance_lost:
|
||||
events.append(
|
||||
@ -740,13 +740,13 @@ def generate_sample_events(samples, chance_no_event=0.2, chance_lost=0.1):
|
||||
events.append(
|
||||
SampleEvent(
|
||||
sample_id=sample.id,
|
||||
event_type="Unmounted",
|
||||
event_type="Unmounting",
|
||||
timestamp=current_time,
|
||||
)
|
||||
)
|
||||
|
||||
# Increment start_time for the next sample
|
||||
start_time += timedelta(minutes=10)
|
||||
start_time += timedelta(minutes=1)
|
||||
|
||||
return events
|
||||
|
||||
|
Reference in New Issue
Block a user