Skip to content

Commit

Permalink
Merge pull request #517 from gemini-hlsw/SCHED-744
Browse files Browse the repository at this point in the history
SCHED-744: Add new time losses values
  • Loading branch information
stroncod authored Oct 17, 2024
2 parents 402f5fc + 28380db commit aabc543
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
1 change: 1 addition & 0 deletions scheduler/core/eventsqueue/nightchanges.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class NightlyTimeline:
A collection of timeline entries per night and site.
"""
timeline: Dict[NightIndex, Dict[Site, List[TimelineEntry]]] = field(init=False, default_factory=dict)
time_losses: Dict[NightIndex, Dict[Site, Dict[str, float]]] = field(init=False, default_factory=dict)
_datetime_formatter: ClassVar[str] = field(init=False, default='%Y-%m-%d %H:%M')

def add(self,
Expand Down
34 changes: 23 additions & 11 deletions scheduler/core/statscalculator/statscalculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,44 +49,56 @@ def calculate_timeline_stats(timeline: NightlyTimeline,
scores_per_program: Dict[ProgramID, float] = {}
programs = {}
for night_idx in nights:
timeline.time_losses.setdefault(night_idx, {})
for site in sites:
time_losses = {StatCalculator._FAULT_KEY: 0,
StatCalculator._WEATHER_KEY: 0,
StatCalculator._UNSCHEDULE_KEY: 0}

timeline_time_losses = {StatCalculator._FAULT_KEY: 0,
StatCalculator._WEATHER_KEY: 0}
timeline.time_losses[night_idx].setdefault(site, {})
# Gather unsolved interruptions during the night.
interruptions = []
for entry in timeline.timeline[night_idx][site]:
if isinstance(entry.event, InterruptionEvent):
interruptions.append(entry.event)
elif isinstance(entry.event, InterruptionResolutionEvent):
interruptions.pop()
interruptions.pop() # remove reported interruption and register the time loss
if isinstance(entry.event, FaultResolutionEvent):
timeline_time_losses[StatCalculator._FAULT_KEY] += int(entry.event.time_loss.total_seconds()/60)
elif isinstance(entry.event, WeatherClosureResolutionEvent):
timeline_time_losses[StatCalculator._WEATHER_KEY] += int(entry.event.time_loss.total_seconds()/60)

# Unsolved interruptions for the night
for e in interruptions:
print('event never finished:', e.description)
if isinstance(e, FaultEvent):
time_loss = timeline.timeline[night_idx][site][-1].event.time - e.time
time_losses[StatCalculator._FAULT_KEY] += time_loss.total_seconds() / 60
timeline_time_losses[StatCalculator._FAULT_KEY] += int(time_loss.total_seconds() / 60)

elif isinstance(e, WeatherClosureEvent):
time_loss = timeline.timeline[night_idx][site][-1].event.time - e.time
time_losses[StatCalculator._WEATHER_KEY] += time_loss.total_seconds() / 60
timeline_time_losses[StatCalculator._WEATHER_KEY] += int(time_loss.total_seconds() / 60)

timeline.time_losses[night_idx][site] = timeline_time_losses
for entry in timeline.timeline[night_idx][site]:
time_losses = {StatCalculator._FAULT_KEY: 0,
StatCalculator._WEATHER_KEY: 0,
StatCalculator._UNSCHEDULE_KEY: 0}

# Morning twilight generates no plan.
if entry.plan_generated is None:
continue

plan = entry.plan_generated # Update last plan

if isinstance(entry.event, InterruptionResolutionEvent):
if isinstance(entry.event, FaultResolutionEvent):
time_losses[StatCalculator._FAULT_KEY] += int(entry.event.time_loss.total_seconds()/60)
elif isinstance(entry.event, WeatherClosureResolutionEvent):
time_losses[StatCalculator._WEATHER_KEY] += int(entry.event.time_loss.total_seconds()/60)
if 'Morning' in entry.event.description:
time_losses[StatCalculator._FAULT_KEY] = timeline_time_losses[StatCalculator._FAULT_KEY]
time_losses[StatCalculator._WEATHER_KEY] = timeline_time_losses[StatCalculator._WEATHER_KEY]

time_losses[StatCalculator._UNSCHEDULE_KEY] = (plan.time_left() -
time_losses[StatCalculator._FAULT_KEY] -
time_losses[StatCalculator._WEATHER_KEY])


n_toos = 0
plan_score = 0
plan_conditions = []
Expand Down
5 changes: 4 additions & 1 deletion scheduler/graphql_mid/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class TimelineEntriesBySite:
time_entries: List[STimelineEntry]
eve_twilight: datetime
morn_twilight: datetime
time_losses: JSON


@strawberry.type
Expand All @@ -172,6 +173,7 @@ def from_computed_timelines(timeline: NightlyTimeline) -> 'SNightTimelines':
s_entries = []
eve_twi = timeline.timeline[n_idx][site][0].event.time
morn_twi = timeline.timeline[n_idx][site][-1].event.time
time_losses = timeline.time_losses[n_idx][site]
for entry in timeline.timeline[n_idx][site]:
if entry.plan_generated is None:
continue
Expand All @@ -182,7 +184,8 @@ def from_computed_timelines(timeline: NightlyTimeline) -> 'SNightTimelines':
te = TimelineEntriesBySite(site=site,
time_entries=s_entries,
eve_twilight=eve_twi,
morn_twilight=morn_twi)
morn_twilight=morn_twi,
time_losses=time_losses)
s_timeline_entries.append(te)
sn = SNightInTimeline(night_index=n_idx, time_entries_by_site=s_timeline_entries)
timelines.append(sn)
Expand Down

0 comments on commit aabc543

Please sign in to comment.