Skip to content

Commit

Permalink
more linting
Browse files Browse the repository at this point in the history
  • Loading branch information
dwreeves committed May 26, 2024
1 parent 474c999 commit ecbedbe
Show file tree
Hide file tree
Showing 34 changed files with 331 additions and 360 deletions.
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ repos:
rev: v2.3.0
hooks:
- id: check-yaml
args: [--allow-multiple-documents]
- id: end-of-file-fixer
- id: trailing-whitespace

Expand All @@ -13,7 +14,7 @@ repos:
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
args: [--fix]
# Run the formatter.
- id: ruff-format

Expand Down
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
FROM python:3.12

MAINTAINER Daniel Reeves "[email protected]"

ADD --chmod=755 https://astral.sh/uv/install.sh /install.sh
RUN /install.sh && rm /install.sh

Expand Down
3 changes: 2 additions & 1 deletion alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def run_migrations_online():
In this scenario we need to create an Engine and associate a connection
with the context.
"""

# If you use Alembic revision's --autogenerate flag this function will
# prevent Alembic from creating an empty migration file if nothing changed.
# Source: https://alembic.sqlalchemy.org/en/latest/cookbook.html
Expand All @@ -80,7 +81,7 @@ def process_revision_directives(context, revision, directives):
context.configure(
connection=connection,
target_metadata=target_metadata,
process_revision_directives=process_revision_directives
process_revision_directives=process_revision_directives,
)

with context.begin_transaction():
Expand Down
62 changes: 33 additions & 29 deletions alembic/versions/rev001.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Create Date: 2022-01-22 15:49:40.837695
"""

import sqlalchemy as sa
from sqlalchemy import schema
from sqlalchemy.engine.reflection import Inspector
Expand All @@ -17,7 +18,7 @@


# revision identifiers, used by Alembic.
revision = '016fff145273'
revision = "016fff145273"
down_revision = None
branch_labels = None
depends_on = None
Expand All @@ -35,44 +36,47 @@ def upgrade():
# - model_outputs
# These are rewritten each time; their data doesn't need to be persisted.

if 'boathouses' not in tables:
op.execute(schema.CreateSequence(schema.Sequence('boathouses_id_seq')))
if "boathouses" not in tables:
op.execute(schema.CreateSequence(schema.Sequence("boathouses_id_seq")))
op.create_table(
'boathouses',
"boathouses",
sa.Column(
'id', sa.Integer(), autoincrement=True, nullable=False,
server_default=sa.text("nextval('boathouses_id_seq'::regclass)")
"id",
sa.Integer(),
autoincrement=True,
nullable=False,
server_default=sa.text("nextval('boathouses_id_seq'::regclass)"),
),
sa.Column('boathouse', sa.String(length=255), nullable=False),
sa.Column('reach', sa.Integer(), nullable=True),
sa.Column('latitude', sa.Numeric(), nullable=True),
sa.Column('longitude', sa.Numeric(), nullable=True),
sa.Column('overridden', sa.Boolean(), nullable=True),
sa.Column('reason', sa.String(length=255), nullable=True),
sa.PrimaryKeyConstraint('boathouse')
sa.Column("boathouse", sa.String(length=255), nullable=False),
sa.Column("reach", sa.Integer(), nullable=True),
sa.Column("latitude", sa.Numeric(), nullable=True),
sa.Column("longitude", sa.Numeric(), nullable=True),
sa.Column("overridden", sa.Boolean(), nullable=True),
sa.Column("reason", sa.String(length=255), nullable=True),
sa.PrimaryKeyConstraint("boathouse"),
)
with open(QUERIES_DIR + '/override_event_triggers_v1.sql', 'r') as f:
with open(QUERIES_DIR + "/override_event_triggers_v1.sql", "r") as f:
sql = sa.text(f.read())
conn.execute(sql)
if 'live_website_options' not in tables:
if "live_website_options" not in tables:
op.create_table(
'live_website_options',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('flagging_message', sa.Text(), nullable=True),
sa.Column('boating_season', sa.Boolean(), nullable=False),
sa.PrimaryKeyConstraint('id')
"live_website_options",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("flagging_message", sa.Text(), nullable=True),
sa.Column("boating_season", sa.Boolean(), nullable=False),
sa.PrimaryKeyConstraint("id"),
)
if 'override_history' not in tables:
if "override_history" not in tables:
op.create_table(
'override_history',
sa.Column('time', sa.TIMESTAMP(), nullable=True),
sa.Column('boathouse', sa.TEXT(), nullable=True),
sa.Column('overridden', sa.BOOLEAN(), nullable=True),
sa.Column('reason', sa.TEXT(), nullable=True)
"override_history",
sa.Column("time", sa.TIMESTAMP(), nullable=True),
sa.Column("boathouse", sa.TEXT(), nullable=True),
sa.Column("overridden", sa.BOOLEAN(), nullable=True),
sa.Column("reason", sa.TEXT(), nullable=True),
)


