Showing posts with label dev-notes. Show all posts
Showing posts with label dev-notes. Show all posts

Thursday, September 1, 2016

pwo/grs - cloudfront invalidation for S3 video; mysql REPLACE



cloudfront invalidation is sort of a pain in the ass.
easier to just use a new name.
even though that means doing a replace in mysql for the video content id

http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html#Invalidation_Requests

UPDATE grs_requirements
SET content_id = REPLACE(content_id, 'vtpp/', 'vtpp4/')
WHERE req_type = 'video'


Friday, July 1, 2016

ASA notes - attempts to use nested test_map_entries with quiz_definition


close but no cigar.
got to a point where the for with the nested TMEs was being submitted without error, but duplicate tme objects are being created.

https://github.com/plataformatec/simple_form/wiki/Nested-Models



/Users/smr/current_projects/pws2016/app/views/quiz_definitions/_form.html.erb
<%= simple_form_for(@quiz_definition) do |qd_fb| %>
  <%= qd_fb.error_notification %>

  <div class="form-inputs">
    <%= qd_fb.input :name %>
    <%= qd_fb.input :category, disabled: true %>
    <p>N.B. currently, this category string is not used to map a quiz defn to categories.
      <code>TODO: replace with category checkboxes</code>
    </p>
    <%= qd_fb.input :minutes_allowed %>
    <%= qd_fb.association :book %>
    <div class="row">
      <div class="col-md-6">
        <table class="table table-bordered table-condensed">
          <tr>
            <th>Chapter</th>
            <th>Available</th>
            <th>Num Questions</th>
          </tr>

          <%= field_set_tag 'Test Map Entry' do %>
            <% @quiz_definition.test_map_entries.each do |test_map_entry| %>
              <%= qd_fb.simple_fields_for "test_map_entries_attributes[]", test_map_entry do |tmf| %>
                <tr>
                  <td><%= test_map_entry.chapnum %></td>
                  <td><%= tmf.input :chapnum %><</td>
                  <td><%= tmf.input :numq %></td>
                </tr>
              <% end %>
            <% end %>
          <% end %>



        </table>
      </div>
    </div>
  </div>

  <div class="form-actions">
    <%= qd_fb.button :submit %>
  </div>
<% end %>



/Users/smr/current_projects/pws2016/app/controllers/quiz_definitions_controller.rb
  private
    # Never trust parameters from the scary internet, only allow the white list through.
    def quiz_definition_params
      params.require(:quiz_definition).permit(:name, :minutes_allowed,
        :test_map_entries_attributes => [:numq, :chapnum]
        )
    end


