From 0f49a5f57ca2997ef22fab7034e6a7a04d021b76 Mon Sep 17 00:00:00 2001 From: Sergio Troncoso Date: Fri, 28 Jul 2023 17:07:42 -0400 Subject: [PATCH] SCHED 410: Fix time accounting for split observations. (#283) * SCHED-410: Add correct atom start/end in Visits for split observations * SCHED-410: Fix iteration through atoms in visit instead of whole sequence in Time accounting --------- Co-authored-by: Sergio --- .../core/components/collector/__init__.py | 19 ++++++++++--------- .../core/components/optimizer/greedymax.py | 6 ++++++ scheduler/core/plans/__init__.py | 6 ++++-- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/scheduler/core/components/collector/__init__.py b/scheduler/core/components/collector/__init__.py index 2ff01556..c765fd96 100644 --- a/scheduler/core/components/collector/__init__.py +++ b/scheduler/core/components/collector/__init__.py @@ -497,25 +497,26 @@ def time_accounting(self, site_plans: Plans) -> None: for v in plan.visits: # Update Observation from Collector. observation = self.get_observation(v.obs_id) + obs_seq = observation.sequence # check that Observation is Observed - if v.atom_end_idx == len(observation.sequence)-1: + if v.atom_end_idx == len(obs_seq)-1: observation.status = ObservationStatus.OBSERVED else: observation.status = ObservationStatus.ONGOING - + # Update by atom in the sequence - for atom_idx, atom in enumerate(observation.sequence): + for atom_idx in range (v.atom_start_idx, v.atom_end_idx): - atom.program_used = atom.prog_time - atom.partner_used = atom.part_time + obs_seq[atom_idx].program_used = obs_seq[atom_idx].prog_time + obs_seq[atom_idx].partner_used = obs_seq[atom_idx].part_time # Charge acquisition to the first atom if atom_idx == 0: if observation.obs_class == ObservationClass.PARTNERCAL: - atom.program_used += observation.acq_overhead + obs_seq[atom_idx].program_used += observation.acq_overhead elif (observation.obs_class == ObservationClass.SCIENCE or observation.obs_class == ObservationClass.PROGCAL): - atom.program_used += observation.acq_overhead + obs_seq[atom_idx].program_used += observation.acq_overhead - atom.observed = True - atom.qa_state = QAState.PASS + obs_seq[atom_idx].observed = True + obs_seq[atom_idx].qa_state = QAState.PASS diff --git a/scheduler/core/components/optimizer/greedymax.py b/scheduler/core/components/optimizer/greedymax.py index a2116e12..5bc7f1f8 100644 --- a/scheduler/core/components/optimizer/greedymax.py +++ b/scheduler/core/components/optimizer/greedymax.py @@ -30,6 +30,8 @@ class ObsPlanData: obs: Observation obs_start: datetime obs_len: int + atom_start: int + atom_end: int visit_score: float @@ -820,6 +822,8 @@ def _add_visit(self, night, obs, max_group_info, best_interval, n_slots_filled) obs=obs, obs_start=start, obs_len=visit_length, + atom_start=atom_start, + atom_end=atom_end, visit_score=visit_score ) @@ -937,6 +941,8 @@ def output_plans(self, plans: Plans) -> None: obs_in_plan = self.obs_in_plan[timeline.site][start_time_slot] plans[timeline.site].add(obs_in_plan.obs, obs_in_plan.obs_start, + obs_in_plan.atom_start, + obs_in_plan.atom_end, start_time_slot, obs_in_plan.obs_len, obs_in_plan.visit_score) diff --git a/scheduler/core/plans/__init__.py b/scheduler/core/plans/__init__.py index 90076d07..17b225a8 100644 --- a/scheduler/core/plans/__init__.py +++ b/scheduler/core/plans/__init__.py @@ -196,13 +196,15 @@ def time2slots(time_slot_length: timedelta, time: timedelta) -> int: def add(self, obs: Observation, start: datetime, + atom_start: int, + atom_end: int, start_time_slot: int, time_slots: int, score: float) -> None: visit = Visit(start, obs.id, - obs.sequence[0].id, - obs.sequence[-1].id, + atom_start, + atom_end, start_time_slot, time_slots, score,