def downgrade():
op.drop_table('live_website_options')
op.drop_table('boathouses')
op.drop_table('override_history')
op.drop_table("live_website_options")
op.drop_table("boathouses")
op.drop_table("override_history")
80 changes: 42 additions & 38 deletions alembic/versions/rev002.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Create Date: 2022-01-22 17:03:23.094306
"""

import sqlalchemy as sa
from sqlalchemy.engine.reflection import Inspector

Expand All @@ -14,8 +15,8 @@


# revision identifiers, used by Alembic.
revision = '39a4e575f68c'
down_revision = '016fff145273'
revision = "39a4e575f68c"
down_revision = "016fff145273"
branch_labels = None
depends_on = None

Expand All @@ -27,65 +28,68 @@ def upgrade():

# Create reach association table
op.create_table(
'reach',
sa.Column('id', sa.Integer(), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('id')
"reach",
sa.Column("id", sa.Integer(), nullable=False),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("id"),
)

# We need to make sure that we can add the foreign key constraint to the
# boathouse relation. If the boathouse table is already populated, this
# necessitates running this now before adding the constraint.
num_boathouses = conn.execute(sa.text('select * from boathouses;')).scalar()
num_boathouses = conn.execute(sa.text("select * from boathouses;")).scalar()
if num_boathouses is not None and num_boathouses > 0:
with open(QUERIES_DIR + '/define_reach.sql', 'r') as f:
with open(QUERIES_DIR + "/define_reach.sql", "r") as f:
sql = sa.text(f.read())
conn.execute(sql)

# Migrate predictions
# Technically speaking, the types won't match the SQLA schema because Pandas
# overwrites the tables.
if 'model_outputs' in tables:
op.alter_column('model_outputs', 'reach', new_column_name='reach_id')
op.drop_column('model_outputs', 'log_odds')
op.rename_table('model_outputs', 'prediction')
if "model_outputs" in tables:
op.alter_column("model_outputs", "reach", new_column_name="reach_id")
op.drop_column("model_outputs", "log_odds")
op.rename_table("model_outputs", "prediction")
else:
op.create_table(
'prediction',
sa.Column('reach_id', sa.Integer(), nullable=False),
sa.Column('time', sa.DateTime(), nullable=False),
sa.Column('probability', sa.Numeric(), nullable=True),
sa.Column('safe', sa.Boolean(), nullable=True),
sa.ForeignKeyConstraint(['reach_id'], ['reach.id'], ),
sa.PrimaryKeyConstraint('reach_id', 'time')
"prediction",
sa.Column("reach_id", sa.Integer(), nullable=False),
sa.Column("time", sa.DateTime(), nullable=False),
sa.Column("probability", sa.Numeric(), nullable=True),
sa.Column("safe", sa.Boolean(), nullable=True),
sa.ForeignKeyConstraint(
["reach_id"],
["reach.id"],
),
sa.PrimaryKeyConstraint("reach_id", "time"),
)

# Migrate override history.
op.alter_column('override_history', 'boathouse', new_column_name='boathouse_name')
op.alter_column("override_history", "boathouse", new_column_name="boathouse_name")

# Migrate website options.
op.rename_table('live_website_options', 'website_options')
op.rename_table("live_website_options", "website_options")

# Migrate boathouse table
op.alter_column('boathouses', 'boathouse', new_column_name='name')
op.alter_column('boathouses', 'reach', new_column_name='reach_id')
op.alter_column('boathouses', 'overridden', server_default='f')
op.create_unique_constraint(None, 'boathouses', ['name'])
op.create_foreign_key(None, 'boathouses', 'reach', ['reach_id'], ['id'])
op.rename_table('boathouses', 'boathouse')
with open(QUERIES_DIR + '/override_event_triggers_v2.sql', 'r') as f:
op.alter_column("boathouses", "boathouse", new_column_name="name")
op.alter_column("boathouses", "reach", new_column_name="reach_id")
op.alter_column("boathouses", "overridden", server_default="f")
op.create_unique_constraint(None, "boathouses", ["name"])
op.create_foreign_key(None, "boathouses", "reach", ["reach_id"], ["id"])
op.rename_table("boathouses", "boathouse")
with open(QUERIES_DIR + "/override_event_triggers_v2.sql", "r") as f:
sql = sa.text(f.read())
conn.execute(sql)


def downgrade():
op.rename_table('boathouse', 'boathouses')
op.drop_constraint(None, 'boathouses', type_='foreignkey')
op.drop_constraint(None, 'boathouses', type_='unique')
op.alter_column('boathouses', 'name', new_column_name='boathouse')
op.alter_column('boathouses', 'reach_id', new_column_name='reach')
op.alter_column('boathouses', 'overridden', server_default=None)

op.drop_table('model_outputs')
op.drop_table('prediction')
op.drop_table('reach')
op.rename_table("boathouse", "boathouses")
op.drop_constraint(None, "boathouses", type_="foreignkey")
op.drop_constraint(None, "boathouses", type_="unique")
op.alter_column("boathouses", "name", new_column_name="boathouse")
op.alter_column("boathouses", "reach_id", new_column_name="reach")
op.alter_column("boathouses", "overridden", server_default=None)

op.drop_table("model_outputs")
op.drop_table("prediction")
op.drop_table("reach")
9 changes: 5 additions & 4 deletions alembic/versions/rev003.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@
Create Date: 2023-04-17 17:42:44.755320
"""

