Skip to content

Commit

Permalink
Merge pull request #236 from dataforgoodfr/feat/234
Browse files Browse the repository at this point in the history
Feat/234
  • Loading branch information
njouanin authored Nov 1, 2024
2 parents f589aa9 + 80031cd commit f0f2a47
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion backend/bloom/domain/excursion.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ class Excursion(BaseModel):
total_time_fishing_in_amp: Union[timedelta, None] = None
total_time_fishing_in_territorial_waters: Union[timedelta, None] = None
total_time_fishing_in_costal_waters: Union[timedelta, None] = None
total_time_extincting_amp: Union[timedelta, None] = None
total_time_default_ais: Union[timedelta, None] = None
created_at: Union[datetime, None] = None
updated_at: Union[datetime, None] = None
2 changes: 1 addition & 1 deletion backend/bloom/infra/database/sql_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class Excursion(Base):
total_time_fishing_in_amp = Column("total_time_fishing_in_amp", Interval)
total_time_fishing_in_territorial_waters = Column("total_time_fishing_in_territorial_waters", Interval)
total_time_fishing_in_costal_waters = Column("total_time_fishing_in_costal_waters", Interval)
total_time_extincting_amp = Column("total_time_extincting_amp", Interval)
total_time_default_ais = Column("total_time_default_ais", Interval)
created_at = Column("created_at", DateTime(timezone=True), server_default=func.now())
updated_at = Column("updated_at", DateTime(timezone=True), onupdate=func.now())

Expand Down
6 changes: 3 additions & 3 deletions backend/bloom/infra/repositories/repository_excursion.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def map_to_sql(excursion: Excursion) -> sql_model.Excursion:
total_time_fishing_in_amp=excursion.total_time_fishing_in_amp,
total_time_fishing_in_territorial_waters=excursion.total_time_fishing_in_territorial_waters,
total_time_fishing_in_costal_waters=excursion.total_time_fishing_in_costal_waters,
total_time_extincting_amp=excursion.total_time_extincting_amp,
total_time_default_ais=excursion.total_time_default_ais,
created_at=excursion.created_at,
updated_at=excursion.updated_at
)
Expand All @@ -160,7 +160,7 @@ def map_to_domain(excursion: sql_model.Excursion) -> Excursion:
total_time_fishing_in_amp=excursion.total_time_fishing_in_amp,
total_time_fishing_in_territorial_waters=excursion.total_time_fishing_in_territorial_waters,
total_time_fishing_in_costal_waters=excursion.total_time_fishing_in_costal_waters,
total_time_extincting_amp=excursion.total_time_extincting_amp,
total_time_default_ais=excursion.total_time_default_ais,
created_at=excursion.created_at,
updated_at=excursion.updated_at
)
Expand All @@ -186,7 +186,7 @@ def map_to_orm(excursion: Excursion) -> sql_model.Excursion:
total_time_fishing_in_amp=excursion.total_time_fishing_in_amp,
total_time_fishing_in_territorial_waters=excursion.total_time_fishing_in_territorial_waters,
total_time_fishing_in_costal_waters=excursion.total_time_fishing_in_costal_waters,
total_time_extincting_amp=excursion.total_time_extincting_amp,
total_time_default_ais=excursion.total_time_default_ais,
created_at=excursion.created_at,
updated_at=excursion.updated_at
)
11 changes: 8 additions & 3 deletions backend/bloom/tasks/create_update_excursions_segments.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def add_excursion(session: Session, vessel_id: int, departure_at: datetime,
total_time_fishing_in_amp=timedelta(0),
total_time_fishing_in_territorial_waters=timedelta(0),
total_time_fishing_in_costal_waters=timedelta(0),
total_time_extincting_amp=timedelta(0)
total_time_default_ais=timedelta(0)
)
new_excursion = excursion_repository.create_excursion(session, new_excursion)
return new_excursion.id
Expand Down Expand Up @@ -303,6 +303,9 @@ def get_time_of_departure():
for segment, zones in result.items():
segment_in_zone = False
for zone in zones:
if segment.type == "DEFAULT_AIS":
# Issue 234: ne pas créer les relations pour les segments en default AIS
continue
segment_in_zone = True
new_rels.append(RelSegmentZone(segment_id=segment.id, zone_id=zone.id))
if zone.category == "amp":
Expand All @@ -321,8 +324,6 @@ def get_time_of_departure():
excursion.total_time_in_amp += segment.segment_duration
elif segment.type == "FISHING":
excursion.total_time_fishing_in_amp += segment.segment_duration
elif segment.type == "DEFAULT_AIS":
excursion.total_time_extincting_amp += segment.segment_duration
if segment.in_costal_waters:
if segment.type == "AT_SEA":
excursion.total_time_in_costal_waters += segment.segment_duration
Expand All @@ -337,6 +338,10 @@ def get_time_of_departure():
excursion.excursion_duration += segment.segment_duration
if segment.type == "FISHING":
excursion.total_time_fishing += segment.segment_duration
elif segment.type == "DEFAULT_AIS":
if excursion.total_time_default_ais is None:
excursion.total_time_default_ais = timedelta(0)
excursion.total_time_default_ais += segment.segment_duration

excursion.total_time_at_sea = excursion.excursion_duration - (
excursion.total_time_in_costal_waters + excursion.total_time_in_territorial_waters)
Expand Down
2 changes: 1 addition & 1 deletion backend/bloom/tasks/load_fct_excursions_from_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def map_excursion_to_domain(row) -> Excursion:
total_time_fishing_in_amp=None,
total_time_fishing_in_territorial_waters=None,
total_time_fishing_in_costal_waters=None,
total_time_extincting_amp=None,
total_time_default_ais=None,
created_at=None,
updated_at=None,
)
Expand Down

0 comments on commit f0f2a47

Please sign in to comment.