Skip to content

Commit

Permalink
Very rough working example
Browse files Browse the repository at this point in the history
  • Loading branch information
cansavvy committed Jun 1, 2023
1 parent 899f2e0 commit 86b6b17
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 48 deletions.
3 changes: 2 additions & 1 deletion manuscript/Book.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
1-Introduction.md
quiz_ch1.md
2-A-new-chapter.md
3-References.md
About-this-Course.md
About-the-Authors.md
About-this-Course.md
1 change: 1 addition & 0 deletions quiz_jsons/quiz_ch1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"question_info_df":[{"question":"First question to ask goes here. (Note- you need a question mark at end like this. Just one is required if using a question mark in your question field)?","question_type":"multiple_choice","shuffle_opt":true,"correct_answer":1,"_row":"First question to ask goes here. (Note- you need a question mark at end like this. Just one is required if using a question mark in your question field)?"},{"question":"Question example with just a question mark?","question_type":"multiple_choice","shuffle_opt":true,"correct_answer":1,"_row":"Question example with just a question mark?"},{"question":"Second question to ask goes here?","question_type":"multiple_choice","shuffle_opt":true,"correct_answer":1,"_row":"Second question to ask goes here?"},{"question":"A more complicated example. Note the question mark at the end of the options! Which of the following are correct","question_type":"multiple_choice","shuffle_opt":true,"correct_answer":1,"_row":"A more complicated example. Note the question mark at the end of the options! Which of the following are correct"},{"question":"A question in which the order of choices is important?","question_type":"multiple_choice","shuffle_opt":false,"correct_answer":4,"_row":"A question in which the order of choices is important?"}],"choice_vectors":[["One correct answer here marked with a \"C\"","Mandatory incorrect answers have an \"m\"","A second mandatory incorrect answer","An optional incorrect answer here marked with an \"o\"","A second optional incorrect answer here"],["One correct answer here marked with a \"C\"","Mandatory incorrect answers have an \"m\"","A second mandatory incorrect answer","An optional incorrect answer here marked with an \"o\"","A second optional incorrect answer here"],["A correct answer here!","Mandatory incorrect answers have an \"m\"","A second mandatory incorrect answer","An optional incorrect answer here marked with an \"o\"","A second optional incorrect answer here"],["All of the examples listed except 5","1, 3, and 5","1, 2, and 3","All of the examples except 1 and 5","All of the examples listed"],["The possible responses should be labeled a, b, c, etc","The correct answer has a capital letter, in this case \"D\" is correct","both a and b","All of the above will always be last choice in this question"]]}
7 changes: 7 additions & 0 deletions resources/course_units.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
md_name type url chapt_title full_urls
1-Introduction.md chapter introduction.html 1 Introduction https://jhudatascience.org/OTTR_Template/introduction.html
quiz_ch1.md quiz NA NA NA
2-A-new-chapter.md chapter a-new-chapter.html 2 A new chapter https://jhudatascience.org/OTTR_Template/a-new-chapter.html
3-References.md chapter references.html 3 References https://jhudatascience.org/OTTR_Template/references.html
About-the-Authors.md chapter about-the-authors.html About the Authors https://jhudatascience.org/OTTR_Template/about-the-authors.html
About-this-Course.md chapter index.html About this Course https://jhudatascience.org/OTTR_Template/index.html
79 changes: 32 additions & 47 deletions scripts/make_material_df.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ library(optparse)
library(magrittr)

option_list <- list(
optparse::make_option(
c("--owner_id"),
type = "character",
default = NULL,
help = "Owner id",
),
optparse::make_option(
c("--course_name"),
type = "character",
default = NULL,
help = "Course name for this",
),
optparse::make_option(
c("--repo"),
type = "character",
Expand All @@ -44,6 +56,11 @@ option_list <- list(
type = "character",
default = NULL,
help = "Output directory where the chapter's screen images should be stored",
),
optparse::make_option(
c("--make_book_txt"),
action = "store_true",
help = "Should book.txt file be made freshly?",
)
)

Expand Down Expand Up @@ -72,65 +89,33 @@ retrieve_chapters <- ottrpal::get_chapters(base_url)
## Get chapter list and urls
chapter_df <- data.frame(
retrieve_chapters,
full_urls = paste0(base_url, retrieve_chapters$url)
full_urls = paste0(base_url, retrieve_chapters$url),
md_name = paste0(gsub(" ", "-", retrieve_chapters$chapt_title), ".md")
)

##### Get Quizzes
quiz_dir <- file.path(root_dir, "quizzes")
quiz_files <- list.files(file.path(root_dir, "quizzes"), pattern = ".md")

## Autogenerate Book.txt file
ottrpal::bookdown_to_book_txt(quiz_dir)
if (opt$make_book_txt) {
# Make book.txt fresh
ottrpal::bookdown_to_book_txt(md_files = list.files(file.path(root_dir, "manuscript"), pattern = ".md"))
}

## Read in Book.txt
book_txt <- readLines(file.path(root_dir, "manuscript", "Book.txt"))

## Make a data frame from this
book_txt_df <- data.frame(file_names = book_txt) %>%
book_txt_df <- data.frame(md_name = book_txt) %>%
dplyr::mutate(type = dplyr::case_when(
grepl("quiz", file_names) ~ "quiz",
grepl("quiz", md_name) ~ "quiz",
TRUE ~ "chapter"))

# Join it to the chapter df
book_txt_df <- book_txt_df %>%
dplyr::inner_join(book_txt_df,
by = "chapt_title")

# We need to make this column so we can link swirl modules to their chapters
chapter_df <- chapter_df %>%
dplyr::mutate(core_file_name = gsub("_quiz.md$", "", chapter_df $quiz_file))

#### Link swirl modules to chapters
swirl_modules <- googlesheets4::read_sheet(
"https://docs.google.com/spreadsheets/d/1b60iMYr6gtJ0X0ifcXlR4u3TSe1JaUW3uIUN9SOl14E/edit#gid=0",
sheet = "Swirl_Key") %>%
dplyr::filter(!is.na(module_name)) %>%
dplyr::select(-rowname)

chapter_df <- chapter_df %>%
dplyr::left_join(swirl_modules,
by = c("core_file_name" = "associated_chapter"))

### Signify which chapters are projects
chapter_df <- chapter_df %>%
dplyr::mutate(type = dplyr::case_when(
grepl("Project$", chapter_df$chapt_title) ~ "Project",
grepl(paste0(topics, collapse = "$|"), chapter_df$chapt_title) ~ "New topic",
TRUE ~ "Chapter"))

chapter_df <- chapter_df %>%
### Establish unit times
dplyr::mutate(unit_time = dplyr::case_when(type == "Chapter" ~ 1,
type == "Project" ~ 5,
TRUE ~ 0)) %>%
dplyr::mutate(swirl_yn = !is.na(module_name),
quiz_yn = !is.na(quiz_file),
unit_time = unit_time + swirl_yn + quiz_yn)

googlesheets4::write_sheet(
chapter_df,
"https://docs.google.com/spreadsheets/d/14PRS2qEed3E636QsorJFkgN94ikj3SeF1AgpoC-0bo0/edit#gid=0",
sheet = "chapter_df"
)
dplyr::left_join(chapter_df,
by = "md_name")

## Write this file.
### You may want to add due dates to this file manually.
readr::write_tsv(book_txt_df, file.path("resources", "course_units.tsv"))

# Write this to a TSV
readr::write_tsv(chapter_df, file.path(root_dir, "materials_order.tsv"))
File renamed without changes.

0 comments on commit 86b6b17

Please sign in to comment.