Showing posts with label GRS. Show all posts
Showing posts with label GRS. Show all posts

Wednesday, November 30, 2016

grs mobile quiz - qids per chapter

as part of moving to a qids-for-quiz approach (as opposed to embedding falcon, prepware quiz info, etc) with the grs mobile apps:

/Users/smr/current_projects/pws2016/app/controllers/sandbox_controller.rb

  # qids per chapter
  def qidsperc
    quiz_definition = QuizDefinition.find_by_name("Private Pilot, Airplane")
    qids_per_chapter = quiz_definition.qids_per_chapter()
    # qids_per_chapter = JSON.pretty_generate(qids_per_chapter)
    render json: qids_per_chapter
  end


/Users/smr/current_projects/pws2016/app/models/quiz_definition.rb

  def qids_per_chapter
    chapters = self.book.chapters
    dict = {}
    qapc = {}
    chapters.each { |chapter| 
      chapnum = chapter.chapnum
      qids = question_ids_for_chapnum(chapnum)  # N.B. these are shuffled
      dict[chapnum] = qids
      qapc[chapnum] = qids.count
    }
    dict[:qapc] = qapc
    return dict
  end

this script generates the json:
http://localhost:3000/sandbox/qidsperc

which you can then save in a file, e.g. qids_per_chapter.json
and embed into the app bundle.



  1. based on Private Pilot, Airplane
  2. this is based on a quiz definition so categories are taken into account
  3. a qapc data structure is baked in