Skip to content

Commit

Permalink
Transfer Estonia code into new clean branch
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardMN committed Sep 16, 2021
1 parent aa85f36 commit 1426e7a
Show file tree
Hide file tree
Showing 25 changed files with 238 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,4 @@ Encoding: UTF-8
Language: en-gb
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.1
RoxygenNote: 7.1.2
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export(Covid19DataHub)
export(Cuba)
export(DataClass)
export(ECDC)
export(Estonia)
export(France)
export(Germany)
export(Google)
Expand Down Expand Up @@ -73,6 +74,7 @@ importFrom(dplyr,slice_tail)
importFrom(dplyr,starts_with)
importFrom(dplyr,summarise)
importFrom(dplyr,tally)
importFrom(dplyr,transmute)
importFrom(dplyr,ungroup)
importFrom(dplyr,vars)
importFrom(httr,GET)
Expand Down
86 changes: 86 additions & 0 deletions R/Estonia.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#' Estonia Class for downloading, cleaning and processing notification data
#' @description Information for downloading, cleaning
#' and processing COVID-19 region data for Estonia
#'
# nolint start
#' @source \url{https://www.terviseamet.ee/et/koroonaviirus/avaandmed}
# nolint end
#' @export
#' @concept dataset
#' @family subnational
#' @examples
#' \dontrun{
#' region <- Estonia$new(verbose = TRUE, steps = TRUE, get = TRUE)
#' region$return()
#' }
Estonia <- R6::R6Class("Estonia",
inherit = DataClass,
public = list(

# Core Attributes
#' @field origin name of origin to fetch data for
origin = "Estonia",
#' @field supported_levels A list of supported levels.
supported_levels = list("1"),
#' @field supported_region_names A list of region names in order of level.
supported_region_names = list("1" = "county"),
#' @field supported_region_codes A list of region codes in order of level.
supported_region_codes = list("1" = "iso_3166_2"),
#' @field common_data_urls List of named links to raw data.
# nolint start
common_data_urls = list(
"main" = "https://opendata.digilugu.ee/opendata_covid19_test_county_all.csv" # nolint
),
# nolint end
#' @field source_data_cols existing columns within the raw data
source_data_cols = c("cases_new", "tested_new", "cases_total", "tested_total"),
#' @field source_text Plain text description of the source of the data
source_text = "Estonian Ministry of Social Affairs",
#' @field source_url Website address for explanation/introduction of the
#' data
source_url = "https://www.terviseamet.ee/et/koroonaviirus/avaandmed",


#' @description Set up a table of region codes for clean data
#' @importFrom tibble tibble
set_region_codes = function() {
self$codes_lookup$`1` <- tibble(
code = c("EE-37",
"EE-39", "EE-45", "EE-52", "EE-50", "EE-56", "EE-60", "EE-68",
"EE-64", "EE-71", "EE-74", "EE-79", "EE-81", "EE-84", "EE-87",
NA),
region = c("Harju", "Hiiu", "Ida-Viru", "J\u00e4rva",
"J\u00f5geva", "L\u00e4\u00e4ne", "L\u00e4\u00e4ne-Viru",
"P\u00e4rnu", "P\u00f5lva", "Rapla","Saare", "Tartu",
"Valga", "Viljandi", "V\u00f5ru", "Unknown")
)
},

#' @description Estonia specific state level data cleaning
#' @importFrom dplyr select mutate transmute
#' @importFrom tidyr pivot_wider
#' @importFrom rlang .data
#'
clean_common = function() {
self$data$clean <- self$data$raw[["main"]] %>%
pivot_wider(
id_cols = c("LastStatisticsDate","StatisticsDate","Country","CountryEHAK","County","CountyEHAK"),
names_from = ResultValue,
values_from = c("DailyTests","TotalTests","DailyCases","TotalCases")) %>%
select(-Country,-CountryEHAK) %>%
mutate(TestPositivity = ifelse((DailyTests_N+DailyTests_P)>0,
(DailyTests_P/(DailyTests_N+DailyTests_P)),
NA)) %>%
transmute(
level_1_region = gsub(" maakond","", .data$County),
level_1_region_code=gsub("00","EE-", .data$CountyEHAK),
date = .data$StatisticsDate,
cases_new = .data$DailyCases_P,
tested_new = .data$DailyTests_P + .data$DailyTests_N,
cases_total = .data$TotalCases_P,
tested_total = .data$TotalTests_P + .data$TotalTests_N,
test_positivity = .data$TestPositivity
)
}
)
)
Binary file modified data/all_country_data.rda
Binary file not shown.
1 change: 1 addition & 0 deletions man/Belgium.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/Brazil.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/Canada.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/Colombia.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/Covid19DataHub.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/Cuba.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

129 changes: 129 additions & 0 deletions man/Estonia.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/France.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/Germany.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/Google.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/India.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/Italy.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/JHU.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/Lithuania.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/Mexico.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/Netherlands.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/SouthAfrica.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/Switzerland.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/UK.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/USA.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/all_country_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1426e7a

Please sign in to comment.