generated from ministryofjustice/hmpps-template-kotlin
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2732 from ministryofjustice/APS-1672-premises-ove…
…rbooking-summary Implemented premises overbooking summary range.
- Loading branch information
Showing
10 changed files
with
451 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...uk/gov/justice/digital/hmpps/approvedpremisesapi/util/Cas1PremiseOverbookingCalculator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package uk.gov.justice.digital.hmpps.approvedpremisesapi.util | ||
|
||
import uk.gov.justice.digital.hmpps.approvedpremisesapi.api.model.Cas1OverbookingRange | ||
import uk.gov.justice.digital.hmpps.approvedpremisesapi.service.cas1.planning.SpacePlanningService | ||
|
||
class Cas1PremiseOverbookingCalculator { | ||
|
||
fun calculate(overbookedDays: List<SpacePlanningService.PremiseCapacityForDay>): List<Cas1OverbookingRange> { | ||
if (overbookedDays.isEmpty()) return emptyList() | ||
|
||
val sortedOverBookedDays = overbookedDays.distinctBy { it.day }.sortedBy { it.day } | ||
|
||
val overbookingRanges = mutableListOf<Cas1OverbookingRange>() | ||
var rangeStart = sortedOverBookedDays.first().day | ||
var previousDay = rangeStart | ||
|
||
// Calculate consecutive overbooking ranges | ||
for (current in sortedOverBookedDays.drop(1)) { | ||
if (current.day != previousDay.plusDays(1)) { | ||
overbookingRanges.add( | ||
Cas1OverbookingRange(startInclusive = rangeStart, endInclusive = previousDay), | ||
) | ||
rangeStart = current.day | ||
} | ||
previousDay = current.day | ||
} | ||
// Add the final range | ||
overbookingRanges.add( | ||
Cas1OverbookingRange(startInclusive = rangeStart, endInclusive = previousDay), | ||
) | ||
return overbookingRanges | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.