From 43a83b3f9d417302b376b1bb644d45329735b007 Mon Sep 17 00:00:00 2001 From: njouanin Date: Tue, 5 Nov 2024 21:47:23 +0100 Subject: [PATCH] Renommages des colonnes des tables fct_ (#237) --- .../7ba4634af5ad_rename_fct_columns.py | 26 +++++++++++++++++++ backend/bloom/dependencies.py | 4 +-- backend/bloom/domain/excursion.py | 4 +-- backend/bloom/domain/segment.py | 2 +- backend/bloom/infra/database/sql_model.py | 6 ++--- .../repositories/repository_excursion.py | 12 ++++----- .../infra/repositories/repository_segment.py | 8 +++--- .../create_update_excursions_segments.py | 16 ++++++------ .../tasks/load_fct_excursions_from_csv.py | 6 ++--- 9 files changed, 55 insertions(+), 29 deletions(-) create mode 100644 backend/alembic/versions/7ba4634af5ad_rename_fct_columns.py diff --git a/backend/alembic/versions/7ba4634af5ad_rename_fct_columns.py b/backend/alembic/versions/7ba4634af5ad_rename_fct_columns.py new file mode 100644 index 00000000..580ad0bb --- /dev/null +++ b/backend/alembic/versions/7ba4634af5ad_rename_fct_columns.py @@ -0,0 +1,26 @@ +"""rename_fct_columns + +Revision ID: 7ba4634af5ad +Revises: 7921b2e3a780 +Create Date: 2024-11-05 21:26:52.687517 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '7ba4634af5ad' +down_revision = '7921b2e3a780' +branch_labels = None +depends_on = None + + +def upgrade() -> None: + op.alter_column("fct_excursion", "total_time_in_costal_waters", new_column_name="total_time_in_zones_with_no_fishing_rights") + op.alter_column("fct_excursion", "total_time_fishing_in_costal_waters", new_column_name="total_time_fishing_in_zones_with_no_fishing_rights") + op.alter_column("fct_segment", "in_costal_waters", new_column_name="in_zone_with_no_fishing_rights") + + +def downgrade() -> None: + pass diff --git a/backend/bloom/dependencies.py b/backend/bloom/dependencies.py index deac07eb..3014e1b4 100644 --- a/backend/bloom/dependencies.py +++ b/backend/bloom/dependencies.py @@ -76,9 +76,9 @@ class TotalTimeActivityTypeEnum(str, Enum): total_time_at_sea: str = "Total Time at Sea" total_time_in_amp: str = "Total Time in AMP" total_time_in_territorial_waters: str = "Total Time in Territorial Waters" - total_time_in_costal_waters: str = "Total Time in Costal Waters" + total_time_in_zones_with_no_fishing_rights: str = "Total Time in zones with no fishing rights" total_time_fishing: str = "Total Time Fishing" total_time_fishing_in_amp: str = "Total Time Fishing in AMP" total_time_fishing_in_territorial_waters: str = "Total Time Fishing in Territorial Waters" - total_time_fishing_in_costal_waters: str = "Total Time Fishing in Costal Waters" + total_time_fishing_in_zones_with_no_fishing_rights: str = "Total Time Fishing in zones with no fishing rights" total_time_fishing_in_extincting_amp: str = "Total Time in Extincting AMP" \ No newline at end of file diff --git a/backend/bloom/domain/excursion.py b/backend/bloom/domain/excursion.py index 5d28d91e..85e15f5d 100644 --- a/backend/bloom/domain/excursion.py +++ b/backend/bloom/domain/excursion.py @@ -24,11 +24,11 @@ class Excursion(BaseModel): total_time_at_sea: Union[timedelta, None] = None total_time_in_amp: Union[timedelta, None] = None total_time_in_territorial_waters: Union[timedelta, None] = None - total_time_in_costal_waters: Union[timedelta, None] = None + total_time_in_zones_with_no_fishing_rights: Union[timedelta, None] = None total_time_fishing: Union[timedelta, None] = None 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_fishing_in_zones_with_no_fishing_rights: Union[timedelta, None] = None total_time_default_ais: Union[timedelta, None] = None created_at: Union[datetime, None] = None updated_at: Union[datetime, None] = None diff --git a/backend/bloom/domain/segment.py b/backend/bloom/domain/segment.py index 9c706a23..a2509cba 100644 --- a/backend/bloom/domain/segment.py +++ b/backend/bloom/domain/segment.py @@ -29,7 +29,7 @@ class Segment(BaseModel): type: Union[str, None] = None in_amp_zone: Union[bool, None] = None in_territorial_waters: Union[bool, None] = None - in_costal_waters: Union[bool, None] = None + in_zone_with_no_fishing_rights: Union[bool, None] = None last_vessel_segment: Union[bool, None] = None created_at: Union[datetime, None] = None updated_at: Union[datetime, None] = None diff --git a/backend/bloom/infra/database/sql_model.py b/backend/bloom/infra/database/sql_model.py index b1a0d2dd..57a3f855 100644 --- a/backend/bloom/infra/database/sql_model.py +++ b/backend/bloom/infra/database/sql_model.py @@ -187,11 +187,11 @@ class Excursion(Base): total_time_at_sea = Column("total_time_at_sea", Interval) total_time_in_amp = Column("total_time_in_amp", Interval) total_time_in_territorial_waters = Column("total_time_in_territorial_waters", Interval) - total_time_in_costal_waters = Column("total_time_in_costal_waters", Interval) + total_time_in_zones_with_no_fishing_rights = Column("total_time_in_zones_with_no_fishing_rights", Interval) total_time_fishing = Column("total_time_fishing", Interval) 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_fishing_in_zones_with_no_fishing_rights = Column("total_time_fishing_in_zones_with_no_fishing_rights", 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()) @@ -216,7 +216,7 @@ class Segment(Base): type = Column("type", String) in_amp_zone = Column("in_amp_zone", Boolean) in_territorial_waters = Column("in_territorial_waters", Boolean) - in_costal_waters = Column("in_costal_waters", Boolean) + in_zone_with_no_fishing_rights = Column("in_zone_with_no_fishing_rights", Boolean) last_vessel_segment = Column("last_vessel_segment", Boolean) created_at = Column("created_at", DateTime(timezone=True), server_default=func.now()) updated_at = Column("updated_at", DateTime(timezone=True), onupdate=func.now()) diff --git a/backend/bloom/infra/repositories/repository_excursion.py b/backend/bloom/infra/repositories/repository_excursion.py index 10bf9ab9..f2801fc1 100644 --- a/backend/bloom/infra/repositories/repository_excursion.py +++ b/backend/bloom/infra/repositories/repository_excursion.py @@ -130,11 +130,11 @@ def map_to_sql(excursion: Excursion) -> sql_model.Excursion: total_time_at_sea=excursion.total_time_at_sea, total_time_in_amp=excursion.total_time_in_amp, total_time_in_territorial_waters=excursion.total_time_in_territorial_waters, - total_time_in_costal_waters=excursion.total_time_in_costal_waters, + total_time_in_zones_with_no_fishing_rights=excursion.total_time_in_zones_with_no_fishing_rights, total_time_fishing=excursion.total_time_fishing, 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_fishing_in_zones_with_no_fishing_rights=excursion.total_time_fishing_in_zones_with_no_fishing_rights, total_time_default_ais=excursion.total_time_default_ais, created_at=excursion.created_at, updated_at=excursion.updated_at @@ -155,11 +155,11 @@ def map_to_domain(excursion: sql_model.Excursion) -> Excursion: total_time_at_sea=excursion.total_time_at_sea, total_time_in_amp=excursion.total_time_in_amp, total_time_in_territorial_waters=excursion.total_time_fishing_in_territorial_waters, - total_time_in_costal_waters=excursion.total_time_fishing_in_costal_waters, + total_time_in_zones_with_no_fishing_rights=excursion.total_time_in_zones_with_no_fishing_rights, total_time_fishing=excursion.total_time_fishing, 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_fishing_in_zones_with_no_fishing_rights=excursion.total_time_fishing_in_zones_with_no_fishing_rights, total_time_default_ais=excursion.total_time_default_ais, created_at=excursion.created_at, updated_at=excursion.updated_at @@ -181,11 +181,11 @@ def map_to_orm(excursion: Excursion) -> sql_model.Excursion: total_time_at_sea=excursion.total_time_at_sea, total_time_in_amp=excursion.total_time_in_amp, total_time_in_territorial_waters=excursion.total_time_fishing_in_territorial_waters, - total_time_in_costal_waters=excursion.total_time_fishing_in_costal_waters, + total_time_in_zones_with_no_fishing_rights=excursion.total_time_in_zones_with_no_fishing_rights, total_time_fishing=excursion.total_time_fishing, 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_fishing_in_zones_with_no_fishing_rights=excursion.total_time_fishing_in_zones_with_no_fishing_rights, total_time_default_ais=excursion.total_time_default_ais, created_at=excursion.created_at, updated_at=excursion.updated_at diff --git a/backend/bloom/infra/repositories/repository_segment.py b/backend/bloom/infra/repositories/repository_segment.py index 4053c489..10ad8c1a 100644 --- a/backend/bloom/infra/repositories/repository_segment.py +++ b/backend/bloom/infra/repositories/repository_segment.py @@ -31,12 +31,12 @@ def get_segments_by_excursions(self, session: Session, id: int) -> pd.DataFrame: sql_model.Segment.segment_duration, sql_model.Segment.in_amp_zone, sql_model.Segment.in_territorial_waters, - sql_model.Segment.in_costal_waters + sql_model.Segment.in_zone_with_no_fishing_rights ).where(sql_model.Segment.excursion_id == id) q = session.execute(stmt) if not q: return None - df = pd.DataFrame(q, columns=["segment_duration", "in_amp_zone", "in_territorial_waters", "in_costal_waters"]) + df = pd.DataFrame(q, columns=["segment_duration", "in_amp_zone", "in_territorial_waters", "in_zone_with_no_fishing_rights"]) return df def get_all_vessels_last_position(self, session: Session) -> List[Segment]: @@ -245,7 +245,7 @@ def map_to_domain(segment: sql_model.Segment) -> Segment: type=segment.type, in_amp_zone=segment.in_amp_zone, in_territorial_waters=segment.in_territorial_waters, - in_costal_waters=segment.in_costal_waters, + in_zone_with_no_fishing_rights=segment.in_zone_with_no_fishing_rights, last_vessel_segment=segment.last_vessel_segment, created_at=segment.created_at, updated_at=segment.updated_at @@ -270,7 +270,7 @@ def map_to_orm(segment: Segment) -> sql_model.Segment: type=segment.type, in_amp_zone=segment.in_amp_zone, in_territorial_waters=segment.in_territorial_waters, - in_costal_waters=segment.in_costal_waters, + in_zone_with_no_fishing_rights=segment.in_zone_with_no_fishing_rights, last_vessel_segment=segment.last_vessel_segment, created_at=segment.created_at, updated_at=segment.updated_at diff --git a/backend/bloom/tasks/create_update_excursions_segments.py b/backend/bloom/tasks/create_update_excursions_segments.py index 4c4c768d..fcac23b3 100644 --- a/backend/bloom/tasks/create_update_excursions_segments.py +++ b/backend/bloom/tasks/create_update_excursions_segments.py @@ -61,11 +61,11 @@ def add_excursion(session: Session, vessel_id: int, departure_at: datetime, total_time_at_sea=timedelta(0), total_time_in_amp=timedelta(0), total_time_in_territorial_waters=timedelta(0), - total_time_in_costal_waters=timedelta(0), + total_time_in_zones_with_no_fishing_rights=timedelta(0), total_time_fishing=timedelta(0), 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_fishing_in_zones_with_no_fishing_rights=timedelta(0), total_time_default_ais=timedelta(0) ) new_excursion = excursion_repository.create_excursion(session, new_excursion) @@ -280,7 +280,7 @@ def get_time_of_departure(): heading_at_end=result["heading_at_end"].iloc[i], type=result["type"].iloc[i], last_vessel_segment=result["last_vessel_segment"].iloc[i], - in_costal_waters=False, + in_zone_with_no_fishing_rights=False, in_amp_zone=False, in_territorial_waters=False ) @@ -311,7 +311,7 @@ def get_time_of_departure(): if zone.category == "amp": segment.in_amp_zone = True elif zone.category.startswith("Fishing coastal waters"): - segment.in_costal_waters = True + segment.in_zone_with_no_fishing_rights = True elif zone.category == "Territorial seas": segment.in_territorial_waters = True if segment_in_zone: @@ -324,11 +324,11 @@ 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 - if segment.in_costal_waters: + if segment.in_zone_with_no_fishing_rights: if segment.type == "AT_SEA": - excursion.total_time_in_costal_waters += segment.segment_duration + excursion.total_time_in_zones_with_no_fishing_rights += segment.segment_duration elif segment.type == "FISHING": - excursion.total_time_fishing_in_costal_waters += segment.segment_duration + excursion.total_time_fishing_in_zones_with_no_fishing_rights += segment.segment_duration if segment.in_territorial_waters: if segment.type == "AT_SEA": excursion.total_time_in_territorial_waters += segment.segment_duration @@ -344,7 +344,7 @@ def get_time_of_departure(): 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) + excursion.total_time_in_zones_with_no_fishing_rights + excursion.total_time_in_territorial_waters) excursions[excursion.id] = excursion diff --git a/backend/bloom/tasks/load_fct_excursions_from_csv.py b/backend/bloom/tasks/load_fct_excursions_from_csv.py index e46e4d8b..6e2fbcaa 100644 --- a/backend/bloom/tasks/load_fct_excursions_from_csv.py +++ b/backend/bloom/tasks/load_fct_excursions_from_csv.py @@ -66,11 +66,11 @@ def map_excursion_to_domain(row) -> Excursion: total_time_at_sea=None, total_time_in_amp=None, total_time_in_territorial_waters=None, - total_time_in_costal_waters=None, + total_time_in_zones_with_no_fishing_rights=None, total_time_fishing=None, total_time_fishing_in_amp=None, total_time_fishing_in_territorial_waters=None, - total_time_fishing_in_costal_waters=None, + total_time_fishing_in_zones_with_no_fishing_rights=None, total_time_default_ais=None, created_at=None, updated_at=None, @@ -91,7 +91,7 @@ def map_segment_to_domain(row) -> Segment: type=None, in_amp_zone=None, in_territorial_waters=None, - in_costal_waters=None, + in_zone_with_no_fishing_rights=None, last_vessel_segment=row["last_vessel_segment"], created_at=None, updated_at=None,