Skip to content

Commit

Permalink
ran linter on all python files
Browse files Browse the repository at this point in the history
  • Loading branch information
agennadi committed Oct 28, 2024
1 parent 4559608 commit 93d729d
Show file tree
Hide file tree
Showing 23 changed files with 162 additions and 103 deletions.
7 changes: 4 additions & 3 deletions backend/api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"""
Provides the environment variables that are read by the application.
"""
class Settings(BaseSettings):


class Settings(BaseSettings):
postgres_user: str
postgres_password: str
postgres_db: str
Expand All @@ -17,7 +19,6 @@ class Settings(BaseSettings):
next_public_api_url: str
node_env: str


class Config:
env_file = ".env.local"
env_file_encoding = "utf-8"
Expand All @@ -29,4 +30,4 @@ def get_settings() -> Settings:
return Settings()


settings = get_settings()
settings = get_settings()
6 changes: 3 additions & 3 deletions backend/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
combined risk records.
"""
# TODO:
# Decide:
# Decide:
# - whether old polygons should be kept #53
# - whether old soft story records should be kept #53
# - whether old combined risk records should be kept #53
# - where current and old polygons, soft story records, and
# combined risk records should be kept #53
# Create:
# Create:
# - a database to back the exposed arguments #54
# - a new API key for OpenGate
# - fuzzy logic to match addresses
# - fuzzy logic to match addresses
# Make: each get method return that of their pydantic annotations
from .routers import combined_risk, polygons, soft_story, seismic, tsunami
from fastapi import FastAPI
Expand Down
7 changes: 4 additions & 3 deletions backend/api/models/comined_risk.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

Base = declarative_base()


class CombinedRisk(Base):
__tablename__ = 'combined_risk'
__tablename__ = "combined_risk"

id = Column(Integer, primary_key=True, autoincrement=True)
address = Column(String(50), nullable=False, unique=True)
soft_story_risk = Column(Boolean, nullable=False, default=False)
Expand All @@ -20,4 +21,4 @@ def __repr__(self):
f"seismic_hazard_risk={self.seismic_hazard_risk}, "
f"landslide_risk={self.landslide_risk}, "
f"liquefaction_risk={self.liquefaction_risk})>"
)
)
16 changes: 11 additions & 5 deletions backend/api/models/landslide_zones.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""All data of the Landslide Zones table from SFData."""

from sqlalchemy import String, Integer
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.orm import Mapped
Expand All @@ -16,18 +17,23 @@ class LandslideZones(DeclarativeBase):
__tablename__ = "landslide_zones"

identifier: Mapped[int] = mapped_column(Integerprimary_key=True)
geometry: Mapped[Geometry] = mapped_column(Geometry('MULTIPOLYGON', srid=4326))
geometry: Mapped[Geometry] = mapped_column(Geometry("MULTIPOLYGON", srid=4326))
gridcode: Mapped[int] = mapped_column(Integer)
sum_shape: Mapped[float] = mapped_column(Float)
shape_length: Mapped[float] = mapped_column(Float)
created_us: Mapped[str] = mapped_column(String)
created_da: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=datetime.utcnow)
created_da: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=datetime.utcnow
)
last_edited: Mapped[str] = mapped_column(String)
last_edi_1: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=datetime.utcnow)
last_edi_1: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=datetime.utcnow
)
shape_Le_1: Mapped[float] = mapped_column(Float)
shape_area: Mapped[float] = mapped_column(Float)
update_timestamp: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=datetime.utcnow)
update_timestamp: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=datetime.utcnow
)

def __repr__(self) -> str:
return f"<LandslideZones(id={self.identifier})>"

12 changes: 8 additions & 4 deletions backend/api/models/liquefaction_zones.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""All data of the Liquefaction Zones table from SFData."""

from sqlalchemy import String
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.orm import Mapped
Expand All @@ -10,17 +11,20 @@
class LiquefactionZones(DeclarativeBase):
"""
All data of the Liquefaction Zones table from SFData.
Contains multipolygon geometries defining soil liquefaction zones as High (H) or
Contains multipolygon geometries defining soil liquefaction zones as High (H) or
Very High (VH) susceptibility.
"""

__tablename__ = "liquefaction_zones"

identifier: Mapped[int] = mapped_column(primary_key=True)
geometry: Mapped[Geometry] = mapped_column(Geometry('MULTIPOLYGON', srid=4326))
geometry: Mapped[Geometry] = mapped_column(Geometry("MULTIPOLYGON", srid=4326))
susceptibility: Mapped[str] = mapped_column(String)
shape_length: Mapped[float] = mapped_column(Float)
shape_area: Mapped[float] = mapped_column(Float)
update_timestamp: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=datetime.utcnow)
update_timestamp: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=datetime.utcnow
)

def __repr__(self) -> str:
return f"<LiquefactionZones(id={self.identifier})>"
return f"<LiquefactionZones(id={self.identifier})>"
10 changes: 7 additions & 3 deletions backend/api/models/neighborhoods.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Neighborhood boundaries in San Francisco"""

