Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjanik/c13559c5f6d9a1381e0cb275ae8eb8f4 to your computer and use it in GitHub Desktop.
Save pjanik/c13559c5f6d9a1381e0cb275ae8eb8f4 to your computer and use it in GitHub Desktop.
BASE_URL = "https://authoring.concord.org"
# disable SQL logger
old_logger = ActiveRecord::Base.logger
ActiveRecord::Base.logger = nil
def parse_json(text)
begin
return !text || text.length == 0 ? {} : JSON.parse(text)
rescue
return {}
end
end
def missing_distractor_text(author_data)
!author_data["questionWrapper"] ||
!author_data["questionWrapper"]["distractorsExplanation"] ||
author_data["questionWrapper"]["distractorsExplanation"].length == 0
end
def missing_distractor_or_correct_text(author_data)
missing_distractor_text(author_data) ||
!author_data["questionWrapper"] ||
!author_data["questionWrapper"]["correctExplanation"] ||
author_data["questionWrapper"]["correctExplanation"].length == 0
end
def mc_question_has_correct_answer(embeddable)
embeddable.choices.any? { |c| c.is_correct == true }
end
def mc_interactive_has_correct_answer(authored_state)
authored_state["questionType"] === "multiple_choice" && authored_state["choices"].any? { |c| c["correct"] == true }
end
def index_in_activity(embeddable)
idx = embeddable.activity.reportable_items.index(embeddable)
!idx ? "error" : idx + 1
end
def result_row(type, embeddable, prompt)
id = type == "built-in question" ? embeddable.id : embeddable.interactive_item_id
"#{type}|#{embeddable.activity.name}|#{id}|Question ##{index_in_activity(embeddable)}|#{embeddable.name}|#{prompt && prompt.first(30)}|#{BASE_URL}/activities/#{embeddable.activity.id}/pages/#{embeddable.page.id}/edit"
end
def run
processed = 0
count = 0
missing_distractor = []
missing_distractor_or_correct = []
te_approved_script_id = ApprovedScript.where("name like 'Teacher Edition%'").first.id
Plugin.where(approved_script_id: te_approved_script_id).find_each do |plugin|
processed += 1
if (processed % 100 == 0)
print "."
end
author_data = parse_json(plugin.author_data)
if missing_distractor_or_correct_text(author_data)
embeddable = plugin.plugin_scope && plugin.plugin_scope.embeddable
if embeddable && embeddable.page && embeddable.activity
if embeddable.class == Embeddable::MultipleChoice && missing_distractor_text(author_data) && mc_question_has_correct_answer(embeddable)
count += 1
missing_distractor.push result_row("built-in question", embeddable, embeddable.prompt)
end
if embeddable.class == ManagedInteractive
int_authored_state = parse_json(embeddable.authored_state)
if mc_interactive_has_correct_answer(int_authored_state)
count += 1
missing_distractor_or_correct.push result_row("interactive", embeddable, int_authored_state["prompt"])
end
end
end
end
end
puts
puts "#{missing_distractor.length} built-in LARA questions are missing distractor explanation in TE wrapper settings."
puts "#{missing_distractor_or_correct.length} MC interactives are missing correct or distractor explanation in TE wrapper settings."
puts
puts "type|activity name|question ID|question index|question name|question prompt|page edit URL"
puts missing_distractor
puts missing_distractor_or_correct
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment