-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathACS.html
1600 lines (1308 loc) · 69.8 KB
/
ACS.html
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="" />
<meta name="author" content="" />
<link rel="stylesheet" href="style.css" />
<script src="https://d3js.org/d3.v7.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/fetch-retry@latest"></script>
<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<script src="geography_lookupNew.js"></script>
<script src="queue.v1.min.js"></script>
<script src="modernizr-custom.js"></script>
<script src="excellentexport.js"></script>
</head>
<!--Arquero-->
<script src="https://cdn.jsdelivr.net/npm/arquero@latest"></script>
<body>
<div id="controls">
<label>Indicator:</label>
<select id='ind_options'></select>
<label>Year:</label>
<select id='year_options'>
<!-- add new years here -->
<option value="2021">2017-2021</option>
<option value="2020">2016-2020</option>
<option value="2019">2015-2019</option>
<option value="2018">2014-2018</option>
<option value="2017">2013-2017</option>
<option value="2016">2012-2016</option>
<option value="2015">2011-2015</option>
<option value="2014">2010-2014</option>
<option value="2013">2009-2013</option>
<option value="2012">2008-2012</option>
<option value="2011">2007-2011</option>
</select>
<a href="#" class="myButton" id="get_data">Get Data</a>
<a href="#" class="export myButton" id="exportChrome" style="display:none">Export Table to CSV</a>
<a href="#" class="export myButton" id="exportIE" style="display:none" onclick="return ExcellentExport.csv(this, 'datatableCsv');">Export Table to CSV</a>
<a href="ACS_Documentation.pdf" style="margin: 0px 0px 10px 10px;" id="download">Documentation</a>
<input id="chkrank" type="checkbox" name="vehicle" />Include Rank<br>
</div>
<div id='tab_loc' class="CSSTableGenerator"></div>
</body>
<script>
//===========================================================================//
// setting initial variable values
//===========================================================================//
// Census API 5-year ACS URL
var api_url = 'https://api.census.gov/data';
var my_key = 'c8b757f7e16f108647304131056db5bb63ba2e93';
//---------------------------------------------------------------------------//
// indicators whose definitions and variables haven't changed
//---------------------------------------------------------------------------//
/*
ACS variable names are {table}_{row}, so when the row number of an estimate changes,
the variable name changes also. If we keep track of those changes, we can account
for them. So I recoded the census_param and race_var objects to include the
correct variable names for specified time periods, then included a test so that
census_var includes the correct variables.
*/
// denom = complete denominator
// denom2 = combined with number to form complete denominator
var census_param = [
{
indicator: "Race and ethnicity", category: "race_vars"
},
{
indicator: "Total population", table: "TOTAL POPULATION", source: 'acs/acs5', category: "population",
time_period: [
{
min: 2010,
max: 2021,
variables: [
{ name: "B01003_001E", label: "Estimate!!Total", type: "num" }
]
}
]
},
{
indicator: "Housing Units", table: "HOUSING UNITS", source: 'acs/acs5', category: "housing",
time_period: [
{
min: 2010,
max: 2021,
variables: [
{ name: "B25001_001E", label: "Estimate!!Total", type: "num" }
]
}
]
},
{
indicator: "Household income", table: "MEDIAN HOUSEHOLD INCOME IN THE PAST 12 MONTHS", source: 'acs/acs5', category: "income",
time_period: [
{
min: 2010,
max: 2021,
variables: [
{ name: "B19013_001E", label: "Estimate!!Median household income in the past 12 months", type: "num" }
]
}
]
},
{
indicator: "Neighborhood poverty", table: "POVERTY STATUS IN THE PAST 12 MONTHS BY SEX BY AGE", source: 'acs/acs5', category: "poverty",
time_period: [
{
min: 2010,
max: 2021,
variables: [
{ name: "B17001_002E", label: "Estimate!!Total!!Income in the past 12 months below poverty level", type: "num" },
{ name: "B17001_001E", label: "Estimate!!Total", type: "denom" }
]
}
]
},
{
indicator: "Independent living difficulty (adults)", table: "DISABILITY CHARACTERISTICS", source: 'acs/acs5', category: "living",
time_period: [
{
min: 2010,
max: 2021,
variables: [
{ name: "B18107_004E", label: "Estimate!!Total:!!Male:!!18 to 34 years:!!With an independent living difficulty", type: "num" },
{ name: "B18107_007E", label: "Estimate!!Total:!!Male:!!35 to 64 years:!!With an independent living difficulty", type: "num" },
{ name: "B18107_010E", label: "Estimate!!Total:!!Male:!!65 to 74 years:!!With an independent living difficulty", type: "num" },
{ name: "B18107_013E", label: "Estimate!!Total:!!Male:!!75 years and over:!!With an independent living difficulty", type: "num" },
{ name: "B18107_017E", label: "Estimate!!Total:!!Female:!!18 to 34 years:!!With an independent living difficulty", type: "num" },
{ name: "B18107_020E", label: "Estimate!!Total:!!Female:!!35 to 64 years:!!With an independent living difficulty", type: "num" },
{ name: "B18107_023E", label: "Estimate!!Total:!!Female:!!65 to 74 years:!!With an independent living difficulty", type: "num" },
{ name: "B18107_026E", label: "Estimate!!Total:!!Female:!!75 years and over:!!With an independent living difficulty", type: "num" },
{ name: "B18107_001E", label: "Estimate!!Total:", type: "denom" }
]
}
]
},
{
indicator: "Ambulatory difficulty (adults)", table: "DISABILITY CHARACTERISTICS", source: 'acs/acs5', category: "living",
time_period: [
{
min: 2010,
max: 2021,
variables: [
{ name: "B18105_007E", label: "Estimate!!Total:!!Male:!!18 to 34 years:!!With an ambulatory difficulty", type: "num" },
{ name: "B18105_010E", label: "Estimate!!Total:!!Male:!!35 to 64 years:!!With an ambulatory difficulty", type: "num" },
{ name: "B18105_013E", label: "Estimate!!Total:!!Male:!!65 to 74 years:!!With an ambulatory difficulty", type: "num" },
{ name: "B18105_016E", label: "Estimate!!Total:!!Male:!!75 years and over:!!With an ambulatory difficulty", type: "num" },
{ name: "B18105_023E", label: "Estimate!!Total:!!Female:!!18 to 34 years:!!With an ambulatory difficulty", type: "num" },
{ name: "B18105_026E", label: "Estimate!!Total:!!Female:!!35 to 64 years:!!With an ambulatory difficulty", type: "num" },
{ name: "B18105_029E", label: "Estimate!!Total:!!Female:!!65 to 74 years:!!With an ambulatory difficulty", type: "num" },
{ name: "B18105_032E", label: "Estimate!!Total:!!Female:!!75 years and over:!!With an ambulatory difficulty", type: "num" },
{ name: "B18105_001E", label: "Estimate!!Total:", type: "denom" }
]
}
]
},
// {
// indicator: "Poverty TOTAL", table: "POVERTY STATUS IN THE PAST 12 MONTHS BY AGE", source: 'acs/acs5',
// time_period: [
// {
// min: 2010,
// max: 2021,
// variables: [
// { name: "B17001_001E", label: "Estimate!!Total", type: "num" }
// ]
// }
// ]
// },
{
indicator: "Child poverty (under age 5)", table: "POVERTY STATUS IN THE PAST 12 MONTHS BY SEX BY AGE", source: 'acs/acs5', category: "under_5_poverty",
time_period: [
{
min: 2010,
max: 2021,
variables: [
{ name: "B17001_004E", label: "Estimate!!Total!!Income in the past 12 months below poverty level!!Male!!Under 5 years", type: "num" },
{ name: "B17001_033E", label: "Estimate!!Total!!Income in the past 12 months at or above poverty level!!Male!!Under 5 years", type: "denom2" },
{ name: "B17001_018E", label: "Estimate!!Total!!Income in the past 12 months below poverty level!!Female!!Under 5 years", type: "num" },
{ name: "B17001_047E", label: "Estimate!!Total!!Income in the past 12 months at or above poverty level!!Female!!Under 5 years", type: "denom2" }
]
}
]
},
{
indicator: "Unemployment", table: "EMPLOYMENT STATUS FOR THE POPULATION 16 YEARS AND OVER", source: 'acs/acs5', category: "unemployment",
time_period: [
{
min: 2010,
max: 2021,
variables: [
{ name: "B23025_005E", label: "Estimate!!Total!!In labor force!!Civilian labor force!!Unemployed", type: "num" },
{ name: "B23025_003E", label: "Estimate!!Total!!In labor force!!Civilian labor force", type: "denom" }
]
}
]
},
{
indicator: "Rent-burdened households", table: "GROSS RENT AS A PERCENTAGE OF HOUSEHOLD INCOME IN THE PAST 12 MONTHS", source: 'acs/acs5', category: "rent",
time_period: [
{
min: 2010,
max: 2021,
variables: [
{ name: "B25070_007E", label: "Estimate!!Total!!30.0 to 34.9 percent", type: "num" },
{ name: "B25070_008E", label: "Estimate!!Total!!35.0 to 39.9 percent", type: "num" },
{ name: "B25070_009E", label: "Estimate!!Total!!40.0 to 49.9 percent", type: "num" },
{ name: "B25070_010E", label: "Estimate!!Total!!50.0 percent or more", type: "num" },
{ name: "B25070_001E", label: "Estimate!!Total", type: "denom" }
]
}
]
},
// {
// indicator: "Older adults living alone", table: "LIVING ARRANGEMENTS OF ADULTS 18 YEARS AND OVER BY AGE", source: 'acs/acs5',
// time_period: [
// {
// min: 2015,
// max: 2021,
// variables: [
// { name: "B09021_023E", label: "Estimate!!Total!!65 years and over!!Lives alone", type: "num" },
// { name: "B09021_022E", label: "Estimate!!Total!!65 years and over", type: "denom" }
// ]
// }
// ]
// },
{
indicator: "Older adults living alone", table: "Relationship by Household Type (Including Living Alone) for the Population 65 Years and Over", source: 'acs/acs5', category: "living_alone",
time_period: [
{
min: 2010,
max: 2011,
variables: [
{ name: "B09017_014E", label: "Estimate!!Total!!In households!!In nonfamily households!!Householder!!Male!!Living alone", type: "num" },
{ name: "B09017_017E", label: "Estimate!!Total!!In households!!In nonfamily households!!Householder!!Female!!Living alone", type: "num" },
{ name: "B09017_001E", label: "Estimate!!Total:", type: "denom" }
]
},
{
min: 2012,
max: 2021,
variables: [
{ name: "B09020_015E", label: "Estimate!!Total!!In households!!In nonfamily households!!Householder!!Male!!Living alone", type: "num" },
{ name: "B09020_018E", label: "Estimate!!Total!!In households!!In nonfamily households!!Householder!!Female!!Living alone", type: "num" },
{ name: "B09020_001E", label: "Estimate!!Total", type: "denom" }
]
}
]
},
{
indicator: "Very old homes", table: "YEAR STRUCTURE BUILT", source: 'acs/acs5', category: "1950_homes",
time_period: [
{
min: 2010,
max: 2014,
variables: [
{ name: "B25034_010E", label: "Estimate!!Total!!Built 1939 or earlier", type: "num" },
{ name: "B25034_009E", label: "Estimate!!Total!!Built 1940 to 1949", type: "num" },
{ name: "B25034_001E", label: "Estimate!!Total", type: "denom2" }
]
},
{
min: 2015,
max: 2021,
variables: [
{ name: "B25034_011E", label: "Estimate!!Total!!Built 1939 or earlier", type: "num" },
{ name: "B25034_010E", label: "Estimate!!Total!!Built 1940 to 1949", type: "num" },
{ name: "B25034_001E", label: "Estimate!!Total", type: "denom2" }
]
}
]
},
{
indicator: "Owner-occupied homes", table: "SELECTED HOUSING CHARACTERISTICS", source: 'acs/acs5/profile', category: "owner_occupied",
time_period: [
{
min: 2010,
max: 2014,
variables: [
{ name: "DP04_0045E", label: "Estimate!!HOUSING TENURE!!Occupied housing units!!Owner-occupied", type: "num" },
{ name: "DP04_0044E", label: "Estimate!!HOUSING TENURE!!Occupied housing units", type: "denom" }
]
},
{
min: 2015,
max: 2021,
variables: [
{ name: "DP04_0046E", label: "Estimate!!HOUSING TENURE!!Occupied housing units!!Owner-occupied", type: "num" },
{ name: "DP04_0045E", label: "Estimate!!HOUSING TENURE!!Occupied housing units", type: "denom" }
]
}
]
},
{
indicator: "Foreign-born", table: "SELECTED SOCIAL CHARACTERISTICS IN THE UNITED STATES", source: 'acs/acs5/profile', category: "foreign_born",
time_period: [
{
min: 2010,
max: 2018,
variables: [
{ name: "DP02_0092E", label: "Estimate!!PLACE OF BIRTH!!Total population!!Foreign born", type: "num" },
{ name: "DP02_0086E", label: "Estimate!!PLACE OF BIRTH!!Total population", type: "denom" }
]
},
{
min: 2019,
max: 2019,
variables: [
{ name: "DP02_0093E", label: "Estimate!!PLACE OF BIRTH!!Total population!!Foreign born", type: "num" },
{ name: "DP02_0087E", label: "Estimate!!PLACE OF BIRTH!!Total population", type: "denom" }
]
},
{
min: 2020,
max: 2021,
variables: [
{ name: "DP02_0094E", label: "Estimate!!PLACE OF BIRTH!!Total population!!Foreign born", type: "num" },
{ name: "DP02_0088E", label: "Estimate!!PLACE OF BIRTH!!Total population", type: "denom" }
]
}
]
},
{
indicator: "Household crowding", table: "SELECTED HOUSING CHARACTERISTICS", source: 'acs/acs5/profile', category: "crowding",
time_period: [
{
min: 2010,
max: 2014,
variables: [
{ name: "DP04_0077E", label: "Estimate!!OCCUPANTS PER ROOM!!Occupied housing units!!1.01 to 1.50", type: "num" },
{ name: "DP04_0078E", label: "Estimate!!OCCUPANTS PER ROOM!!Occupied housing units!!1.51 or more", type: "num" },
{ name: "DP04_0075E", label: "Estimate!!OCCUPANTS PER ROOM!!Occupied housing units", type: "denom" }
]
},
{
min: 2015,
max: 2021,
variables: [
{ name: "DP04_0078E", label: "Estimate!!OCCUPANTS PER ROOM!!Occupied housing units!!1.01 to 1.50", type: "num" },
{ name: "DP04_0079E", label: "Estimate!!OCCUPANTS PER ROOM!!Occupied housing units!!1.51 or more", type: "num" },
{ name: "DP04_0076E", label: "Estimate!!OCCUPANTS PER ROOM!!Occupied housing units", type: "denom" }
]
}
]
},
{
indicator: "Graduated high school", table: "SELECTED SOCIAL CHARACTERISTICS IN THE UNITED STATES", source: 'acs/acs5/profile', category: "high_school",
time_period: [
{
min: 2010,
max: 2018,
variables: [
{ name: "DP02_0061E", label: "Estimate!!EDUCATIONAL ATTAINMENT!!Population 25 years and over!!High school graduate (includes equivalency)", type: "num" },
{ name: "DP02_0062E", label: "Estimate!!EDUCATIONAL ATTAINMENT!!Population 25 years and over!!Some college no degree", type: "num" },
{ name: "DP02_0063E", label: "Estimate!!EDUCATIONAL ATTAINMENT!!Population 25 years and over!!Associate's degree", type: "num" },
{ name: "DP02_0064E", label: "Estimate!!EDUCATIONAL ATTAINMENT!!Population 25 years and over!!Bachelor's degree", type: "num" },
{ name: "DP02_0065E", label: "Estimate!!EDUCATIONAL ATTAINMENT!!Population 25 years and over!!Graduate or professional degree", type: "num" },
{ name: "DP02_0058E", label: "Estimate!!EDUCATIONAL ATTAINMENT!!Population 25 years and over", type: "denom" }
]
},
{
min: 2019,
max: 2021,
variables: [
{ name: "DP02_0062E", label: "Estimate!!EDUCATIONAL ATTAINMENT!!Population 25 years and over!!High school graduate (includes equivalency)", type: "num" },
{ name: "DP02_0063E", label: "Estimate!!EDUCATIONAL ATTAINMENT!!Population 25 years and over!!Some college no degree", type: "num" },
{ name: "DP02_0064E", label: "Estimate!!EDUCATIONAL ATTAINMENT!!Population 25 years and over!!Associate's degree", type: "num" },
{ name: "DP02_0065E", label: "Estimate!!EDUCATIONAL ATTAINMENT!!Population 25 years and over!!Bachelor's degree", type: "num" },
{ name: "DP02_0066E", label: "Estimate!!EDUCATIONAL ATTAINMENT!!Population 25 years and over!!Graduate or professional degree", type: "num" },
{ name: "DP02_0059E", label: "Estimate!!EDUCATIONAL ATTAINMENT!!Population 25 years and over", type: "denom" }
]
}
]
},
{
indicator: "Limited English", table: "SELECTED SOCIAL CHARACTERISTICS IN THE UNITED STATES", source: 'acs/acs5/profile', category: "limited_english",
time_period: [
{
min: 2010,
max: 2018,
variables: [
{ name: "DP02_0113E", label: "Estimate!!LANGUAGE SPOKEN AT HOME!!Population 5 years and over!!Language other than English!!Speak English less than 'very well'", type: "num" },
{ name: "DP02_0110E", label: "Estimate!!LANGUAGE SPOKEN AT HOME!!Population 5 years and over", type: "denom" }
]
},
{
min: 2019,
max: 2019,
variables: [
{ name: "DP02_0114E", label: "Estimate!!LANGUAGE SPOKEN AT HOME!!Population 5 years and over!!Language other than English!!Speak English less than 'very well'", type: "num" },
{ name: "DP02_0111E", label: "Estimate!!LANGUAGE SPOKEN AT HOME!!Population 5 years and over", type: "denom" }
]
},
{
min: 2020,
max: 2021,
variables: [
{ name: "DP02_0115E", label: "Estimate!!LANGUAGE SPOKEN AT HOME!!Population 5 years and over!!Language other than English!!Speak English less than 'very well'", type: "num" },
{ name: "DP02_0112E", label: "Estimate!!LANGUAGE SPOKEN AT HOME!!Population 5 years and over", type: "denom" }
]
}
]
},
{
indicator: "Commuting modes", category: "transportation"
},
];
//---------------------------------------------------------------------------//
// Commuting modes
//---------------------------------------------------------------------------//
var transportation = [
{
indicator: "Car, truck, or van", table: "MEANS OF TRANSPORTATION TO WORK", source: 'acs/acs5', category: "transportation",
time_period: [
{
min: 2010,
max: 2021,
variables: [
{ name: "B08301_002E", label: "Estimate!!Total!!Car, truck, or van", type: "num" },
{ name: "B08301_001E", label: "Estimate!!Total", type: "denom" }
]
}
]
},
{
indicator: "Public transportation", table: "MEANS OF TRANSPORTATION TO WORK", source: 'acs/acs5', category: "transportation",
time_period: [
{
min: 2010,
max: 2021,
variables: [
{ name: "B08301_010E", label: "Estimate!!Total!!Public transportation (excluding taxicab)", type: "num" },
{ name: "B08301_001E", label: "Estimate!!Total", type: "denom" }
]
}
]
},
{
indicator: "Bicycle", table: "MEANS OF TRANSPORTATION TO WORK", source: 'acs/acs5', category: "transportation",
time_period: [
{
min: 2010,
max: 2021,
variables: [
{ name: "B08301_018E", label: "Estimate!!Total!!Bicycle", type: "num" },
{ name: "B08301_001E", label: "Estimate!!Total", type: "denom" }
]
}
]
},
{
indicator: "Walked", table: "MEANS OF TRANSPORTATION TO WORK", source: 'acs/acs5', category: "transportation",
time_period: [
{
min: 2010,
max: 2021,
variables: [
{ name: "B08301_019E", label: "Estimate!!Total!!Walked", type: "num" },
{ name: "B08301_001E", label: "Estimate!!Total", type: "denom" }
]
}
]
},
]
//---------------------------------------------------------------------------//
// variables for race indicators
//---------------------------------------------------------------------------//
/*
Because we want to compare Hispanic vs. non-Hispanic, and people reporting
"Hispanic" can be of any race, we use the "race alone" variables under "Not
Hispanic or Latino", which ensures that our race categories are mutually
exclusive, i.e., they will sum to <= 100%. If we use the estimates under
"RACE!!One race", the counts could include people reporting "Hispanic"
(e.g., "White" and "Hispanic"), which would make the estimates higher, and
probably sum to > 100%.
*/
var race_vars = [
{
indicator: "Hispanic alone (percent)", table: "ACS DEMOGRAPHIC AND HOUSING ESTIMATES", source: 'acs/acs5/profile', category: "race_vars",
time_period: [
{
min: 2010,
max: 2016,
variables: [
{ name: "DP05_0066E", label: "Estimate!!HISPANIC OR LATINO AND RACE!!Total population!!Hispanic or Latino (of any race)", type: "num" },
{ name: "DP05_0065E", label: "Estimate!!HISPANIC OR LATINO AND RACE!!Total population", type: "denom" }
]
},
{
min: 2017,
max: 2021,
variables: [
{ name: "DP05_0071E", label: "Estimate!!HISPANIC OR LATINO AND RACE!!Total population!!Hispanic or Latino (of any race)", type: "num" },
{ name: "DP05_0070E", label: "Estimate!!HISPANIC OR LATINO AND RACE!!Total population", type: "denom" }
]
}
]
},
{
indicator: "White alone (percent)", table: "ACS DEMOGRAPHIC AND HOUSING ESTIMATES", source: 'acs/acs5/profile', category: "race_vars",
time_period: [
{
min: 2010,
max: 2016,
variables: [
{ name: "DP05_0072E", label: "Estimate!!HISPANIC OR LATINO AND RACE!!Total population!!Not Hispanic or Latino!!White alone", type: "num" },
{ name: "DP05_0065E", label: "Estimate!!HISPANIC OR LATINO AND RACE!!Total population", type: "denom" }
]
},
{
min: 2017,
max: 2021,
variables: [
{ name: "DP05_0077E", label: "Estimate!!HISPANIC OR LATINO AND RACE!!Total population!!Not Hispanic or Latino!!White alone", type: "num" },
{ name: "DP05_0070E", label: "Estimate!!HISPANIC OR LATINO AND RACE!!Total population", type: "denom" }
]
}
]
},
{
indicator: "Black alone (percent)", table: "ACS DEMOGRAPHIC AND HOUSING ESTIMATES", source: 'acs/acs5/profile', category: "race_vars",
time_period: [
{
min: 2010,
max: 2016,
variables: [
{ name: "DP05_0073E", label: "Estimate!!HISPANIC OR LATINO AND RACE!!Total population!!Not Hispanic or Latino!!Black or African American alone", type: "num" },
{ name: "DP05_0065E", label: "Estimate!!HISPANIC OR LATINO AND RACE!!Total population", type: "denom" }
]
},
{
min: 2017,
max: 2021,
variables: [
{ name: "DP05_0078E", label: "Estimate!!HISPANIC OR LATINO AND RACE!!Total population!!Not Hispanic or Latino!!Black or African American alone", type: "num" },
{ name: "DP05_0070E", label: "Estimate!!HISPANIC OR LATINO AND RACE!!Total population", type: "denom" }
]
}
]
},
{
indicator: "Asian alone (percent)", table: "ACS DEMOGRAPHIC AND HOUSING ESTIMATES", source: 'acs/acs5/profile', category: "race_vars",
time_period: [
{
min: 2010,
max: 2016,
variables: [
{ name: "DP05_0075E", label: "Estimate!!HISPANIC OR LATINO AND RACE!!Total population!!Not Hispanic or Latino!!Asian alone", type: "num" },
{ name: "DP05_0065E", label: "Estimate!!HISPANIC OR LATINO AND RACE!!Total population", type: "denom" }
]
},
{
min: 2017,
max: 2021,
variables: [
{ name: "DP05_0080E", label: "Estimate!!HISPANIC OR LATINO AND RACE!!Total population!!Not Hispanic or Latino!!Asian alone", type: "num" },
{ name: "DP05_0070E", label: "Estimate!!HISPANIC OR LATINO AND RACE!!Total population", type: "denom" }
]
}
]
},
{
indicator: "Non-white (percent)", table: "ACS DEMOGRAPHIC AND HOUSING ESTIMATES", source: 'acs/acs5/profile', category: "race_vars",
time_period: [
{
min: 2010,
max: 2016,
variables: [
{ name: "DP05_0072E", label: "Estimate!!HISPANIC OR LATINO AND RACE!!Total population!!Not Hispanic or Latino!!White alone", type: "num" },
{ name: "DP05_0065E", label: "Estimate!!HISPANIC OR LATINO AND RACE!!Total population", type: "denom" }
]
},
{
min: 2017,
max: 2021,
variables: [
{ name: "DP05_0077E", label: "Estimate!!HISPANIC OR LATINO AND RACE!!Total population!!Not Hispanic or Latino!!White alone", type: "num" },
{ name: "DP05_0070E", label: "Estimate!!HISPANIC OR LATINO AND RACE!!Total population", type: "denom" }
]
}
]
},
{
indicator: "Total population (race)", table: "TOTAL POPULATION", source: 'acs/acs5', category: "race_vars",
time_period: [
{
min: 2010,
max: 2021,
variables: [
{ name: "B01003_001E", label: "Estimate!!Total", type: "num" }
]
}
]
}
];
//---------------------------------------------------------------------------//
// setting up UI
//---------------------------------------------------------------------------//
// populate indicator dropdown
var options = $("#ind_options");
$.each(census_param, function (i, d) {
options.append($("<option />").val(i).text(d.indicator));
});
//===========================================================================//
// helper functions
//===========================================================================//
//---------------------------------------------------------------------------//
// fetch with timeout
//---------------------------------------------------------------------------//
// from https://dmitripavlutin.com/timeout-fetch-request/
async function fetchWithTimeout(resource, options = {}) {
const { timeout = 8000 } = options;
const controller = new AbortController();
const id = setTimeout(() => controller.abort(), timeout);
const response = await fetch(resource, {
...options,
signal: controller.signal
});
clearTimeout(id);
return response;
}
// fetch with timeout and retries
var fetch_rt = fetchRetry(fetchWithTimeout);
//---------------------------------------------------------------------------//
// turn HTML table into JS table
//---------------------------------------------------------------------------//
// taken from https://gist.github.com/mattheo-gist/4151867
function tableToObj(table) {
var rows = table.rows;
var propCells = rows[0].cells;
var propNames = [];
var results = [];
var obj, row, cells;
// Use the first row for the property names
// Could use a header section but result is the same if
// there is only one header row
for (var i=0, iLen=propCells.length; i<iLen; i++) {
propNames.push(propCells[i].textContent || propCells[i].innerText);
}
// Use the rows for data
// Could use tbody rows here to exclude header & footer
// but starting from 1 gives required result
for (var j=1, jLen=rows.length; j<jLen; j++) {
cells = rows[j].cells;
obj = {};
for (var k=0; k<iLen; k++) {
obj[propNames[k]] = cells[k].textContent || cells[k].innerText;
}
results.push(obj)
}
return results;
}
//---------------------------------------------------------------------------//
// make Arquero table
//---------------------------------------------------------------------------//
// turn html table into array, convert to Arquero, sort, then replace table element
function make_arq_table() {
GeoType_order =
aq.table({
GeoType: [
"Citywide",
"Borough",
"Subboro",
"UHF42",
"CD",
"NTA2010",
"NTA2020"
],
GeoType_order: [
1, 2, 3, 4, 5, 6, 7
]
})
datatableCsv = document.getElementById("datatableCsv");
table_obj = tableToObj(datatableCsv);
arq_table = aq.from(table_obj);
console.log("arq_table");
arq_table.print()
arq_table =
arq_table
.join_left(GeoType_order, "GeoType")
.orderby(
"IndicatorName",
"TimePeriod",
"GeoType_order",
"GeoEntity",
"MeasureType"
)
.select(aq.not("GeoType_order"))
// easy way to center all columns in "toHTML"
var colnames_arr = Array.from(arq_table.columnNames(), name => [name, "c"]);
var colnames_obj = Object.fromEntries(colnames_arr);
document.getElementById('datatableCsv').innerHTML = arq_table.toHTML({limit: Infinity, align: colnames_obj, style: {table: "font-weight: normal;"}}); // print dataTable to HTML
}
//---------------------------------------------------------------------------//
// array of number-only indicators
//---------------------------------------------------------------------------//
let num_only = [
"Total population",
"Poverty TOTAL",
"Housing Units",
"Household income"
]
//===========================================================================//
// main data functions
//===========================================================================//
//---------------------------------------------------------------------------//
// getdata (which calls hit_api with the correct indicator(s))
//---------------------------------------------------------------------------//
var datatableCsv;
var table_obj;
var arq_table;
function getdata(i_val, y_val) {
console.log("census_param[i_val]", census_param[i_val]);
// if this is the Race and ethnicity indicator, or the transportation indicator, loop through the constituent indicators
if (census_param[i_val].category === "race_vars") {
race_vars.forEach(indicator => hit_api(indicator, y_val));
}
else if (census_param[i_val].category === "transportation") {
transportation.forEach(indicator => hit_api(indicator, y_val));
}
else {
hit_api(census_param[i_val], y_val);
}
}
//---------------------------------------------------------------------------//
// hit_api (which constructs API calls from paramaters)
//---------------------------------------------------------------------------//
var nta_data_in_geo;
async function hit_api(this_ind, year) {
console.log("this_ind", this_ind);
// reset this value each time we hit the API
nta_data_in_geo = {};
// filter the time period by selected year to get the correct variables
var census_var = this_ind.time_period.filter(time => year >= time.min && year <= time.max)[0].variables;
var indicator = this_ind.indicator;
var category = this_ind.category;
// delete old table
$('#tab_loc').empty();
// create table and add header corresponding to EPHT Indicator Tool input fields
$('#tab_loc').append('<table id="datatableCsv">');
var row = $('<tr>');
var this_url = api_url + '/' + year + '/' + this_ind.source + '?';
row.append($('<th>').text('IndicatorName'));
row.append($('<th>').text('MeasureType'));
row.append($('<th>').text('GeoType'));
row.append($('<th>').text('GeoEntity'));
row.append($('<th>').text('TimePeriod'));
row.append($('<th>').text('DataValue'));
row.append($('<th>').text('UnreliabilityFlag'));
row.append($('<th>').text('ConfidenceInterval'));
$('#tab_loc table').append(row);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// constructing paths
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// ---- COUNTY PATH ---- //
var county = $.map(county2boro, function (n, i) { return n.county; });
var county_path = this_url + "key=" + my_key + "&get=";
for (i = 0; i < census_var.length; ++i) {
county_path += (i == (census_var.length - 1)) ? census_var[i].name : census_var[i].name + ",";
}
county_path += "&for=county:" + county.toString() + "&in=state:36";
// ---- ZCTA PATH ---- //
var zcta = $.map(zcta2UHF, function (n, i) { return n.ZCTA; });
var zcta_path = this_url + "key=" + my_key + "&get=";
for (i = 0; i < census_var.length; ++i) {
zcta_path += (i == (census_var.length - 1)) ? census_var[i].name : census_var[i].name + ",";
}
// starting in 2020, ZCTA doesn't need state - if you give state, it won't work
if (year <= 2019) {
zcta_path += "&for=zip+code+tabulation+area:" + zcta.toString() + "&in=state:36";
} else {
zcta_path += "&for=zip+code+tabulation+area:" + zcta.toString();
}
// ---- PUMA PATH ---- //
var puma = $.map(puma2subboro, function (n, i) { return n.PUMA; });
var puma_path = this_url + "key=" + my_key + "&get=";
for (i = 0; i < census_var.length; ++i) {
puma_path += (i == (census_var.length - 1)) ? census_var[i].name : census_var[i].name + ",";
}
puma_path += "&for=public+use+microdata+area:" + puma.toString() + "&in=state:36";
// ---- PUMA CD ---- //
var pumacd = $.map(puma2subboro, function (n, i) { return n.PUMA; });
var puma_path_cd = this_url + "key=" + my_key + "&get=";
for (i = 0; i < census_var.length; ++i) {
puma_path_cd += (i == (census_var.length - 1)) ? census_var[i].name : census_var[i].name + ",";
}
puma_path_cd += "&for=public+use+microdata+area:" + pumacd.toString() + "&in=state:36";
// switching apths depneding on year, to get NTA 2020
if (year < 2020) {
// ---- BX ---- //
var nta2010BX = $.map(tractToNTA2010BX, function (n, i) { return n.TRACT; });
var nta_pathBX = this_url + "key=" + my_key + "&get=";
for (i = 0; i < census_var.length; ++i) {
nta_pathBX += (i == (census_var.length - 1)) ? census_var[i].name : census_var[i].name + ",";
}
nta_pathBX += "&for=tract:" + nta2010BX.toString() + "&in=state:36+county:005";
// ---- BK ---- //
var nta2010BK = $.map(tractToNTA2010BK, function (n, i) { return n.TRACT; });
var nta_pathBK = this_url + "key=" + my_key + "&get=";
for (i = 0; i < census_var.length; ++i) {
nta_pathBK += (i == (census_var.length - 1)) ? census_var[i].name : census_var[i].name + ",";
}
nta_pathBK += "&for=tract:" + nta2010BK.toString() + "&in=state:36+county:047";
// ---- MN ---- //
var nta2010MN = $.map(tractToNTA2010MN, function (n, i) { return n.TRACT; });
var nta_pathMN = this_url + "key=" + my_key + "&get=";
for (i = 0; i < census_var.length; ++i) {
nta_pathMN += (i == (census_var.length - 1)) ? census_var[i].name : census_var[i].name + ",";
}
nta_pathMN += "&for=tract:" + nta2010MN.toString() + "&in=state:36+county:061";
// ---- QN ---- //
var nta2010QN = $.map(tractToNTA2010QN, function (n, i) { return n.TRACT; });
var nta_pathQN = this_url + "key=" + my_key + "&get=";
for (i = 0; i < census_var.length; ++i) {
nta_pathQN += (i == (census_var.length - 1)) ? census_var[i].name : census_var[i].name + ",";
}
nta_pathQN += "&for=tract:" + nta2010QN.toString() + "&in=state:36+county:081";
// ---- SI ---- //
var nta2010SI = $.map(tractToNTA2010SI, function (n, i) { return n.TRACT; });
var nta_pathSI = this_url + "key=" + my_key + "&get=";
for (i = 0; i < census_var.length; ++i) {
nta_pathSI += (i == (census_var.length - 1)) ? census_var[i].name : census_var[i].name + ",";
}
nta_pathSI += "&for=tract:" + nta2010SI.toString() + "&in=state:36+county:085";
}
if (year >= 2020) {
// ---- BX ---- //
var nta2020BX = $.map(tractToNTA2020BX, function (n, i) { return n.TRACT; });
var nta_pathBX = this_url + "key=" + my_key + "&get=";
for (i = 0; i < census_var.length; ++i) {
nta_pathBX += (i == (census_var.length - 1)) ? census_var[i].name : census_var[i].name + ",";
}
nta_pathBX += "&for=tract:" + nta2020BX.toString() + "&in=state:36+county:005";
// handling the part of the bronx that is actually in manhattan (or vise versa)
var nta_BX0802 = this_url + "key=" + my_key + "&get=";
for (i = 0; i < census_var.length; ++i) {
nta_BX0802 += (i == (census_var.length - 1)) ? census_var[i].name : census_var[i].name + ",";
}
nta_BX0802 += "&for=tract:030900&in=state:36+county:061";
// ---- BK ---- //
var nta2020BK = $.map(tractToNTA2020BK, function (n, i) { return n.TRACT; });
var nta_pathBK = this_url + "key=" + my_key + "&get=";
for (i = 0; i < census_var.length; ++i) {
nta_pathBK += (i == (census_var.length - 1)) ? census_var[i].name : census_var[i].name + ",";
}
nta_pathBK += "&for=tract:" + nta2020BK.toString() + "&in=state:36+county:047";
// ---- MN ---- //
var nta2020MN = $.map(tractToNTA2020MN, function (n, i) { return n.TRACT; });
var nta_pathMN = this_url + "key=" + my_key + "&get=";
for (i = 0; i < census_var.length; ++i) {
nta_pathMN += (i == (census_var.length - 1)) ? census_var[i].name : census_var[i].name + ",";
}
nta_pathMN += "&for=tract:" + nta2020MN.toString() + "&in=state:36+county:061";
// ---- QN ---- //
var nta2020QN = $.map(tractToNTA2020QN, function (n, i) { return n.TRACT; });
var nta_pathQN = this_url + "key=" + my_key + "&get=";
for (i = 0; i < census_var.length; ++i) {
nta_pathQN += (i == (census_var.length - 1)) ? census_var[i].name : census_var[i].name + ",";
}
nta_pathQN += "&for=tract:" + nta2020QN.toString() + "&in=state:36+county:081";
// ---- SI ---- //
var nta2020SI = $.map(tractToNTA2020SI, function (n, i) { return n.TRACT; });
var nta_pathSI = this_url + "key=" + my_key + "&get=";
for (i = 0; i < census_var.length; ++i) {
nta_pathSI += (i == (census_var.length - 1)) ? census_var[i].name : census_var[i].name + ",";
}
nta_pathSI += "&for=tract:" + nta2020SI.toString() + "&in=state:36+county:085";
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// get and parse json
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// unnested so asynchronous; all requests happen in parrallel = much faster
// "make_arq_table" reconstructs the originally intended row order
// "await Promise.all" will pause execution of "hit_api" until all the downloading and parsing is complete, which
// allows for the whole table to be constructed before converting it into an array and then into an Arquero table