Skip to content

Commit

Permalink
[Cartographie & Missions] Corrections mineures (#2566)
Browse files Browse the repository at this point in the history
## Linked issues

- Resolve #2512

----

- [ ] Tests E2E (Cypress)
  • Loading branch information
louptheron committed Oct 13, 2023
2 parents b57abe0 + 34fc381 commit e38a4fd
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import java.time.ZonedDateTime

interface LastPositionRepository {
fun findAll(): List<LastPosition>
fun findAllInLast48Hours(): List<LastPosition>
fun findAllInLastMonthOrWithBeaconMalfunction(): List<LastPosition>
fun findAllWithBeaconMalfunctionBeforeLast48Hours(): List<LastPosition>
fun findLastPositionDate(): ZonedDateTime
fun removeAlertToLastPositionByVesselIdentifierEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import fr.gouv.cnsp.monitorfish.domain.repositories.LastPositionRepository
@UseCase
class GetLastPositions(private val lastPositionRepository: LastPositionRepository) {
fun execute(): List<LastPosition> {
return lastPositionRepository.findAll()
return lastPositionRepository.findAllInLastMonthOrWithBeaconMalfunction()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class JpaLastPositionRepository(
}

@Cacheable(value = ["vessels_positions"])
override fun findAllInLast48Hours(): List<LastPosition> {
val nowMinus48Hours = ZonedDateTime.now().minusHours(48)
return dbLastPositionRepository.findAllByDateTimeGreaterThanEqual(nowMinus48Hours)
override fun findAllInLastMonthOrWithBeaconMalfunction(): List<LastPosition> {
val nowMinusOneMonth = ZonedDateTime.now().minusMonths(1)
return dbLastPositionRepository.findAllByDateTimeGreaterThanEqualOrBeaconMalfunctionIdNotNull(nowMinusOneMonth)
// We NEED this non filterNotNull (even if the IDE say not so, as the SQL request may return null internalReferenceNumber)
.filterNotNull()
.map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import java.time.ZonedDateTime
interface DBLastPositionRepository : JpaRepository<LastPositionEntity, Int> {
fun findAllByDateTimeLessThanEqualAndBeaconMalfunctionIdNotNull(dateTime: ZonedDateTime): List<LastPositionEntity>

fun findAllByDateTimeGreaterThanEqual(dateTime: ZonedDateTime): List<LastPositionEntity>
/**
* We need to get all recent positions OR positions with a beacon malfunction
*/
fun findAllByDateTimeGreaterThanEqualOrBeaconMalfunctionIdNotNull(dateTime: ZonedDateTime): List<LastPositionEntity>

@Query(
"select last_position_datetime_utc from last_positions where last_position_datetime_utc < now() order by last_position_datetime_utc desc limit 1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ COPY public.last_positions (vessel_id, cfr, external_immatriculation, mmsi, ircs
vessel_identifier, estimated_current_latitude, estimated_current_longitude,
impact_risk_factor, probability_risk_factor, detectability_risk_factor, risk_factor,
under_charter, is_at_port, alerts, beacon_malfunction_id, reportings) FROM stdin;
\N ABC000339263 CN775734 023858744 YHIZ PAYSAGE ROMAN LIER FR 20210004 48.0970000000000013 -4.3230000000000004 0.5 351 2020-12-31 23:19:00 01:01:00 2020-07-08 02:53:00 2020-07-08 01:54:00 6.5 17 Evrard Saint EmmanuelVille SI [{"gear": "PS1", "mesh": 10.0, "dimensions": 380.0}] {} [{"gear": "PS1", "weight": 1400.0, "faoZone": "27.7.e", "species": "PIL"}] 0 144 2019-12-22 15:42:00 f \N INTERNAL_REFERENCE_NUMBER 48.1029308080762021 -4.32440242826396037 3.57112043211236596 3.39079180965200067 3.44572579581290483 3.45375553585179773 f t {THREE_MILES_TRAWLING_ALERT} \N \N
\N ABC000126173 XN916551 312649432 EIL2780 ROND PRISON GARDER FR \N 47.2989999999999995 -2.51500000000000012 0 351 2020-12-31 23:36:00 01:00:00 \N \N 6.32000000000000028 18 Grondin Herve-la-Forêt FQ null {} null 0 7 2020-07-31 08:56:00 f REJET COE 10KG\r\nREJET WHB 50KG\r\nREJET HOM 200KG\r\nREJET SCL 150KG\r\nREJET BIB 50KG INTERNAL_REFERENCE_NUMBER 47.2989999999999995 -2.51500000000000012 1.29840274900197983 2.57117246789857745 1.52456657541915774 1.72700838038104321 f f {} \N \N
\N ABC000339263 CN775734 023858744 YHIZ PAYSAGE ROMAN LIER FR 20210004 48.0970000000000013 -4.3230000000000004 0.5 351 2020-12-31 23:19:00 01:01:00 2020-07-08 02:53:00 2020-07-08 01:54:00 6.5 17 Evrard Saint EmmanuelVille SI [{"gear": "PS1", "mesh": 10.0, "dimensions": 380.0}] {} [{"gear": "PS1", "weight": 1400.0, "faoZone": "27.7.e", "species": "PIL"}] 0 144 2019-12-22 15:42:00 f \N INTERNAL_REFERENCE_NUMBER 48.1029308080762021 -4.32440242826396037 3.57112043211236596 3.39079180965200067 3.44572579581290483 3.45375553585179773 f t {THREE_MILES_TRAWLING_ALERT} 124 \N
\N ABC000126173 XN916551 312649432 EIL2780 ROND PRISON GARDER FR \N 47.2989999999999995 -2.51500000000000012 0 351 2020-12-31 23:36:00 01:00:00 \N \N 6.32000000000000028 18 Grondin Herve-la-Forêt FQ null {} null 0 7 2020-07-31 08:56:00 f REJET COE 10KG\r\nREJET WHB 50KG\r\nREJET HOM 200KG\r\nREJET SCL 150KG\r\nREJET BIB 50KG INTERNAL_REFERENCE_NUMBER 47.2989999999999995 -2.51500000000000012 1.29840274900197983 2.57117246789857745 1.52456657541915774 1.72700838038104321 f f {} 123 \N
\N ABC000262563 NL342908 632033196 MN0259 ENTRETENIR NOIRE VENTRE FR 20210106 44.4309999999999974 -1.39599999999999991 0.800000000000000044 357 2020-12-31 23:51:00 01:00:00 2020-07-12 19:35:00 2020-07-07 23:20:00 6.62000000000000011 20.7899999999999991 Cordier ClercVille EC [{"gear": "OTB", "mesh": 70.0, "dimensions": 100.0}] {SWW01/02/03,PEL03} [{"gear": "OTB", "weight": 482.0, "faoZone": "27.8.b", "species": "MAC"}, {"gear": "OTB", "weight": 20.1, "faoZone": "27.8.b", "species": "TRA"}, {"gear": "OTB", "weight": 209.93, "faoZone": "27.8.b", "species": "BIB"}, {"gear": "OTB", "weight": 77.1, "faoZone": "27.8.b", "species": "GUR"}, {"gear": "OTB", "weight": 45.4, "faoZone": "27.8.b", "species": "MUR"}, {"gear": "OTB", "weight": 187.88, "faoZone": "27.8.b", "species": "MNZ"}, {"gear": "OTB", "weight": 69.29, "faoZone": "27.8.b", "species": "SMD"}, {"gear": "OTB", "weight": 366.3, "faoZone": "27.8.b", "species": "HKE"}, {"gear": "OTB", "weight": 28.8, "faoZone": "27.8.b", "species": "GUG"}, {"gear": "OTB", "weight": 1.2, "faoZone": "27.8.b", "species": "TRI"}, {"gear": "OTB", "weight": 37.41, "faoZone": "27.8.b", "species": "RJM"}, {"gear": "OTB", "weight": 65.6, "faoZone": "27.8.b", "species": "SQR"}, {"gear": "OTB", "weight": 10.0, "faoZone": "27.8.b", "species": "COB"}, {"gear": "OTB", "weight": 0.8, "faoZone": "27.8.b", "species": "MGR"}, {"gear": "OTB", "weight": 32.14, "faoZone": "27.8.b", "species": "SOL"}, {"gear": "OTB", "weight": 8.5, "faoZone": "27.8.b", "species": "BRB"}, {"gear": "OTB", "weight": 254.1, "faoZone": "27.8.b", "species": "CTC"}, {"gear": "OTB", "weight": 1.1, "faoZone": "27.8.b", "species": "SCO"}, {"gear": "OTB", "weight": 66.99, "faoZone": "27.8.b", "species": "LEZ"}, {"gear": "OTB", "weight": 1.6, "faoZone": "27.8.b", "species": "SBA"}, {"gear": "OTB", "weight": 210.7, "faoZone": "27.8.b", "species": "JOD"}, {"gear": "OTB", "weight": 0.65, "faoZone": "27.8.b", "species": "BLL"}, {"gear": "OTB", "weight": 272.6, "faoZone": "27.8.b", "species": "BSS"}] 947.42999999999995 8 2020-08-03 20:05:00 f CTL DOC OK INTERNAL_REFERENCE_NUMBER 44.4334992837590974 -1.3961828035342001 2.54482043627649546 3.05314559629186988 3.03943056892603636 2.937323614598911 f f {} \N \N
\N ABC000333370 PE683913 996909113 HM9088 CENTRE OCCUPER GARÇON FR 20210176 49.6370000000000005 -1.62000000000000011 0 0 2020-12-31 23:15:00 01:00:00 2020-07-12 18:46:00 2020-07-12 10:23:00 5.90000000000000036 15.8000000000000007 Parent Sainte LucBourg WU [{"gear": "DRB", "mesh": 92.0, "dimensions": null}] {} [{"gear": "DRB", "weight": 2000.0, "faoZone": "27.7.d", "species": "SCE"}] 0 11 2020-01-23 23:04:00 f \N INTERNAL_REFERENCE_NUMBER 49.6370000000000005 -1.62000000000000011 2.66969937458634377 2.46412607468664646 1.51048578694462776 1.96042246604452752 f f {} \N \N
\N ABC000830601 SM062444 090389119 YFI6751 MATIN PORTIER MIEUX FR 20210018 49.3879999999999981 -1.04899999999999993 0 0 2020-12-31 23:23:00 01:00:00 2020-07-12 19:08:00 2020-07-12 08:42:00 5.79999999999999982 15.6999999999999993 Guerin-sur-Laurent Duboisdan JC [{"gear": "DRB", "mesh": null, "dimensions": null}] {} [{"gear": "DRB", "weight": 1650.0, "faoZone": "27.7.d", "species": "SCE"}] 0 23 2020-08-31 23:35:00 f \N INTERNAL_REFERENCE_NUMBER 49.3879999999999981 -1.04899999999999993 1.79132287902757525 1.31471516052260995 2.16846009390428662 1.79622192427431071 f f {} \N \N
Expand Down Expand Up @@ -1010,7 +1010,7 @@ COPY public.last_positions (vessel_id, cfr, external_immatriculation, mmsi, ircs
\.


-- Shift dates to present
-- Shift all positions dates to present
update last_positions
set last_position_datetime_utc = last_position_datetime_utc + (now() - '2021-01-01 00:00:00Z'::TIMESTAMPTZ);
update last_positions
Expand Down Expand Up @@ -1123,3 +1123,6 @@ SET vessel_id = 12 WHERE cfr = 'FR263465414';
UPDATE last_positions
SET vessel_id = 13 WHERE cfr = 'FR263454484';

update last_positions
set last_position_datetime_utc = NOW() - ('2 YEARS')::interval
where cfr = 'ABC000339263';
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ class JpaLastPositionRepositoryITests : AbstractDBTests() {

@Test
@Transactional
fun `findAllInLast48Hours Should returns the last positions in the last 48 hours`() {
fun `findAllInLastMonth Should returns the last positions in the last month`() {
// Then
val positions = jpaLastPositionRepository.findAllInLast48Hours()
val positions = jpaLastPositionRepository.findAllInLastMonthOrWithBeaconMalfunction()

assertThat(positions).hasSize(999)
assertThat(positions).hasSize(1003)
val assertedVessel = positions.find { it.internalReferenceNumber == "ABC000339263" }
assertThat(assertedVessel?.dateTime).isBefore(ZonedDateTime.now().minusMonths(1))
}

@Test
Expand All @@ -69,7 +71,7 @@ class JpaLastPositionRepositoryITests : AbstractDBTests() {
// Then
val positions = jpaLastPositionRepository.findAllWithBeaconMalfunctionBeforeLast48Hours()

assertThat(positions).hasSize(1)
assertThat(positions).hasSize(2)
assertThat(positions.first().internalReferenceNumber).isEqualTo("ABC000939217")
assertThat(positions.first().vesselName).isEqualTo("FRAIS AVIS MODE")
assertThat(positions.first().beaconMalfunctionId).isEqualTo(7)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export function CustomZones({ hideLayersListWhenSearching = false, namespace }:

const HowTo = styled.li`
color: ${p => p.theme.color.slateGray};
padding: 24px 44px;
padding: 24px 24px;
font-style: italic;
`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export const ChevronIcon = styled(Icon.Chevron)<{
$isOpen: boolean
}>`
margin-right: 16px;
transform: ${p => (!p.$isOpen ? 'rotate(180deg)' : 'rotate(0deg)')};
transform: ${p => (!p.$isOpen ? 'rotate(0deg)' : 'rotate(180deg)')};
transition: all 0.5s;
`

0 comments on commit e38a4fd

Please sign in to comment.