from sqlalchemy import String, Integer
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.orm import Mapped
Expand All @@ -14,12 +15,15 @@ class Neighborhoods(DeclarativeBase):
"""
Stores neighborhood boundaries as multipolygon geometries.
"""

__tablename__ = "neighborhoods"

identifier: Mapped[int] = mapped_column(Integer, primary_key=True)
neighborhood: Mapped[str] = mapped_column(String(MAPPED_COLUMN_STRING_LENGTH))
geometry: Mapped[Geometry] = mapped_column(Geometry('MULTIPOLYGON', srid=4326))
update_timestamp: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=datetime.utc_now)

geometry: Mapped[Geometry] = mapped_column(Geometry("MULTIPOLYGON", srid=4326))
update_timestamp: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=datetime.utc_now
)

def __repr__(self) -> str:
return f"<Neighborhoods(id={self.identifier}>"
12 changes: 8 additions & 4 deletions backend/api/models/seismic_hazard_zones.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""All data of the Seismic Hazard table from SFData."""

from sqlalchemy import Integer
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.orm import Mapped
Expand All @@ -12,11 +13,14 @@ class SeismicHazardZones(DeclarativeBase):
All data of the Seismic Hazard table from SFData.
Contains multipolygon geometries defining seismic hazard areas.
"""

__tablename__ = "seismic_hazard_zones"

identifier: Mapped[int] = mapped_column(Integer, primary_key=True)
geometry: Mapped[Geometry] = mapped_column(Geometry('MULTIPOLYGON', srid=4326))
update_timestamp: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=datetime.utcnow)

geometry: Mapped[Geometry] = mapped_column(Geometry("MULTIPOLYGON", srid=4326))
update_timestamp: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=datetime.utcnow
)

def __repr__(self) -> str:
return f"<SeismicHazardZones(id={self.identifier})>"
return f"<SeismicHazardZones(id={self.identifier})>"
20 changes: 14 additions & 6 deletions backend/api/models/soft_story_properties.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""All data of the Soft Story table from SFData."""

from sqlalchemy import String, Integer
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.orm import Mapped
Expand All @@ -14,9 +15,10 @@ class SoftStoryProperties(DeclarativeBase):
"""
All data of the Soft Story table from SFData.
Contains point geometries for properties.
Contains point geometries for properties.
Used for spatial comparison to determine hazard zone overlaps.
"""

__tablename__ = "soft_story_properties"

identifier: Mapped[int] = mapped_column(Integer, primary_key=True)
Expand All @@ -28,10 +30,16 @@ class SoftStoryProperties(DeclarativeBase):
tier: Mapped[int] = mapped_column(Integer)
status: Mapped[str] = mapped_column(String(MAPPED_COLUMN_STRING_LENGTH))
bos_district: Mapped[int] = mapped_column(Integer)
point: Mapped[Geometry] = mapped_column(Geometry('POINT', srid=4326))
sfdata_as_of: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=datetime.utcnow)
sfdata_loaded_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=datetime.utcnow)
update_timestamp: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=datetime.utcnow)
point: Mapped[Geometry] = mapped_column(Geometry("POINT", srid=4326))
sfdata_as_of: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=datetime.utcnow
)
sfdata_loaded_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=datetime.utcnow
)
update_timestamp: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=datetime.utcnow
)

def __repr__(self) -> str:
return f"<SoftStoryProperties(id={self.identifier}, property_address={self.property_address})>"
return f"<SoftStoryProperties(id={self.identifier}, property_address={self.property_address})>"
10 changes: 7 additions & 3 deletions backend/api/models/tsunami.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tsunami Risk Zone data"""

from sqlalchemy import String, Integer
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.orm import Mapped
Expand All @@ -14,8 +15,9 @@ class TsunamiZones(DeclarativeBase):
"""
All data of the Tsunami Hazard table from conservation.ca.gov.
"""

