Skip to content

Commit fac536f

Browse files
committed
Refactor slot sorting logic in schedule.py
- Introduced a new helper function to sort slots by day and slot number. - Updated the sorting mechanism in the slots ordered query for improved clarity and maintainability.
1 parent 6ed763c commit fac536f

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/pycamp_bot/commands/schedule.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,24 @@
1717
COMIDAS = ['Desayuno', 'Almuerzo', 'Merienda', 'Cena']
1818

1919

20+
def _slot_sort_key(slot):
21+
"""
22+
Ordena los slots por día y número de slot.
23+
Ej: A1, A2, A10, B1, B2, B3, etc.
24+
"""
25+
code = slot.code
26+
letra_dia = code[0]
27+
if len(code) == 1:
28+
return (letra_dia, 0)
29+
numero = int(code[1:])
30+
return (letra_dia, numero)
31+
32+
2033
def _slots_ordered_query():
21-
"""Orden A1…A9,A10 sin orden lexicográfico incorrecto."""
22-
return sorted(
23-
Slot.select(),
24-
key=lambda s: (s.code[0], int(s.code[1:])) if len(s.code) > 1 else (s.code[0], 0),
25-
)
34+
"""Ordena los slots por día y número de slot.
35+
Ej: A1, A2, A10, B1, B2, B3, etc.
36+
"""
37+
return sorted(Slot.select(), key=_slot_sort_key)
2638

2739

2840
async def cancel(update, context):

0 commit comments

Comments
 (0)