Add question pools.

This commit is contained in:
Matt
2021-01-17 23:01:10 -06:00
parent 9d571e0de0
commit f6ac65f193
2 changed files with 30 additions and 15 deletions

View File

@ -9,3 +9,5 @@ Written in R because I'm much quicker at that than Python, and it seemed like a
Pull requests always welcome! Pull requests always welcome!
If you want to run this yourself (for dev or fun), you can download the question pools from
https://github.com/russolsen/ham_radio_question_pool and place in `/lib`.

View File

@ -86,35 +86,48 @@ mastodon_token <- login(auth$mastodon$server, auth$mastodon$email, auth$mastodon
# Test vector of toots # Test vector of toots
# This is where a df of questions, answer options, and any figures will go # This is where a df of questions, answer options, and any figures will go
db <- data.frame(license = letters, # db <- data.frame(license = letters,
question = LETTERS, # question = LETTERS,
ans1 = rev(letters), # ans1 = rev(letters),
ans2 = letters, # ans2 = letters,
ans3 = rev(letters), # ans3 = rev(letters),
ans4 = rev(LETTERS), # ans4 = rev(LETTERS),
ans_correct = letters, # ans_correct = letters,
fig_path = rev(LETTERS)) # fig_path = rev(LETTERS))
# TODO pull all questions from https://github.com/russolsen/ham_radio_question_pool
# Arrange data frame accordingly.
# Read in the awesome question sets from https://github.com/russolsen/ham_radio_question_pool
db_tech <- read.csv("lib/ham_radio_question_pool-master/technician-2018-2022/technician.csv", stringsAsFactors = F)
db_general <- read.csv("lib/ham_radio_question_pool-master/general-2019-2023/general.csv", stringsAsFactors = F)
db_extra <- read.csv("lib/ham_radio_question_pool-master/extra-2020-2024/extra.csv", stringsAsFactors = F)
# add name of exam
db_tech[['exam']] <- "Technician"
db_general[['exam']] <- "General"
db_extra[['exam']] <- "Extra"
# Combine all
db <- rbind(db_tech,
db_general,
db_extra)
# TODO add figures
db[['fig_path']] <- NA
# Choose a random row to toot # Choose a random row to toot
toot_row <- db[sample(1:nrow(db), 1), ] toot_row <- db[sample(1:nrow(db), 1), ]
# Scramble answers # Scramble answers
ans_options <- rep(paste0("\n- ", ans_options <- rep(paste0("\n- ",
sample(as.character(toot_row[1,3:6])), sample(as.character(toot_row[,4:7])),
collapse = "")) collapse = ""))
# Build question # Build question
post_text <- paste0(toot_row[['license']], post_text <- paste0(toot_row[['exam']],
" ",
toot_row[['id']],
": ", ": ",
toot_row[['question']], toot_row[['question']],
ans_options) ans_options)
# Toot the thing! # Toot the thing!
post_status(mastodon_token, # post_status(mastodon_token,
post_text) # post_text)
# Check for image # Check for image
if(!is.na(toot_row[['fig_path']])){ if(!is.na(toot_row[['fig_path']])){