-
Notifications
You must be signed in to change notification settings - Fork 1
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 #109 from MTES-MCT/rapport-fixes
Rapport de patrouille - Add nbDaysAtSea - loading on button frontend …
- Loading branch information
Showing
26 changed files
with
611 additions
and
226 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
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
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
53 changes: 53 additions & 0 deletions
53
...dgampa/rapportnav/domain/use_cases/mission/status/GetNbOfDaysAtSeaFromNavigationStatus.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,53 @@ | ||
package fr.gouv.dgampa.rapportnav.domain.use_cases.mission.status | ||
|
||
import fr.gouv.dgampa.rapportnav.config.UseCase | ||
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ActionStatusEntity | ||
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.status.ActionStatusType | ||
import java.time.ZonedDateTime | ||
import kotlin.time.DurationUnit | ||
|
||
@UseCase | ||
class GetNbOfDaysAtSeaFromNavigationStatus( | ||
private val getStatusDurations: GetStatusDurations, | ||
) { | ||
|
||
/** | ||
* Computes the amount of days with min 4h of navigation | ||
* En français: un jour de mer est décompté dès que le navire effectue plus de 4 heures de navigation en mer. | ||
* | ||
* This function will get the duration for every Navigating status, group them by date, | ||
* check whether it exceeds 4 hours and sum it all up | ||
* | ||
* @param missionStartDateTime The start time of the mission. | ||
* @param missionEndDateTime The end time of the mission (optional). If provided, durations are calculated | ||
* until this time; otherwise, durations are calculated until the current time for all but the last action. | ||
* @param actions The list of action status entities (optional). If not provided, default durations with zero | ||
* values for all possible status and reason combinations are returned. | ||
* @param durationUnit which duration unit (seconds, minutes, hours) | ||
* @return An integer representing the amount of days with min 4h of navigation | ||
*/ | ||
fun execute( | ||
missionStartDateTime: ZonedDateTime, | ||
missionEndDateTime: ZonedDateTime? = null, | ||
actions: List<ActionStatusEntity>? = listOf(), | ||
durationUnit: DurationUnit = DurationUnit.HOURS | ||
): Int { | ||
if (actions.isNullOrEmpty()) { | ||
return 0 | ||
} | ||
val statusesWithDurations = getStatusDurations.computeActionDurationsPerAction( | ||
missionStartDateTime = missionStartDateTime, | ||
missionEndDateTime = missionEndDateTime, | ||
actions = actions, | ||
durationUnit = durationUnit | ||
).filter { it.status === ActionStatusType.NAVIGATING } | ||
val actionsPerDay = statusesWithDurations.groupBy { it.date?.toLocalDate() } | ||
val exceedsFourHoursPerDay = actionsPerDay.mapValues { (_, statuses) -> | ||
statuses.sumOf { it.duration } > 4 | ||
} | ||
val numberOfDaysExceedingFourHours = exceedsFourHoursPerDay.count { it.value } | ||
return numberOfDaysExceedingFourHours | ||
} | ||
|
||
} |
Oops, something went wrong.