__tablename__ = "tsunami_zones"

identifier: Mapped[int] = mapped_column(Integer, primary_key=True)
evacuate: Mapped[str] = mapped_column(String(MAPPED_COLUMN_STRING_LENGTH))
county: Mapped[str] = mapped_column(String(MAPPED_COLUMN_STRING_LENGTH))
Expand All @@ -26,8 +28,10 @@ class TsunamiZones(DeclarativeBase):
shape_length: Mapped[float] = mapped_column(Float)
shape_area: Mapped[float] = mapped_column(Float)
# This data is ingested as PolygonZ but should be stored as MultiPolygon
geometry: Mapped[Geometry] = mapped_column(Geometry('MULTIPOLYGON', srid=4326))
update_timestamp: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=datetime.utcnow)
geometry: Mapped[Geometry] = mapped_column(Geometry("MULTIPOLYGON", srid=4326))
update_timestamp: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=datetime.utcnow
)

def __repr__(self) -> str:
return f"<TsunamiZones(id={self.identifier})>"
3 changes: 2 additions & 1 deletion backend/api/routers/combined_risk.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Router to CRUD combined risk."""

from fastapi import APIRouter
from ..tags import Tags

Expand Down Expand Up @@ -41,4 +42,4 @@ async def get_combined_risks(address: str) -> dict:
three booleans.
"""
# TODO: Return a dictionary to avoid validation error
pass
pass
9 changes: 4 additions & 5 deletions backend/api/routers/polygons.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
"""Router to CRUD polygons."""

from fastapi import APIRouter
from pydantic import BaseModel
from ..tags import Tags


router = APIRouter(
prefix="/api/polygons",
tags=[Tags.POLYGONS]
)
router = APIRouter(prefix="/api/polygons", tags=[Tags.POLYGONS])


class Polygon(BaseModel):
"""GIS data container of vertices defining a polygon."""

pass


Expand Down Expand Up @@ -44,4 +43,4 @@ async def get_polygon(id: int, table_name: str) -> Polygon:
"""
Get this polygon from that table.
"""
pass
pass
30 changes: 15 additions & 15 deletions backend/api/routers/reinforced_soft_story.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,38 @@
@router.delete("/{address}")
async def delete_reinforced(address: str):
"""
Delete the record that the building at an address, having a soft
Delete the record that the building at an address, having a soft
story, has been reinforced.
Check a small group of reinforced soft stories and raise an
Check a small group of reinforced soft stories and raise an
exception if the building lacks an original soft story.
"""
pass


@router.put("/{address}")
async def put_reinforced(address: str,
soft_story: Annotated[
bool, Query(alias="soft-story")]):
async def put_reinforced(
address: str, soft_story: Annotated[bool, Query(alias="soft-story")]
):
"""
Update whether the building at an address, having a soft story,
Update whether the building at an address, having a soft story,
has been reinforced.
Check a small group of reinforced soft stories and raise an
Check a small group of reinforced soft stories and raise an
exception if the building lacks an original soft story.
"""
pass


@router.post("/{address}")
async def post_reinforced(address: str,
soft_story: Annotated[
bool, Query(alias="soft-story")]):
async def post_reinforced(
address: str, soft_story: Annotated[bool, Query(alias="soft-story")]
):
"""
Add that the building at an address, having a soft story, has
Add that the building at an address, having a soft story, has
been reinforced.
Check a small table of reinforced soft stories and raise an
Check a small table of reinforced soft stories and raise an
exception if the building lacks an original soft story.
"""
pass
Expand All @@ -52,11 +52,11 @@ async def post_reinforced(address: str,
@router.get("/{address}")
async def get_reinforced(address: str) -> bool:
"""
Return whether the building at an address, having a soft story,
Return whether the building at an address, having a soft story,
has been reinforced.
Check a small table of reinforced soft stories and raise an
Check a small table of reinforced soft stories and raise an
exception if the building lacks an original soft story.
"""
# TODO: Change return type to boolean to avoid validation error
pass
pass
3 changes: 2 additions & 1 deletion backend/api/routers/seismic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Router to get seismic risk and CRUD seismic polygons."""

from fastapi import APIRouter
from ..tags import Tags

Expand All @@ -16,4 +17,4 @@ async def get_seismic_risk(address: str) -> bool:
polygon.
"""
# TODO: Change return type to boolean to avoid validation error
pass
pass
Loading

0 comments on commit 93d729d

Please sign in to comment.