Add beamtime relationships and enhance sample handling
This commit adds relationships to link Pucks and Samples to Beamtime in the models, enabling better data association. Includes changes to assign beamtime IDs during data generation and updates in API response models for improved data loading. Removed redundant code in testfunctions.ipynb to clean up the notebook.
This commit is contained in:
@ -407,9 +407,9 @@ beamtimes = [
|
||||
),
|
||||
Beamtime(
|
||||
id=2,
|
||||
pgroups="p20002",
|
||||
pgroups="p20003",
|
||||
shift="afternoon",
|
||||
beamtime_name="p20001-test",
|
||||
beamtime_name="p20003-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(),
|
||||
@ -677,8 +677,15 @@ pucks = [
|
||||
# Define samples
|
||||
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
|
||||
}
|
||||
|
||||
for puck in pucks:
|
||||
dewar_id = puck.dewar_id # Assuming puck has dewar_id
|
||||
assigned_beamtime = dewar_to_beamtime[dewar_id]
|
||||
|
||||
positions_with_samples = random.randint(1, 16)
|
||||
occupied_positions = random.sample(range(1, 17), positions_with_samples)
|
||||
|
||||
@ -689,6 +696,7 @@ for puck in pucks:
|
||||
sample_name=f"Sample{sample_id_counter:03}",
|
||||
position=pos,
|
||||
puck_id=puck.id,
|
||||
beamtime_id=assigned_beamtime, # IMPORTANT: Use the dewar's beamtime
|
||||
)
|
||||
samples.append(sample)
|
||||
sample_id_counter += 1
|
||||
|
Reference in New Issue
Block a user