Refactor beamtime relationships in models and related APIs
Updated relationships for beamtime in models to support many-to-many associations with pucks, samples, and dewars. Refactored API endpoints to accommodate these changes, ensuring accurate assignment and retrieval of data. Improved sample data generation logic and incremented the application version for the new updates.
This commit is contained in:
@ -407,17 +407,43 @@ beamtimes = [
|
||||
),
|
||||
Beamtime(
|
||||
id=2,
|
||||
pgroups="p20003",
|
||||
pgroups="p20001",
|
||||
shift="afternoon",
|
||||
beamtime_name="p20003-test",
|
||||
beamtime_name="p20001-test",
|
||||
beamline="X06DA",
|
||||
start_date=datetime.strptime("07.05.2025", "%d.%m.%Y").date(),
|
||||
end_date=datetime.strptime("08.05.2025", "%d.%m.%Y").date(),
|
||||
start_date=datetime.strptime("06.05.2025", "%d.%m.%Y").date(),
|
||||
end_date=datetime.strptime("07.05.2025", "%d.%m.%Y").date(),
|
||||
status="confirmed",
|
||||
comments="this is a test beamtime",
|
||||
proposal_id=2,
|
||||
local_contact_id=2,
|
||||
),
|
||||
Beamtime(
|
||||
id=3,
|
||||
pgroups="p20003",
|
||||
shift="morning",
|
||||
beamtime_name="p20003-test",
|
||||
beamline="X06SA",
|
||||
start_date=datetime.strptime("06.05.2025", "%d.%m.%Y").date(),
|
||||
end_date=datetime.strptime("06.05.2025", "%d.%m.%Y").date(),
|
||||
status="confirmed",
|
||||
comments="this is a test beamtime",
|
||||
proposal_id=1,
|
||||
local_contact_id=1,
|
||||
),
|
||||
Beamtime(
|
||||
id=4,
|
||||
pgroups="p20002",
|
||||
shift="night",
|
||||
beamtime_name="p20002-test",
|
||||
beamline="X06DA",
|
||||
start_date=datetime.strptime("08.05.2025", "%d.%m.%Y").date(),
|
||||
end_date=datetime.strptime("08.05.2025", "%d.%m.%Y").date(),
|
||||
status="confirmed",
|
||||
comments="this is a test beamtime",
|
||||
proposal_id=3,
|
||||
local_contact_id=2,
|
||||
),
|
||||
]
|
||||
|
||||
# Define shipments
|
||||
@ -679,7 +705,8 @@ samples = []
|
||||
sample_id_counter = 1
|
||||
# Assign a beamtime to each dewar
|
||||
dewar_to_beamtime = {
|
||||
dewar.id: random.choice([1, 2]) for dewar in dewars # Or use actual beamtime ids
|
||||
dewar.id: random.choice([1, 2, 3, 4])
|
||||
for dewar in dewars # Or use actual beamtime ids
|
||||
}
|
||||
|
||||
# Update dewars and their pucks with consistent beamtime
|
||||
@ -688,10 +715,9 @@ for dewar in dewars:
|
||||
|
||||
for puck in pucks:
|
||||
dewar_id = puck.dewar_id # Assuming puck has dewar_id
|
||||
assigned_beamtime = dewar_to_beamtime[dewar_id]
|
||||
puck.beamtime_id = (
|
||||
assigned_beamtime # Associate puck to the same beamtime as its dewar
|
||||
)
|
||||
assigned_beamtime = dewar_to_beamtime[dewar_id] # this is the id (int)
|
||||
# Fix here: use assigned_beamtime (which is the id)
|
||||
assigned_beamtime_obj = next(b for b in beamtimes if b.id == assigned_beamtime)
|
||||
|
||||
positions_with_samples = random.randint(1, 16)
|
||||
occupied_positions = random.sample(range(1, 17), positions_with_samples)
|
||||
@ -703,11 +729,14 @@ for puck in pucks:
|
||||
sample_name=f"Sample{sample_id_counter:03}",
|
||||
position=pos,
|
||||
puck_id=puck.id,
|
||||
beamtime_id=assigned_beamtime,
|
||||
)
|
||||
sample.beamtimes.append(
|
||||
assigned_beamtime_obj
|
||||
) # assigned_beamtime_obj is a Beamtime instance
|
||||
samples.append(sample)
|
||||
sample_id_counter += 1
|
||||
|
||||
|
||||
# Define possible event types for samples
|
||||
event_types = ["Mounting", "Failed", "Unmounting", "Lost"]
|
||||
|
||||
|
Reference in New Issue
Block a user