-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shattering #84
Merged
Merged
Shattering #84
Changes from 14 commits
Commits
Show all changes
118 commits
Select commit
Hold shift + click to select a range
50dd897
refactor out tiles for now
raphaellaude 6d81538
shattering models
raphaellaude d91b544
parent child procedure and management commands
raphaellaude e76a9e1
clean up cli
raphaellaude 05ad503
start testing cli
raphaellaude 507ab52
show cli coverage too
raphaellaude 98b87ea
reorg args and allow for child layer to be null
raphaellaude aeb6ae3
materialize unioned gerrydb views
raphaellaude 8cc7fc0
refactor districtmap to use only gerrydb table names rather than uuids
raphaellaude ae5397b
fix tests
raphaellaude b43b1e5
update procedures and udf api
raphaellaude feb30c2
fix silly issue
raphaellaude b6ca1d6
getting close
raphaellaude 324266d
fix by just forcing gerrydb table name in districtrmap to be unique
raphaellaude 23ffe27
Add event listener, context menu information in store
nofurtherinformation 7e599df
Draft Context Menu component
nofurtherinformation 1e44fe1
update models to match
raphaellaude 1c7e129
partition parent child edges on districtrmap
raphaellaude 6ce61f7
move tileset commands to pipelines
raphaellaude 3e4036b
begin to refactor fe
raphaellaude e50387c
add blocks if there is a live document
raphaellaude 4b07a6a
paint on startup
raphaellaude ed75eb0
use context menu from themes
raphaellaude d5b9f04
clean up
raphaellaude 58335f7
progress on fixing tests
raphaellaude b6f8db7
passing tests
raphaellaude 65672eb
SHATTERING ON THE FE
raphaellaude d6b0d39
send parents back
raphaellaude e5530bb
making progress
raphaellaude 33b7692
document how to set up shatterable districtr maps
raphaellaude 6af1bb5
Docker compose config and data load script (#88)
nofurtherinformation 937874e
Add shatter IDs to store, subscribe and mutate map
nofurtherinformation d79cb20
Add parent/child layer rendering
nofurtherinformation fb1d9e4
Add shatter state change to context menu
nofurtherinformation feffb61
clean up layers
nofurtherinformation 790fb23
Cleanup log
nofurtherinformation f807f1a
cleanup unused source id
nofurtherinformation b9a39c8
remove boolean parameter
raphaellaude 5ce9c1d
Refactor zustand accessors
nofurtherinformation d9c2422
Additional zustand accessor refactor
nofurtherinformation 3694115
refactor zustand state accessors - map
nofurtherinformation 86209b3
Add events to child layers
nofurtherinformation 0719df0
Refactor hover state to store
nofurtherinformation 6a26d4a
Refactor map zone assignment rendering to mapStore
nofurtherinformation 55deda4
Clean up hover events
nofurtherinformation 67c09fe
Enhance set shatter Ids
nofurtherinformation 7bfca34
Child layer interactivity and zone assignment cleanup
nofurtherinformation c5ded83
Update mapStore.ts
nofurtherinformation 3a1a8b4
Performance - clean up when zone assignments run
nofurtherinformation 96312e6
Optimize zone assignments rendering logic
nofurtherinformation dcd74a7
Add map lock on shatter
nofurtherinformation 0261d28
Style fix for map container
nofurtherinformation d712ab0
fix layer order
nofurtherinformation 53f781c
clean up shatter events to remove parents
nofurtherinformation 3e92c2c
Return parent path with assignments
nofurtherinformation 9a7c791
Load shatter IDs into state on document load
nofurtherinformation d32bcdf
Also return parents
nofurtherinformation c9f3742
Formatting
nofurtherinformation 0aae53a
Shatter assignment bug fix
nofurtherinformation 83da9b3
Fix remove layer order
nofurtherinformation e35da2e
Only allow context menu on pan
nofurtherinformation 4dd026b
Clean up map updates
nofurtherinformation 3993be4
Revert color while painting
nofurtherinformation 485f25a
reorganize mutations, queries
nofurtherinformation e16b5f0
reorganize subscriptions
nofurtherinformation fc2eb90
Remove mutation logic from components
nofurtherinformation 44e2d08
move to global query client
nofurtherinformation 6249070
update layers and helpers to track rendering state
nofurtherinformation 1f451fe
clean up
nofurtherinformation 770f2b2
clean up
nofurtherinformation 987fc85
nextjs type safety
nofurtherinformation 367da46
Remove tracking map rendering state
nofurtherinformation 145e78e
Revert "Remove tracking map rendering state"
nofurtherinformation b09e265
Add where condition for districtr map uuid
nofurtherinformation 64be91d
materialized view should actually use column data
raphaellaude 989919d
try using specific python version
raphaellaude 5e6cb7d
Subscribe shatter filters to mapRenderingState
nofurtherinformation 24801ef
clean up subscriptions and filtering
nofurtherinformation e43cc92
merge main backend app changes
raphaellaude a0832d4
sort out alembic history
raphaellaude 746955e
Merge branch 'main' into shattering
nofurtherinformation a00b9d3
ruff
nofurtherinformation bfe6f53
update load data script
nofurtherinformation 8bcb1db
Zone can be none after erased
nofurtherinformation bc8241b
erase events cleanup (on mouse move)
nofurtherinformation 911ecbd
Add paintable IDs and bbox to state on shatter
nofurtherinformation b4495bd
change map fill opacity on shatter, helper
nofurtherinformation f6bd236
query features filtered to captive ids
nofurtherinformation c90cc5e
add exit shatter view
nofurtherinformation 533952d
turf bbox
nofurtherinformation e742977
refactor handleShatter to features, not IDs
nofurtherinformation 93639d5
Only paint/select parents when not shattered
nofurtherinformation 33da1a0
wip dive back in to shattered
nofurtherinformation ab2e2d8
clean up
nofurtherinformation 88b8cfe
remove children when painting
nofurtherinformation 5b4cc31
Revert "remove children when painting"
nofurtherinformation 18d1691
Revert "clean up"
nofurtherinformation 248247b
Revert "wip dive back in to shattered"
nofurtherinformation 8670d72
Revert "Only paint/select parents when not shattered"
nofurtherinformation d8d553b
Revert "refactor handleShatter to features, not IDs"
nofurtherinformation b22393d
Revert "turf bbox"
nofurtherinformation 5467492
Revert "add exit shatter view"
nofurtherinformation c5b39de
Revert "query features filtered to captive ids"
nofurtherinformation a21a89e
Revert "change map fill opacity on shatter, helper"
nofurtherinformation 2dac210
Revert "Add paintable IDs and bbox to state on shatter"
nofurtherinformation 1bccead
update script
raphaellaude e830ef1
handle non shattering maps
raphaellaude 9f01d14
disable shattering if no child layer
raphaellaude 5e9ef4d
optionals
raphaellaude 03d365d
ssr safety
nofurtherinformation a1302cc
Clear state on create document
nofurtherinformation 1bc972c
swap .union for new set
nofurtherinformation 7bbfa55
missing brackets
nofurtherinformation 1c85564
make load data script better for future refactor
nofurtherinformation 58a2e38
ruff
nofurtherinformation 378da62
UDF Fix for shattering null parents
nofurtherinformation 3ee9595
Swap onClick for onSelect
nofurtherinformation a1c7de2
Bump limit to 30
nofurtherinformation File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
backend/app/alembic/versions/ccb2a6b81a8b_shattering.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
"""shattering | ||
|
||
Revision ID: ccb2a6b81a8b | ||
Revises: 8437ce954087 | ||
Create Date: 2024-09-13 09:44:34.534198 | ||
|
||
""" | ||
|
||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
import app.models | ||
import sqlmodel.sql.sqltypes | ||
from pathlib import Path | ||
|
||
SQL_PATH = Path(__file__).parent.parent.parent / "sql" | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "ccb2a6b81a8b" | ||
down_revision: Union[str, None] = "8437ce954087" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"districtrmap", | ||
sa.Column( | ||
"created_at", | ||
sa.TIMESTAMP(timezone=True), | ||
server_default=sa.text("CURRENT_TIMESTAMP"), | ||
nullable=False, | ||
), | ||
sa.Column( | ||
"updated_at", | ||
sa.TIMESTAMP(timezone=True), | ||
server_default=sa.text("CURRENT_TIMESTAMP"), | ||
nullable=False, | ||
), | ||
sa.Column("uuid", app.models.UUIDType(), nullable=False), | ||
sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False), | ||
sa.Column( | ||
"gerrydb_table_name", sqlmodel.sql.sqltypes.AutoString(), nullable=True | ||
), | ||
sa.Column("num_districts", sa.Integer(), nullable=True), | ||
sa.Column("tiles_s3_path", sqlmodel.sql.sqltypes.AutoString(), nullable=True), | ||
sa.Column("parent_layer", sqlmodel.sql.sqltypes.AutoString(), nullable=False), | ||
sa.Column("child_layer", sqlmodel.sql.sqltypes.AutoString(), nullable=True), | ||
sa.ForeignKeyConstraint( | ||
["child_layer"], | ||
["gerrydbtable.name"], | ||
), | ||
sa.ForeignKeyConstraint( | ||
["parent_layer"], | ||
["gerrydbtable.name"], | ||
), | ||
sa.PrimaryKeyConstraint("uuid"), | ||
sa.UniqueConstraint("uuid"), | ||
sa.UniqueConstraint("gerrydb_table_name"), | ||
) | ||
op.create_table( | ||
"parentchildedges", | ||
sa.Column( | ||
"created_at", | ||
sa.TIMESTAMP(timezone=True), | ||
server_default=sa.text("CURRENT_TIMESTAMP"), | ||
nullable=False, | ||
), | ||
sa.Column( | ||
"updated_at", | ||
sa.TIMESTAMP(timezone=True), | ||
server_default=sa.text("CURRENT_TIMESTAMP"), | ||
nullable=False, | ||
), | ||
sa.Column("districtr_map", app.models.UUIDType(), nullable=False), | ||
sa.Column("parent_path", sa.String(), nullable=False), | ||
sa.Column("child_path", sa.String(), nullable=False), | ||
sa.ForeignKeyConstraint( | ||
["districtr_map"], | ||
["districtrmap.uuid"], | ||
), | ||
sa.PrimaryKeyConstraint("districtr_map", "parent_path", "child_path"), | ||
) | ||
op.drop_column("gerrydbtable", "tiles_s3_path") | ||
# ### end Alembic commands ### | ||
|
||
for file_name in [ | ||
"parent_child_relationships.sql", | ||
"create_shatterable_gerrydb_view.sql", | ||
"create_districtr_map_udf.sql", | ||
"shatter_parent.sql", | ||
]: | ||
with open(SQL_PATH / file_name, "r") as f: | ||
sql = f.read() | ||
op.execute(sql) | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column( | ||
"gerrydbtable", | ||
sa.Column("tiles_s3_path", sa.VARCHAR(), autoincrement=False, nullable=True), | ||
) | ||
op.drop_table("parentchildedges") | ||
op.drop_table("districtrmap") | ||
# ### end Alembic commands ### | ||
op.execute("DROP PROCEDURE IF EXISTS add_parent_child_relationships(TEXT)") | ||
op.execute( | ||
"DROP PROCEDURE IF EXISTS create_shatterable_gerrydb_view(TEXT, TEXT, TEXT)" | ||
) | ||
for func_name in [ | ||
"create_districtr_map", | ||
"shatter_parent", | ||
]: | ||
op.execute(f"DROP FUNCTION IF EXISTS {func_name}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,15 @@ | |
from pydantic import UUID4, BaseModel | ||
from sqlmodel import ( | ||
Field, | ||
ForeignKey, | ||
SQLModel, | ||
UUID, | ||
TIMESTAMP, | ||
UniqueConstraint, | ||
text, | ||
Column, | ||
MetaData, | ||
String, | ||
) | ||
from app.constants import DOCUMENT_SCHEMA | ||
|
||
|
@@ -40,15 +42,58 @@ class TimeStampMixin(SQLModel): | |
) | ||
|
||
|
||
class GerryDBTable(TimeStampMixin, SQLModel, table=True): | ||
class DistrictrMap(TimeStampMixin, SQLModel, table=True): | ||
uuid: str = Field(sa_column=Column(UUIDType, unique=True, primary_key=True)) | ||
name: str = Field(nullable=False, unique=True) | ||
name: str = Field(nullable=False) | ||
# This is intentionally not a foreign key on `GerryDBTable` because in some cases | ||
# this may be the GerryDBTable but in others the pop table may be a materialized | ||
# view of two GerryDBTables in the case of shatterable maps. | ||
# We'll want to enforce the constraint tha the gerrydb_table_name is either in | ||
# GerrydbTable.name or a materialized view of two GerryDBTables some other way. | ||
gerrydb_table_name: str | None = Field(nullable=True, unique=True) | ||
# Null means default number of districts? Should we have a sensible default? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (O) Sensible default hard to set globally, IMO, maybe later we are more geo-aware and can default to the num of congressional districts in a state but for now I think null is fine. |
||
num_districts: int | None = Field(nullable=True, default=None) | ||
tiles_s3_path: str | None = Field(nullable=True) | ||
parent_layer: str = Field( | ||
sa_column=Column(UUIDType, ForeignKey("gerrydbtable.uuid"), nullable=False) | ||
) | ||
child_layer: str | None = Field( | ||
sa_column=Column( | ||
UUIDType, ForeignKey("gerrydbtable.uuid"), default=None, nullable=True | ||
) | ||
) | ||
# schema? will need to contrain the schema | ||
# where does this go? | ||
# when you create the view, pull the columns that you need | ||
# we'll want discrete management steps | ||
|
||
|
||
class GerryDBViewPublic(BaseModel): | ||
class DistrictrMapPublic(BaseModel): | ||
name: str | ||
tiles_s3_path: str | None | ||
gerrydb_table_name: str | ||
parent_layer: str | ||
child_layer: str | None = None | ||
tiles_s3_path: str | None = None | ||
num_districts: int | None = None | ||
|
||
|
||
class GerryDBTable(TimeStampMixin, SQLModel, table=True): | ||
uuid: str = Field(sa_column=Column(UUIDType, unique=True, primary_key=True)) | ||
# Must correspond to the layer name in the tileset | ||
name: str = Field(nullable=False, unique=True) | ||
|
||
|
||
class ParentChildEdges(TimeStampMixin, SQLModel, table=True): | ||
districtr_map: str = Field( | ||
raphaellaude marked this conversation as resolved.
Show resolved
Hide resolved
|
||
sa_column=Column( | ||
UUIDType, | ||
ForeignKey("districtrmap.uuid"), | ||
nullable=False, | ||
primary_key=True, | ||
) | ||
) | ||
parent_path: str = Field(sa_column=Column(String, nullable=False, primary_key=True)) | ||
child_path: str = Field(sa_column=Column(String, nullable=False, primary_key=True)) | ||
|
||
|
||
class Document(TimeStampMixin, SQLModel, table=True): | ||
|
@@ -91,6 +136,10 @@ class AssignmentsCreate(BaseModel): | |
assignments: list[Assignments] | ||
|
||
|
||
class GEOIDS(BaseModel): | ||
geoids: list[str] | ||
|
||
|
||
class ZonePopulation(BaseModel): | ||
zone: int | ||
total_pop: int |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(pp) not caused by this PR, but just noticing- limit(1) is going to prevent run time errors if we do for some reason violate uniqueness constraints, but, uh, we have uniqueness constraints on the database. I think we should be consistent-- pair result.one() with a .limit(1) each time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally but I'd prefer to actually remove the limit and handle the runtime error, allowing us to send an informative error and catch bugs earlier. Bugs ofc not caused by erroneous db state-because we have our constraints in place-but in our queries
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With that said, let's address this in a separate mini pr