From 6a19b8841ef88e34d83c90edb9f160394fad305f Mon Sep 17 00:00:00 2001 From: Ajay Gandecha Date: Mon, 11 Nov 2024 14:34:17 -0500 Subject: [PATCH] Fix Queue Sort Order (#640) * Added sort to queued tickets by start time * Fix sorted order for students view --- backend/services/office_hours/office_hours.py | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/backend/services/office_hours/office_hours.py b/backend/services/office_hours/office_hours.py index 83e78a06..849d2e64 100644 --- a/backend/services/office_hours/office_hours.py +++ b/backend/services/office_hours/office_hours.py @@ -158,11 +158,16 @@ def get_office_hour_get_help_overview( active_ticket = active_tickets[0] if len(active_tickets) > 0 else None # Find queue position - queue_tickets = [ - ticket - for ticket in queue_entity.tickets - if ticket.state == TicketState.QUEUED - ] + queue_tickets = ( + sorted( + [ + ticket + for ticket in queue_entity.tickets + if ticket.state == TicketState.QUEUED + ], + key=lambda ticket: ticket.created_at, + ), + ) queue_position = ( queue_tickets.index(active_ticket) + 1 @@ -230,7 +235,10 @@ def _to_oh_queue_overview( other_called=[ self._to_oh_ticket_overview(ticket) for ticket in called_tickets ], - queue=[self._to_oh_ticket_overview(ticket) for ticket in queued_tickets], + queue=sorted( + [self._to_oh_ticket_overview(ticket) for ticket in queued_tickets], + key=lambda ticket: ticket.created_at, + ), personal_tickets_called=len(personal_completed_tickets), average_minutes=personal_average_minutes, total_tickets_called=len(completed_tickets),