Skip to content

Commit

Permalink
Develop (#233)
Browse files Browse the repository at this point in the history
* Handle better NAs
* Offline data update
  • Loading branch information
GuidoMaggio authored Nov 29, 2022
1 parent e4a7f5e commit 3186f9e
Show file tree
Hide file tree
Showing 9 changed files with 294 additions and 333 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: Covid19Mirai
Title: Covid-19 Data Analysis
Version: 2.9.1
Version: 2.9.2
Authors@R:
c(person("Riccardo", "Porreca", role = ("aut"),
email = "riccardo.porreca@mirai-solutions.com"),
Expand Down
7 changes: 5 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
### Covid19Mirai 2.9.2
- Swiss data at level 2 have delay

### Covid19Mirai 2.9.1
- Update to R 4.0.3 and GH Actions update (#218)
- Update to R 4.2.1 (#218)

### Covid19Mirai 2.9.0
- Update to R 4.0.3 and GH Actions update (#226)
Expand All @@ -8,7 +11,7 @@
- Fixed tests (#221)

### Covid19Mirai 2.8.0
- updated to Covid19datahub 3.0.2 (#217)
- Updated to Covid19datahub 3.0.2 (#217)

### Covid19Mirai 2.7.4
- Complete vaccination data (#201)
Expand Down
6 changes: 2 additions & 4 deletions R/mod_country_comparison.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ mod_country_comparison_server <- function(input, output, session, data, countrie
# message_firstday(nn),
# sep = "<br/>"))
# })

all_countries_data <- data %>%
filter(contagion_day > 0) %>%
arrange(desc(date))
Expand All @@ -118,9 +117,8 @@ mod_country_comparison_server <- function(input, output, session, data, countrie


observeEvent(input$select_countries,{
if (input$select_countries != "") {
if (all(input$select_countries != "")) {
# Data ----

countries_data <- all_countries_data %>%
filter(Country.Region %in% input$select_countries) #%>%
#arrange(desc(date))
Expand Down Expand Up @@ -222,6 +220,6 @@ mod_country_comparison_server <- function(input, output, session, data, countrie
# tables ----
callModule(mod_add_table_server, "add_table_countries", countries_data, maxrowsperpage = 10)
}
})
}, ignoreInit = TRUE)

}
67 changes: 38 additions & 29 deletions R/mod_map_calc_continent.R
Original file line number Diff line number Diff line change
Expand Up @@ -590,8 +590,10 @@ legend_fun <- function(x, var){
dg = nchar(as.character(round(max(abs(minxv),maxv, na.rm =T))))
#dg = nchar(as.character(round(maxv)))
domain = choose_domain(x, var)

cvx = sd(x,na.rm = T) / mean(x,na.rm = T)
#if (dg < 6 || (var %in% domainlin_vars()) || cvx<1){
if (!is.finite(cvx))
cvx <- 0
bin = domain(x)

if ((grepl("growth",var) && grepl("fact",var)) || (var %in% .rate_vars) || (var %in% domainlin_vars()) || cvx<1){
Expand Down Expand Up @@ -709,34 +711,41 @@ domainlin_vars <- function(x) {
#' @param var character vector of variable name
#' @return numeric vector of range
choose_domain <- function(x, var) {
if (is.numeric(x)) {
maxy = max(x, na.rm = T)
minxy = min(x, na.rm = T)
dg = nchar(as.character(round(max(abs(minxy),maxy))))
cvx = sd(x,na.rm = T) / mean(x,na.rm = T)
if (var %in% .rate_vars){ # if rate
domain = domainrate
} else if (var %in% .index_vars){ # if rate
domain = domainindex
} else if ((grepl("growth",var) && grepl("fact",var))){
# growth factors variables
domain = domaingrowth
# } else if ((var %in% domainlin_vars()) || cvx<1) {
# domain = domainlin
#} else if (dg < 6) {
} else if ((var %in% domainlin_vars()) || cvx<1) {
if (var %in% .neg_vars && any(x<0, na.rm = TRUE))
domain = domainlin_neg
else
domain = domainlin
} else {
if (var %in% .neg_vars && any(x<0, na.rm = TRUE))
domain = domainlog_neg
else
domain = domainlog
if (all(is.na(x))) {
domain <- function(x) {
c(0,1)
}
} else
domain = domainfact
} else {
if (is.numeric(x)) {
maxy = max(x, na.rm = T)
minxy = min(x, na.rm = T)
dg = nchar(as.character(round(max(abs(minxy),maxy))))
cvx = sd(x,na.rm = T) / mean(x,na.rm = T)
if (var %in% .rate_vars){ # if rate
domain = domainrate
} else if (var %in% .index_vars){ # if rate
domain = domainindex
} else if ((grepl("growth",var) && grepl("fact",var))){
# growth factors variables
domain = domaingrowth
# } else if ((var %in% domainlin_vars()) || cvx<1) {
# domain = domainlin
#} else if (dg < 6) {
} else if ((var %in% domainlin_vars()) || cvx<1) {
if (var %in% .neg_vars && any(x<0, na.rm = TRUE))
domain = domainlin_neg
else
domain = domainlin
} else {
if (var %in% .neg_vars && any(x<0, na.rm = TRUE))
domain = domainlog_neg
else
domain = domainlog
}
} else
domain = domainfact
}

domain
}
#' Utility derive palette given datadisplay.brewer.all()
Expand Down Expand Up @@ -795,7 +804,7 @@ pal_fun = function(var,x){
#' @param var character vector of variable name
#' @return rescaled x
pal_fun_calc <- function(x, var){
if (is.numeric(x)){
if (is.numeric(x) && all(!is.na(x))){
# maxv = max(x)
# dg = nchar(as.character(round(maxv)))
maxv = max(x, na.rm = T)
Expand Down
Binary file modified inst/datahub/DATA.rds
Binary file not shown.
Binary file modified inst/datahub/Selected_Country.rds
Binary file not shown.
Binary file modified inst/datahub/Top_Countries.rds
Binary file not shown.
Loading

0 comments on commit 3186f9e

Please sign in to comment.