Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Estonia data #417

Merged
merged 7 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/workflows/Estonia.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
on:
schedule:
- cron: '36 12 * * *'
workflow_dispatch:

name: Estonia

jobs:
Estonia:
runs-on: macOS-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@v1

- name: Query dependencies
run: |
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}

- name: Cache R packages
uses: actions/cache@v2
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-

- name: Install dependencies
run: |
install.packages(c("remotes"))
remotes::install_deps(dependencies = TRUE)
install.packages("devtools")
shell: Rscript {0}

- name: Install package
run: R CMD INSTALL .

- name: Test dataset
run: |
options("testDownload" = TRUE)
options("testSource" = "Estonia")
devtools::load_all()
testthat::test_file("tests/testthat/test-regional-datasets.R", reporter = c("summary", "fail"))
shell: Rscript {0}
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: covidregionaldata
Title: Subnational Data for COVID-19 Epidemiology
Version: 0.9.2.1000
Version: 0.9.2.2000
Authors@R:
c(person(given = "Joseph",
family = "Palmer",
Expand Down 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
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# covidregionaldata 0.9.3

This release is currrently under development

## New data sets

- Support for level 1 region data in Estonia (thanks to @RichardMN). See `?Estonia` for details.

# covidregionaldata 0.9.2

This release adds support for the Covid19 Data Hub which includes Google and Apple mobility data amongst a large range of other data sets, data from the European Commission's Joint Research Centre which is at both the regional and national level, and individual sources for regional data from several countries. Package updates have been made in line with a software review at the [Journal of Open Source Software](https://github.com/openjournals/joss-reviews/issues/3290). Finally, this release exposes more of the testing infrastructure to users and adds a package hexsticker.
Expand Down
90 changes: 90 additions & 0 deletions R/Estonia.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#' 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.

Loading