Skip to content

Commit

Permalink
tract data update
Browse files Browse the repository at this point in the history
  • Loading branch information
nofurtherinformation committed May 15, 2024
1 parent 0aeacd7 commit 44b1c6f
Show file tree
Hide file tree
Showing 60 changed files with 57 additions and 30 deletions.
47 changes: 31 additions & 16 deletions app/tract/[tract]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import { getContentDirs } from "utils/contentDirs"
import { getThresholdValue } from "utils/data/formatDataTemplate"
import { getSummaryStats } from "utils/data/summaryStats"
import StoreList from "components/StoreList"
import wasmInit, {readParquet} from "parquet-wasm";

import { parquetRead } from "hyparquet"
import { readFileSync } from "fs"

const Map = dynamic(() => import("components/Map/Map"), { ssr: false })

type TractRouteProps = {
Expand Down Expand Up @@ -111,7 +116,6 @@ const TractPage: React.FC<TractRouteProps> = async ({ params }) => {
// dynamic routes to use mdx content
getContentDirs()
const tract = params.tract

const [tractData, generalStatText] = await Promise.all([
getSummaryStats<TractData>('tract', tract),
getMdxContent("statistics", "tract.mdx"),
Expand All @@ -128,28 +132,32 @@ const TractPage: React.FC<TractRouteProps> = async ({ params }) => {
// @ts-ignore
const marketPowerTemplate = generalStatText?.data?.statistics?.overview?.find((f) => f.measure === "hhi")
// @ts-ignore
const racialEquityTemplate = generalStatText?.data?.statistics?.overview?.find((f) => f.measure === "segregation")
const segregationTemplate = generalStatText?.data?.statistics?.overview?.find((f) => f.measure === "segregation")
// @ts-ignore
const economicAdvantageTemplate = generalStatText?.data?.statistics?.overview?.find((f) => f.measure === "adi")

// @ts-ignore
const tractName = data.NAME.toLowerCase().includes("tract") ? data.NAME : `${data.NAME} tract`

// @ts-ignore
const [foodAccess, marketPower, racialEquity] = [
data[foodAccesstemplate.column as keyof typeof data],
const [foodAccess, marketPower, segregation, economicAdvantage] = [
+data[foodAccesstemplate.column as keyof typeof data],
100 - +data[marketPowerTemplate.column as keyof typeof data],
100 - +data[racialEquityTemplate.column as keyof typeof data],
100 - +data[segregationTemplate.column as keyof typeof data],
+data[economicAdvantageTemplate.column as keyof typeof data]
]

console.log('food access', foodAccesstemplate)
const foodAccessText = getThresholdValue(foodAccess, data, foodAccesstemplate)
const marketPowerText = getThresholdValue(marketPower, data, marketPowerTemplate)
const racialEquityText = getThresholdValue(racialEquity, data, racialEquityTemplate)
const segregationText = getThresholdValue(segregation, data, segregationTemplate)
const economicAdvantageText = getThresholdValue(economicAdvantage, data, economicAdvantageTemplate)

return (
<div className="min-h-[100vh] bg-theme-canvas-500 p-4">
{/* grid two equal columns
collapse on mobile */}
<div className="grid gap-8 lg:grid-cols-2">
<div>
<div className="grid gap-8 lg:grid-cols-4">
<div className="col-span-1">
<a href="/tract" className="align-center mb-4 flex items-center pb-2 text-sm text-gray-600">
<ArrowLeftIcon className="mr-2 inline size-4" />
Back to counties
Expand All @@ -163,8 +171,8 @@ const TractPage: React.FC<TractRouteProps> = async ({ params }) => {
</p>
</div>
</div>
<div>
<div className="relative grid gap-8 lg:grid-cols-3">
<div className="col-start-2 col-end-6 py-8">
<div className="relative grid gap-8 lg:grid-cols-4">
<DataLockup
title={foodAccesstemplate.title}
tooltip={foodAccesstemplate.tooltip}
Expand All @@ -180,10 +188,17 @@ const TractPage: React.FC<TractRouteProps> = async ({ params }) => {
border
/>
<DataLockup
title={racialEquityTemplate.title}
tooltip={racialEquityTemplate.tooltip}
value={racialEquity}
description={racialEquityText}
title={economicAdvantageTemplate.title}
tooltip={economicAdvantageTemplate.tooltip}
value={economicAdvantage}
description={economicAdvantageText}
border
/>
<DataLockup
title={segregationTemplate.title}
tooltip={segregationTemplate.tooltip}
value={segregation}
description={segregationText}
/>
</div>
</div>
Expand Down Expand Up @@ -228,7 +243,7 @@ const TractPage: React.FC<TractRouteProps> = async ({ params }) => {
{/* <div className="my-8 h-[100vh] w-full bg-white p-8 shadow-xl">
<TimeseriesChart id={tract} />
</div> */}
<div className="my-8 h-[100vh] w-full bg-white p-8 shadow-xl">
<div className="my-8 h-[100vh] w-full bg-white p-8 shadow-xl overflow-y-auto">
<StoreList id={tract} />
</div>
</div>
Expand Down
5 changes: 4 additions & 1 deletion components/StoreList/StoreList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export const StoreList: React.FC<StoreListProps<string[]>> = ({
label: "Estimated Percent of Sales",
formatter: percentFormatter.format,
},
"ADDRESS LINE 1": {
label: "Address"
}
},
title,
}) => {
Expand Down Expand Up @@ -65,7 +68,7 @@ export const StoreList: React.FC<StoreListProps<string[]>> = ({
{columns.map((col, j: number) => {
const _val = row[col as keyof typeof row]
// @ts-ignore
const val = formatters.hasOwnProperty(col) ? formatters[col].formatter(_val) : _val
const val = formatters[col]?.formatter?.(_val) || _val
return <td key={j}>{val}</td>
})}
</tr>
Expand Down
34 changes: 21 additions & 13 deletions content/statistics/tract.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ stat:
templates:
- body: >
The median ICE value in the tract for black or african american and
white segregation is %%segregation\_2021%%.
white segregation is %%segregation\_2021%%.
This means %%NAME%% is among the
Expand Down Expand Up @@ -88,24 +88,33 @@ stat:
* Non-hispanic Some Another race: %%%100|\*|PCT NH SOME OTHER%%%
* Non-hispanic Two or more races: %%100|\*|PCT NH TWO OR MORE%%%
overview:
- title: Racial Equity
column: segregation_2021_percentile
tooltip: "Racial equity is reflects segregation in the tract. It uses a measure called ICE (Indicators of Concentration at the Extremes), which looks at how concentrated and how separate populations live within an area. In this case, the ICE metric reflects how segregated black or african american and white people tend to be in the tract.\n\nThis score reflects the median tract value for the tract. The score is relative to the rest of the United tracts, where one hundred (100) is the most evenly competitive marketplace and zero (0) is a market with a total monopoly.\n\nFor more information on how this measure is calculated, read our\_[methodology](http://localhost:3000/about#methodology).\n"
- title: Economic Advantage
column: ADI_NATRANK
tooltip: >
Economic advantage of this tract relative to the whole country ... ADI
description here
templates:
- body: |
%%NAME%% is more advantaged than %%ADI\_NATRANK%%% of all tracts.
measure: adi
- title: Segregation
column: segregation_2023_percentile
tooltip: "This measure of segregation reflects how separated are people who are Black or African American and White as reported in the census. It uses a measure called the Indicators of Concentration at the Extremes, which looks at how concentrated and how separate populations live within an area. In this case, this measure reflects how segregated black or african american and white people tend to be in the tract.\n\nThis score reflects the median tract value for the tract. The score is relative to the rest of the United tracts, where one hundred (100) is the most evenly competitive marketplace and zero (0) is a market with a total monopoly.\n\nFor more information on how this measure is calculated, read our\_[methodology](http://localhost:3000/about#methodology).\n"
templates:
- body: >
%%NAME%% has segregation among the
%%100|-|segregation\_2021\_percentile%%% most segregated counties.
%%100|-|segregation\_2023\_percentile%%% most segregated counties.
measure: segregation
- title: Market Power
column: hhi_2021_percentile
column: hhi_2023_percentile
tooltip: "Market power is a measure of diversity in the marketplace. It looks at how dominant single grocery stores are in an area. This measure is calculated using the Herfindahl–Hirschman Index (HHI).\n\nThis score reflects the median tract value for the tract. The score is relative to the rest of the United tracts, where one hundred (100) is the most evenly competitive marketplace and zero (0) is a market with a total monopoly.\n\nFor more information on how this measure is calculated, read our\_[methodology](http://localhost:3000/about#methodology).\n"
templates:
- body: >
This tract has market power better than
%%100|-|hhi\_2021\_percentile%%% of all counties.
%%100|-|hhi\_2023\_percentile%%% of all counties.
measure: hhi
- title: Food Access
column: gravity_2021_percentile
column: gravity_2023_percentile
tooltip: >
Food access reflects the amount of grocery supply available relative to
people living in a given area. This measure is calculated using a gravity
Expand All @@ -114,19 +123,18 @@ overview:
together.
The score is
relative to the rest of the United States, where one hundred (100) is the
best food access and zero (0) is the worst food access.
The score is relative to the rest of the United States, where one hundred
(100) is the best food access and zero (0) is the worst food access.
For more information on how this measure is calculated, read our
[methodology](/about#methodology).
templates:
- body: "The access people have to buy groceries. %%NAME%% is in the top\_%%100|-|gravity\\_2021\\_percentile%%% of all counties.\n"
- body: "The access people have to buy groceries. %%NAME%% is in the top\_%%100|-|gravity\\_2023\\_percentile%%% of all tracts.\n"
threshold: 75
- body: >
The access people have to buy groceries. %%NAME%% has better food
access than %%100|-|gravity\_2021\_percentile%%% of counties.
access than %%100|-|gravity\_2023\_percentile%%% of tracts.
threshold: 25
- body: "The access people have to buy groceries. %%NAME%% is in the bottom\_%%gravity\\_2021\\_percentile%% of all counties.\n"
threshold: 0
Expand Down
Binary file modified public/data/summary/tract/01.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/02.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/04.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/05.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/06.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/08.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/09.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/10.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/11.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/12.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/13.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/15.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/16.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/17.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/18.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/19.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/20.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/21.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/22.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/23.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/24.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/25.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/26.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/27.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/28.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/29.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/30.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/31.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/32.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/33.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/34.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/35.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/36.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/37.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/38.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/39.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/40.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/41.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/42.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/44.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/45.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/46.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/47.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/48.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/49.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/50.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/51.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/53.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/54.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/55.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/56.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/60.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/66.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/69.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/72.min.msgpack.gz
Binary file not shown.
Binary file modified public/data/summary/tract/78.min.msgpack.gz
Binary file not shown.
1 change: 1 addition & 0 deletions scripts/precompute_summary_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
current_dir = path.dirname(path.abspath(__file__))
data_dir = path.join(current_dir, '..', 'public', 'data')
# %%
df_full = pd.read_parquet(path.join(data_dir, 'full_tract.parquet'))
# %%
year = '2023'

Expand Down

0 comments on commit 44b1c6f

Please sign in to comment.