Skip to content
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

Chart enhancements + stub of places and districtingProblems #167

Merged
merged 85 commits into from
Nov 19, 2024

Conversation

mariogiampieri
Copy link
Collaborator

@mariogiampieri mariogiampieri commented Nov 11, 2024

Description

  • Chart behavior based on MapDocument properties, including a target number of districts (manually set for now) and a total population. This chart behavior includes:
    • an ideal population per zone indicated as a vertical labelled line
    • the chart x-max set based on ideal pop * 2 or dataMax, whichever is larger (i.e. if someone is going overboard the chart will follow
    • separately, setting the # of colors in the palette to equal the target # of districts.

Re: places and problems, to circle back on:

  • Create draft DistrictrPlace and DistrictrProblem models, following v1 places / problems and syntax that a user selects to start a session. This was in service of getting the proper target # districts for each map. I suspect that we'll want to discuss and revise how these objects fit in with our data model. For now at least, they provide a target for each test map, based on districtr v1 statewide places and problems
  • Per the above, utility scripts (still WIP) to load data from districtr v1 into these new tables. Again, we should discuss where these things should live long term (holding for a later branch)

Reviewers

  • Primary:
  • Secondary:

Checklist

  • Added/Updated related documentation (if applicable).
  • Added/Updated related unit tests (if applicable).

Screenshots (if applicable):

image

@mariogiampieri
Copy link
Collaborator Author

Ok, the chart is working as intended now, with a pin put in the places and problems. The num_districts can be manually set for now for the chart to behave properly.

@mariogiampieri mariogiampieri changed the title Chart enhancements + broaching places and districtingProblems port over Chart enhancements + stem of places and districtingProblems Nov 16, 2024
@mariogiampieri mariogiampieri changed the title Chart enhancements + stem of places and districtingProblems Chart enhancements + stub of places and districtingProblems Nov 16, 2024
@mariogiampieri mariogiampieri marked this pull request as ready for review November 16, 2024 15:52
Copy link
Collaborator

@nofurtherinformation nofurtherinformation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a couple small comments but FE stuff looks good to me for user testing. I didn't look too deeply into the backend work here for now

}
}, [summaryStats, numDistricts]);

const calculateChartObject = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PP: calculateChartObject and the useEffect on 72 would be more readable with useMemo instead

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

useEffect(() => {
if (summaryStats && numDistricts) {
const totalPop = summaryStats.totpop ? getEntryTotal(summaryStats.totpop.data) : 0;
setIdealPopulation(totalPop / numDistricts);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PP: This could make more sense as mapStore.summaryStats.idealPopulation -- are there other places we'd want to have this number available?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be queries.ts:72

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! good call

Copy link
Collaborator

@raphaellaude raphaellaude left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only one blocking comment to delete unused UDF. Let's handle the two_or_more_races_pop issue in a separate PR to get this in.

@@ -44,30 +88,49 @@ export const HorizontalBar = () => {
return (
<Flex gap="3" direction="column">
<Heading as="h3" size="3">
Population by Zone
Population by District
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PP: looks like Moon has been using sentence case which I think is better style -> Population by district


export const P1ZoneSummaryStatsKeys = [
'other_pop',
'asian_pop',
'amin_pop',
'nhpi_pop',
'black_pop',
'white_pop'
] as const
'white_pop',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I: Will want to add two_or_more_races_pop here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will handle in separate PR

@@ -192,7 +192,7 @@ export const CleanedP1ZoneSummaryStatsKeys = [
'nhpi_pop_pct',
'black_pop_pct',
'white_pop_pct',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I: and add two_or_more_races_pop here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will handle in separate PR

@@ -5,7 +5,7 @@
from starlette.middleware.cors import CORSMiddleware
from sqlalchemy.dialects.postgresql import insert
import logging
from sqlalchemy import bindparam
from sqlalchemy import bindparam, func
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: is func used here? I don't see it in the diff

@@ -0,0 +1,40 @@
DROP FUNCTION IF EXISTS get_summary_stats_pop_totals;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

H: This function isn't being used now, no? We can delete in favor of using the either get_summary_p1_totals or get_summary_p4_totals (and eventually others...)?

amin_pop BIGINT,
nhpi_pop BIGINT,
black_pop BIGINT,
white_pop BIGINT
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

H: Even though we should remove this function, we'll need to add two_or_more_races_pop to get_summary_p1_totals.

if __name__ == "__main__":
cli()


def upsert_places_and_problems():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PP: Move above if __name__ == "__main__" but add raise NotImplementedError in the function body. Or just warnings.warn("Not implemented") or something

Copy link
Collaborator

@raphaellaude raphaellaude left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mariogiampieri mariogiampieri merged commit 69fb2d2 into main Nov 19, 2024
2 checks passed
@mariogiampieri mariogiampieri deleted the feat/chart-enhancements branch November 19, 2024 05:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants