Skip to content

Commit

Permalink
feat: #374 add enable/zone_enable column to dim_zone/fct_metrics to e…
Browse files Browse the repository at this point in the history
…xclude some zone of processing
  • Loading branch information
rv2931 committed Dec 17, 2024
1 parent 354b3bf commit 3068939
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""add enable field to dim_zone
Revision ID: 5801cb8f1af5
Revises: 5bfe00a08853
Create Date: 2024-12-17 22:28:50.714813
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '5801cb8f1af5'
down_revision = '5bfe00a08853'
branch_labels = None
depends_on = None


def upgrade() -> None:
"""
This evolution was motivated by the fact that some areas are PMA but contains
some ports that are not registered. This leads to incorrect vessel activity
The solution proposed here is to add enable column to dim_zone and fct_metrics
to be able to choose if theses zone are took in account in aggregations or not
even if they are present and calculated
"""
# add column enable
op.add_column("dim_zone",sa.Column("enable",sa.Boolean(),nullable=False,default=True, server_default="True"))
op.add_column("fct_metrics",sa.Column("zone_enable",sa.Boolean(),nullable=False,default=True, server_default="True"))
pass


def downgrade() -> None:
op.drop_column("fct_metrics","zone_enable")
op.drop_column("dim_zone","enable")
pass
2 changes: 2 additions & 0 deletions backend/bloom/infra/database/sql_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class Zone(Base):
centroid = Column("centroid", Geometry(geometry_type="POINT", srid=settings.srid))
json_data = Column("json_data", JSONB)
created_at = Column("created_at", DateTime(timezone=True), server_default=func.now())
enable = Column("enable",Boolean(), server_default=True)


class WhiteZone(Base):
Expand Down Expand Up @@ -276,5 +277,6 @@ class Metrics(Base):
zone_id= Column("zone_id", Integer, ForeignKey("dim_zone.id"))
zone_category= Column("zone_category", String, ForeignKey("dim_zone.category"))
zone_sub_category= Column("zone_sub_category", String, ForeignKey("dim_zone.sub_category"))
zone_enable = Column("enable",Boolean(), server_default=True)


1 change: 1 addition & 0 deletions backend/bloom/infra/repositories/repository_vessel.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def get_vessel_times_in_zones( self,
)
.select_from(sql_model.Metrics)
.where(sql_model.Metrics.vessel_id==vessel_id)
.where(sql_model.Zone.enable == True)\
.where(sql_model.Metrics.timestamp.between(datetime_range.start_at,datetime_range.end_at))
).group_by(sql_model.Metrics.vessel_id,
sql_model.Metrics.zone_id,
Expand Down
3 changes: 3 additions & 0 deletions backend/bloom/services/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def getZoneVisited(self,
)
)
)\
.where(sql_model.Zone.enable == True)\
.group_by(sql_model.Zone.id)
if (category):
stmt = stmt.where(sql_model.Zone.category == category)
Expand Down Expand Up @@ -165,6 +166,7 @@ def getZoneVisitingTimeByVessel(self,
)
)
)\
.where(sql_model.Zone.enable == True)\
.group_by(sql_model.Zone.id,sql_model.Vessel.id)

stmt = stmt.order_by(func.sum(sql_model.Segment.segment_duration).asc())\
Expand Down Expand Up @@ -213,6 +215,7 @@ def getVesselVisitingTimeByZone(self,
)
)
)\
.where(sql_model.Zone.enable == True)\
.group_by(sql_model.Vessel,
sql_model.Zone,)
if category:
Expand Down

0 comments on commit 3068939

Please sign in to comment.