Skip to content

Commit

Permalink
Renommages des colonnes des tables fct_ (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
njouanin committed Nov 5, 2024
1 parent d710374 commit 43a83b3
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 29 deletions.
26 changes: 26 additions & 0 deletions backend/alembic/versions/7ba4634af5ad_rename_fct_columns.py
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions backend/bloom/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 2 additions & 2 deletions backend/bloom/domain/excursion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion backend/bloom/domain/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions backend/bloom/infra/database/sql_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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())
Expand Down
12 changes: 6 additions & 6 deletions backend/bloom/infra/repositories/repository_excursion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions backend/bloom/infra/repositories/repository_segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions backend/bloom/tasks/create_update_excursions_segments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions backend/bloom/tasks/load_fct_excursions_from_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 43a83b3

Please sign in to comment.