forked from nprapps/walmart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyze.sh
executable file
·38 lines (31 loc) · 1.06 KB
/
analyze.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
source globals.sh
echo "Compute population within 1 mile of a Walmart"
for fips in "${FIPS[@]}"
do
name=${NAMES["${fips}"]};
place_fips=${PLACES["${fips}"]};
pop=${POPS["${fips}"]};
# Compute 1 miles in meters
meters=`echo "1 * 1609.344" | bc`;
echo "* ${name}"
for year in "${YEARS[@]}"
do
echo " * ${year}"
psql walmart -c "
SELECT
sum(blocks.pop10) as pop_near_walmart,
${pop} as pop_total,
round(sum(blocks.pop10) / ${pop} * 100, 2) as pct
FROM
blocks,
places
WHERE
-- Filter to state blocks first for performance
blocks.statefp10 = '${fips}' AND
places.statefp10 = '${fips}' AND
places.placefp10 = '${place_fips}' AND
ST_Within(blocks.centroid, places.wkb_geometry) AND
blocks.nearest${year} < ${meters};"
done
done