Skip to content

Commit

Permalink
feat: add function to format agenda into human-readable text
Browse files Browse the repository at this point in the history
A new function, format_agenda, has been introduced to convert a machine-readable agenda into a human-readable format.
  • Loading branch information
bakaburg1 committed Apr 16, 2024
1 parent 5e943af commit 0d27980
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions R/data_management.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0d27980

Please # to comment.