first attempt (this way doesn't work with strong parameters)
<%= qd_fb.simple_fields_for :test_map_entries do |tme_fb| %>
  <tr>
    <td><%= tme_fb.object.chapnum %></td>
    <td>&nbsp;</td>
    <td><%= tme_fb.input :numq %></td>
  </tr>
  <%#= tme_fb.input :chapnum %>
<% end %>


original form object:
<%= simple_form_for(@quiz_definition) do |f| %>
  <%= f.error_notification %>

  <div class="form-inputs">
    <%= f.input :name %>
    <%= f.input :category %>
    <%= f.input :minutes_allowed %>
    <%= f.association :book %>
  </div>

  <div class="form-actions">
    <%= f.button :submit %>
  </div>
<% end %>








Monday, May 30, 2016

export qti notes


##################################################
# core question unit is an item
##################################################
questions are (can be) html
wrapped in CDATA
presentation block: question and answer stems
resprocessing block:
  scoring and answer-specific feedback
  referes to the response_lid ident
  one respcondition block for each answer choice

some of the questions cause the yaml output for the entire file to get borked (e.g. asanum 8393.2):
            <mattext texttype="text/html"><![CDATA[See the Update PDF for the figure associated with this question. You must follow the Order of Operations rule:
1.(v31) + (v43) ÷ 172



<item title="The working voltage" ident="QUE_1004">
<presentation>
  <material>
  <mattext texttype="text/html"><![CDATA[The working voltage of a capacitor in an ac circuit should be]]></mattext>
  </material>
  <response_lid ident="QUE_1005_RL" rcardinality="Single" rtiming="No">
    <render_choice>
    <response_label ident="QUE_1006_A1">
    <material>
    <mattext texttype="text/html"><![CDATA[equal to the highest applied voltage.]]></mattext>
    </material>
    </response_label>

    <response_label ident="QUE_1007_A2">
    <material>
    <mattext texttype="text/html"><![CDATA[at least 20 percent greater than the highest applied voltage.]]></mattext>
    </material>
    </response_label>

    <response_label ident="QUE_1008_A3">
    <material>
    <mattext texttype="text/html"><![CDATA[at least 50 percent greater than the highest applied voltage.]]></mattext>
    </material>
    </response_label>

    </render_choice>
  </response_lid>
</presentation>

<resprocessing>
  <outcomes>
    <decvar vartype="Integer" defaultval="0" varname="que_score"/>
  </outcomes>
  <respcondition>
    <conditionvar>
      <varequal respident="QUE_1005_RL">QUE_1006_A1</varequal>
    </conditionvar>
    <setvar varname="que_score" action="Add">0</setvar>
    <displayfeedback feedbacktype="Response" linkrefid="QUE_1003_ALL"/>
  </respcondition>
  <respcondition>
    <conditionvar>
      <varequal respident="QUE_1005_RL">QUE_1007_A2</varequal>
    </conditionvar>
    <setvar varname="que_score" action="Add">0</setvar>
    <displayfeedback feedbacktype="Response" linkrefid="QUE_1003_ALL"/>
  </respcondition>
  <respcondition>
  <conditionvar>
    <varequal respident="QUE_1005_RL">QUE_1008_A3</varequal>
  </conditionvar>
  <setvar varname="que_score" action="Set">1</setvar>
  <displayfeedback feedbacktype="Response" linkrefid="QUE_1003_ALL"/>
  </respcondition>
  <respcondition>
  <conditionvar>
    <other/>
  </conditionvar>
  <displayfeedback feedbacktype="Response" linkrefid="QUE_1003_ALL"/>
  </respcondition>
</resprocessing>

<itemfeedback ident="QUE_1003_ALL" view="All">
  <material>
  <mattext texttype="text/html"><![CDATA[The working voltage of a capacitor is the highest voltage that can be steadily applied to it without the danger of the dielectric breaking down. The working voltage depends upon the material used as the dielectric and on its thickness. A capacitor used in an AC circuit should have a working voltage at least 50 percent greater than the highest voltage that will be applied to it.]]></mattext>
  </material>
</itemfeedback>
</item>


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

  def qti_export
    # quiz_id=40
    # @quiz = InstructorQuiz.find(quiz_id)
    # @qids = JSON.parse(@quiz.qids)
    # @qids_json = JSON.parse(@quiz.qids)

    @qids = (1..100)  #for testing

    # @qids = @qids[450, 1]  #slice for testing
    # @qids = @qids[0, 100]  #slice for testing

    qdbm = QuestionDatabaseMiner.new
    @questions = qdbm.questions_for_qids(@qids)

    incremental_id = 1000
    respident = ""
    ans1_ident = ""
    ans2_ident = ""
    ans3_ident = ""

    builder = Nokogiri::XML::Builder.new do |xml|
      xml.questestinterop {  # root node can be named whatever
        xml.assessment(title:"QUIZ NAME HERE", ident:"A#{incremental_id+=1}") {
          xml.section(title:"Main", ident:"S#{incremental_id+=1}") {
            (@questions).each_index { |i|
              q_obj = @questions[i]
              qnum = i + 1
              fdbk_link_id = "QUE_#{incremental_id+=1}_ALL"
              # xml.debug_data(index:i, asaqnum:q_obj.asaqnum)
              xml.item(title:"Question #{qnum}", ident:"QUE_#{incremental_id+=1}") {
                # presentation block
                xml.presentation() {
                  xml.material {
                    xml.mattext q_obj.question
                  }
                  respident = "QUE_#{incremental_id+=1}_RL"
                  xml.response_lid(ident:respident, rcardinality:"Single", rtiming:"No") {
                    xml.render_choice {
                      ans1_ident = "QUE_#{incremental_id+=1}_A1"
                      xml.response_label(ident:ans1_ident) {
                        xml.material {
                          xml.mattext(texttype:"text/html") { xml.cdata(q_obj.answerA.replace_prepware_placeholders_utf8!) }
                        }
                      }
                      ans2_ident = "QUE_#{incremental_id+=1}_A2"
                      xml.response_label(ident:ans2_ident) {
                        xml.material {
                          xml.mattext(texttype:"text/html") { xml.cdata(q_obj.answerB.replace_prepware_placeholders_utf8!) }
                        }
                      }
                      ans3_ident = "QUE_#{incremental_id+=1}_A3"
                      xml.response_label(ident:ans3_ident) {
                        xml.material {
                          xml.mattext(texttype:"text/html") { xml.cdata(q_obj.answerC.replace_prepware_placeholders_utf8!) }
                        }
                      }
                    }
                  }
                }
                # resprocessing block
                xml.resprocessing {
                  xml.outcomes {
                    xml.decvar(vartype:"Integer", defaultval:"0", varname:"que_score")
                  }
                  # answer A
                  xml.respcondition {
                    xml.conditionvar {
                      xml.varequal(respident:respident) { xml.text(ans1_ident) }
                    }
                    xml.setvar(varname:"que_score", action:"Set") { 
                      isCorrect = (q_obj.correctChoice == "A") ? 1 : 0
                      xml.text(isCorrect) 
                    }
                    xml.displayfeedback(feedbacktype:"Response", linkrefid:fdbk_link_id)
                  }
                  # answer B
                  xml.respcondition {
                    xml.conditionvar {
                      xml.varequal(respident:respident) { xml.text(ans2_ident) }
                    }
                    xml.setvar(varname:"que_score", action:"Set") { 
                      isCorrect = (q_obj.correctChoice == "B") ? 1 : 0
                      xml.text(isCorrect) 
                    }
                    xml.displayfeedback(feedbacktype:"Response", linkrefid:fdbk_link_id)
                  }
                  # answer C
                  xml.respcondition {
                    xml.conditionvar {
                      xml.varequal(respident:respident) { xml.text(ans3_ident) }
                    }
                    xml.setvar(varname:"que_score", action:"Set") { 
                      isCorrect = (q_obj.correctChoice == "C") ? 1 : 0
                      xml.text(isCorrect) 
                    }
                    xml.displayfeedback(feedbacktype:"Response", linkrefid:fdbk_link_id)
                  }
                }
                # itemfeedback block
                xml.itemfeedback(ident:fdbk_link_id, view:"All") {
                  xml.material {
                    xml.mattext(texttype:"text/html") { 
                      xml.cdata(q_obj.explanationCommonToAllAnswerStems.replace_prepware_placeholders_utf8!) 
                    }
                  }
                }
              }
            }
          }
        }
      }
    end
    @xml = builder.to_xml
    aFile = File.new("/tmp/qti_test.xml", "w")
    aFile.write(@xml)
    aFile.close
  end