From 16b3c485d7abf95a05322cdd02fdd135afc573db Mon Sep 17 00:00:00 2001 From: Leonid Pershin Date: Mon, 27 Jul 2026 23:48:44 +0300 Subject: [PATCH] Refactor GridPlanner to improve slot fitting logic and enhance code clarity Reintroduced the Fit method in the GridPlanner class with detailed documentation, clarifying the logic for determining slot duration based on available space. This change enhances the readability and maintainability of the code while ensuring accurate slot management during grid generation. --- .../Templates/Generate/GridPlanner.cs | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/backend/src/TeleWave.Application/Programming/Templates/Generate/GridPlanner.cs b/backend/src/TeleWave.Application/Programming/Templates/Generate/GridPlanner.cs index c43804b..8e2d666 100644 --- a/backend/src/TeleWave.Application/Programming/Templates/Generate/GridPlanner.cs +++ b/backend/src/TeleWave.Application/Programming/Templates/Generate/GridPlanner.cs @@ -360,6 +360,19 @@ public sealed class GridPlanner( PlanRun Run ) { + /// + /// Длина слота: желаемая, но не больше свободного места. Остаток короче минимального слота + /// приклеивается к текущему — огрызок в сетке читается как ошибка, а не как решение. Остаток + /// побольше достанется следующему слоту, и под него подберут группу подходящей длины. + /// + private static int Fit(int wanted, int available) + { + var duration = Math.Min(Round(wanted), available); + return available - duration < MinSlotMinutes + ? available + : Math.Max(duration, MinSlotMinutes); + } + /// /// Длина слота и число единиц в нём. Блок из N единиц занимает ровно столько, сколько эти /// единицы идут, — округление до пяти минут; хвост короче минимального слота приклеивается @@ -461,19 +474,6 @@ public sealed class GridPlanner( private static int RepeatMinutes(GridBand band) => band.BlockMinutes > 0 ? band.BlockMinutes : 120; - /// - /// Длина слота: желаемая, но не больше свободного места. Остаток короче минимального слота - /// приклеивается к текущему — огрызок в сетке читается как ошибка, а не как решение. Остаток - /// побольше достанется следующему слоту, и под него подберут группу подходящей длины. - /// - private static int Fit(int wanted, int available) - { - var duration = Math.Min(Round(wanted), available); - return available - duration < MinSlotMinutes - ? available - : Math.Max(duration, MinSlotMinutes); - } - private static int Round(int minutes) => Math.Max(SlotStepMinutes, minutes / SlotStepMinutes * SlotStepMinutes);