From e862eceb341d364c42b8cf2f7a37fdc4e179c16c Mon Sep 17 00:00:00 2001 From: tmont Date: Mon, 27 Apr 2020 20:02:31 -0700 Subject: [PATCH] population and growth rate --- data/SCPRC-EST2019-18+POP-RES.csv | 54 +++++++ data/population-world-wikipedia.tsv | 234 ++++++++++++++++++++++++++++ generate.js | 147 ++++++++++++++++- tmpl/country.pug | 22 ++- tmpl/master.pug | 13 +- tmpl/state.pug | 18 ++- tmpl/world.pug | 24 ++- 7 files changed, 494 insertions(+), 18 deletions(-) create mode 100644 data/SCPRC-EST2019-18+POP-RES.csv create mode 100644 data/population-world-wikipedia.tsv diff --git a/data/SCPRC-EST2019-18+POP-RES.csv b/data/SCPRC-EST2019-18+POP-RES.csv new file mode 100644 index 0000000..b1c16f3 --- /dev/null +++ b/data/SCPRC-EST2019-18+POP-RES.csv @@ -0,0 +1,54 @@ +SUMLEV,REGION,DIVISION,STATE,NAME,POPESTIMATE2019,POPEST18PLUS2019,PCNT_POPEST18PLUS +010,0,0,00,United States,328239523,255200373,77.7 +040,3,6,01,Alabama,4903185,3814879,77.8 +040,4,9,02,Alaska,731545,551562,75.4 +040,4,8,04,Arizona,7278717,5638481,77.5 +040,3,7,05,Arkansas,3017804,2317649,76.8 +040,4,9,06,California,39512223,30617582,77.5 +040,4,8,08,Colorado,5758736,4499217,78.1 +040,1,1,09,Connecticut,3565287,2837847,79.6 +040,3,5,10,Delaware,973764,770192,79.1 +040,3,5,11,District of Columbia,705749,577581,81.8 +040,3,5,12,Florida,21477737,17247808,80.3 +040,3,5,13,Georgia,10617423,8113542,76.4 +040,4,9,15,Hawaii,1415872,1116004,78.8 +040,4,8,16,Idaho,1787065,1338864,74.9 +040,2,3,17,Illinois,12671821,9853946,77.8 +040,2,3,18,Indiana,6732219,5164245,76.7 +040,2,4,19,Iowa,3155070,2428229,77 +040,2,4,20,Kansas,2913314,2213064,76 +040,3,6,21,Kentucky,4467673,3464802,77.6 +040,3,7,22,Louisiana,4648794,3561164,76.6 +040,1,1,23,Maine,1344212,1095370,81.5 +040,3,5,24,Maryland,6045680,4710993,77.9 +040,1,1,25,Massachusetts,6892503,5539703,80.4 +040,2,3,26,Michigan,9986857,7842924,78.5 +040,2,4,27,Minnesota,5639632,4336475,76.9 +040,3,6,28,Mississippi,2976149,2277566,76.5 +040,2,4,29,Missouri,6137428,4766843,77.7 +040,4,8,30,Montana,1068778,840190,78.6 +040,2,4,31,Nebraska,1934408,1458334,75.4 +040,4,8,32,Nevada,3080156,2387517,77.5 +040,1,1,33,New Hampshire,1359711,1104458,81.2 +040,1,2,34,New Jersey,8882190,6943612,78.2 +040,4,8,35,New Mexico,2096829,1620991,77.3 +040,1,2,36,New York,19453561,15425262,79.3 +040,3,5,37,North Carolina,10488084,8187369,78.1 +040,2,4,38,North Dakota,762062,581891,76.4 +040,2,3,39,Ohio,11689100,9111081,77.9 +040,3,7,40,Oklahoma,3956971,3004733,75.9 +040,4,9,41,Oregon,4217737,3351175,79.5 +040,1,2,42,Pennsylvania,12801989,10167376,79.4 +040,1,1,44,Rhode Island,1059361,854866,80.7 +040,3,5,45,South Carolina,5148714,4037531,78.4 +040,2,4,46,South Dakota,884659,667558,75.5 +040,3,6,47,Tennessee,6829174,5319123,77.9 +040,3,7,48,Texas,28995881,21596071,74.5 +040,4,8,49,Utah,3205958,2274774,71 +040,1,1,50,Vermont,623989,509984,81.7 +040,3,5,51,Virginia,8535519,6674671,78.2 +040,4,9,53,Washington,7614893,5951832,78.2 +040,3,5,54,West Virginia,1792147,1432580,79.9 +040,2,3,55,Wisconsin,5822434,4555837,78.2 +040,4,8,56,Wyoming,578759,445025,76.9 +040,X,X,72,Puerto Rico Commonwealth,3193694,2620963,82.1 diff --git a/data/population-world-wikipedia.tsv b/data/population-world-wikipedia.tsv new file mode 100644 index 0000000..125d85b --- /dev/null +++ b/data/population-world-wikipedia.tsv @@ -0,0 +1,234 @@ +Country Continent Region Pop_2018 Pop_2019 Change + China Asia Eastern Asia 1,427,647,786 1,433,783,686 +0.43% + India Asia Southern Asia 1,352,642,280 1,366,417,754 +1.02% + United States Americas Northern America 327,096,265 329,064,917 +0.60% + Indonesia Asia South-eastern Asia 267,670,543 270,625,568 +1.10% + Pakistan Asia Southern Asia 212,228,286 216,565,318 +2.04% + Brazil Americas South America 209,469,323 211,049,527 +0.75% + Nigeria Africa Western Africa 195,874,683 200,963,599 +2.60% + Bangladesh Asia Southern Asia 161,376,708 163,046,161 +1.03% + Russia Europe Eastern Europe 145,734,038 145,872,256 +0.09% + Mexico Americas Central America 126,190,788 127,575,529 +1.10% + Japan Asia Eastern Asia 127,202,192 126,860,301 −0.27% + Ethiopia Africa Eastern Africa 109,224,414 112,078,730 +2.61% + Philippines Asia South-eastern Asia 106,651,394 108,116,615 +1.37% + Egypt Africa Northern Africa 98,423,598 100,388,073 +2.00% + Vietnam Asia South-eastern Asia 95,545,962 96,462,106 +0.96% + DR Congo Africa Middle Africa 84,068,091 86,790,567 +3.24% + Germany Europe Western Europe 83,124,418 83,517,045 +0.47% + Turkey Asia Western Asia 82,340,088 83,429,615 +1.32% + Iran Asia Southern Asia 81,800,188 82,913,906 +1.36% + Thailand Asia South-eastern Asia 68,863,514 69,037,513 +0.25% + United Kingdom Europe Northern Europe 67,141,684 67,530,172 +0.58% + France Europe Western Europe 64,990,511 65,129,728 +0.21% + Italy Europe Southern Europe 60,627,291 60,550,075 −0.13% + South Africa Africa Southern Africa 57,792,518 58,558,270 +1.33% + Tanzania Africa Eastern Africa 56,313,438 58,005,463 +3.00% + Myanmar Asia South-eastern Asia 53,708,320 54,045,420 +0.63% + Kenya Africa Eastern Africa 51,392,565 52,573,973 +2.30% + South Korea Asia Eastern Asia 51,171,706 51,225,308 +0.10% + Colombia Americas South America 49,661,048 50,339,443 +1.37% + Spain Europe Southern Europe 46,692,858 46,736,776 +0.09% + Argentina Americas South America 44,361,150 44,780,677 +0.95% + Uganda Africa Eastern Africa 42,729,036 44,269,594 +3.61% + Ukraine Europe Eastern Europe 44,246,156 43,993,638 −0.57% + Algeria Africa Northern Africa 42,228,408 43,053,054 +1.95% + Sudan Africa Northern Africa 41,801,533 42,813,238 +2.42% + Iraq Asia Western Asia 38,433,600 39,309,783 +2.28% + Afghanistan Asia Southern Asia 37,171,921 38,041,754 +2.34% + Poland Europe Eastern Europe 37,921,592 37,887,768 −0.09% + Canada Americas Northern America 37,074,562 37,411,047 +0.91% + Morocco Africa Northern Africa 36,029,093 36,471,769 +1.23% + Saudi Arabia Asia Western Asia 33,702,756 34,268,528 +1.68% + Uzbekistan Asia Central Asia 32,476,244 32,981,716 +1.56% + Peru Americas South America 31,989,260 32,510,453 +1.63% + Malaysia Asia South-eastern Asia 31,528,033 31,949,777 +1.34% + Angola Africa Middle Africa 30,809,787 31,825,295 +3.30% + Mozambique Africa Eastern Africa 29,496,004 30,366,036 +2.95% + Yemen Asia Western Asia 28,498,683 29,161,922 +2.33% + Ghana Africa Western Africa 28,206,728 28,833,629 +2.22% + Nepal Asia Southern Asia 28,095,714 28,608,710 +1.83% + Venezuela Americas South America 28,887,118 28,515,829 −1.29% + Madagascar Africa Eastern Africa 26,262,313 26,969,307 +2.69% + North Korea Asia Eastern Asia 25,549,604 25,666,161 +0.46% + Ivory Coast Africa Western Africa 25,069,230 25,716,544 +2.58% + Cameroon Africa Middle Africa 25,216,267 25,876,380 +2.62% + Australia Oceania Australia and New Zealand 24,898,152 25,203,198 +1.23% + Taiwan Asia Eastern Asia 23,726,460 23,773,876 +0.20% + Niger Africa Western Africa 22,442,822 23,310,715 +3.87% + Sri Lanka Asia Southern Asia 21,228,763 21,323,733 +0.45% + Burkina Faso Africa Western Africa 19,751,466 20,321,378 +2.89% + Mali Africa Western Africa 19,077,749 19,658,031 +3.04% + Romania Europe Eastern Europe 19,506,114 19,364,557 −0.73% + Malawi Africa Eastern Africa 18,143,217 18,628,747 +2.68% + Chile Americas South America 18,729,160 18,952,038 +1.19% + Kazakhstan Asia Central Asia 18,319,618 18,551,427 +1.27% + Zambia Africa Eastern Africa 17,351,708 17,861,030 +2.94% + Guatemala Americas Central America 17,247,849 17,581,472 +1.93% + Ecuador Americas South America 17,084,358 17,373,662 +1.69% + Netherlands Europe Western Europe 17,059,560 17,097,130 +0.22% + Syria Asia Western Asia 16,945,057 17,070,135 +0.74% + Cambodia Asia South-eastern Asia 16,249,792 16,486,542 +1.46% + Senegal Africa Western Africa 15,854,323 16,296,364 +2.79% + Chad Africa Middle Africa 15,477,729 15,946,876 +3.03% + Somalia Africa Eastern Africa 15,008,226 15,442,905 +2.90% + Zimbabwe Africa Eastern Africa 14,438,802 14,645,468 +1.43% + Guinea Africa Western Africa 12,414,293 12,771,246 +2.88% + Rwanda Africa Eastern Africa 12,301,970 12,626,950 +2.64% + Benin Africa Western Africa 11,485,044 11,801,151 +2.75% + Tunisia Africa Northern Africa 11,565,201 11,694,719 +1.12% + Belgium Europe Western Europe 11,482,178 11,539,328 +0.50% + Bolivia Americas South America 11,353,142 11,513,100 +1.41% + Cuba Americas Caribbean 11,338,134 11,333,483 −0.04% + Haiti Americas Caribbean 11,123,178 11,263,770 +1.26% + South Sudan Africa Eastern Africa 10,975,927 11,062,113 +0.79% + Burundi Africa Eastern Africa 10,524,117 10,864,245 +3.23% + Dominican Republic Americas Caribbean 10,627,141 10,738,958 +1.05% + Czech Republic Europe Eastern Europe 10,665,677 10,689,209 +0.22% + Greece Europe Southern Europe 10,522,246 10,473,455 −0.46% + Portugal Europe Southern Europe 10,256,193 10,226,187 −0.29% + Jordan Asia Western Asia 9,965,318 10,101,694 +1.37% + Azerbaijan Asia Western Asia 9,949,537 10,047,718 +0.99% + Sweden Europe Northern Europe 9,971,638 10,036,379 +0.65% + United Arab Emirates Asia Western Asia 9,630,959 9,770,529 +1.45% + Honduras Americas Central America 9,587,522 9,746,117 +1.65% + Hungary Europe Eastern Europe 9,707,499 9,684,679 −0.24% + Belarus Europe Eastern Europe 9,452,617 9,452,411 0.00% + Tajikistan Asia Central Asia 9,100,835 9,321,018 +2.42% + Austria Europe Western Europe 8,891,388 8,955,102 +0.72% + Papua New Guinea Oceania Melanesia 8,606,323 8,776,109 +1.97% + Serbia Europe Southern Europe 8,802,754 8,772,235 −0.35% + Switzerland Europe Western Europe 8,525,611 8,591,365 +0.77% + Israel Asia Western Asia 8,381,516 8,519,377 +1.64% + Togo Africa Western Africa 7,889,093 8,082,366 +2.45% + Sierra Leone Africa Western Africa 7,650,150 7,813,215 +2.13% + Hong Kong Asia Eastern Asia 7,371,730 7,436,154 +0.87% + Laos Asia South-eastern Asia 7,061,507 7,169,455 +1.53% + Paraguay Americas South America 6,956,066 7,044,636 +1.27% + Bulgaria Europe Eastern Europe 7,051,608 7,000,119 −0.73% + Lebanon Asia Western Asia 6,859,408 6,855,713 −0.05% + Libya Africa Northern Africa 6,678,559 6,777,452 +1.48% + Nicaragua Americas Central America 6,465,501 6,545,502 +1.24% + El Salvador Americas Central America 6,420,746 6,453,553 +0.51% + Kyrgyzstan Asia Central Asia 6,304,030 6,415,850 +1.77% + Turkmenistan Asia Central Asia 5,850,901 5,942,089 +1.56% + Singapore Asia South-eastern Asia 5,757,499 5,804,337 +0.81% + Denmark Europe Northern Europe 5,752,126 5,771,876 +0.34% + Finland Europe Northern Europe 5,522,576 5,532,156 +0.17% + Slovakia Europe Eastern Europe 5,453,014 5,457,013 +0.07% + Congo Africa Middle Africa 5,244,359 5,380,508 +2.60% + Norway Europe Northern Europe 5,337,962 5,378,857 +0.77% + Costa Rica Americas Central America 4,999,441 5,047,561 +0.96% + Palestine Asia Western Asia 4,862,979 4,981,420 +2.44% + Oman Asia Western Asia 4,829,473 4,974,986 +3.01% + Liberia Africa Western Africa 4,818,973 4,937,374 +2.46% + Ireland Europe Northern Europe 4,818,690 4,882,495 +1.32% + New Zealand Oceania Australia and New Zealand 4,743,131 4,783,063 +0.84% + Central African Republic Africa Middle Africa 4,666,368 4,745,185 +1.69% + Mauritania Africa Western Africa 4,403,313 4,525,696 +2.78% + Panama Americas Central America 4,176,869 4,246,439 +1.67% + Kuwait Asia Western Asia 4,137,312 4,207,083 +1.69% + Croatia Europe Southern Europe 4,156,405 4,130,304 −0.63% + Moldova Europe Eastern Europe 4,051,944 4,043,263 −0.21% + Georgia Asia Western Asia 4,002,942 3,996,765 −0.15% + Eritrea Africa Eastern Africa 3,452,786 3,497,117 +1.28% + Uruguay Americas South America 3,449,285 3,461,734 +0.36% + Bosnia and Herzegovina Europe Southern Europe 3,323,925 3,301,000 −0.69% + Mongolia Asia Eastern Asia 3,170,216 3,225,167 +1.73% + Armenia Asia Western Asia 2,951,745 2,957,731 +0.20% + Jamaica Americas Caribbean 2,934,847 2,948,279 +0.46% + Puerto Rico Americas Caribbean 3,039,596 2,933,408 −3.49% + Albania Europe Southern Europe 2,882,740 2,880,917 −0.06% + Qatar Asia Western Asia 2,781,682 2,832,067 +1.81% + Lithuania Europe Northern Europe 2,801,264 2,759,627 −1.49% + Namibia Africa Southern Africa 2,448,301 2,494,530 +1.89% + Gambia Africa Western Africa 2,280,094 2,347,706 +2.97% + Botswana Africa Southern Africa 2,254,068 2,303,697 +2.20% + Gabon Africa Middle Africa 2,119,275 2,172,579 +2.52% + Lesotho Africa Southern Africa 2,108,328 2,125,268 +0.80% + North Macedonia Europe Southern Europe 2,082,957 2,083,459 +0.02% + Slovenia Europe Southern Europe 2,077,837 2,078,654 +0.04% + Guinea-Bissau Africa Western Africa 1,874,303 1,920,922 +2.49% + Latvia Europe Northern Europe 1,928,459 1,906,743 −1.13% + Bahrain Asia Western Asia 1,569,446 1,641,172 +4.57% + Trinidad and Tobago Americas Caribbean 1,389,843 1,394,973 +0.37% + Equatorial Guinea Africa Middle Africa 1,308,975 1,355,986 +3.59% + Estonia Europe Northern Europe 1,322,920 1,325,648 +0.21% + East Timor Asia South-eastern Asia 1,267,974 1,293,119 +1.98% + Mauritius Africa Eastern Africa 1,189,265 1,198,575 +0.78% + Cyprus Asia Western Asia 1,170,125 1,179,551 +0.81% + Eswatini Africa Southern Africa 1,136,281 1,148,130 +1.04% + Djibouti Africa Eastern Africa 958,923 973,560 +1.53% + Fiji Oceania Melanesia 883,483 889,953 +0.73% + Réunion Africa Eastern Africa 882,526 888,927 +0.73% + Comoros Africa Eastern Africa 832,322 850,886 +2.23% + Guyana Americas South America 779,006 782,766 +0.48% + Bhutan Asia Southern Asia 754,388 763,092 +1.15% + Solomon Islands Oceania Melanesia 652,857 669,823 +2.60% + Macau Asia Eastern Asia 631,636 640,445 +1.39% + Montenegro Europe Southern Europe 627,809 627,987 +0.03% + Luxembourg Europe Western Europe 604,245 615,729 +1.90% + Western Sahara Africa Northern Africa 567,402 582,463 +2.65% + Suriname Americas South America 575,990 581,372 +0.93% + Cape Verde Africa Western Africa 543,767 549,935 +1.13% + Maldives Asia Southern Asia 515,696 530,953 +2.96% + Guadeloupe Americas Caribbean 446,928 447,905 +0.22% + Malta Europe Southern Europe 439,248 440,372 +0.26% + Brunei Asia South-eastern Asia 428,963 433,285 +1.01% + Belize Americas Central America 383,071 390,353 +1.90% + Bahamas Americas Caribbean 385,637 389,482 +1.00% + Martinique Americas Caribbean 375,673 375,554 −0.03% + Iceland Europe Northern Europe 336,713 339,031 +0.69% + Vanuatu Oceania Melanesia 292,680 299,882 +2.46% + Barbados Americas Caribbean 286,641 287,025 +0.13% + New Caledonia Oceania Melanesia 279,993 282,750 +0.98% + French Guiana Americas South America 275,713 282,731 +2.55% + French Polynesia Oceania Polynesia 277,679 279,287 +0.58% + Mayotte Africa Eastern Africa 259,531 266,150 +2.55% + São Tomé and Príncipe Africa Middle Africa 211,028 215,056 +1.91% + Samoa Oceania Polynesia 196,129 197,097 +0.49% + Saint Lucia Americas Caribbean 181,889 182,790 +0.50% + Guernsey and Jersey Europe Northern Europe 170,499 172,259 +1.03% + Guam Oceania Micronesia 165,768 167,294 +0.92% + Curaçao Americas Caribbean 162,752 163,424 +0.41% + Kiribati Oceania Micronesia 115,847 117,606 +1.52% + F.S. Micronesia Oceania Micronesia 112,640 113,815 +1.04% + Grenada Americas Caribbean 111,454 112,003 +0.49% + Tonga Oceania Polynesia 110,589 110,940 +0.32% + Saint Vincent and the Grenadines Americas Caribbean 110,211 110,589 +0.34% + Aruba Americas Caribbean 105,845 106,314 +0.44% + U.S. Virgin Islands Americas Caribbean 104,680 104,578 −0.10% + Seychelles Africa Eastern Africa 97,096 97,739 +0.66% + Antigua and Barbuda Americas Caribbean 96,286 97,118 +0.86% + Isle of Man Europe Northern Europe 84,077 84,584 +0.60% + Andorra Europe Southern Europe 77,006 77,142 +0.18% + Dominica Americas Caribbean 71,625 71,808 +0.26% + Cayman Islands Americas Caribbean 64,174 64,948 +1.21% + Bermuda Americas Northern America 62,756 62,506 −0.40% + Marshall Islands Oceania Micronesia 58,413 58,791 +0.65% + Greenland Americas Northern America 56,564 56,672 +0.19% + Northern Mariana Islands Oceania Micronesia 56,882 56,188 −1.22% + American Samoa Oceania Polynesia 55,465 55,312 −0.28% + Saint Kitts and Nevis Americas Caribbean 52,441 52,823 +0.73% + Faroe Islands Europe Northern Europe 48,497 48,678 +0.37% + Sint Maarten Americas Caribbean 41,940 42,388 +1.07% + Monaco Europe Western Europe 38,682 38,964 +0.73% + Turks and Caicos Islands Americas Caribbean 37,665 38,191 +1.40% + Liechtenstein Europe Western Europe 37,910 38,019 +0.29% + San Marino Europe Southern Europe 33,785 33,860 +0.22% + Gibraltar Europe Southern Europe 33,718 33,701 −0.05% + British Virgin Islands Americas Caribbean 29,802 30,030 +0.77% + Caribbean Netherlands Americas Caribbean 25,711 25,979 +1.04% + Palau Oceania Micronesia 17,907 18,008 +0.56% + Cook Islands Oceania Polynesia 17,518 17,548 +0.17% + Anguilla Americas Caribbean 14,731 14,869 +0.94% + Tuvalu Oceania Polynesia 11,508 11,646 +1.20% + Wallis and Futuna Oceania Polynesia 11,661 11,432 −1.96% + Nauru Oceania Micronesia 10,670 10,756 +0.81% + Saint Helena, Ascension and Tristan da Cunha Africa Western Africa 6,035 6,059 +0.40% + Saint Pierre and Miquelon Americas Northern America 5,849 5,822 −0.46% + Montserrat Americas Caribbean 4,993 4,989 −0.08% + Falkland Islands Americas South America 3,234 3,377 +4.42% + Niue Oceania Polynesia 1,620 1,615 −0.31% + Tokelau Oceania Polynesia 1,319 1,340 +1.59% + Vatican City Europe Southern Europe 801 799 −0.25% diff --git a/generate.js b/generate.js index 045f315..0f50c33 100755 --- a/generate.js +++ b/generate.js @@ -7,8 +7,9 @@ const pug = require('pug'); const publicDir = path.join(__dirname, 'public'); const templatesDir = path.join(__dirname, 'tmpl'); -const dataDir = path.resolve(path.join(__dirname, '..', 'COVID-19', 'csse_covid_19_data')); -const timeSeriesDir = path.join(dataDir, 'csse_covid_19_time_series'); +const dataDir = path.join(__dirname, 'data'); +const covidDataDir = path.resolve(path.join(__dirname, '..', 'COVID-19', 'csse_covid_19_data')); +const timeSeriesDir = path.join(covidDataDir, 'csse_covid_19_time_series'); const promiseMe = (fn) => { return new Promise((resolve, reject) => { @@ -41,6 +42,8 @@ const deathsGlobalCsv = path.join(timeSeriesDir, 'time_series_covid19_deaths_glo const confirmedGlobalCsv = path.join(timeSeriesDir, 'time_series_covid19_confirmed_global.csv'); const deathsUSCsv = path.join(timeSeriesDir, 'time_series_covid19_deaths_US.csv'); const confirmedUSCsv = path.join(timeSeriesDir, 'time_series_covid19_confirmed_US.csv'); +const populationStatesCsv = path.join(dataDir, 'SCPRC-EST2019-18+POP-RES.csv'); +const populationCountriesCsv = path.join(dataDir, 'population-world-wikipedia.tsv'); const zeroPad = value => value < 10 ? `0${value}` : value.toString(); const toSafeName = x => x.replace(/[^A-Za-z]/g, '-').toLowerCase(); @@ -56,6 +59,14 @@ const processGlobalDeaths = async () => { const timeSeriesUSRaw = fs.readFileSync(deathsUSCsv, { encoding: 'utf8' }); console.log(`read US deaths CSV in ${Date.now() - start}ms`); + start = Date.now(); + const populationUSRaw = fs.readFileSync(populationStatesCsv, {encoding: 'utf8'}); + console.log(`read US states population CSV in ${Date.now() - start}ms`); + + start = Date.now(); + const populationCountriesRaw = fs.readFileSync(populationCountriesCsv, {encoding: 'utf8'}); + console.log(`read countries population CSV in ${Date.now() - start}ms`); + start = Date.now(); let tsGlobalRecords = parseCsv(timeSeriesGlobalRaw, { cast: true, @@ -70,10 +81,82 @@ const processGlobalDeaths = async () => { }); console.log(`parsed US deaths CSV in ${Date.now() - start}ms`); + start = Date.now(); + let populationUSStateRecords = parseCsv(populationUSRaw, { + cast: true, + columns: true, + }); + console.log(`parsed US states population CSV in ${Date.now() - start}ms`); + + start = Date.now(); + let populationCountriesRecords = parseCsv(populationCountriesRaw, { + cast: true, + columns: true, + delimiter: '\t', + ltrim: true, + rtrim: true, + }); + console.log(`parsed countries population CSV in ${Date.now() - start}ms`); + + const statePopulationMap = populationUSStateRecords + .sort((a, b) => a.NAME.localeCompare(b.NAME)) + .reduce((map, item) => { + map[item.NAME] = Number(item.POPESTIMATE2019); + return map; + }, {}); + + const countryNameMap = { + 'Cape Verde': 'Cabo Verde', + 'DR Congo': 'Congo (Brazzaville)', + 'Congo': 'Congo (Kinshasa)', + 'Ivory Coast': 'Cote d\'Ivoire', + 'Czech Republic': 'Czechia', + 'Vatican City': 'Holy See', + 'South Korea': 'Korea, South', + 'Taiwan': 'Taiwan*', + 'East Timor': 'Timor-Leste', + 'Palestine': 'West Bank and Gaza', + 'Myanmar': 'Burma', + 'São Tomé and Príncipe': 'Sao Tome and Principe', + }; + + const countryPopulationMap = populationCountriesRecords + .sort((a, b) => a.Country.localeCompare(b.Country)) + .reduce((map, item) => { + map[item.Country] = Number(item.Pop_2019.toString().replace(/,/g, '')); + const otherName = countryNameMap[item.Country]; + if (otherName) { + map[otherName] = map[item.Country]; + } + return map; + }, {}); + + countryPopulationMap['Diamond Princess'] = statePopulationMap['Diamond Princess'] = 3711; + countryPopulationMap['MS Zaandam'] = 1829; + countryPopulationMap['Kosovo'] = 1810463; + statePopulationMap['Grand Princess'] = 3533; + // tsGlobalRecords = tsGlobalRecords.filter((record) => { - // return record['Country/Region'] === 'Spain'; + // return record['Country/Region'] === 'US'; // }); + const getGrowthRate = (record) => { + const ts = record.timeSeriesDaily; + const len = ts.length; + if (len < 2) { + return 0; + } + const latest = len - 1; + const earliest = Math.max(len - 14, 0); + const pow = 1/(latest - earliest + 1); + const hi = ts[latest].value; + const lo = Math.max(ts[earliest].value, 0.5); + if (hi === 0 && lo < 1) { + return 0; + } + return Math.pow((hi / lo), pow) - 1; + }; + // state/county data is separated for the US and doesn't need to be rolled up tsUSRecords.forEach((usRecord) => { const newRecord = { @@ -191,6 +274,27 @@ const processGlobalDeaths = async () => { delete record.Long; delete record.Admin2; delete record.Population; + + if (!record.population && !record.state && !record.county) { + const mappedPop = countryPopulationMap[record.country]; + if (!mappedPop) { + console.log(require('util').inspect(countryPopulationMap, false, null, true)); + throw new Error('found no population for ' + record.country); + } + record.population = mappedPop; + } else if (!record.population && record.state && !record.county && record.country === 'United States') { + // US territories and cruise ships + const mappedPop = statePopulationMap[record.state]; + if (!mappedPop) { + console.log(require('util').inspect(statePopulationMap, false, null, true)); + throw new Error('found no population for ' + record.state); + } + // console.log(`setting population to ${mappedPop} for ${record.state}`); + record.population = mappedPop; + } + + record.deathsPerMillion = !!record.population ? record.total / record.population * 1000000 : 0; + record.deathGrowthRate = getGrowthRate(record); }); tsGlobalRecords.sort((a, b) => { @@ -206,6 +310,7 @@ const processGlobalDeaths = async () => { tsGlobalRecords.forEach((record) => { perCountryTotals[record.country] = perCountryTotals[record.country] || { total: 0, + population: 0, timeSeriesDaily: {}, timeSeriesMonthly: {}, states: [], @@ -213,6 +318,10 @@ const processGlobalDeaths = async () => { }; const item = perCountryTotals[record.country]; + if (!record.state && !record.county) { + // country population + item.population = record.population; + } // roll up up state/county data if (record.state && record.county) { @@ -222,11 +331,23 @@ const processGlobalDeaths = async () => { country: record.country, countrySafeName: record.countrySafeName, total: 0, + population: 0, + deathsPerMillion: 0, timeSeriesDaily: {}, timeSeriesMonthly: {}, counties: [], }; + if (!stateItem.population && record.country === 'United States') { + const population = statePopulationMap[record.state]; + if (!population) { + console.log(require('util').inspect(statePopulationMap, false, null, true)); + throw new Error('no population for ' + record.state); + } + + stateItem.population = population; + } + stateItem.total += record.total; record.timeSeriesDaily.forEach((ts) => { stateItem.timeSeriesDaily[ts.key] = stateItem.timeSeriesDaily[ts.key] || { @@ -284,6 +405,8 @@ const processGlobalDeaths = async () => { countrySafeName: item.countrySafeName, total: item.total, counties: item.counties, + population: item.population, + deathsPerMillion: item.population > 0 ? item.total / item.population * 1000000 : 0, timeSeriesDaily: Object.keys(item.timeSeriesDaily).sort().map((date) => { return { key: date, @@ -300,17 +423,28 @@ const processGlobalDeaths = async () => { }), }; + stateItem.deathGrowthRate = getGrowthRate(stateItem); + // insert into states array for the country perCountryTotals[item.country].states.push(stateItem); }); const countryArr = Object.keys(perCountryTotals).map((countryName) => { const item = perCountryTotals[countryName]; - return { + if (!item.population) { + // some countries don't have roll up (e.g. Canada, China, Australia) + // and only contain province data instead of data for the whole country. + // population doesn't get set in those cases. + item.population = countryPopulationMap[countryName]; + } + + const countryItem = { name: countryName, safeName: item.safeName, total: item.total, states: item.states, + population: item.population, + deathsPerMillion: item.population > 0 ? item.total / item.population * 1000000 : 0, timeSeriesDaily: Object.keys(item.timeSeriesDaily).sort().map((date) => { return { key: date, @@ -326,6 +460,9 @@ const processGlobalDeaths = async () => { }; }), }; + + countryItem.deathGrowthRate = getGrowthRate(countryItem); + return countryItem; }); const worldData = { @@ -374,6 +511,8 @@ const processGlobalDeaths = async () => { }; }); + worldData.deathGrowthRate = getGrowthRate(worldData); + console.log(`transformed data in ${Date.now() - start}ms`); start = Date.now(); diff --git a/tmpl/country.pug b/tmpl/country.pug index b736149..f67e2be 100644 --- a/tmpl/country.pug +++ b/tmpl/country.pug @@ -11,10 +11,15 @@ block main thead: tr th # th(data-col="name"): +sortableLinks("name") State/Province + if data.name === 'United States' + th.text-center(data-col="population"): +sortableLinks("population") Population th.text-center(data-col="total"): +sortableLinks("total") Deaths + if data.name === 'United States' + th.text-center(data-col="million"): +sortableLinks("million") …/1M th.text-center.sorted(data-col="yesterday"): +sortableLinks("yesterday") …since yesterday th.text-center(data-col="week"): +sortableLinks("week") …since last week th.text-center(data-col="month"): +sortableLinks("month") …month-to-date + th.text-center(data-col="growth"): +sortableLinks("growth") …growth rate th.text-center Last 14 days - data.states.sort((a, b) => { @@ -30,7 +35,17 @@ block main - const yesterday = item.timeSeriesDaily[item.timeSeriesDaily.length - 1].delta || 0; - const lastWeek = item.timeSeriesDaily[item.timeSeriesDaily.length - 1].value - item.timeSeriesDaily[item.timeSeriesDaily.length - 7].value; - const lastMonth = item.timeSeriesMonthly[item.timeSeriesMonthly.length - 1].delta || 0; - tr(id=("row-" + item.safeName) data-name=item.name data-total=item.total data-yesterday=yesterday data-week=lastWeek data-month=lastMonth) + tr( + id=("row-" + item.safeName) + data-name=item.name + data-population=item.population + data-total=item.total + data-million=item.deathsPerMillion + data-yesterday=yesterday + data-week=lastWeek + data-month=lastMonth + data-growth=item.deathGrowthRate + ) td.sort-order= i + 1 td if item.name @@ -44,10 +59,15 @@ block main em.text-muted All #{item.country} else em.text-muted Other #{item.country} + if data.name === 'United States' + td.text-right: +formatNumber(item.population) td.text-right: +formatNumber(item.total) + if data.name === 'United States' + td.text-right: +formatNumber(Math.round(item.deathsPerMillion)) td.text-right.sorted: +formatNumber(yesterday) td.text-right: +formatNumber(lastWeek) td.text-right: +formatNumber(lastMonth) + td.text-right= Number(item.deathGrowthRate * 100).toFixed(2) + '%' td canvas.mx-auto(id="sparkline-" + i width="200" height="50") script. diff --git a/tmpl/master.pug b/tmpl/master.pug index a470b3e..4268c53 100644 --- a/tmpl/master.pug +++ b/tmpl/master.pug @@ -130,7 +130,7 @@ html span.sortables.mr-2.d-inline-flex.flex-column(style="font-size: 50%") a(href="#sort:" + col + ":asc") ▲ a(href="#sort:" + col + ":desc") ▼ - span + span.d-inline-block.text-truncate block mixin heroChart(title) @@ -234,16 +234,13 @@ html resortTable('name'); break; case 'total': - sortByNumberThenName('total'); - break; case 'yesterday': - sortByNumberThenName('yesterday'); - break; case 'week': - sortByNumberThenName('week'); - break; case 'month': - sortByNumberThenName('month'); + case 'population': + case 'million': + case 'growth': + sortByNumberThenName(value); break; } }; diff --git a/tmpl/state.pug b/tmpl/state.pug index 2c5c757..5f274d3 100644 --- a/tmpl/state.pug +++ b/tmpl/state.pug @@ -11,10 +11,13 @@ block main thead: tr th # th(data-col="name"): +sortableLinks("name") County/Region + th.text-center(data-col="population"): +sortableLinks("population") Population th.text-center(data-col="total"): +sortableLinks("total") Deaths + th.text-center(data-col="million"): +sortableLinks("million") …1/M th.text-center.sorted(data-col="yesterday"): +sortableLinks("yesterday") …since yesterday th.text-center(data-col="week"): +sortableLinks("week") …since last week th.text-center(data-col="month"): +sortableLinks("month") …month-to-date + th.text-center(data-col="growth"): +sortableLinks("growth") …growth rate th Last 14 days - @@ -32,17 +35,30 @@ block main - const yesterday = item.timeSeriesDaily[item.timeSeriesDaily.length - 1].delta || 0; - const lastWeek = item.timeSeriesDaily[item.timeSeriesDaily.length - 1].value - item.timeSeriesDaily[item.timeSeriesDaily.length - 7].value; - const lastMonth = item.timeSeriesMonthly[item.timeSeriesMonthly.length - 1].delta || 0; - tr(id=("row-" + item.countySafeName) data-name=item.county data-total=item.total data-yesterday=yesterday data-week=lastWeek data-month=lastMonth) + tr( + id=("row-" + item.countySafeName) + data-name=item.county + data-population=item.population + data-total=item.total + data-million=item.deathsPerMillion + data-yesterday=yesterday + data-week=lastWeek + data-month=lastMonth + data-growth=item.deathGrowthRate + ) td.sort-order= i + 1 td if item.county = item.county else em.text-muted Other #{item.state} + td.text-right: +formatNumber(item.population) td.text-right: +formatNumber(item.total) + td.text-right: +formatNumber(Math.round(item.deathsPerMillion)) td.text-right.sorted: +formatNumber(yesterday) td.text-right: +formatNumber(lastWeek) td.text-right: +formatNumber(lastMonth) + td.text-right= Number(item.deathGrowthRate * 100).toFixed(2) + '%' td canvas(id="sparkline-" + i width="200" height="50") script. diff --git a/tmpl/world.pug b/tmpl/world.pug index 48022b7..3dca5c0 100644 --- a/tmpl/world.pug +++ b/tmpl/world.pug @@ -9,11 +9,14 @@ block main thead: tr th # th(data-col="name"): +sortableLinks("name") Country + th.text-center(data-col="population"): +sortableLinks("population") Population th.text-center(data-col="total"): +sortableLinks("total") Deaths + th.text-center(data-col="million"): +sortableLinks("million") …/1M th.text-center.sorted(data-col="yesterday"): +sortableLinks("yesterday") …since yesterday th.text-center(data-col="week"): +sortableLinks("week") …since last week th.text-center(data-col="month"): +sortableLinks("month") …month-to-date - th Last 14 days + th.text-center(data-col="growth"): +sortableLinks("growth") …growth rate + th.text-center Last 14 days - data.countries.sort((a, b) => { const yesterdayA = a.timeSeriesDaily[a.timeSeriesDaily.length - 1].delta; @@ -29,15 +32,28 @@ block main - const yesterday = item.timeSeriesDaily[item.timeSeriesDaily.length - 1].delta || 0; - const lastWeek = item.timeSeriesDaily[item.timeSeriesDaily.length - 1].value - item.timeSeriesDaily[item.timeSeriesDaily.length - 7].value; - const lastMonth = item.timeSeriesMonthly[item.timeSeriesMonthly.length - 1].delta || 0; - tr(id="row-" + item.safeName data-name=item.name data-total=item.total data-yesterday=yesterday data-week=lastWeek data-month=lastMonth) + tr( + id=("row-" + item.safeName) + data-name=item.name + data-population=item.population + data-total=item.total + data-million=item.deathsPerMillion + data-yesterday=yesterday + data-week=lastWeek + data-month=lastMonth + data-growth=item.deathGrowthRate + ) td.sort-order= i + 1 - td: a(href="./countries/" + item.safeName + ".html")= item.name + td: a.d-inline-block.text-truncate(href="./countries/" + item.safeName + ".html" style="max-width: 125px")= item.name + td.text-right: +formatNumber(item.population) td.text-right: +formatNumber(item.total) + td.text-right: +formatNumber(Math.round(item.deathsPerMillion)) td.text-right.sorted: +formatNumber(yesterday) td.text-right: +formatNumber(lastWeek) td.text-right: +formatNumber(lastMonth) + td.text-right= Number(item.deathGrowthRate * 100).toFixed(2) + '%' td - canvas(id="sparkline-" + i width="200" height="50") + canvas.mx-auto(id="sparkline-" + i width="200" height="50") script. makeSparkline( "sparkline-#{i}",