Skip to content

Commit

Permalink
Merge pull request #477 from MTES-MCT/feature/474-aem-v2
Browse files Browse the repository at this point in the history
feat(AEM): v2 of AEM base on mission-action
  • Loading branch information
xtiannyeto authored Jan 9, 2025
2 parents 382c0bf + d071f8a commit 51f7c02
Show file tree
Hide file tree
Showing 29 changed files with 1,960 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package fr.gouv.dgampa.rapportnav.domain.entities.aem.v2

import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionEnvActionEntity
import fr.gouv.dgampa.rapportnav.domain.utils.AEMUtils

data class AEMCulturalMaritime2(
val nbrOfHourAtSea: Double? = 0.0, //4.4.1
val nbrOfScientificOperation: Double? = 0.0, // 4.4.2
val nbrOfBCMPoliceOperation: Double? = 0.0, // 4.4.3
) {
constructor(
envActions: List<MissionEnvActionEntity?>
) : this(
nbrOfScientificOperation = scientificCampaignActionEntities(envActions).size.toDouble(),
nbrOfBCMPoliceOperation = culturalMaritimeActionEntities(envActions).size.toDouble(),
nbrOfHourAtSea = AEMUtils.getDurationInHours2(culturalMaritimeActionEntities(envActions)),
)

companion object {
private val scientificCampaignControlPlanSubThemeIds = listOf(165);
private val culturalMaritimeWellBeingControlPlanThemeIds = listOf(104);
private fun culturalMaritimeActionEntities(envActions: List<MissionEnvActionEntity?>): List<MissionEnvActionEntity?> {
return envActions.filter { action ->
action?.controlPlans?.map { c -> c.themeId }
?.intersect(culturalMaritimeWellBeingControlPlanThemeIds)?.isEmpty() == false
}
}

private fun scientificCampaignActionEntities(envActions: List<MissionEnvActionEntity?>): List<MissionEnvActionEntity?> {
return envActions.filter { action ->
action?.controlPlans?.flatMap { it.subThemeIds!! }
?.intersect(scientificCampaignControlPlanSubThemeIds)?.isEmpty() == false
}
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package fr.gouv.dgampa.rapportnav.domain.entities.aem.v2

import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionEnvActionEntity
import fr.gouv.dgampa.rapportnav.domain.utils.AEMUtils

data class AEMEnvTraffic2(
val nbrOfHourAtSea: Double? = 0.0, //3.3.1
val nbrOfRedirectShip: Double? = 0.0, // 3.3.3
val nbrOfSeizure: Double? = 0.0 // 3.3.4
) {
constructor(
envActions: List<MissionEnvActionEntity?>
) : this(
nbrOfHourAtSea = AEMUtils.getDurationInHours2(protectedSpeciesActionEntities(envActions)),
nbrOfRedirectShip = getNbrRedirectShip(envActions),
nbrOfSeizure = getNbrOfSeizure(envActions)
) {}
companion object {
private val protectedSpeciesControlPlanThemeIds = listOf(103);
fun getNbrRedirectShip(envActions: List<MissionEnvActionEntity?>): Double {
return 0.0; //TODO Complete from MonitorEnv
}

fun getNbrOfSeizure(envActions: List<MissionEnvActionEntity?>): Double {
return 0.0; //TODO Complete from MonitorEnv
}

fun protectedSpeciesActionEntities(envActions: List<MissionEnvActionEntity?>): List<MissionEnvActionEntity?> {

val protectedSpeciesActions = envActions.filter {
it?.controlPlans?.map { c -> c.themeId }
?.intersect(protectedSpeciesControlPlanThemeIds)?.isEmpty() == false
}
return protectedSpeciesActions;
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package fr.gouv.dgampa.rapportnav.domain.entities.aem.v2

import fr.gouv.dgampa.rapportnav.domain.entities.mission.fish.fishActions.InfractionType
import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionFishActionEntity
import fr.gouv.dgampa.rapportnav.domain.utils.ComputeDurationUtils

data class AEMIllegalFish2(
val nbrOfHourAtSea: Double? = 0.0, //4.3.1
val nbrOfPolFishAction: Double? = 0.0, // 4.3.3
val nbrOfTargetedVessel: Double? = 0.0, // 4.3.5
val nbrOfInfractionWithPV: Double? = 0.0, // 4.3.6
val nbrOfInfraction: Double? = 0.0, // 4.3.7
val nbrOfSeizureAndDiversionVessel: Double? = 0.0, // 4.3.8
val quantityOfFish: Double? = 0.0 //4.3.9
) {
constructor(
fishActions: List<MissionFishActionEntity?>
) : this(
nbrOfHourAtSea = getNbrOfHourAtSea(fishActions),
nbrOfPolFishAction = fishActions.size.toDouble(),
nbrOfTargetedVessel = fishActions.size.toDouble(),
nbrOfInfraction = getNbrOfInfraction(fishActions),
nbrOfInfractionWithPV = getNbrOfInfractionWithPV(fishActions),
nbrOfSeizureAndDiversionVessel = getNbrOfSeizureAndDiversionVessel(fishActions),
quantityOfFish = getQuantityOfFish(fishActions)
) {
}

companion object {
fun getNbrOfHourAtSea(fishActions: List<MissionFishActionEntity?>): Double {
return fishActions.fold(0.0) { acc, fishAction ->
acc.plus(
ComputeDurationUtils.durationInHours(
startDateTimeUtc = fishAction?.startDateTimeUtc,
endDateTimeUtc = fishAction?.endDateTimeUtc
)
)
};
}

fun getNbrOfInfraction(fishActions: List<MissionFishActionEntity?>): Double {
return fishActions.filterNotNull().fold(0.0) { acc, c ->
acc.plus(c.gearInfractions?.count { it.natinf != null } ?: 0)
.plus(c.otherInfractions?.count { it.natinf != null } ?: 0)
.plus(c.speciesInfractions?.count { it.natinf != null } ?: 0)
.plus(c.logbookInfractions?.count { it.natinf != null } ?: 0)
};
}

fun getNbrOfInfractionWithPV(fishActions: List<MissionFishActionEntity?>): Double {
return fishActions.filterNotNull()
.fold(0.0) { acc, c ->
acc.plus(c.gearInfractions?.filter { g -> g.infractionType == InfractionType.WITH_RECORD }?.size ?: 0)
.plus(
c.otherInfractions?.filter { o -> o.infractionType == InfractionType.WITH_RECORD }?.size ?: 0
)
.plus(
c.speciesInfractions?.filter { s -> s.infractionType == InfractionType.WITH_RECORD }?.size ?: 0
)
.plus(
c.logbookInfractions?.filter { l -> l.infractionType == InfractionType.WITH_RECORD }?.size ?: 0
)
};
}

fun getNbrOfSeizureAndDiversionVessel(fishActions: List<MissionFishActionEntity?>): Double {
return fishActions.filter { it?.seizureAndDiversion == true }.size.toDouble();
}

fun getQuantityOfFish(fishActions: List<MissionFishActionEntity?>): Double {
return fishActions
.filterNotNull()
.sumOf { it.speciesQuantitySeized?.toDouble() ?: 0.0 } }

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package fr.gouv.dgampa.rapportnav.domain.entities.aem.v2

import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ActionType
import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionNavActionEntity
import fr.gouv.dgampa.rapportnav.domain.utils.AEMUtils

data class AEMIllegalImmigration2(
val nbrOfHourAtSea: Double? = 0.0, //3.4.1
val nbrOfInterceptedVessel: Double? = 0.0, // 3.4.3
val nbrOfInterceptedMigrant: Double? = 0.0, // 3.4.4
val nbrOfSuspectedSmuggler: Double? = 0.0 // 3.4.4
) {
constructor(
navActions: List<MissionNavActionEntity>
) : this(
nbrOfHourAtSea = AEMUtils.getDurationInHours2(getIllegalActions(navActions)),
nbrOfInterceptedVessel = getNbrOfInterceptedVessel(getIllegalActions(navActions)),
nbrOfInterceptedMigrant = getNbrOfInterceptedMigrant(getIllegalActions(navActions)),
nbrOfSuspectedSmuggler = getNbrOfSuspectedSmuggler(getIllegalActions(navActions))
) {}

companion object {
fun getNbrOfInterceptedVessel(illegalActions: List<MissionNavActionEntity?>): Double {
return illegalActions.fold(0.0) { acc, illegalAction ->
acc.plus(
illegalAction?.nbOfInterceptedVessels ?: 0
)
}
}

fun getNbrOfInterceptedMigrant(illegalActions: List<MissionNavActionEntity?>): Double {
return illegalActions.fold(0.0) { acc, illegalAction ->
acc.plus(
illegalAction?.nbOfInterceptedMigrants ?: 0
)
}
}

fun getNbrOfSuspectedSmuggler(illegalActions: List<MissionNavActionEntity?>): Double {
return illegalActions.fold(0.0) { acc, illegalAction ->
acc.plus(
illegalAction?.nbOfSuspectedSmugglers ?: 0
)
}
}

private fun getIllegalActions(navActions: List<MissionNavActionEntity>): List<MissionNavActionEntity?> {
return navActions.filter { it.actionType == ActionType.ILLEGAL_IMMIGRATION }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package fr.gouv.dgampa.rapportnav.domain.entities.aem.v2

import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ActionType
import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionNavActionEntity
import fr.gouv.dgampa.rapportnav.domain.utils.AEMUtils

data class AEMMigrationRescue2(
val nbrOfHourAtSea: Double? = 0.0, // 1.2.1
val nbrOfOperation: Double? = 0.0,// 1.2.3
val nbrOfVesselsTrackedWithoutIntervention: Double? = 0.0, //1.2.4
val nbrAssistedVesselsReturningToShore: Double? = 0.0, //1.2.5
val nbrOfRescuedOperation: Double? = 0.0, //1.2.6
val nbrPersonsRescued: Double? = 0.0,// 1.2.7
) {
constructor(
navActions: List<MissionNavActionEntity>
) : this(
nbrOfRescuedOperation = getMigrationRescueActions(navActions).size.toDouble(),
nbrOfHourAtSea = AEMUtils.getDurationInHours2(getMigrationRescueActions(navActions)),
nbrPersonsRescued = getNbrPersonsRescued(getMigrationRescueActions(navActions)),
nbrOfOperation = getMigrationRescueActions(navActions).size.toDouble(), //TODO: Define correctly what that means
nbrAssistedVesselsReturningToShore = getAssistedVesselsReturningToShore(getMigrationRescueActions(navActions)),
nbrOfVesselsTrackedWithoutIntervention = getNbrOfVesselsTrackedWithoutIntervention(
getMigrationRescueActions(
navActions
)
)

)

companion object {
fun getNbrPersonsRescued(actionRescues: List<MissionNavActionEntity?>): Double {
return actionRescues.fold(0.0) { acc, actionRescue -> acc.plus(actionRescue?.numberPersonsRescued ?: 0) }
}

fun getNbrOfVesselsTrackedWithoutIntervention(actionRescues: List<MissionNavActionEntity?>): Double {
return actionRescues.fold(0.0) { acc, actionRescue ->
acc.plus(
actionRescue?.nbOfVesselsTrackedWithoutIntervention ?: 0
)
}
}

fun getAssistedVesselsReturningToShore(actionRescues: List<MissionNavActionEntity?>): Double {
return actionRescues.fold(0.0) { acc, actionRescue ->
acc.plus(
actionRescue?.nbAssistedVesselsReturningToShore ?: 0
)
}
}

private fun getMigrationRescueActions(navActions: List<MissionNavActionEntity>): List<MissionNavActionEntity?> {
return navActions.filter { it.actionType == ActionType.RESCUE }
.filter { it.isMigrationRescue == true }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package fr.gouv.dgampa.rapportnav.domain.entities.aem.v2

import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.InfractionTypeEnum
import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionEnvActionEntity
import fr.gouv.dgampa.rapportnav.domain.utils.AEMUtils

data class AEMNotPollutionControlSurveillance2(
val nbrOfHourAtSea: Double? = 0.0, //4.1.1
val nbrOfAction: Double? = 0.0, // 4.1.3
val nbrOfInfraction: Double? = 0.0, // 4.1.4
val nbrOfInfractionWithNotice: Double? = 0.0 // 4.1.5
) {
constructor(
envActions: List<MissionEnvActionEntity?>
) : this(
nbrOfHourAtSea = AEMUtils.getDurationInHours2(getNotPollutionActions(envActions)),
nbrOfAction = getNotPollutionActions(envActions).size.toDouble(),
nbrOfInfraction = getNbrOfInfraction(getNotPollutionActions(envActions)),
nbrOfInfractionWithNotice = getNbrOfInfractionWithNotice(getNotPollutionActions(envActions))
) {

}

companion object {

fun getNbrOfInfraction(notPollutionActions: List<MissionEnvActionEntity?>): Double {
return notPollutionActions
.fold(0.0) { acc, c ->
acc.plus(c?.envInfractions?.flatMap { it.natinf ?: listOf() }?.size ?: 0)
}
}

fun getNbrOfInfractionWithNotice(notPollutionActions: List<MissionEnvActionEntity?>): Double {
return notPollutionActions.fold(0.0) { acc, c ->
acc.plus(
c?.envInfractions?.filter { it.infractionType == InfractionTypeEnum.WITH_REPORT }?.size ?: 0
)
}
}

private fun getNotPollutionActions(envActions: List<MissionEnvActionEntity?>): List<MissionEnvActionEntity?> {
val illicitRejects = listOf(19, 102);
return envActions.filter {
it?.controlPlans?.map { c -> c.themeId }?.intersect(illicitRejects)?.isEmpty() == true
}
}

}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package fr.gouv.dgampa.rapportnav.domain.entities.aem.v2

import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ActionType
import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionNavActionEntity
import fr.gouv.dgampa.rapportnav.domain.utils.AEMUtils

data class AEMOutOfMigrationRescue2(
val nbrOfHourAtSea: Double? = 0.0, //1.1.1
val nbrOfRescuedOperation: Double? = 0.0, //1.1.3.
val nbrPersonsRescued: Double? = 0.0, //1.1.4
) {
constructor(
navActions: List<MissionNavActionEntity>
) : this(
nbrOfRescuedOperation = getMigrationRescueActions(navActions).size.toDouble(),
nbrPersonsRescued = getNbrPersonsRescued(getMigrationRescueActions(navActions)),
nbrOfHourAtSea = AEMUtils.getDurationInHours2(getMigrationRescueActions(navActions)),
) {
}

companion object {
fun getNbrPersonsRescued(actionRescues: List<MissionNavActionEntity?>): Double {
return actionRescues.fold(0.0) { acc, actionRescue -> acc.plus(actionRescue?.numberPersonsRescued ?: 0) }
}

private fun getMigrationRescueActions(navActions: List<MissionNavActionEntity>): List<MissionNavActionEntity?> {
return navActions.filter { it.actionType == ActionType.RESCUE }
.filter { it.isMigrationRescue != true };
}
}
}
Loading

0 comments on commit 51f7c02

Please sign in to comment.