From 7805fd319dce603d614bf06c86d13e4b8c776db4 Mon Sep 17 00:00:00 2001 From: "USMortality.com" Date: Tue, 4 Apr 2023 22:14:37 -0700 Subject: [PATCH] fixes --- archive.sh | 13 +++++++------ de.sh | 13 +++++++------ tools/import_csv.sh | 4 ++-- us.sh | 11 ++++++----- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/archive.sh b/archive.sh index 4f003f9..641d4b8 100755 --- a/archive.sh +++ b/archive.sh @@ -1,4 +1,5 @@ #!/bin/bash +[[ $OSTYPE == 'darwin'* ]] && alias date=gdate function import_csv() { cd tools @@ -30,11 +31,11 @@ function archive() { mysql -h 127.0.0.1 -u root -e "SET GLOBAL local_infile=1;" if [ "$1" = "project" ]; then - start=$(gdate -d "(date) - 10 weeks" +%F) + start=$(date -d "(date) - 10 weeks" +%F) else - start=$(gdate -d "(date) - 3 weeks" +%F) + start=$(date -d "(date) - 3 weeks" +%F) fi -end=$(gdate -d "(date) - 3 weeks" +%F) +end=$(date -d "(date) - 3 weeks" +%F) # Population mysql -h 127.0.0.1 -u root -e "DROP DATABASE IF EXISTS population;" @@ -42,14 +43,14 @@ import_csv population.csv population import_csv population_std.csv population # Single week -# week=$(gdate -d $end +%Y)"_"$(gdate -d $end +%U) +# week=$(date -d $end +%Y)"_"$(date -d $end +%U) # archive $week # Process death files for last n weeks mysql -h 127.0.0.1 -u root -e "DROP DATABASE IF EXISTS archive;" while ! [[ $start > $end ]]; do - start=$(gdate -d "$start + 1 week" +%F) - week=$(gdate -d $start +%Y)"_"$(gdate -d $start +%U) + start=$(date -d "$start + 1 week" +%F) + week=$(date -d $start +%Y)"_"$(date -d $start +%U) archive "${week}" done diff --git a/de.sh b/de.sh index 8670c9a..9df65a0 100755 --- a/de.sh +++ b/de.sh @@ -1,4 +1,5 @@ #!/bin/bash +[[ $OSTYPE == 'darwin'* ]] && alias date=gdate function import_csv() { cd tools @@ -7,8 +8,8 @@ function import_csv() { } # Download latest data -start=$(gdate -d "(date) - 2 weeks" +%F) -week=$(gdate -d $start +%Y)"_"$(gdate -d $start +%U) +start=$(date -d "(date) - 2 weeks" +%F) +week=$(date -d $start +%Y)"_"$(date -d $start +%U) wget https://s3.mortality.watch/data/mortality/deu/deaths.csv \ -O data/de/Tote_${week}.csv @@ -22,12 +23,12 @@ rm data/population.tsv data/einwohner.csv ln -sf "de/esp2013.csv" "data/population_std.csv" -start=$(gdate -d "(date) - 10 weeks" +%F) -end=$(gdate -d "(date) - 3 weeks" +%F) +start=$(date -d "(date) - 10 weeks" +%F) +end=$(date -d "(date) - 3 weeks" +%F) while ! [[ $start > $end ]]; do - start=$(gdate -d "$start + 1 week" +%F) - week=$(gdate -d $start +%Y)"_"$(gdate -d $start +%U) + start=$(date -d "$start + 1 week" +%F) + week=$(date -d $start +%Y)"_"$(date -d $start +%U) ln -sf "de/Tote_${week}.csv" "data/deaths.csv" import_csv deaths.csv deaths diff --git a/tools/import_csv.sh b/tools/import_csv.sh index 3011ee1..65688b9 100755 --- a/tools/import_csv.sh +++ b/tools/import_csv.sh @@ -27,7 +27,7 @@ cd $(dirname $FILE_PATH) ln -s "$FILE" "$TABLE_NAME.csv" # Import data. -mysqlimport --local -h 127.0.0.1 -u root --columns=$COLUMNS --fields-terminated-by="," --fields-optionally-enclosed-by='"' --ignore-lines=1 $DB "$TABLE_NAME.csv" +mysqlimport --local -h 127.0.0.1 -u root --fields-terminated-by="," --fields-optionally-enclosed-by='"' --ignore-lines=1 $DB "$TABLE_NAME.csv" unlink "$TABLE_NAME.csv" -cd ~- \ No newline at end of file +cd ~- diff --git a/us.sh b/us.sh index 56a14de..6236d50 100755 --- a/us.sh +++ b/us.sh @@ -1,4 +1,5 @@ #!/bin/bash +[[ $OSTYPE == 'darwin'* ]] && alias date=gdate function import_csv() { cd tools @@ -7,7 +8,7 @@ function import_csv() { } # Update Data -date=$(gdate --date="14 days ago" +"%Y")"_"$(gdate --date="14 days ago" +"%U") +date=$(date --date="14 days ago" +"%Y")"_"$(date --date="14 days ago" +"%U") wget "https://data.cdc.gov/api/views/y5bj-9g5w/rows.csv?accessType=DOWNLOAD" \ -O "data/us/Weekly_counts_of_deaths_by_jurisdiction_and_age_group_${date}.csv" @@ -22,16 +23,16 @@ mysql -h 127.0.0.1 -u root -e "SET GLOBAL sql_mode = '';" ln -sf "us/population20152021.csv" "data/population.csv" ln -sf "us/std_population2000.csv" "data/population_std.csv" -start=$(gdate -d "(date) - 10 weeks" +%F) -end=$(gdate -d "(date) - 3 weeks" +%F) +start=$(date -d "(date) - 10 weeks" +%F) +end=$(date -d "(date) - 3 weeks" +%F) # Import Covid Deaths ln -sf "us/Weekly_Counts_of_Deaths_by_State_and_Select_Causes_2014-2019.csv" "data/covid_deaths_2014-2019.csv" import_csv "covid_deaths_2014-2019.csv" deaths while ! [[ $start > $end ]]; do - start=$(gdate -d "$start + 1 week" +%F) - week=$(gdate -d $start +%Y)"_"$(gdate -d $start +%U) + start=$(date -d "$start + 1 week" +%F) + week=$(date -d $start +%Y)"_"$(date -d $start +%U) echo "Week $week" ln -sf "us/Weekly_counts_of_deaths_by_jurisdiction_and_age_group_${week}.csv" "data/deaths.csv"