from alembic import op


# revision identifiers, used by Alembic.
revision = '793fab3b5438'
down_revision = '39a4e575f68c'
revision = "793fab3b5438"
down_revision = "39a4e575f68c"
branch_labels = None
depends_on = None


def upgrade():
op.alter_column('prediction', 'probability', new_column_name='predicted_ecoli_cfu_100ml')
op.alter_column("prediction", "probability", new_column_name="predicted_ecoli_cfu_100ml")


def downgrade():
op.alter_column('prediction', 'predicted_ecoli_cfu_100ml', new_column_name='probability')
op.alter_column("prediction", "predicted_ecoli_cfu_100ml", new_column_name="probability")
9 changes: 5 additions & 4 deletions alembic/versions/rev004.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@
Create Date: 2023-05-21 12:57:25.545426
"""

from alembic import op


# revision identifiers, used by Alembic.
revision = 'e433f34dd4bd'
down_revision = '793fab3b5438'
revision = "e433f34dd4bd"
down_revision = "793fab3b5438"
branch_labels = None
depends_on = None


def upgrade():
op.alter_column('prediction', 'predicted_ecoli_cfu_100ml', new_column_name='probability')
op.alter_column("prediction", "predicted_ecoli_cfu_100ml", new_column_name="probability")


def downgrade():
op.alter_column('prediction', 'probability', new_column_name='predicted_ecoli_cfu_100ml')
op.alter_column("prediction", "probability", new_column_name="predicted_ecoli_cfu_100ml")
2 changes: 1 addition & 1 deletion app/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `/app` Content
# `/app` Content

- `/blueprints`: custom endpoints for the flagging website (all the logic that helps to render the HTML pages or JSONs.)
- `/data`: database, predictive models, and functions to retrieve live data.
Expand Down
2 changes: 1 addition & 1 deletion app/blueprints/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Contents of blueprints

- `__init__.py`: required to treat directory as a module
- `frontend.py`: render public facing frontend stuff
- `frontend.py`: render public facing frontend stuff
- `api.py`: provide info and updates on api status
2 changes: 1 addition & 1 deletion app/blueprints/openapi/boathouse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ responses:
reason:
description: If overridden, we may provide a reason why.
type: string
x-nullable: true
x-nullable: true
6 changes: 3 additions & 3 deletions app/data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
- `/_store`: contains pickle files used to test webpage offline using data provided already from usgus.pickle and hobolink.pickle
- `__init__.py`: required to treat directory as a package
- `database.py`: file handling database connection
- `hobolink.py`: retrieve hobolink by requesting a response and parsing data from hobolink
- `model.py`: outputs table model by processing usgs and hobolink data
- `task_queue`: set up task queue
- `hobolink.py`: retrieve hobolink by requesting a response and parsing data from hobolink
- `model.py`: outputs table model by processing usgs and hobolink data
- `task_queue`: set up task queue
- `usgs.py`: retrieve hobolink by requesting a response and parsing data from usgs
2 changes: 1 addition & 1 deletion app/static/favicon/site.webmanifest
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"","short_name":"","icons":[{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"}
{"name":"","short_name":"","icons":[{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"}
2 changes: 1 addition & 1 deletion app/static/images/github.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/static/images/iconmonstr-info-9.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/static/images/twitter.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions app/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ nav a:hover {
border-top: thin solid #dce9f2;
box-shadow: 0 4px 10px -2px #dce9f2;
overflow: hidden;

max-height: 300px; /* exclusively for transition */
transition: padding 0.3s, max-height 0.3s, border-top-width 0.3s;
}
Expand Down Expand Up @@ -288,7 +288,7 @@ nav a:hover {
border: 1px solid black;
border-collapse: collapse;
padding: 15px;
margin: 0 auto;
margin: 0 auto;
}

.twitter-tweet {
Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ There are a lot of extensions included in this documentation in addition to Mate

- Most of the extensions come from [PyMdown Extensions](https://facelessuser.github.io/pymdown-extensions/).
- We use a tool called [Mermaid](https://mermaid-js.github.io/mermaid-live-editor/) for our flow charts.
- We use the [macros plugin](https://squidfunk.github.io/mkdocs-material/reference/variables/) but only to parameterize the flagging website URL (the `flagging_website_url` field inside of `mkdocs.yml`).
- We use the [macros plugin](https://squidfunk.github.io/mkdocs-material/reference/variables/) but only to parameterize the flagging website URL (the `flagging_website_url` field inside of `mkdocs.yml`).

All of these tools are added and configured inside `mkdocs.yml`. Note you need to pip install them for them to work when you deploy; see deployment script below.

Expand Down
2 changes: 1 addition & 1 deletion docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ markdown_extensions:
custom_fences:
- name: mermaid
class: mermaid
format: !!python/name:pymdownx.superfences.fence_div_format
format: "!!python/name:pymdownx.superfences.fence_div_format"
- sane_lists
extra:
flagging_website_url: https://crwa-flagging.herokuapp.com
Expand Down
1 change: 0 additions & 1 deletion docs/src/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ The Charles River Watershed Association ("CRWA") was formed in 1965, the same ye
> CRWA is one of the country’s oldest watershed organizations and has figured prominently in major cleanup and protection efforts. Since our earliest days of advocacy, we have worked with government officials and citizen groups from 35 Massachusetts watershed towns from Hopkinton to Boston.
The EPA also relies on sample data collected by the CRWA to construct its report card.

Loading

0 comments on commit ecbedbe

Please sign in to comment.