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 a list of all checks for each venue type #50

8 changes: 4 additions & 4 deletions R/register.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ CONFIG <- new.env()
# Registers can be further divided into filter subgroups
# For cases where an entry does not fall into any subgroup, it's rendered files
# are stored in a folder with its own name
CONFIG$FILTER_SUB_GROUPS <- list(
CONFIG$FILTER_SUBCATEGORIES <- list(
venues = list("community", "journal", "conference")
)
CONFIG$MD_COLUMNS_WIDTHS <- "|:-------|:--------------------------------|:------------------|:---|:--------------------------|:----------|"
Expand All @@ -20,6 +20,8 @@ CONFIG$DICT_VENUE_NAMES <- list(
"community (in press)" = "In press",
"community (preprint)" = "Preprint"
)
CONFIG$NON_REG_INDEX_POSTFIX_TEMP_DIR <- "/docs/templates/codecheckers_venues_list/index_postfix_template.html"
CONFIG$REG_INDEX_POSTFIX_TEMP_DIR <- "/docs/templates/reg_tables/index_postfix_template.html"


#' Function for rendering the register into different view
Expand Down Expand Up @@ -65,7 +67,7 @@ register_render <- function(register = read.csv("register.csv", as.is = TRUE),
}

# Rendering files
# if ("md" %in% outputs) render_register_mds(list_register_tables)
if ("md" %in% outputs) render_register_mds(list_register_tables)
if ("html" %in% outputs) {
render_register_htmls(list_register_tables)

Expand All @@ -74,11 +76,9 @@ register_render <- function(register = read.csv("register.csv", as.is = TRUE),
}
}
if ("json" %in% outputs) {
# render_register_jsons(list_register_tables)
for (filter in filter_by){
render_non_register_jsons(list_register_tables[[filter]], page_type = filter)
}

}

return(register_table)
Expand Down
2 changes: 1 addition & 1 deletion R/utils_create_filtered_register_csvs.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ get_output_dir <- function(filter, column_value) {
#' @param venue_name The venue_name obtained from the "Type" column of the register
#' @return The venue category. If the venue does not belong to any category NULL is returned
determine_venue_category <- function(venue_name){
list_venue_categories <- CONFIG$FILTER_SUB_GROUPS[["venues"]]
list_venue_categories <- CONFIG$FILTER_SUBCATEGORIES[["venues"]]
for (category in list_venue_categories){
if (grepl(category, venue_name, ignore.case=TRUE)) {
return(category)
Expand Down
35 changes: 24 additions & 11 deletions R/utils_render_reigster_html.r
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,17 @@ generate_html_document_yml <- function(output_dir) {
#' @param register_table_name The register table name. If this is NULL we are generating list of venues/ codecheckers
#'
#' @importFrom whisker whisker.render
create_index_postfix_html <- function(output_dir, filter, register_table_name = NULL){
create_index_postfix_html <- function(output_dir, filter, register_table_name, is_reg_table){
# When we have a reg table name, we adjusting the hrefs of the postfix
if (!is.null(register_table_name)){
postfix_template <- readLines(paste0(getwd(), "/docs/templates/reg_tables/index_postfix_template.html"), warn = FALSE)
# Render the template with the correct hrefs
if (is_reg_table){
postfix_template <- readLines(paste0(getwd(), CONFIG$REG_INDEX_POSTFIX_TEMP_DIR), warn = FALSE)
hrefs <- generate_html_postfix_hrefs_reg(filter, register_table_name)
}

# Generating the postfix for non-register table pages (e.g. list of venues and codecheckers)
else{
postfix_template <- readLines(paste0(getwd(), "/docs/templates/codecheckers_venues_list/index_postfix_template.html"), warn = FALSE)
hrefs <- list(
json_href = paste0("https://codecheck.org.uk/register/", filter, "/index.json")
)
postfix_template <- readLines(paste0(getwd(), CONFIG$NON_REG_INDEX_POSTFIX_TEMP_DIR), warn = FALSE)
hrefs <- generate_html_postfix_hrefs_non_reg(filter, register_table_name)
}

output <- whisker.render(postfix_template, hrefs)
Expand Down Expand Up @@ -112,6 +109,22 @@ generate_html_postfix_hrefs_reg <- function(filter, register_table_name) {
return(hrefs)
}

generate_html_postfix_hrefs_non_reg <- function(filter, register_table_name){
if (!(register_table_name %in% list("all_venues", "codecheckers"))){
angelina-momin marked this conversation as resolved.
Show resolved Hide resolved
hrefs <- list(
json_href = paste0("https://codecheck.org.uk/register/", filter, "/", register_table_name,"/index.json")
)
}

else{
hrefs <- list(
json_href = paste0("https://codecheck.org.uk/register/", filter, "/index.json")
)
}

return(hrefs)
}

#' Generate full href for for different href types.
#'
#' @param filter The filter name
Expand Down Expand Up @@ -167,8 +180,8 @@ generate_href <- function(filter, register_table_name, href_type) {
#' @param output_dir The output directory of the section files
#' @param filter The filter name
#' @param register_table_name The register table name
create_index_section_files <- function(output_dir, filter, register_table_name = NULL) {
create_index_postfix_html(output_dir, filter, register_table_name)
create_index_section_files <- function(output_dir, filter, register_table_name, is_reg_table) {
create_index_postfix_html(output_dir, filter, register_table_name, is_reg_table)
create_index_prefix_html(output_dir)
create_index_header_html(output_dir)
}
Expand All @@ -184,7 +197,7 @@ render_register_html <- function(filter, register_table, register_table_name){
register_table <- add_repository_links_html(register_table)

# Dynamically create the index header, prefix and postfix files
create_index_section_files(output_dir, filter, register_table_name)
create_index_section_files(output_dir, filter, register_table_name, is_reg_table = TRUE)
generate_html_document_yml(output_dir)

# Capture the HTML output from a markdown file
Expand Down
1 change: 0 additions & 1 deletion R/utils_render_table_codecheckers.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ render_table_codecheckers_html <- function(list_codechecker_reg_tables){
table_codecheckers <- table_codecheckers[, c("Codechecker name", "ORCID_ID_Link", "No. of codechecks")]
names(table_codecheckers)[names(table_codecheckers) == "ORCID_ID_Link"] <- "ORCID ID"

table_codecheckers <- kable(table_codecheckers)
return(table_codecheckers)
}

152 changes: 125 additions & 27 deletions R/utils_render_table_non_registers.R
Original file line number Diff line number Diff line change
@@ -1,37 +1,53 @@
render_non_register_tables_html <- function(list_reg_tables, page_type){
if (page_type == "codecheckers") {
angelina-momin marked this conversation as resolved.
Show resolved Hide resolved
# Wrapping the single table in a list
list_tables <- list("codecheckers" = render_table_codecheckers_html(list_reg_tables))
} else if (page_type == "venues") {
list_tables <- render_tables_venues_html(list_reg_tables)
}
return(list_tables)
}

#' Renders non-register pages such as codecheckers or venues page.
#'
#' @param list_reg_tables The list of register tables to link to in this html page
render_non_register_htmls <- function(list_reg_tables, page_type){
output_dir <- paste0("docs/", page_type, "/")
list_tables <- render_non_register_tables_html(list_reg_tables, page_type)

for (table_name in names(list_tables)){
table <- list_tables[[table_name]]

no_codechecks <- sum(sapply(list_reg_tables, nrow))
if (page_type == "codecheckers"){
table <- render_table_codecheckers_html(list_reg_tables)
# Counting number of codecheckers based of number of codechecker reg tables
# The table is a kable table and hence we cannot count rows
no_codecheckers <- length(list_reg_tables)
subtext <- paste("In total,", no_codecheckers, "codecheckers contributed", no_codechecks, "codechecks")
}
# Case where we are dealing with venue subcategories
if (page_type == "venues" & table_name != "all_venues"){
output_dir <- paste0("docs/", page_type, "/", table_name, "/")
}

else if (page_type == "venues"){
table <- render_table_venues_html(list_reg_tables)
else{
output_dir <- paste0("docs/", page_type, "/")
}

no_venues <- length(list_reg_tables)
subtext <- paste("In total,", no_codechecks, "codechecks were completed for", no_venues, "venues")
html_header <- generate_html_header(table, page_type, table_name)
generate_html(table, table_name, page_type, html_header, output_dir)
}
}

generate_html <- function(table, table_subcategory, page_type, html_header, output_dir){

table <- kable(table)

# Creating and adjusting the markdown table
md_table <- load_md_template(CONFIG$MD_NON_REG_TEMPLATE)
title <- paste0("CODECHECK List of ", page_type)
md_table <- gsub("\\$title\\$", title, md_table)
md_table <- gsub("\\$subtitle\\$", subtext, md_table)
md_table <- gsub("\\$title\\$", html_header[["title"]], md_table)
md_table <- gsub("\\$subtitle\\$", html_header[["subtext"]], md_table)
md_table <- gsub("\\$content\\$", paste(table, collapse = "\n"), md_table)

# Saving the table to a temp md file
temp_md_path <- paste0(output_dir, "temp.md")
writeLines(md_table, temp_md_path)

# Creating the correct html yaml and index files
create_index_section_files(output_dir, page_type)
print(table_subcategory)
create_index_section_files(output_dir, page_type, table_subcategory, is_reg_table = FALSE)
generate_html_document_yml(output_dir)
yaml_path <- normalizePath(file.path(getwd(), paste0(output_dir, "html_document.yml")))

Expand Down Expand Up @@ -59,18 +75,100 @@ render_non_register_htmls <- function(list_reg_tables, page_type){
#'
#' @param list_reg_tables The list of register tables needed for the information.
render_non_register_jsons <- function(list_reg_tables, page_type){
output_dir <- paste0("docs/", page_type, "/")

if (page_type == "codeheckers"){
table <- render_table_codecheckers_json(list_reg_tables)
if (page_type == "codecheckers"){
list_tables <- list("codecheckers" = render_table_codecheckers_json(list_reg_tables))
}

else if (page_type == "venues") {
table <- render_table_venues_json(list_reg_tables)
list_tables <- render_tables_venues_json(list_reg_tables)
}

for (table_name in names(list_tables)){
table <- list_tables[[table_name]]
output_dir <- paste0("docs/", page_type, "/")

# Case where we are dealing with venue subcategories
if (page_type == "venues" & table_name != "all_venues"){
output_dir <- paste0("docs/", page_type, "/", table_name, "/")
}

jsonlite::write_json(
table,
path = paste0(output_dir, "index.json"),
pretty = TRUE
)
}
jsonlite::write_json(
table,
path = paste0(output_dir, "index.json"),
pretty = TRUE
}

generate_html_title_non_registers <- function(page_type, table_name){
title_base <- "CODECHECK List of"

# Adjusting title for venues subcategory
if (page_type == "venues" & table_name != "all_venues"){
# Replacing the word with plural
plural_subcategory <- switch (table_name,
"conference" = "conferences",
"journal" = "journals",
"community" = "communities"
)
title <- paste(title_base, plural_subcategory)
}

else{
# The base title is "CODECHECK List of venues/ codecheckers"
title <- paste(title_base, page_type)
}

return(title)
}

generate_html_subtext_non_register <- function(table, page_type, table_name){

# Extracting the no. of codechecks from the string in the column "No. of codechecks"
# The line "sub" replaces everything starting from the first space
list_no_codechecks <- as.numeric(sub(" .*", "", table$`No. of codechecks`))
total_codechecks <- sum(list_no_codechecks)

# Setting the codecheck word
codecheck_word <- if (total_codechecks == 1) "codecheck" else "codechecks"

if (page_type == "codecheckers"){
no_codecheckers <- nrow(table)
subtext <- paste("In total,", no_codecheckers, "codecheckers contributed", total_codechecks, codecheck_word)
}

else if (page_type == "venues"){
# For the general venues list
if (table_name == "all_venues"){
no_venues <- nrow(table)
subtext <- paste("In total,", total_codechecks, codecheck_word, "were completed for", no_venues, "venues")
}

else{
no_venues_subcat <- nrow(table)
venue_name_subtext <- table_name

if (no_venues_subcat > 1){
venue_name_subtext <- switch (table_name,
"conference" = "conferences",
"journal" = "journals",
"community" = "communities"
)
}
subtext <- paste("In total,", total_codechecks, codecheck_word, "were completed for", no_venues_subcat, venue_name_subtext)
}
}


return(subtext)
}

generate_html_header <- function(table, page_type, table_name){

html_header <- list(
"title" = generate_html_title_non_registers(page_type, table_name),
"subtext" = generate_html_subtext_non_register(table, page_type, table_name)
)
}

return(html_header)
}
Loading
Loading