forked from covid19datahub/COVID19
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
emanuele-guidotti
committed
Mar 1, 2021
1 parent
9c4b88d
commit 7960bfb
Showing
6 changed files
with
5,812 additions
and
726 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
covid19br_git <- function(cache, level){ | ||
|
||
if(level<=2){ | ||
|
||
# download | ||
url <- "https://raw.githubusercontent.com/wcota/covid19br/master/cases-brazil-states.csv" | ||
x <- read.csv(url, cache = cache) | ||
|
||
# formatting | ||
x <- map_data(x, c( | ||
"date" = "date", | ||
"state" = "state", | ||
"deaths" = "deaths", | ||
"totalCases" = "confirmed", | ||
"recovered" = "recovered", | ||
"tests" = "tests", | ||
"vaccinated" = "vaccines_1", | ||
"vaccinated_second" = "vaccines_2" | ||
)) | ||
|
||
# total number of doses | ||
x$vaccines <- x$vaccines_1 + x$vaccines_2 | ||
|
||
# filter | ||
idx <- which(x$state=="TOTAL") | ||
if(level==1) | ||
x <- x[idx,] | ||
else | ||
x <- x[-idx,] | ||
|
||
} | ||
else { | ||
|
||
# url | ||
url <- "https://raw.githubusercontent.com/wcota/covid19br/master/cases-brazil-cities-time.csv.gz" | ||
|
||
# download | ||
tmp <- tempfile() | ||
download.file(url, destfile=tmp, mode="wb", quiet = TRUE) | ||
x <- read.csv(tmp, cache = cache) | ||
|
||
# formatting | ||
x <- map_data(x, c( | ||
"date" = "date", | ||
"ibgeID" = "code", | ||
"state" = "state", | ||
"deaths" = "deaths", | ||
"totalCases" = "confirmed" | ||
)) | ||
|
||
# filter cities | ||
x <- x[nchar(x$code)==7,] | ||
|
||
} | ||
|
||
# date | ||
x$date <- as.Date(x$date) | ||
|
||
# return | ||
return(x) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
gov_br <- function(cache, level){ | ||
|
||
if(level!=3) | ||
return(NULL) | ||
|
||
# url | ||
url <- "https://s3-sa-east-1.amazonaws.com/ckan.saude.gov.br/PNI/vacina/2021/part-00000-090405dc-80c4-4889-84c3-a9a390d06947-c000.csv" | ||
|
||
# download | ||
tmp <- tempfile() | ||
download.file(url, tmp) | ||
|
||
# read | ||
colClasses <- rep("NULL", 32) | ||
colClasses[8] <- "character" | ||
colClasses[28] <- "Date" | ||
x <- read.csv(tmp, colClasses = colClasses) | ||
|
||
# clean | ||
file.remove(tmp) | ||
|
||
# formatting | ||
colnames(x) <- c("city", "date") | ||
|
||
# cumulate | ||
x <- x %>% | ||
dplyr::filter(date > "2020-12-01") %>% | ||
dplyr::group_by(city, date) %>% | ||
dplyr::summarise(vaccines = dplyr::n()) %>% | ||
dplyr::group_by(city) %>% | ||
dplyr::arrange(date) %>% | ||
dplyr::mutate(vaccines = cumsum(vaccines)) | ||
|
||
# return | ||
return(x) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.