From 0d27980f21ea3ab1df2ed289df421b7034b2fd22 Mon Sep 17 00:00:00 2001 From: Angelo D'Ambrosio Date: Tue, 16 Apr 2024 09:54:49 +0200 Subject: [PATCH] feat: add function to format agenda into human-readable text A new function, format_agenda, has been introduced to convert a machine-readable agenda into a human-readable format. --- R/data_management.R | 54 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/R/data_management.R b/R/data_management.R index 1da4cd1..58a73c7 100644 --- a/R/data_management.R +++ b/R/data_management.R @@ -580,7 +580,61 @@ format_summary_tree <- function( invisible(output) } +#' Formats an agenda into a human-readable text +#' +#' The agenda functions returns a machine-readable agenda. This function takes +#' an agenda in R list format as generated by the `infer_agenda_from_transcript` +#' function and formats it into a human-readable text. +#' +#' @param agenda A list containing the agenda items. It is contains a number of +#' information about each talk, such as the session, title, speakers, +#' moderators, start and ending times. +#' @param event_start_time If agenda timings are in seconds, the starting time +#' is needed to convert them to actual clock time. If `NULL` it will use the +#' timing as reported in the agenda. +#' +#' @return A string containing the formatted agenda, invisibly. +#' +#' @export +format_agenda <- function( + agenda, + event_start_time = getOption("minutemaker_event_start_time") +) { + # Import agenda from file + if (is.character(agenda)) { + agenda <- dget(agenda) + } + + # Initialize the output string + output <- "" + + # Covert times from second to clock time if possible + agenda <- convert_agenda_times( + agenda, convert_to = "clock", + event_start_time = event_start_time, conversion_format = "%R" + ) + + # Generate a text version of the summary, with session, title, speakers, + # moderators and summary, if not NULL/empty + purrr::map_chr(agenda, ~ { + .x$speakers <- stringr::str_flatten_comma(.x$speakers) + .x$moderators <- stringr::str_flatten_comma(.x$moderators) + .x$session <- ifelse(is.null(.x$session), "", .x$session) + .x$title <- ifelse(is.null(.x$title), "", .x$title) + .x$description <- ifelse(is.null(.x$description), "", .x$description) + + stringr::str_glue_data(.x, + "Session: {session}; + Title: {title}; + Description: {description}; + Speakers: {speakers}; + Moderators: {moderators}; + Time: {from} - {to};") |> + stringr::str_remove_all("\\n?\\w+:\\s*;") |> # Remove empty fields + stringr::str_replace_all("\\.;", ";") + }) |> paste(collapse = "\n\n####################\n\n") +} #' Import transcript from subtitle file