Skip to content

Commit

Permalink
Fix few UI and add logger for use-case perfs
Browse files Browse the repository at this point in the history
  • Loading branch information
louptheron committed Sep 13, 2024
1 parent 50651aa commit 904f61e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import fr.gouv.cnsp.monitorfish.domain.repositories.ReportingRepository
import fr.gouv.cnsp.monitorfish.domain.use_cases.control_units.GetAllControlUnits
import org.slf4j.LoggerFactory
import java.time.ZonedDateTime
import kotlin.time.measureTimedValue

@UseCase
class GetVesselReportings(
Expand All @@ -29,41 +30,51 @@ class GetVesselReportings(
vesselIdentifier: VesselIdentifier?,
fromDate: ZonedDateTime,
): VesselReportings {
val controlUnits = getAllControlUnits.execute()

val reportings =
findReportings(
val (controlUnits, controlUnitsTimeTaken) = measureTimedValue { getAllControlUnits.execute() }
logger.info("TIME_RECORD - 'getAllControlUnits' took $controlUnitsTimeTaken")

val (reportings, reportingsTimeTaken) =
measureTimedValue { findReportings(
vesselId,
vesselIdentifier,
internalReferenceNumber,
fromDate,
ircs,
externalReferenceNumber,
)
) }
logger.info("TIME_RECORD - 'findReportings' took $reportingsTimeTaken")

val current =
getReportingsAndOccurrences(reportings.filter { !it.isArchived })
.sortedWith(compareByDescending { it.reporting.validationDate ?: it.reporting.creationDate })
.map { reportingAndOccurrences ->
enrichWithInfractionAndControlUnit(reportingAndOccurrences, controlUnits)
}

val yearsRange = fromDate.year..ZonedDateTime.now().year
val archivedYearsToReportings =
yearsRange.associateWith { year ->
val reportingsOfYear =
reportings
.filter { it.isArchived }
.filter { filterByYear(it, year) }

getReportingsAndOccurrences(reportingsOfYear)
val (current, currentTimeTaken) =
measureTimedValue {
getReportingsAndOccurrences(reportings.filter { !it.isArchived })
.sortedWith(compareByDescending { it.reporting.validationDate ?: it.reporting.creationDate })
.map { reportingAndOccurrences ->
enrichWithInfractionAndControlUnit(reportingAndOccurrences, controlUnits)
}
}
logger.info("TIME_RECORD - 'current' took $currentTimeTaken")

val yearsRange = fromDate.year..ZonedDateTime.now().year
val (archivedYearsToReportings, archivedYearsToReportingsTimeTaken) =
measureTimedValue {
yearsRange.associateWith { year ->
val reportingsOfYear =
reportings
.filter { it.isArchived }
.filter { filterByYear(it, year) }

getReportingsAndOccurrences(reportingsOfYear)
.sortedWith(compareByDescending { it.reporting.validationDate ?: it.reporting.creationDate })
.map { reportingAndOccurrences ->
enrichWithInfractionAndControlUnit(reportingAndOccurrences, controlUnits)
}
}
}
logger.info("TIME_RECORD - 'archivedYearsToReportings' took $archivedYearsToReportingsTimeTaken")

val infractionSuspicionsSummary = getInfractionSuspicionsSummary(reportings.filter { it.isArchived })
val (infractionSuspicionsSummary, infractionSuspicionsSummaryTimeTaken) = measureTimedValue { getInfractionSuspicionsSummary(reportings.filter { it.isArchived }) }
logger.info("TIME_RECORD - 'infractionSuspicionsSummary' took $infractionSuspicionsSummaryTimeTaken")
val numberOfInfractionSuspicions = infractionSuspicionsSummary.sumOf { it.numberOfOccurrences }
val numberOfObservation =
reportings
Expand Down Expand Up @@ -93,7 +104,7 @@ class GetVesselReportings(
.groupBy { (it.value as AlertType).type }
.map { (type, reportings) ->
ReportingTitleAndNumberOfOccurrences(
title = type.alertName,
title = "${type.alertName} (NATINF ${reportings[0].value.natinfCode})",
numberOfOccurrences = reportings.size,
)
}
Expand All @@ -113,7 +124,7 @@ class GetVesselReportings(
}

return@map ReportingTitleAndNumberOfOccurrences(
title = infraction?.infraction ?: "NATINF $natinfCode",
title = infraction?.infraction?.let {"$it (NATINF $natinfCode)"} ?: "NATINF $natinfCode",
numberOfOccurrences = reportings.size,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,14 +413,14 @@ class GetVesselReportingsUTests {
val infractionSuspicionsSummary = result.summary.infractionSuspicionsSummary
assertThat(result.summary.infractionSuspicionsSummary).hasSize(4)
assertThat(infractionSuspicionsSummary[0].numberOfOccurrences).isEqualTo(2)
assertThat(infractionSuspicionsSummary[0].title).isEqualTo("12 milles - Pêche sans droits historiques")
assertThat(infractionSuspicionsSummary[0].title).isEqualTo("12 milles - Pêche sans droits historiques (NATINF 2610)")
assertThat(infractionSuspicionsSummary[1].numberOfOccurrences).isEqualTo(1)
assertThat(infractionSuspicionsSummary[1].title).isEqualTo("Non-emission de message \"FAR\" en 48h")
assertThat(infractionSuspicionsSummary[1].title).isEqualTo("Non-emission de message \"FAR\" en 48h (NATINF 27689)")
assertThat(infractionSuspicionsSummary[2].numberOfOccurrences).isEqualTo(1)
assertThat(
infractionSuspicionsSummary[2].title,
).isEqualTo(
"Peche maritime non autorisee dans les eaux maritimes ou salees francaises par un navire de pays tiers a l'union europeenne",
"Peche maritime non autorisee dans les eaux maritimes ou salees francaises par un navire de pays tiers a l'union europeenne (NATINF 7059)",
)
assertThat(infractionSuspicionsSummary[3].numberOfOccurrences).isEqualTo(1)
assertThat(infractionSuspicionsSummary[3].title).isEqualTo("NATINF 123456")
Expand Down
3 changes: 0 additions & 3 deletions frontend/cypress/e2e/vessel_sidebar/reporting.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,10 @@ context('Vessel sidebar reporting tab', () => {

// Dates occurrences of an alert
cy.get('*[data-cy="vessel-sidebar-reporting-tab-archive-year"]').eq(0).click()
cy.get('[data-cy="reporting-card"]').should('not.contain', '2è alerte le')
cy.get('[data-cy="reporting-card"]').should('not.contain', '1ère alerte le')
cy.clickLink('Voir les dates des autres alertes')
cy.get('[data-cy="reporting-card"]').should('contain', '2è alerte le')
cy.get('[data-cy="reporting-card"]').should('contain', '1ère alerte le')
cy.clickLink('Masquer les dates des autres alertes')
cy.get('[data-cy="reporting-card"]').should('not.contain', '2è alerte le')
cy.get('[data-cy="reporting-card"]').should('not.contain', '1ère alerte le')

cy.get('*[data-cy^="vessel-search-selected-vessel-close-title"]', { timeout: 10000 }).click()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function ReportingCard({
reporting.type === ReportingType.ALERT ? reporting.validationDate : reporting.creationDate,
true
)
const otherOccurrencesDates = [reporting].concat(otherOccurrencesOfSameAlert).map((alert, index, array) => {
const otherOccurrencesDates = otherOccurrencesOfSameAlert.map((alert, index, array) => {
const dateTime = getDateTime(alert.validationDate, true)

return `${getFrenchOrdinal(array.length - (index + 1))} alerte le ${dateTime}`
Expand Down Expand Up @@ -107,14 +107,16 @@ export function ReportingCard({
)}
</Body>
{isArchived ? (
<NumberOfAlerts isArchived>{otherOccurrencesOfSameAlert.length + 1}</NumberOfAlerts>
otherOccurrencesOfSameAlert.length > 0 && (
<NumberOfAlerts isArchived>{otherOccurrencesOfSameAlert.length + 1}</NumberOfAlerts>
)
) : (
<Actions hasOccurrences={otherOccurrencesOfSameAlert.length > 0}>
{otherOccurrencesOfSameAlert.length > 0 && (
<NumberOfAlerts>{otherOccurrencesOfSameAlert.length + 1}</NumberOfAlerts>
)}
{reporting.type !== ReportingType.ALERT && (
<IconButton
<StyledIconButton
accent={Accent.TERTIARY}
color={THEME.color.charcoal}
data-cy={`edit-reporting-card-${reporting.id}`}
Expand All @@ -124,7 +126,7 @@ export function ReportingCard({
title="Editer"
/>
)}
<IconButton
<StyledIconButton
accent={Accent.TERTIARY}
color={THEME.color.charcoal}
data-cy="archive-reporting-card"
Expand All @@ -133,7 +135,7 @@ export function ReportingCard({
onClick={() => dispatch(archiveReporting(reporting.id, reporting.type))}
title="Archiver"
/>
<IconButton
<StyledIconButton
accent={Accent.TERTIARY}
color={THEME.color.charcoal}
data-cy="delete-reporting-card"
Expand All @@ -157,6 +159,10 @@ const Wrapper = styled.div<{
margin-bottom: 16px;
`

const StyledIconButton = styled(IconButton)`
padding-top: 8px;
`

const OtherOccurrenceAlertDate = styled.span`
font-size: 11px;
margin-top: 4px;
Expand Down Expand Up @@ -206,7 +212,7 @@ const Actions = styled.div<{
const NumberOfAlerts = styled.span<{
isArchived?: boolean | undefined
}>`
margin-top: ${p => (p.isArchived ? 8 : 0)}px;
margin-top: ${p => (p.isArchived ? 8 : 8)}px;
margin-right: ${p => (p.isArchived ? '8px' : 'unset')};
margin-left: ${p => (p.isArchived ? 'auto' : 'unset')};
background: ${p => p.theme.color.maximumRed} 0% 0% no-repeat padding-box;
Expand Down

0 comments on commit 904f61e

Please sign in to comment.